Debian Codegraph @

ansible_collections/check_point/mgmt/plugins/modules/cp_mgmt_threat_rule.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_threat_rule
33 short_description: Manages threat-rule objects on Check Point over Web Services API
34 description:
35 - Manages threat-rule 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: "1.0.0"
39 author: "Or Soffer (@chkp-orso)"
40 options:
41 position:
42 description:
43 - Position in the rulebase. The use of values "top" and "bottom" may not be idempotent.
44 type: str
45 layer:
46 description:
47 - Layer that the rule belongs to identified by the name or UID.
48 type: str
49 name:
50 description:
51 - Object name.
52 type: str
53 required: True
54 action:
55 description:
56 - Action-the enforced profile.
57 type: str
58 destination:
59 description:
60 - Collection of Network objects identified by the name or UID.
61 type: list
62 elements: str
63 destination_negate:
64 description:
65 - True if negate is set for destination.
66 type: bool
67 enabled:
68 description:
69 - Enable/Disable the rule.
70 type: bool
71 install_on:
72 description:
73 - Which Gateways identified by the name or UID to install the policy on.
74 type: list
75 elements: str
76 protected_scope:
77 description:
78 - Collection of objects defining Protected Scope identified by the name or UID.
79 type: list
80 elements: str
81 protected_scope_negate:
82 description:
83 - True if negate is set for Protected Scope.
84 type: bool
85 service:
86 description:
87 - Collection of Network objects identified by the name or UID.
88 type: list
89 elements: str
90 service_negate:
91 description:
92 - True if negate is set for Service.
93 type: bool
94 source:
95 description:
96 - Collection of Network objects identified by the name or UID.
97 type: list
98 elements: str
99 source_negate:
100 description:
101 - True if negate is set for source.
102 type: bool
103 track:
104 description:
105 - Packet tracking.
106 type: str
107 track_settings:
108 description:
109 - Threat rule track settings.
110 type: dict
111 suboptions:
112 packet_capture:
113 description:
114 - Packet capture.
115 type: bool
116 comments:
117 description:
118 - Comments string.
119 type: str
120 details_level:
121 description:
122 - 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
123 representation of the object.
124 type: str
125 choices: ['uid', 'standard', 'full']
126 ignore_warnings:
127 description:
128 - Apply changes ignoring warnings.
129 type: bool
130 ignore_errors:
131 description:
132 - 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.
133 type: bool
134 extends_documentation_fragment: check_point.mgmt.checkpoint_objects
135 """
136
137 EXAMPLES = """
138 - name: add-threat-rule
139 cp_mgmt_threat_rule:
140 comments: ''
141 install_on: Policy Targets
142 layer: New Layer 1
143 name: First threat rule
144 position: 1
145 protected_scope: All_Internet
146 state: present
147 track: None
148
149 - name: set-threat-rule
150 cp_mgmt_threat_rule:
151 action: New Profile 1
152 comments: commnet for the first rule
153 install_on: Policy Targets
154 layer: New Layer 1
155 name: Rule Name
156 position: 1
157 protected_scope: All_Internet
158 state: present
159
160 - name: delete-threat-rule
161 cp_mgmt_threat_rule:
162 layer: New Layer 1
163 name: Rule Name
164 state: absent
165 """
166
167 RETURN = """
168 cp_mgmt_threat_rule:
169 description: The checkpoint object created or updated.
170 returned: always, except when deleting the object.
171 type: dict
172 """
173
174 from ansible.module_utils.basic import AnsibleModule
175 from ansible_collections.check_point.mgmt.plugins.module_utils.checkpoint import (
176 checkpoint_argument_spec_for_objects,
177 api_call,
178 api_call_for_rule,
179 )
180
181
182 def main():
183 argument_spec = dict(
184 position=dict(type="str"),
185 layer=dict(type="str"),
186 name=dict(type="str", required=True),
187 action=dict(type="str"),
188 destination=dict(type="list", elements="str"),
189 destination_negate=dict(type="bool"),
190 enabled=dict(type="bool"),
191 install_on=dict(type="list", elements="str"),
192 protected_scope=dict(type="list", elements="str"),
193 protected_scope_negate=dict(type="bool"),
194 service=dict(type="list", elements="str"),
195 service_negate=dict(type="bool"),
196 source=dict(type="list", elements="str"),
197 source_negate=dict(type="bool"),
198 track=dict(type="str"),
199 track_settings=dict(
200 type="dict", options=dict(packet_capture=dict(type="bool"))
201 ),
202 comments=dict(type="str"),
203 details_level=dict(type="str", choices=["uid", "standard", "full"]),
204 ignore_warnings=dict(type="bool"),
205 ignore_errors=dict(type="bool"),
206 )
207 argument_spec.update(checkpoint_argument_spec_for_objects)
208
209 module = AnsibleModule(
210 argument_spec=argument_spec, supports_check_mode=True
211 )
212 api_call_object = "threat-rule"
213
214 if module.params["position"] is None:
215 result = api_call(module, api_call_object)
216 else:
217 result = api_call_for_rule(module, api_call_object)
218
219 module.exit_json(**result)
220
221
222 if __name__ == "__main__":
223 main()