Debian Codegraph @

ansible_collections/fortinet/fortimanager/plugins/modules/fmgr_casb_useractivity.py

raw symbols SCIP
1 #!/usr/bin/python
2 from __future__ import absolute_import, division, print_function
3 # Copyright 2019-2024 Fortinet, Inc.
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 __metaclass__ = type
7
8 ANSIBLE_METADATA = {'status': ['preview'],
9 'supported_by': 'community',
10 'metadata_version': '1.1'}
11
12 DOCUMENTATION = '''
13 ---
14 module: fmgr_casb_useractivity
15 short_description: Configure CASB user activity.
16 version_added: "2.3.0"
17 extends_documentation_fragment:
18 - fortinet.fortimanager.general
19 - fortinet.fortimanager.general.full_crud
20 options:
21 revision_note:
22 description: The change note that can be specified when an object is created or updated.
23 type: str
24 adom:
25 description: The parameter (adom) in requested url.
26 type: str
27 required: true
28 casb_useractivity:
29 description: The top level parameters set.
30 required: false
31 type: dict
32 suboptions:
33 application:
34 type: str
35 description: CASB SaaS application name.
36 casb_name:
37 aliases: ['casb-name']
38 type: str
39 description: CASB user activity signature name.
40 category:
41 type: str
42 description: CASB user activity category.
43 choices: ['activity-control', 'tenant-control', 'domain-control',
44 'safe-search-control', 'other', 'advanced-tenant-control']
45 control_options:
46 aliases: ['control-options']
47 type: list
48 elements: dict
49 description: Control options.
50 suboptions:
51 name:
52 type: str
53 description: CASB control option name.
54 operations:
55 type: list
56 elements: dict
57 description: Operations.
58 suboptions:
59 action:
60 type: str
61 description: CASB operation action.
62 choices: ['append', 'prepend', 'replace', 'new',
63 'new-on-not-found', 'delete']
64 case_sensitive:
65 aliases: ['case-sensitive']
66 type: str
67 description: CASB operation search case sensitive.
68 choices: ['disable', 'enable']
69 direction:
70 type: str
71 description: CASB operation direction.
72 choices: ['request', 'response']
73 header_name:
74 aliases: ['header-name']
75 type: str
76 description: CASB operation header name to search.
77 name:
78 type: str
79 description: CASB control option operation name.
80 search_key:
81 aliases: ['search-key']
82 type: str
83 description: CASB operation key to search.
84 search_pattern:
85 aliases: ['search-pattern']
86 type: str
87 description: CASB operation search pattern.
88 choices: ['simple', 'substr', 'regexp']
89 target:
90 type: str
91 description: CASB operation target.
92 choices: ['header', 'path', 'body']
93 value_from_input:
94 aliases: ['value-from-input']
95 type: str
96 description: Enable/disable value from user input.
97 choices: ['disable', 'enable']
98 values:
99 type: list
100 elements: str
101 description: CASB operation new values.
102 value_name_from_input:
103 aliases: ['value-name-from-input']
104 type: str
105 description: CASB operation value name from user input.
106 status:
107 type: str
108 description: CASB control option status.
109 choices: ['disable', 'enable']
110 description:
111 type: str
112 description: CASB user activity description.
113 match:
114 type: list
115 elements: dict
116 description: Match.
117 suboptions:
118 id:
119 type: int
120 description: CASB user activity match rules ID.
121 rules:
122 type: list
123 elements: dict
124 description: Rules.
125 suboptions:
126 case_sensitive:
127 aliases: ['case-sensitive']
128 type: str
129 description: CASB user activity match case sensitive.
130 choices: ['disable', 'enable']
131 domains:
132 type: list
133 elements: str
134 description: CASB user activity domain list.
135 header_name:
136 aliases: ['header-name']
137 type: str
138 description: CASB user activity rule header name.
139 id:
140 type: int
141 description: CASB user activity rule ID.
142 match_pattern:
143 aliases: ['match-pattern']
144 type: str
145 description: CASB user activity rule match pattern.
146 choices: ['simple', 'substr', 'regexp']
147 match_value:
148 aliases: ['match-value']
149 type: str
150 description: CASB user activity rule match value.
151 methods:
152 type: list
153 elements: str
154 description: CASB user activity method list.
155 negate:
156 type: str
157 description: Enable/disable what the matching strategy must not be.
158 choices: ['disable', 'enable']
159 type:
160 type: str
161 description: CASB user activity rule type.
162 choices: ['domains', 'host', 'path', 'header', 'header-value',
163 'method', 'body']
164 body_type:
165 aliases: ['body-type']
166 type: str
167 description: CASB user activity match rule body type.
168 choices: ['json']
169 jq:
170 type: str
171 description: CASB user activity rule match jq script.
172 strategy:
173 type: str
174 description: CASB user activity rules strategy.
175 choices: ['or', 'and']
176 tenant_extraction:
177 aliases: ['tenant-extraction']
178 type: dict
179 description: Tenant extraction.
180 suboptions:
181 filters:
182 type: list
183 elements: dict
184 description: Filters.
185 suboptions:
186 body_type:
187 aliases: ['body-type']
188 type: str
189 description: CASB tenant extraction filter body type.
190 choices: ['json']
191 direction:
192 type: str
193 description: CASB tenant extraction filter direction.
194 choices: ['request', 'response']
195 header_name:
196 aliases: ['header-name']
197 type: str
198 description: CASB tenant extraction filter header name.
199 id:
200 type: int
201 description: CASB tenant extraction filter ID.
202 place:
203 type: str
204 description: CASB tenant extraction filter place type.
205 choices: ['path', 'header', 'body']
206 jq:
207 type: str
208 description: CASB user activity tenant extraction jq script.
209 status:
210 type: str
211 description: Enable/disable CASB tenant extraction.
212 choices: ['disable', 'enable']
213 type:
214 type: str
215 description: CASB user activity tenant extraction type.
216 choices: ['json-query']
217 match_strategy:
218 aliases: ['match-strategy']
219 type: str
220 description: CASB user activity match strategy.
221 choices: ['or', 'and']
222 name:
223 type: str
224 description: CASB user activity name.
225 required: true
226 type:
227 type: str
228 description: CASB user activity type.
229 choices: ['built-in', 'customized']
230 uuid:
231 type: str
232 description: Universally Unique Identifier
233 status:
234 type: str
235 description: CASB user activity status.
236 choices: ['disable', 'enable']
237 '''
238
239 EXAMPLES = '''
240 - name: Example playbook (generated based on argument schema)
241 hosts: fortimanagers
242 connection: httpapi
243 gather_facts: false
244 tasks:
245 - name: Configure CASB user activity.
246 fortinet.fortimanager.fmgr_casb_useractivity:
247 # workspace_locking_adom: <global or your adom name>
248 adom: <your own value>
249 state: present # <value in [present, absent]>
250 casb_useractivity:
251 name: "your value" # Required variable, string
252 # application: <string>
253 # casb_name: <string>
254 # category: <value in [activity-control, tenant-control, domain-control, ...]>
255 # control_options:
256 # - name: <string>
257 # operations:
258 # - action: <value in [append, prepend, replace, ...]>
259 # case_sensitive: <value in [disable, enable]>
260 # direction: <value in [request, response]>
261 # header_name: <string>
262 # name: <string>
263 # search_key: <string>
264 # search_pattern: <value in [simple, substr, regexp]>
265 # target: <value in [header, path, body]>
266 # value_from_input: <value in [disable, enable]>
267 # values: <list or string>
268 # value_name_from_input: <string>
269 # status: <value in [disable, enable]>
270 # description: <string>
271 # match:
272 # - id: <integer>
273 # rules:
274 # - case_sensitive: <value in [disable, enable]>
275 # domains: <list or string>
276 # header_name: <string>
277 # id: <integer>
278 # match_pattern: <value in [simple, substr, regexp]>
279 # match_value: <string>
280 # methods: <list or string>
281 # negate: <value in [disable, enable]>
282 # type: <value in [domains, host, path, ...]>
283 # body_type: <value in [json]>
284 # jq: <string>
285 # strategy: <value in [or, and]>
286 # tenant_extraction:
287 # filters:
288 # - body_type: <value in [json]>
289 # direction: <value in [request, response]>
290 # header_name: <string>
291 # id: <integer>
292 # place: <value in [path, header, body]>
293 # jq: <string>
294 # status: <value in [disable, enable]>
295 # type: <value in [json-query]>
296 # match_strategy: <value in [or, and]>
297 # type: <value in [built-in, customized]>
298 # uuid: <string>
299 # status: <value in [disable, enable]>
300 '''
301
302 RETURN = '''
303 meta:
304 description: The result of the request.
305 type: dict
306 returned: always
307 contains:
308 request_url:
309 description: The full url requested.
310 returned: always
311 type: str
312 sample: /sys/login/user
313 response_code:
314 description: The status of api request.
315 returned: always
316 type: int
317 sample: 0
318 response_data:
319 description: The api response.
320 type: list
321 returned: always
322 response_message:
323 description: The descriptive message of the api response.
324 type: str
325 returned: always
326 sample: OK.
327 system_information:
328 description: The information of the target system.
329 type: dict
330 returned: always
331 rc:
332 description: The status the request.
333 type: int
334 returned: always
335 sample: 0
336 version_check_warning:
337 description: Warning if the parameters used in the playbook are not supported by the current FortiManager version.
338 type: list
339 returned: complex
340 '''
341 from ansible.module_utils.basic import AnsibleModule
342 from ansible.module_utils.connection import Connection
343 from ansible_collections.fortinet.fortimanager.plugins.module_utils.napi import NAPIManager, check_galaxy_version, check_parameter_bypass
344 from ansible_collections.fortinet.fortimanager.plugins.module_utils.common import get_module_arg_spec
345
346
347 def main():
348 urls_list = [
349 '/pm/config/adom/{adom}/obj/casb/user-activity',
350 '/pm/config/global/obj/casb/user-activity'
351 ]
352 module_arg_spec = {
353 'adom': {'required': True, 'type': 'str'},
354 'revision_note': {'type': 'str'},
355 'casb_useractivity': {
356 'type': 'dict', 'v_range': [['7.4.1', '']],
357 'options': {
358 'application': {'v_range': [['7.4.1', '']], 'type': 'str'},
359 'casb-name': {'v_range': [['7.4.1', '']], 'type': 'str'},
360 'category': {
361 'v_range': [['7.4.1', '']],
362 'choices': ['activity-control', 'tenant-control', 'domain-control', 'safe-search-control', 'other', 'advanced-tenant-control'],
363 'type': 'str'
364 },
365 'control-options': {
366 'v_range': [['7.4.1', '']],
367 'type': 'list',
368 'options': {
369 'name': {'v_range': [['7.4.1', '']], 'type': 'str'},
370 'operations': {
371 'v_range': [['7.4.1', '']],
372 'type': 'list',
373 'options': {
374 'action': {
375 'v_range': [['7.4.1', '']],
376 'choices': ['append', 'prepend', 'replace', 'new', 'new-on-not-found', 'delete'],
377 'type': 'str'
378 },
379 'case-sensitive': {'v_range': [['7.4.1', '']], 'choices': ['disable', 'enable'], 'type': 'str'},
380 'direction': {'v_range': [['7.4.1', '']], 'choices': ['request', 'response'], 'type': 'str'},
381 'header-name': {'v_range': [['7.4.1', '']], 'type': 'str'},
382 'name': {'v_range': [['7.4.1', '']], 'type': 'str'},
383 'search-key': {'v_range': [['7.4.1', '']], 'no_log': True, 'type': 'str'},
384 'search-pattern': {'v_range': [['7.4.1', '']], 'choices': ['simple', 'substr', 'regexp'], 'type': 'str'},
385 'target': {'v_range': [['7.4.1', '']], 'choices': ['header', 'path', 'body'], 'type': 'str'},
386 'value-from-input': {'v_range': [['7.4.1', '']], 'choices': ['disable', 'enable'], 'type': 'str'},
387 'values': {'v_range': [['7.4.1', '']], 'type': 'list', 'elements': 'str'},
388 'value-name-from-input': {'v_range': [['7.6.4', '']], 'type': 'str'}
389 },
390 'elements': 'dict'
391 },
392 'status': {'v_range': [['7.4.2', '']], 'choices': ['disable', 'enable'], 'type': 'str'}
393 },
394 'elements': 'dict'
395 },
396 'description': {'v_range': [['7.4.1', '']], 'type': 'str'},
397 'match': {
398 'v_range': [['7.4.1', '']],
399 'type': 'list',
400 'options': {
401 'id': {'v_range': [['7.4.1', '']], 'type': 'int'},
402 'rules': {
403 'v_range': [['7.4.1', '']],
404 'type': 'list',
405 'options': {
406 'case-sensitive': {'v_range': [['7.4.1', '']], 'choices': ['disable', 'enable'], 'type': 'str'},
407 'domains': {'v_range': [['7.4.1', '']], 'type': 'list', 'elements': 'str'},
408 'header-name': {'v_range': [['7.4.1', '']], 'type': 'str'},
409 'id': {'v_range': [['7.4.1', '']], 'type': 'int'},
410 'match-pattern': {'v_range': [['7.4.1', '']], 'choices': ['simple', 'substr', 'regexp'], 'type': 'str'},
411 'match-value': {'v_range': [['7.4.1', '']], 'type': 'str'},
412 'methods': {'v_range': [['7.4.1', '']], 'type': 'list', 'elements': 'str'},
413 'negate': {'v_range': [['7.4.1', '']], 'choices': ['disable', 'enable'], 'type': 'str'},
414 'type': {
415 'v_range': [['7.4.1', '']],
416 'choices': ['domains', 'host', 'path', 'header', 'header-value', 'method', 'body'],
417 'type': 'str'
418 },
419 'body-type': {'v_range': [['7.6.2', '']], 'choices': ['json'], 'type': 'str'},
420 'jq': {'v_range': [['7.6.2', '']], 'type': 'str'}
421 },
422 'elements': 'dict'
423 },
424 'strategy': {'v_range': [['7.4.1', '']], 'choices': ['or', 'and'], 'type': 'str'},
425 'tenant-extraction': {
426 'v_range': [['7.6.2', '']],
427 'type': 'dict',
428 'options': {
429 'filters': {
430 'v_range': [['7.6.2', '']],
431 'type': 'list',
432 'options': {
433 'body-type': {'v_range': [['7.6.2', '']], 'choices': ['json'], 'type': 'str'},
434 'direction': {'v_range': [['7.6.2', '']], 'choices': ['request', 'response'], 'type': 'str'},
435 'header-name': {'v_range': [['7.6.2', '']], 'type': 'str'},
436 'id': {'v_range': [['7.6.2', '']], 'type': 'int'},
437 'place': {'v_range': [['7.6.2', '']], 'choices': ['path', 'header', 'body'], 'type': 'str'}
438 },
439 'elements': 'dict'
440 },
441 'jq': {'v_range': [['7.6.2', '']], 'type': 'str'},
442 'status': {'v_range': [['7.6.2', '']], 'choices': ['disable', 'enable'], 'type': 'str'},
443 'type': {'v_range': [['7.6.2', '']], 'choices': ['json-query'], 'type': 'str'}
444 }
445 }
446 },
447 'elements': 'dict'
448 },
449 'match-strategy': {'v_range': [['7.4.1', '']], 'choices': ['or', 'and'], 'type': 'str'},
450 'name': {'v_range': [['7.4.1', '']], 'required': True, 'type': 'str'},
451 'type': {'v_range': [['7.4.1', '']], 'choices': ['built-in', 'customized'], 'type': 'str'},
452 'uuid': {'v_range': [['7.4.1', '']], 'type': 'str'},
453 'status': {'v_range': [['7.4.2', '']], 'choices': ['disable', 'enable'], 'type': 'str'}
454 }
455 }
456 }
457
458 module_option_spec = get_module_arg_spec('full crud')
459 module_arg_spec.update(module_option_spec)
460 check_galaxy_version(module_arg_spec)
461 module = AnsibleModule(argument_spec=check_parameter_bypass(module_arg_spec, 'casb_useractivity'),
462 supports_check_mode=True)
463 if not module._socket_path:
464 module.fail_json(msg='MUST RUN IN HTTPAPI MODE')
465 connection = Connection(module._socket_path)
466 fmgr = NAPIManager('full crud', module_arg_spec, urls_list,
467 'name', 'data', module, connection)
468 fmgr.process_crud()
469 module.exit_json(meta=module.params)
470
471
472 if __name__ == '__main__':
473 main()