Debian Codegraph @

ansible_collections/community/general/plugins/modules/utm_proxy_frontend.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_frontend
11
12 author:
13 - Johannes Brunswicker (@MatrixCrawler)
14
15 short_description: Create, update or destroy reverse_proxy frontend entry in Sophos UTM
16
17 description:
18 - Create, update or destroy a reverse_proxy frontend 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 add_content_type_header:
33 description:
34 - Whether to add the content type header or not.
35 type: bool
36 default: false
37 address:
38 type: str
39 description:
40 - The reference name of the network/interface_address object.
41 default: REF_DefaultInternalAddress
42 allowed_networks:
43 type: list
44 elements: str
45 description:
46 - A list of reference names for the allowed networks.
47 default: ['REF_NetworkAny']
48 certificate:
49 type: str
50 description:
51 - The reference name of the ca/host_key_cert object.
52 default: ""
53 comment:
54 type: str
55 description:
56 - An optional comment to add to the object.
57 default: ""
58 disable_compression:
59 description:
60 - Whether to enable the compression.
61 type: bool
62 default: false
63 domain:
64 type: list
65 elements: str
66 description:
67 - A list of domain names for the frontend object.
68 exceptions:
69 type: list
70 elements: str
71 description:
72 - A list of exception ref names (reverse_proxy/exception).
73 default: []
74 htmlrewrite:
75 description:
76 - Whether to enable HTML rewrite or not.
77 type: bool
78 default: false
79 htmlrewrite_cookies:
80 description:
81 - Whether to enable HTML rewrite cookie or not.
82 type: bool
83 default: false
84 implicitredirect:
85 description:
86 - Whether to enable implicit redirection or not.
87 type: bool
88 default: false
89 lbmethod:
90 type: str
91 description:
92 - Which loadbalancer method should be used.
93 choices:
94 - ""
95 - bybusyness
96 - bytraffic
97 - byrequests
98 default: bybusyness
99 locations:
100 type: list
101 elements: str
102 description:
103 - A list of location ref names (reverse_proxy/location).
104 default: []
105 port:
106 type: int
107 description:
108 - The frontend http port.
109 default: 80
110 preservehost:
111 description:
112 - Whether to preserve host header.
113 type: bool
114 default: false
115 profile:
116 type: str
117 description:
118 - The reference string of the reverse_proxy/profile.
119 default: ""
120 status:
121 description:
122 - Whether to activate the frontend entry or not.
123 type: bool
124 default: true
125 type:
126 type: str
127 description:
128 - Which protocol should be used.
129 choices:
130 - http
131 - https
132 default: http
133 xheaders:
134 description:
135 - Whether to pass the host header or not.
136 type: bool
137 default: false
138
139 extends_documentation_fragment:
140 - community.general._utm
141 - community.general._attributes
142 """
143
144 EXAMPLES = r"""
145 - name: Create utm proxy_frontend
146 community.general.utm_proxy_frontend:
147 utm_host: sophos.host.name
148 utm_token: abcdefghijklmno1234
149 name: TestFrontendEntry
150 host: REF_OBJECT_STRING
151 state: present
152
153 - name: Remove utm proxy_frontend
154 community.general.utm_proxy_frontend:
155 utm_host: sophos.host.name
156 utm_token: abcdefghijklmno1234
157 name: TestFrontendEntry
158 state: absent
159 """
160
161 RETURN = r"""
162 result:
163 description: The utm object that was created.
164 returned: success
165 type: complex
166 contains:
167 _ref:
168 description: The reference name of the object.
169 type: str
170 _locked:
171 description: Whether or not the object is currently locked.
172 type: bool
173 _type:
174 description: The type of the object.
175 type: str
176 name:
177 description: The name of the object.
178 type: str
179 add_content_type_header:
180 description: Whether to add the content type header.
181 type: bool
182 address:
183 description: The reference name of the address.
184 type: str
185 allowed_networks:
186 description: List of reference names of networks associated.
187 type: list
188 certificate:
189 description: Reference name of certificate (ca/host_key_cert).
190 type: str
191 comment:
192 description: The comment string.
193 type: str
194 disable_compression:
195 description: State of compression support.
196 type: bool
197 domain:
198 description: List of hostnames.
199 type: list
200 exceptions:
201 description: List of associated proxy exceptions.
202 type: list
203 htmlrewrite:
204 description: State of HTML rewrite.
205 type: bool
206 htmlrewrite_cookies:
207 description: Whether the HTML rewrite cookie is set.
208 type: bool
209 implicitredirect:
210 description: Whether to use implicit redirection.
211 type: bool
212 lbmethod:
213 description: The method of loadbalancer to use.
214 type: str
215 locations:
216 description: The reference names of reverse_proxy/locations associated with the object.
217 type: list
218 port:
219 description: The port of the frontend connection.
220 type: int
221 preservehost:
222 description: Preserve host header.
223 type: bool
224 profile:
225 description: The associated reverse_proxy/profile.
226 type: str
227 status:
228 description: Whether the frontend object is active or not.
229 type: bool
230 type:
231 description: The connection type.
232 type: str
233 xheaders:
234 description: The xheaders state.
235 type: bool
236 """
237
238 from ansible_collections.community.general.plugins.module_utils._utm_utils import UTM, UTMModule
239
240
241 def main():
242 endpoint = "reverse_proxy/frontend"
243 key_to_check_for_changes = [
244 "add_content_type_header",
245 "address",
246 "allowed_networks",
247 "certificate",
248 "comment",
249 "disable_compression",
250 "domain",
251 "exceptions",
252 "htmlrewrite",
253 "htmlrewrite_cookies",
254 "implicitredirect",
255 "lbmethod",
256 "locations",
257 "port",
258 "preservehost",
259 "profile",
260 "status",
261 "type",
262 "xheaders",
263 ]
264 module = UTMModule(
265 argument_spec=dict(
266 name=dict(type="str", required=True),
267 add_content_type_header=dict(type="bool", default=False),
268 address=dict(type="str", default="REF_DefaultInternalAddress"),
269 allowed_networks=dict(type="list", elements="str", default=["REF_NetworkAny"]),
270 certificate=dict(type="str", default=""),
271 comment=dict(type="str", default=""),
272 disable_compression=dict(type="bool", default=False),
273 domain=dict(type="list", elements="str"),
274 exceptions=dict(type="list", elements="str", default=[]),
275 htmlrewrite=dict(type="bool", default=False),
276 htmlrewrite_cookies=dict(type="bool", default=False),
277 implicitredirect=dict(type="bool", default=False),
278 lbmethod=dict(type="str", default="bybusyness", choices=["bybusyness", "bytraffic", "byrequests", ""]),
279 locations=dict(type="list", elements="str", default=[]),
280 port=dict(type="int", default=80),
281 preservehost=dict(type="bool", default=False),
282 profile=dict(type="str", default=""),
283 status=dict(type="bool", default=True),
284 type=dict(type="str", default="http", choices=["http", "https"]),
285 xheaders=dict(type="bool", default=False),
286 )
287 )
288 try:
289 UTM(module, endpoint, key_to_check_for_changes).execute()
290 except Exception as e:
291 module.fail_json(msg=f"{e}")
292
293
294 if __name__ == "__main__":
295 main()