Debian Codegraph @

ansible_collections/community/general/plugins/modules/utm_proxy_location.py

raw
1 #!/usr/bin/python
2
3 # Copyright (c) 2018, Johannes Brunswicker <[email protected]>
4 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
5 # SPDX-License-Identifier: GPL-3.0-or-later
6
7 from __future__ import annotations
8
9 DOCUMENTATION = r"""
10 module: utm_proxy_location
11
12 author:
13 - Johannes Brunswicker (@MatrixCrawler)
14
15 short_description: Create, update or destroy reverse_proxy location entry in Sophos UTM
16
17 description:
18 - Create, update or destroy a reverse_proxy location entry in SOPHOS UTM.
19 - This module needs to have the REST Ability of the UTM to be activated.
20 attributes:
21 check_mode:
22 support: none
23 diff_mode:
24 support: none
25
26 options:
27 name:
28 type: str
29 description:
30 - The name of the object that identifies the entry.
31 required: true
32 access_control:
33 description:
34 - Whether to activate the access control for the location.
35 type: str
36 default: '0'
37 choices:
38 - '0'
39 - '1'
40 allowed_networks:
41 description:
42 - A list of allowed networks.
43 type: list
44 elements: str
45 default:
46 - REF_NetworkAny
47 auth_profile:
48 type: str
49 description:
50 - The reference name of the auth profile.
51 default: ''
52 backend:
53 type: list
54 elements: str
55 description:
56 - A list of backends that are connected with this location declaration.
57 default: []
58 be_path:
59 type: str
60 description:
61 - The path of the backend.
62 default: ''
63 comment:
64 type: str
65 description:
66 - The optional comment string.
67 default: ''
68 denied_networks:
69 type: list
70 elements: str
71 description:
72 - A list of denied network references.
73 default: []
74 hot_standby:
75 description:
76 - Activate hot standby mode.
77 type: bool
78 default: false
79 path:
80 type: str
81 description:
82 - The path of the location.
83 default: "/"
84 status:
85 description:
86 - Whether the location is active or not.
87 type: bool
88 default: true
89 stickysession_id:
90 type: str
91 description:
92 - The stickysession ID.
93 default: ROUTEID
94 stickysession_status:
95 description:
96 - Enable the stickysession.
97 type: bool
98 default: false
99 websocket_passthrough:
100 description:
101 - Enable the websocket passthrough.
102 type: bool
103 default: false
104
105 extends_documentation_fragment:
106 - community.general._utm
107 - community.general._attributes
108 """
109
110 EXAMPLES = r"""
111 - name: Create UTM proxy_location
112 utm_proxy_backend:
113 utm_host: sophos.host.name
114 utm_token: abcdefghijklmno1234
115 name: TestLocationEntry
116 backend: REF_OBJECT_STRING
117 state: present
118
119 - name: Remove UTM proxy_location
120 utm_proxy_backend:
121 utm_host: sophos.host.name
122 utm_token: abcdefghijklmno1234
123 name: TestLocationEntry
124 state: absent
125 """
126
127 RETURN = r"""
128 result:
129 description: The utm object that was created.
130 returned: success
131 type: complex
132 contains:
133 _ref:
134 description: The reference name of the object.
135 type: str
136 _locked:
137 description: Whether or not the object is currently locked.
138 type: bool
139 _type:
140 description: The type of the object.
141 type: str
142 name:
143 description: The name of the object.
144 type: str
145 access_control:
146 description: Whether to use access control state.
147 type: str
148 allowed_networks:
149 description: List of allowed network reference names.
150 type: list
151 auth_profile:
152 description: The auth profile reference name.
153 type: str
154 backend:
155 description: The backend reference name.
156 type: str
157 be_path:
158 description: The backend path.
159 type: str
160 comment:
161 description: The comment string.
162 type: str
163 denied_networks:
164 description: The list of the denied network names.
165 type: list
166 hot_standby:
167 description: Use hot standby.
168 type: bool
169 path:
170 description: Path name.
171 type: str
172 status:
173 description: Whether the object is active or not.
174 type: bool
175 stickysession_id:
176 description: The identifier of the stickysession.
177 type: str
178 stickysession_status:
179 description: Whether to use stickysession or not.
180 type: bool
181 websocket_passthrough:
182 description: Whether websocket passthrough is used or not.
183 type: bool
184 """
185
186 from ansible_collections.community.general.plugins.module_utils._utm_utils import UTM, UTMModule
187
188
189 def main():
190 endpoint = "reverse_proxy/location"
191 key_to_check_for_changes = [
192 "access_control",
193 "allowed_networks",
194 "auth_profile",
195 "backend",
196 "be_path",
197 "comment",
198 "denied_networks",
199 "hot_standby",
200 "path",
201 "status",
202 "stickysession_id",
203 "stickysession_status",
204 "websocket_passthrough",
205 ]
206 module = UTMModule(
207 argument_spec=dict(
208 name=dict(type="str", required=True),
209 access_control=dict(type="str", default="0", choices=["0", "1"]),
210 allowed_networks=dict(type="list", elements="str", default=["REF_NetworkAny"]),
211 auth_profile=dict(type="str", default=""),
212 backend=dict(type="list", elements="str", default=[]),
213 be_path=dict(type="str", default=""),
214 comment=dict(type="str", default=""),
215 denied_networks=dict(type="list", elements="str", default=[]),
216 hot_standby=dict(type="bool", default=False),
217 path=dict(type="str", default="/"),
218 status=dict(type="bool", default=True),
219 stickysession_id=dict(type="str", default="ROUTEID"),
220 stickysession_status=dict(type="bool", default=False),
221 websocket_passthrough=dict(type="bool", default=False),
222 )
223 )
224 try:
225 UTM(module, endpoint, key_to_check_for_changes).execute()
226 except Exception as e:
227 module.fail_json(msg=f"{e}")
228
229
230 if __name__ == "__main__":
231 main()