Debian Codegraph @

ansible_collections/check_point/mgmt/plugins/modules/cp_mgmt_access_role.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_role
33 short_description: Manages access-role objects on Check Point over Web Services API
34 description:
35 - Manages access-role 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 name:
42 description:
43 - Object name.
44 type: str
45 required: True
46 machines_list:
47 description:
48 - Machines that can access the system.
49 type: list
50 elements: dict
51 suboptions:
52 source:
53 description:
54 - Active Directory name or UID or Identity Tag.
55 type: str
56 selection:
57 description:
58 - Name or UID of an object selected from source.
59 type: list
60 elements: str
61 base_dn:
62 description:
63 - When source is "Active Directory" use "base-dn" to refine the query in AD database.
64 type: str
65 machines:
66 description:
67 - Any or All Identified.
68 type: str
69 choices: ['any', 'all identified']
70 networks:
71 description:
72 - Collection of Network objects identified by the name or UID that can access the system.
73 type: list
74 elements: str
75 remote_access_clients:
76 description:
77 - Remote access clients identified by name or UID.
78 type: str
79 tags:
80 description:
81 - Collection of tag identifiers.
82 type: list
83 elements: str
84 users_list:
85 description:
86 - Users that can access the system.
87 type: list
88 elements: dict
89 suboptions:
90 source:
91 description:
92 - Active Directory name or UID or Identity Tag or Internal User Groups or LDAP groups or Guests.
93 type: str
94 selection:
95 description:
96 - Name or UID of an object selected from source.
97 type: list
98 elements: str
99 base_dn:
100 description:
101 - When source is "Active Directory" use "base-dn" to refine the query in AD database.
102 type: str
103 users:
104 description:
105 - Any or All Identified.
106 type: str
107 choices: ['any', 'all identified']
108 color:
109 description:
110 - Color of the object. Should be one of existing colors.
111 type: str
112 choices: ['aquamarine', 'black', 'blue', 'crete blue', 'burlywood', 'cyan', 'dark green', 'khaki', 'orchid', 'dark orange', 'dark sea green',
113 'pink', 'turquoise', 'dark blue', 'firebrick', 'brown', 'forest green', 'gold', 'dark gold', 'gray', 'dark gray', 'light green', 'lemon chiffon',
114 'coral', 'sea green', 'sky blue', 'magenta', 'purple', 'slate blue', 'violet red', 'navy blue', 'olive', 'orange', 'red', 'sienna', 'yellow']
115 comments:
116 description:
117 - Comments string.
118 type: str
119 details_level:
120 description:
121 - 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
122 representation of the object.
123 type: str
124 choices: ['uid', 'standard', 'full']
125 ignore_warnings:
126 description:
127 - Apply changes ignoring warnings.
128 type: bool
129 ignore_errors:
130 description:
131 - 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.
132 type: bool
133 extends_documentation_fragment: check_point.mgmt.checkpoint_objects
134 """
135
136 EXAMPLES = """
137 - name: add-access-role
138 cp_mgmt_access_role:
139 name: New Access Role 1
140 networks: any
141 remote_access_clients: any
142 state: present
143 users: any
144
145 - name: set-access-role
146 cp_mgmt_access_role:
147 users_list:
148 - source: "Internal User Groups"
149 selection: usersGroup
150 name: New Access Role 1
151 state: present
152
153 - name: delete-access-role
154 cp_mgmt_access_role:
155 name: New Access Role 1
156 state: absent
157 """
158
159 RETURN = """
160 cp_mgmt_access_role:
161 description: The checkpoint object created or updated.
162 returned: always, except when deleting the object.
163 type: dict
164 """
165
166 from ansible.module_utils.basic import AnsibleModule
167 from ansible_collections.check_point.mgmt.plugins.module_utils.checkpoint import (
168 checkpoint_argument_spec_for_objects,
169 api_call,
170 )
171
172
173 def main():
174 argument_spec = dict(
175 name=dict(type="str", required=True),
176 machines_list=dict(
177 type="list",
178 elements="dict",
179 options=dict(
180 source=dict(type="str"),
181 selection=dict(type="list", elements="str"),
182 base_dn=dict(type="str"),
183 ),
184 ),
185 machines=dict(type="str", choices=["any", "all identified"]),
186 networks=dict(type="list", elements="str"),
187 remote_access_clients=dict(type="str"),
188 tags=dict(type="list", elements="str"),
189 users_list=dict(
190 type="list",
191 elements="dict",
192 options=dict(
193 source=dict(type="str"),
194 selection=dict(type="list", elements="str"),
195 base_dn=dict(type="str"),
196 ),
197 ),
198 users=dict(type="str", choices=["any", "all identified"]),
199 color=dict(
200 type="str",
201 choices=[
202 "aquamarine",
203 "black",
204 "blue",
205 "crete blue",
206 "burlywood",
207 "cyan",
208 "dark green",
209 "khaki",
210 "orchid",
211 "dark orange",
212 "dark sea green",
213 "pink",
214 "turquoise",
215 "dark blue",
216 "firebrick",
217 "brown",
218 "forest green",
219 "gold",
220 "dark gold",
221 "gray",
222 "dark gray",
223 "light green",
224 "lemon chiffon",
225 "coral",
226 "sea green",
227 "sky blue",
228 "magenta",
229 "purple",
230 "slate blue",
231 "violet red",
232 "navy blue",
233 "olive",
234 "orange",
235 "red",
236 "sienna",
237 "yellow",
238 ],
239 ),
240 comments=dict(type="str"),
241 details_level=dict(type="str", choices=["uid", "standard", "full"]),
242 ignore_warnings=dict(type="bool"),
243 ignore_errors=dict(type="bool"),
244 )
245 argument_spec.update(checkpoint_argument_spec_for_objects)
246
247 module = AnsibleModule(
248 argument_spec=argument_spec, supports_check_mode=True
249 )
250 api_call_object = "access-role"
251
252 if module.params["machines_list"] is not None:
253 if module.params["machines"] is not None:
254 raise AssertionError(
255 "The use of both 'machines_list' and 'machines' arguments isn't allowed"
256 )
257 module.params["machines"] = module.params["machines_list"]
258 module.params.pop("machines_list")
259
260 if module.params["users_list"] is not None:
261 if module.params["users"] is not None:
262 raise AssertionError(
263 "The use of both 'users_list' and 'users' arguments isn't allowed"
264 )
265 module.params["users"] = module.params["users_list"]
266 module.params.pop("users_list")
267
268 result = api_call(module, api_call_object)
269 module.exit_json(**result)
270
271
272 if __name__ == "__main__":
273 main()