Debian Codegraph @

ansible_collections/fortinet/fortios/plugins/modules/fortios_icap_profile.py

raw symbols SCIP
1 #!/usr/bin/python
2 from __future__ import absolute_import, division, print_function
3
4 # Copyright: (c) 2022 Fortinet
5 # GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
6 #
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11
12 __metaclass__ = type
13
14 ANSIBLE_METADATA = {
15 "status": ["preview"],
16 "supported_by": "community",
17 "metadata_version": "1.1",
18 }
19
20 DOCUMENTATION = """
21 ---
22 module: fortios_icap_profile
23 short_description: Configure ICAP profiles in Fortinet's FortiOS and FortiGate.
24 description:
25 - This module is able to configure a FortiGate or FortiOS (FOS) device by allowing the
26 user to set and modify icap feature and profile category.
27 Examples include all parameters and values need to be adjusted to datasources before usage.
28 Tested with FOS v6.0.0
29 version_added: "2.0.0"
30 author:
31 - Link Zheng (@chillancezen)
32 - Jie Xue (@JieX19)
33 - Hongbin Lu (@fgtdev-hblu)
34 - Frank Shen (@frankshen01)
35 - Miguel Angel Munoz (@mamunozgonzalez)
36 - Nicolas Thomas (@thomnico)
37 notes:
38 - Legacy fortiosapi has been deprecated, httpapi is the preferred way to run playbooks
39
40 - The module supports check_mode.
41
42 requirements:
43 - ansible>=2.16
44 options:
45 access_token:
46 description:
47 - Token-based authentication.
48 Generated from GUI of Fortigate.
49 type: str
50 required: false
51 enable_log:
52 description:
53 - Enable/Disable logging for task.
54 type: bool
55 required: false
56 default: false
57 vdom:
58 description:
59 - Virtual domain, among those defined previously. A vdom is a
60 virtual instance of the FortiGate that can be configured and
61 used as a different unit.
62 type: str
63 default: root
64 member_path:
65 type: str
66 description:
67 - Member attribute path to operate on.
68 - Delimited by a slash character if there are more than one attribute.
69 - Parameter marked with member_path is legitimate for doing member operation.
70 member_state:
71 type: str
72 description:
73 - Add or delete a member under specified attribute path.
74 - When member_state is specified, the state option is ignored.
75 choices:
76 - 'present'
77 - 'absent'
78
79 state:
80 description:
81 - Indicates whether to create or remove the object.
82 type: str
83 required: true
84 choices:
85 - 'present'
86 - 'absent'
87 icap_profile:
88 description:
89 - Configure ICAP profiles.
90 default: null
91 type: dict
92 suboptions:
93 response_204:
94 description:
95 - Enable/disable allowance of 204 response from ICAP server.
96 type: str
97 choices:
98 - 'disable'
99 - 'enable'
100 size_limit_204:
101 description:
102 - 204 response size limit to be saved by ICAP client in megabytes (1 - 10).
103 type: int
104 chunk_encap:
105 description:
106 - Enable/disable chunked encapsulation .
107 type: str
108 choices:
109 - 'disable'
110 - 'enable'
111 comment:
112 description:
113 - Comment.
114 type: str
115 extension_feature:
116 description:
117 - Enable/disable ICAP extension features.
118 type: list
119 elements: str
120 choices:
121 - 'scan-progress'
122 file_transfer:
123 description:
124 - Configure the file transfer protocols to pass transferred files to an ICAP server as REQMOD.
125 type: list
126 elements: str
127 choices:
128 - 'ssh'
129 - 'ftp'
130 file_transfer_failure:
131 description:
132 - Action to take if the ICAP server cannot be contacted when processing a file transfer.
133 type: str
134 choices:
135 - 'error'
136 - 'bypass'
137 file_transfer_path:
138 description:
139 - Path component of the ICAP URI that identifies the file transfer processing service.
140 type: str
141 file_transfer_server:
142 description:
143 - ICAP server to use for a file transfer. Source icap.server.name icap.server-group.name.
144 type: str
145 icap_block_log:
146 description:
147 - Enable/disable UTM log when infection found .
148 type: str
149 choices:
150 - 'disable'
151 - 'enable'
152 icap_headers:
153 description:
154 - Configure ICAP forwarded request headers.
155 type: list
156 elements: dict
157 suboptions:
158 base64_encoding:
159 description:
160 - Enable/disable use of base64 encoding of HTTP content.
161 type: str
162 choices:
163 - 'disable'
164 - 'enable'
165 content:
166 description:
167 - HTTP header content.
168 type: str
169 id:
170 description:
171 - HTTP forwarded header ID. see <a href='#notes'>Notes</a>.
172 required: true
173 type: int
174 name:
175 description:
176 - HTTP forwarded header name.
177 type: str
178 methods:
179 description:
180 - The allowed HTTP methods that will be sent to ICAP server for further processing.
181 type: list
182 elements: str
183 choices:
184 - 'delete'
185 - 'get'
186 - 'head'
187 - 'options'
188 - 'post'
189 - 'put'
190 - 'trace'
191 - 'connect'
192 - 'other'
193 name:
194 description:
195 - ICAP profile name.
196 required: true
197 type: str
198 ocr_only:
199 description:
200 - Enable/disable this FortiGate unit to submit only OCR interested content to the ICAP server.
201 type: str
202 choices:
203 - 'disable'
204 - 'enable'
205 preview:
206 description:
207 - Enable/disable preview of data to ICAP server.
208 type: str
209 choices:
210 - 'disable'
211 - 'enable'
212 preview_data_length:
213 description:
214 - Preview data length to be sent to ICAP server.
215 type: int
216 replacemsg_group:
217 description:
218 - Replacement message group. Source system.replacemsg-group.name.
219 type: str
220 request:
221 description:
222 - Enable/disable whether an HTTP request is passed to an ICAP server.
223 type: str
224 choices:
225 - 'disable'
226 - 'enable'
227 request_failure:
228 description:
229 - Action to take if the ICAP server cannot be contacted when processing an HTTP request.
230 type: str
231 choices:
232 - 'error'
233 - 'bypass'
234 request_path:
235 description:
236 - Path component of the ICAP URI that identifies the HTTP request processing service.
237 type: str
238 request_server:
239 description:
240 - ICAP server to use for an HTTP request. Source icap.server.name icap.server-group.name.
241 type: str
242 respmod_default_action:
243 description:
244 - Default action to ICAP response modification (respmod) processing.
245 type: str
246 choices:
247 - 'forward'
248 - 'bypass'
249 respmod_forward_rules:
250 description:
251 - ICAP response mode forward rules.
252 type: list
253 elements: dict
254 suboptions:
255 action:
256 description:
257 - Action to be taken for ICAP server.
258 type: str
259 choices:
260 - 'forward'
261 - 'bypass'
262 header_group:
263 description:
264 - HTTP header group.
265 type: list
266 elements: dict
267 suboptions:
268 case_sensitivity:
269 description:
270 - Enable/disable case sensitivity when matching header.
271 type: str
272 choices:
273 - 'disable'
274 - 'enable'
275 header:
276 description:
277 - HTTP header regular expression.
278 type: str
279 header_name:
280 description:
281 - HTTP header.
282 type: str
283 id:
284 description:
285 - ID. see <a href='#notes'>Notes</a>.
286 required: true
287 type: int
288 host:
289 description:
290 - Address object for the host. Source firewall.address.name firewall.addrgrp.name firewall.proxy-address.name.
291 type: str
292 http_resp_status_code:
293 description:
294 - HTTP response status code.
295 type: list
296 elements: dict
297 suboptions:
298 code:
299 description:
300 - HTTP response status code. see <a href='#notes'>Notes</a>.
301 required: true
302 type: int
303 name:
304 description:
305 - Address name.
306 required: true
307 type: str
308 response:
309 description:
310 - Enable/disable whether an HTTP response is passed to an ICAP server.
311 type: str
312 choices:
313 - 'disable'
314 - 'enable'
315 response_failure:
316 description:
317 - Action to take if the ICAP server cannot be contacted when processing an HTTP response.
318 type: str
319 choices:
320 - 'error'
321 - 'bypass'
322 response_path:
323 description:
324 - Path component of the ICAP URI that identifies the HTTP response processing service.
325 type: str
326 response_req_hdr:
327 description:
328 - Enable/disable addition of req-hdr for ICAP response modification (respmod) processing.
329 type: str
330 choices:
331 - 'disable'
332 - 'enable'
333 response_server:
334 description:
335 - ICAP server to use for an HTTP response. Source icap.server.name icap.server-group.name.
336 type: str
337 scan_progress_interval:
338 description:
339 - Scan progress interval value.
340 type: int
341 streaming_content_bypass:
342 description:
343 - Enable/disable bypassing of ICAP server for streaming content.
344 type: str
345 choices:
346 - 'disable'
347 - 'enable'
348 timeout:
349 description:
350 - Time (in seconds) that ICAP client waits for the response from ICAP server.
351 type: int
352 """
353
354 EXAMPLES = """
355 - name: Configure ICAP profiles.
356 fortinet.fortios.fortios_icap_profile:
357 vdom: "{{ vdom }}"
358 state: "present"
359 access_token: "<your_own_value>"
360 icap_profile:
361 response_204: "disable"
362 size_limit_204: "1"
363 chunk_encap: "disable"
364 comment: "Comment."
365 extension_feature: "scan-progress"
366 file_transfer: "ssh"
367 file_transfer_failure: "error"
368 file_transfer_path: "<your_own_value>"
369 file_transfer_server: "<your_own_value> (source icap.server.name icap.server-group.name)"
370 icap_block_log: "disable"
371 icap_headers:
372 -
373 base64_encoding: "disable"
374 content: "<your_own_value>"
375 id: "16"
376 name: "default_name_17"
377 methods: "delete"
378 name: "default_name_19"
379 ocr_only: "disable"
380 preview: "disable"
381 preview_data_length: "0"
382 replacemsg_group: "<your_own_value> (source system.replacemsg-group.name)"
383 request: "disable"
384 request_failure: "error"
385 request_path: "<your_own_value>"
386 request_server: "<your_own_value> (source icap.server.name icap.server-group.name)"
387 respmod_default_action: "forward"
388 respmod_forward_rules:
389 -
390 action: "forward"
391 header_group:
392 -
393 case_sensitivity: "disable"
394 header: "<your_own_value>"
395 header_name: "<your_own_value>"
396 id: "35"
397 host: "myhostname (source firewall.address.name firewall.addrgrp.name firewall.proxy-address.name)"
398 http_resp_status_code:
399 -
400 code: "<you_own_value>"
401 name: "default_name_39"
402 response: "disable"
403 response_failure: "error"
404 response_path: "<your_own_value>"
405 response_req_hdr: "disable"
406 response_server: "<your_own_value> (source icap.server.name icap.server-group.name)"
407 scan_progress_interval: "10"
408 streaming_content_bypass: "disable"
409 timeout: "30"
410 """
411
412 RETURN = """
413 build:
414 description: Build number of the fortigate image
415 returned: always
416 type: str
417 sample: '1547'
418 http_method:
419 description: Last method used to provision the content into FortiGate
420 returned: always
421 type: str
422 sample: 'PUT'
423 http_status:
424 description: Last result given by FortiGate on last operation applied
425 returned: always
426 type: str
427 sample: "200"
428 mkey:
429 description: Master key (id) used in the last call to FortiGate
430 returned: success
431 type: str
432 sample: "id"
433 name:
434 description: Name of the table used to fulfill the request
435 returned: always
436 type: str
437 sample: "urlfilter"
438 path:
439 description: Path of the table used to fulfill the request
440 returned: always
441 type: str
442 sample: "webfilter"
443 revision:
444 description: Internal revision number
445 returned: always
446 type: str
447 sample: "17.0.2.10658"
448 serial:
449 description: Serial number of the unit
450 returned: always
451 type: str
452 sample: "FGVMEVYYQT3AB5352"
453 status:
454 description: Indication of the operation's result
455 returned: always
456 type: str
457 sample: "success"
458 vdom:
459 description: Virtual domain used
460 returned: always
461 type: str
462 sample: "root"
463 version:
464 description: Version of the FortiGate
465 returned: always
466 type: str
467 sample: "v5.6.3"
468 """
469 from ansible.module_utils.basic import AnsibleModule
470 from ansible.module_utils.connection import Connection
471 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
472 FortiOSHandler,
473 )
474 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
475 check_legacy_fortiosapi,
476 )
477 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
478 schema_to_module_spec,
479 )
480 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
481 check_schema_versioning,
482 )
483 from ansible_collections.fortinet.fortios.plugins.module_utils.fortimanager.common import (
484 FAIL_SOCKET_MSG,
485 )
486 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.data_post_processor import (
487 remove_invalid_fields,
488 )
489 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
490 is_same_comparison,
491 )
492 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
493 serialize,
494 )
495 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
496 find_current_values,
497 )
498 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
499 unify_data_format,
500 )
501
502
503 def filter_icap_profile_data(json):
504 option_list = [
505 "response_204",
506 "size_limit_204",
507 "chunk_encap",
508 "comment",
509 "extension_feature",
510 "file_transfer",
511 "file_transfer_failure",
512 "file_transfer_path",
513 "file_transfer_server",
514 "icap_block_log",
515 "icap_headers",
516 "methods",
517 "name",
518 "ocr_only",
519 "preview",
520 "preview_data_length",
521 "replacemsg_group",
522 "request",
523 "request_failure",
524 "request_path",
525 "request_server",
526 "respmod_default_action",
527 "respmod_forward_rules",
528 "response",
529 "response_failure",
530 "response_path",
531 "response_req_hdr",
532 "response_server",
533 "scan_progress_interval",
534 "streaming_content_bypass",
535 "timeout",
536 ]
537
538 json = remove_invalid_fields(json)
539 dictionary = {}
540
541 for attribute in option_list:
542 if attribute in json and json[attribute] is not None:
543 dictionary[attribute] = json[attribute]
544
545 return dictionary
546
547
548 def flatten_single_path(data, path, index):
549 if (
550 not data
551 or index == len(path)
552 or path[index] not in data
553 or (not data[path[index]] and not isinstance(data[path[index]], list))
554 ):
555 return
556
557 if index == len(path) - 1:
558 data[path[index]] = " ".join(str(elem) for elem in data[path[index]])
559 if len(data[path[index]]) == 0:
560 data[path[index]] = None
561 elif isinstance(data[path[index]], list):
562 for value in data[path[index]]:
563 flatten_single_path(value, path, index + 1)
564 else:
565 flatten_single_path(data[path[index]], path, index + 1)
566
567
568 def flatten_multilists_attributes(data):
569 multilist_attrs = [
570 ["file_transfer"],
571 ["methods"],
572 ["extension_feature"],
573 ]
574
575 for attr in multilist_attrs:
576 flatten_single_path(data, attr, 0)
577
578 return data
579
580
581 def underscore_to_hyphen(data):
582 new_data = None
583 if isinstance(data, list):
584 new_data = []
585 for i, elem in enumerate(data):
586 new_data.append(underscore_to_hyphen(elem))
587 elif isinstance(data, dict):
588 new_data = {}
589 for k, v in data.items():
590 new_data[k.replace("_", "-")] = underscore_to_hyphen(v)
591 else:
592 return data
593 return new_data
594
595
596 def valid_attr_to_invalid_attr(data):
597 speciallist = {"204_response": "response_204", "204_size_limit": "size_limit_204"}
598
599 for k, v in speciallist.items():
600 if v == data:
601 return k
602
603 return data
604
605
606 def valid_attr_to_invalid_attrs(data):
607 if isinstance(data, list):
608 new_data = []
609 for elem in data:
610 elem = valid_attr_to_invalid_attrs(elem)
611 new_data.append(elem)
612 data = new_data
613 elif isinstance(data, dict):
614 new_data = {}
615 for k, v in data.items():
616 new_data[valid_attr_to_invalid_attr(k)] = valid_attr_to_invalid_attrs(v)
617 data = new_data
618
619 return valid_attr_to_invalid_attr(data)
620
621
622 def icap_profile(data, fos, check_mode=False):
623
624 state = None
625 vdom = data["vdom"]
626 parameters = None
627 state = data.get("state", None)
628 icap_profile_data = data["icap_profile"]
629
630 filtered_data = filter_icap_profile_data(icap_profile_data)
631 filtered_data = flatten_multilists_attributes(filtered_data)
632 converted_data = underscore_to_hyphen(valid_attr_to_invalid_attrs(filtered_data))
633
634 # check_mode starts from here
635 if check_mode:
636 diff = {
637 "before": "",
638 "after": filtered_data,
639 }
640 mkeyname = fos.get_mkeyname(None, None)
641 mkey = fos.get_mkey("icap", "profile", filtered_data, vdom=vdom)
642 current_data = fos.get(
643 "icap", "profile", vdom=vdom, mkey=mkey, parameters=parameters
644 )
645 is_existed = (
646 current_data
647 and current_data.get("http_status") == 200
648 and (
649 mkeyname
650 and isinstance(current_data.get("results"), list)
651 and len(current_data["results"]) > 0
652 or not mkeyname
653 and current_data["results"] # global object response
654 )
655 )
656
657 # 2. if it exists and the state is 'present' then compare current settings with desired
658 if state == "present" or state is True or state is None:
659 # for non global modules, mkeyname must exist and it's a new module when mkey is None
660 if mkeyname is not None and mkey is None:
661 return False, True, filtered_data, diff
662
663 # if mkey exists then compare each other
664 # record exits and they're matched or not
665 copied_filtered_data = filtered_data.copy()
666 copied_filtered_data.pop(mkeyname, None)
667 unified_filtered_data = unify_data_format(copied_filtered_data)
668
669 current_data_results = current_data.get("results", {})
670 current_config = (
671 current_data_results[0]
672 if mkeyname
673 and isinstance(current_data_results, list)
674 and len(current_data_results) > 0
675 else current_data_results
676 )
677 if is_existed:
678 unified_current_values = find_current_values(
679 unified_filtered_data,
680 unify_data_format(current_config),
681 )
682
683 is_same = is_same_comparison(
684 serialize(unified_current_values), serialize(unified_filtered_data)
685 )
686
687 return (
688 False,
689 not is_same,
690 filtered_data,
691 {"before": unified_current_values, "after": unified_filtered_data},
692 )
693
694 # record does not exist
695 return False, True, filtered_data, diff
696
697 if state == "absent":
698 if mkey is None:
699 return (
700 False,
701 False,
702 filtered_data,
703 {"before": current_data["results"][0], "after": ""},
704 )
705
706 if is_existed:
707 return (
708 False,
709 True,
710 filtered_data,
711 {"before": current_data["results"][0], "after": ""},
712 )
713 return False, False, filtered_data, {}
714
715 return True, False, {"reason: ": "Must provide state parameter"}, {}
716 # pass post processed data to member operations
717 # no need to do underscore_to_hyphen since do_member_operation handles it by itself
718 data_copy = data.copy()
719 data_copy["icap_profile"] = filtered_data
720 fos.do_member_operation(
721 "icap",
722 "profile",
723 data_copy,
724 )
725
726 if state == "present" or state is True:
727 return fos.set(
728 "icap", "profile", data=converted_data, vdom=vdom, parameters=parameters
729 )
730
731 elif state == "absent":
732 return fos.delete(
733 "icap",
734 "profile",
735 mkey=converted_data["name"],
736 vdom=vdom,
737 parameters=parameters,
738 )
739 else:
740 fos._module.fail_json(msg="state must be present or absent!")
741
742
743 def is_successful_status(resp):
744 return (
745 "status" in resp
746 and resp["status"] == "success"
747 or "http_status" in resp
748 and resp["http_status"] == 200
749 or "http_method" in resp
750 and resp["http_method"] == "DELETE"
751 and resp["http_status"] == 404
752 )
753
754
755 def fortios_icap(data, fos, check_mode):
756
757 if data["icap_profile"]:
758 resp = icap_profile(data, fos, check_mode)
759 else:
760 fos._module.fail_json(msg="missing task body: %s" % ("icap_profile"))
761 if isinstance(resp, tuple) and len(resp) == 4:
762 return resp
763 return (
764 not is_successful_status(resp),
765 is_successful_status(resp)
766 and (resp["revision_changed"] if "revision_changed" in resp else True),
767 resp,
768 {},
769 )
770
771
772 versioned_schema = {
773 "type": "list",
774 "elements": "dict",
775 "children": {
776 "replacemsg_group": {"v_range": [["v6.0.0", ""]], "type": "string"},
777 "name": {"v_range": [["v6.0.0", ""]], "type": "string", "required": True},
778 "comment": {"v_range": [["v7.2.4", ""]], "type": "string"},
779 "request": {
780 "v_range": [["v6.0.0", ""]],
781 "type": "string",
782 "options": [{"value": "disable"}, {"value": "enable"}],
783 },
784 "response": {
785 "v_range": [["v6.0.0", ""]],
786 "type": "string",
787 "options": [{"value": "disable"}, {"value": "enable"}],
788 },
789 "file_transfer": {
790 "v_range": [["v7.2.0", ""]],
791 "type": "list",
792 "options": [{"value": "ssh"}, {"value": "ftp"}],
793 "multiple_values": True,
794 "elements": "str",
795 },
796 "streaming_content_bypass": {
797 "v_range": [["v6.0.0", ""]],
798 "type": "string",
799 "options": [{"value": "disable"}, {"value": "enable"}],
800 },
801 "ocr_only": {
802 "v_range": [["v7.6.1", ""]],
803 "type": "string",
804 "options": [{"value": "disable"}, {"value": "enable"}],
805 },
806 "preview": {
807 "v_range": [["v6.2.0", ""]],
808 "type": "string",
809 "options": [{"value": "disable"}, {"value": "enable"}],
810 },
811 "preview_data_length": {"v_range": [["v6.2.0", ""]], "type": "integer"},
812 "request_server": {"v_range": [["v6.0.0", ""]], "type": "string"},
813 "response_server": {"v_range": [["v6.0.0", ""]], "type": "string"},
814 "file_transfer_server": {"v_range": [["v7.2.0", ""]], "type": "string"},
815 "request_failure": {
816 "v_range": [["v6.0.0", ""]],
817 "type": "string",
818 "options": [{"value": "error"}, {"value": "bypass"}],
819 },
820 "response_failure": {
821 "v_range": [["v6.0.0", ""]],
822 "type": "string",
823 "options": [{"value": "error"}, {"value": "bypass"}],
824 },
825 "file_transfer_failure": {
826 "v_range": [["v7.2.0", ""]],
827 "type": "string",
828 "options": [{"value": "error"}, {"value": "bypass"}],
829 },
830 "request_path": {"v_range": [["v6.0.0", ""]], "type": "string"},
831 "response_path": {"v_range": [["v6.0.0", ""]], "type": "string"},
832 "file_transfer_path": {"v_range": [["v7.2.0", ""]], "type": "string"},
833 "methods": {
834 "v_range": [["v6.0.0", ""]],
835 "type": "list",
836 "options": [
837 {"value": "delete"},
838 {"value": "get"},
839 {"value": "head"},
840 {"value": "options"},
841 {"value": "post"},
842 {"value": "put"},
843 {"value": "trace"},
844 {"value": "connect", "v_range": [["v7.2.0", ""]]},
845 {"value": "other"},
846 ],
847 "multiple_values": True,
848 "elements": "str",
849 },
850 "response_req_hdr": {
851 "v_range": [["v6.2.0", ""]],
852 "type": "string",
853 "options": [{"value": "disable"}, {"value": "enable"}],
854 },
855 "respmod_default_action": {
856 "v_range": [["v6.4.0", ""]],
857 "type": "string",
858 "options": [{"value": "forward"}, {"value": "bypass"}],
859 },
860 "icap_block_log": {
861 "v_range": [["v7.0.1", ""]],
862 "type": "string",
863 "options": [{"value": "disable"}, {"value": "enable"}],
864 },
865 "chunk_encap": {
866 "v_range": [["v7.0.2", ""]],
867 "type": "string",
868 "options": [{"value": "disable"}, {"value": "enable"}],
869 },
870 "extension_feature": {
871 "v_range": [["v7.0.2", ""]],
872 "type": "list",
873 "options": [{"value": "scan-progress"}],
874 "multiple_values": True,
875 "elements": "str",
876 },
877 "scan_progress_interval": {"v_range": [["v7.0.2", ""]], "type": "integer"},
878 "timeout": {"v_range": [["v7.2.0", ""]], "type": "integer"},
879 "icap_headers": {
880 "type": "list",
881 "elements": "dict",
882 "children": {
883 "id": {
884 "v_range": [["v6.2.0", ""]],
885 "type": "integer",
886 "required": True,
887 },
888 "name": {"v_range": [["v6.2.0", ""]], "type": "string"},
889 "content": {"v_range": [["v6.2.0", ""]], "type": "string"},
890 "base64_encoding": {
891 "v_range": [["v6.2.0", ""]],
892 "type": "string",
893 "options": [{"value": "disable"}, {"value": "enable"}],
894 },
895 },
896 "v_range": [["v6.2.0", ""]],
897 },
898 "respmod_forward_rules": {
899 "type": "list",
900 "elements": "dict",
901 "children": {
902 "name": {
903 "v_range": [["v6.4.0", ""]],
904 "type": "string",
905 "required": True,
906 },
907 "host": {"v_range": [["v6.4.0", ""]], "type": "string"},
908 "header_group": {
909 "type": "list",
910 "elements": "dict",
911 "children": {
912 "id": {
913 "v_range": [["v6.4.0", ""]],
914 "type": "integer",
915 "required": True,
916 },
917 "header_name": {"v_range": [["v6.4.0", ""]], "type": "string"},
918 "header": {"v_range": [["v6.4.0", ""]], "type": "string"},
919 "case_sensitivity": {
920 "v_range": [["v6.4.0", ""]],
921 "type": "string",
922 "options": [{"value": "disable"}, {"value": "enable"}],
923 },
924 },
925 "v_range": [["v6.4.0", ""]],
926 },
927 "action": {
928 "v_range": [["v6.4.0", ""]],
929 "type": "string",
930 "options": [{"value": "forward"}, {"value": "bypass"}],
931 },
932 "http_resp_status_code": {
933 "type": "list",
934 "elements": "dict",
935 "children": {
936 "code": {
937 "v_range": [["v6.4.0", ""]],
938 "type": "integer",
939 "required": True,
940 }
941 },
942 "v_range": [["v6.4.0", ""]],
943 },
944 },
945 "v_range": [["v6.4.0", ""]],
946 },
947 "size_limit_204": {"v_range": [["v7.2.0", ""]], "type": "integer"},
948 "response_204": {
949 "v_range": [["v7.2.0", ""]],
950 "type": "string",
951 "options": [{"value": "disable"}, {"value": "enable"}],
952 },
953 },
954 "v_range": [["v6.0.0", ""]],
955 }
956
957
958 def main():
959 module_spec = schema_to_module_spec(versioned_schema)
960 mkeyname = "name"
961 fields = {
962 "access_token": {"required": False, "type": "str", "no_log": True},
963 "enable_log": {"required": False, "type": "bool", "default": False},
964 "vdom": {"required": False, "type": "str", "default": "root"},
965 "member_path": {"required": False, "type": "str"},
966 "member_state": {
967 "type": "str",
968 "required": False,
969 "choices": ["present", "absent"],
970 },
971 "state": {"required": True, "type": "str", "choices": ["present", "absent"]},
972 "icap_profile": {
973 "required": False,
974 "type": "dict",
975 "default": None,
976 "options": {},
977 },
978 }
979 for attribute_name in module_spec["options"]:
980 fields["icap_profile"]["options"][attribute_name] = module_spec["options"][
981 attribute_name
982 ]
983 if mkeyname and mkeyname == attribute_name:
984 fields["icap_profile"]["options"][attribute_name]["required"] = True
985
986 module = AnsibleModule(argument_spec=fields, supports_check_mode=True)
987 check_legacy_fortiosapi(module)
988
989 is_error = False
990 has_changed = False
991 result = None
992 diff = None
993
994 versions_check_result = None
995 if module._socket_path:
996 connection = Connection(module._socket_path)
997 if "access_token" in module.params:
998 connection.set_custom_option("access_token", module.params["access_token"])
999
1000 if "enable_log" in module.params:
1001 connection.set_custom_option("enable_log", module.params["enable_log"])
1002 else:
1003 connection.set_custom_option("enable_log", False)
1004 fos = FortiOSHandler(connection, module, mkeyname, admin_passwd_header=False)
1005 versions_check_result = check_schema_versioning(
1006 fos, versioned_schema, "icap_profile"
1007 )
1008
1009 is_error, has_changed, result, diff = fortios_icap(
1010 module.params, fos, module.check_mode
1011 )
1012
1013 else:
1014 module.fail_json(**FAIL_SOCKET_MSG)
1015
1016 if versions_check_result and versions_check_result["matched"] is False:
1017 module.warn(
1018 "Ansible has detected version mismatch between FortOS system and your playbook, see more details by specifying option -vvv"
1019 )
1020
1021 if not is_error:
1022 if versions_check_result and versions_check_result["matched"] is False:
1023 module.exit_json(
1024 changed=has_changed,
1025 version_check_warning=versions_check_result,
1026 meta=result,
1027 diff=diff,
1028 )
1029 else:
1030 module.exit_json(changed=has_changed, meta=result, diff=diff)
1031 else:
1032 if versions_check_result and versions_check_result["matched"] is False:
1033 module.fail_json(
1034 msg="Error in repo",
1035 version_check_warning=versions_check_result,
1036 meta=result,
1037 )
1038 else:
1039 module.fail_json(msg="Error in repo", meta=result)
1040
1041
1042 if __name__ == "__main__":
1043 main()