Debian Codegraph @

ansible_collections/check_point/mgmt/plugins/modules/cp_mgmt_access_rules.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 #
4 # Ansible module to manage Check Point Firewall (c) 2019
5 #
6 # Ansible is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # Ansible is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
18 #
19
20 from __future__ import absolute_import, division, print_function
21
22 __metaclass__ = type
23
24 ANSIBLE_METADATA = {
25 "metadata_version": "1.1",
26 "status": ["preview"],
27 "supported_by": "community",
28 }
29
30 DOCUMENTATION = """
31 ---
32 module: cp_mgmt_access_rules
33 short_description: Manages access-rules objects on Check Point over Web Services API
34 description:
35 - Manages access-rules objects on Check Point devices including creating, updating and removing objects.
36 - All operations are performed over Web Services API.
37 - Available from R80 management version.
38 version_added: "2.2.0"
39 author: "Shiran Golzar (@chkp-shirango)"
40 options:
41 layer:
42 description:
43 - Layer that the rule belongs to identified by the name or UID.
44 type: str
45 required: true
46 rules:
47 description:
48 - List of rules.
49 type: list
50 elements: dict
51 required: true
52 suboptions:
53 name:
54 description:
55 - Object name.
56 type: str
57 required: True
58 action:
59 description:
60 - a "Accept", "Drop", "Ask", "Inform", "Reject", "User Auth", "Client Auth", "Apply Layer".
61 type: str
62 action_settings:
63 description:
64 - Action settings.
65 type: dict
66 suboptions:
67 enable_identity_captive_portal:
68 description:
69 - N/A
70 type: bool
71 limit:
72 description:
73 - N/A
74 type: str
75 content:
76 description:
77 - List of processed file types that this rule applies on.
78 type: list
79 elements: dict
80 content_direction:
81 description:
82 - On which direction the file types processing is applied.
83 type: str
84 choices: ['any', 'up', 'down']
85 content_negate:
86 description:
87 - True if negate is set for data.
88 type: bool
89 custom_fields:
90 description:
91 - Custom fields.
92 type: dict
93 suboptions:
94 field_1:
95 description:
96 - First custom field.
97 type: str
98 field_2:
99 description:
100 - Second custom field.
101 type: str
102 field_3:
103 description:
104 - Third custom field.
105 type: str
106 destination:
107 description:
108 - Collection of Network objects identified by the name or UID.
109 type: list
110 elements: str
111 destination_negate:
112 description:
113 - True if negate is set for destination.
114 type: bool
115 enabled:
116 description:
117 - Enable/Disable the rule.
118 type: bool
119 inline_layer:
120 description:
121 - Inline Layer identified by the name or UID. Relevant only if "Action" was set to "Apply Layer".
122 type: str
123 install_on:
124 description:
125 - Which Gateways identified by the name or UID to install the policy on.
126 type: list
127 elements: str
128 service:
129 description:
130 - Collection of Network objects identified by the name or UID.
131 type: list
132 elements: str
133 service_negate:
134 description:
135 - True if negate is set for service.
136 type: bool
137 source:
138 description:
139 - Collection of Network objects identified by the name or UID.
140 type: list
141 elements: str
142 source_negate:
143 description:
144 - True if negate is set for source.
145 type: bool
146 time:
147 description:
148 - List of time objects. For example, "Weekend", "Off-Work", "Every-Day".
149 type: list
150 elements: str
151 track:
152 description:
153 - Track Settings.
154 type: dict
155 suboptions:
156 accounting:
157 description:
158 - Turns accounting for track on and off.
159 type: bool
160 alert:
161 description:
162 - Type of alert for the track.
163 type: str
164 choices: ['none', 'alert', 'snmp', 'mail', 'user alert 1', 'user alert 2', 'user alert 3']
165 enable_firewall_session:
166 description:
167 - Determine whether to generate session log to firewall only connections.
168 type: bool
169 per_connection:
170 description:
171 - Determines whether to perform the log per connection.
172 type: bool
173 per_session:
174 description:
175 - Determines whether to perform the log per session.
176 type: bool
177 type:
178 description:
179 - a "Log", "Extended Log", "Detailed Log", "None".
180 type: str
181 user_check:
182 description:
183 - User check settings.
184 type: dict
185 suboptions:
186 confirm:
187 description:
188 - N/A
189 type: str
190 choices: ['per rule', 'per category', 'per application/site', 'per data type']
191 custom_frequency:
192 description:
193 - N/A
194 type: dict
195 suboptions:
196 every:
197 description:
198 - N/A
199 type: int
200 unit:
201 description:
202 - N/A
203 type: str
204 choices: ['hours', 'days', 'weeks', 'months']
205 frequency:
206 description:
207 - N/A
208 type: str
209 choices: ['once a day', 'once a week', 'once a month', 'custom frequency...']
210 interaction:
211 description:
212 - N/A
213 type: str
214 vpn_list:
215 description:
216 - Communities or Directional.
217 type: list
218 elements: dict
219 suboptions:
220 community:
221 description:
222 - List of community name or UID.
223 type: list
224 elements: str
225 directional:
226 description:
227 - Communities directional match condition.
228 type: list
229 elements: dict
230 suboptions:
231 from:
232 description:
233 - From community name or UID.
234 type: str
235 to:
236 description:
237 - To community name or UID.
238 type: str
239 vpn:
240 description:
241 - Any or All_GwToGw.
242 type: str
243 choices: ['Any', 'All_GwToGw']
244 comments:
245 description:
246 - Comments string.
247 type: str
248 details_level:
249 description:
250 - The level of detail for some of the fields in the response can vary from showing only the UID value of the object to a fully detailed
251 representation of the object.
252 type: str
253 choices: ['uid', 'standard', 'full']
254 ignore_warnings:
255 description:
256 - Apply changes ignoring warnings.
257 type: bool
258 ignore_errors:
259 description:
260 - Apply changes ignoring errors. You won't be able to publish such a changes. If ignore-warnings flag was omitted - warnings will also be ignored.
261 type: bool
262 state:
263 description:
264 - State of the access rule (present or absent). Defaults to present.
265 type: str
266 default: present
267 choices:
268 - 'present'
269 - 'absent'
270 details_level:
271 description:
272 - The level of detail for some of the fields in the response can vary from showing only the UID value of the object to a fully detailed
273 representation of the object.
274 type: str
275 choices: ['uid', 'standard', 'full']
276 extends_documentation_fragment: check_point.mgmt.checkpoint_objects_action_module
277 """
278
279 EXAMPLES = """
280 - name: add-access-rules
281 cp_mgmt_access_rules:
282 rules:
283 - name: Rule 1
284 service:
285 - SMTP
286 - AOL
287 state: present
288 - name: Rule 2
289 service:
290 - SMTP
291 state: present
292 layer: Network
293 auto_publish_session: true
294 """
295
296 RETURN = """
297 cp_mgmt_access_rules:
298 description: The checkpoint object created or updated.
299 returned: always, except when deleting the object.
300 type: dict
301 """
302
303 from ansible.module_utils.basic import AnsibleModule
304 from ansible_collections.check_point.mgmt.plugins.module_utils.checkpoint import (
305 checkpoint_argument_spec_for_action_module,
306 )
307
308
309 def main():
310 argument_spec = dict(
311 rules=dict(
312 type="list",
313 required=True,
314 elements="dict",
315 options=dict(
316 name=dict(type="str", required=True),
317 action=dict(type="str"),
318 action_settings=dict(
319 type="dict",
320 options=dict(
321 enable_identity_captive_portal=dict(type="bool"),
322 limit=dict(type="str"),
323 ),
324 ),
325 content=dict(type="list", elements="dict"),
326 content_direction=dict(
327 type="str", choices=["any", "up", "down"]
328 ),
329 content_negate=dict(type="bool"),
330 custom_fields=dict(
331 type="dict",
332 options=dict(
333 field_1=dict(type="str"),
334 field_2=dict(type="str"),
335 field_3=dict(type="str"),
336 ),
337 ),
338 destination=dict(type="list", elements="str"),
339 destination_negate=dict(type="bool"),
340 enabled=dict(type="bool"),
341 inline_layer=dict(type="str"),
342 install_on=dict(type="list", elements="str"),
343 service=dict(type="list", elements="str"),
344 service_negate=dict(type="bool"),
345 source=dict(type="list", elements="str"),
346 source_negate=dict(type="bool"),
347 time=dict(type="list", elements="str"),
348 track=dict(
349 type="dict",
350 options=dict(
351 accounting=dict(type="bool"),
352 alert=dict(
353 type="str",
354 choices=[
355 "none",
356 "alert",
357 "snmp",
358 "mail",
359 "user alert 1",
360 "user alert 2",
361 "user alert 3",
362 ],
363 ),
364 enable_firewall_session=dict(type="bool"),
365 per_connection=dict(type="bool"),
366 per_session=dict(type="bool"),
367 type=dict(type="str"),
368 ),
369 ),
370 user_check=dict(
371 type="dict",
372 options=dict(
373 confirm=dict(
374 type="str",
375 choices=[
376 "per rule",
377 "per category",
378 "per application/site",
379 "per data type",
380 ],
381 ),
382 custom_frequency=dict(
383 type="dict",
384 options=dict(
385 every=dict(type="int"),
386 unit=dict(
387 type="str",
388 choices=[
389 "hours",
390 "days",
391 "weeks",
392 "months",
393 ],
394 ),
395 ),
396 ),
397 frequency=dict(
398 type="str",
399 choices=[
400 "once a day",
401 "once a week",
402 "once a month",
403 "custom frequency...",
404 ],
405 ),
406 interaction=dict(type="str"),
407 ),
408 ),
409 vpn_list=dict(
410 type="list",
411 elements="dict",
412 options=dict(
413 community=dict(type="list", elements="str"),
414 directional=dict(
415 type="list",
416 elements="dict",
417 options=dict(to=dict(type="str")),
418 ),
419 ),
420 ),
421 vpn=dict(type="str", choices=["Any", "All_GwToGw"]),
422 comments=dict(type="str"),
423 details_level=dict(
424 type="str", choices=["uid", "standard", "full"]
425 ),
426 ignore_warnings=dict(type="bool"),
427 ignore_errors=dict(type="bool"),
428 state=dict(
429 type="str",
430 choices=["present", "absent"],
431 default="present",
432 ),
433 ),
434 ),
435 layer=dict(type="str", required=True),
436 details_level=dict(type="str", choices=["uid", "standard", "full"]),
437 )
438
439 argument_spec["rules"]["options"]["vpn_list"]["options"]["directional"][
440 "options"
441 ]["from"] = dict(type="str")
442 argument_spec.update(checkpoint_argument_spec_for_action_module)
443
444 module = AnsibleModule(argument_spec=argument_spec)
445
446 module.exit_json()
447
448
449 if __name__ == "__main__":
450 main()