| 1 |
|
| 2 |
from __future__ import absolute_import, division, print_function |
| 3 |
|
| 4 |
|
| 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_icap_profile |
| 15 |
short_description: Configure ICAP profiles. |
| 16 |
version_added: "2.0.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 |
icap_profile: |
| 29 |
description: The top level parameters set. |
| 30 |
required: false |
| 31 |
type: dict |
| 32 |
suboptions: |
| 33 |
methods: |
| 34 |
type: list |
| 35 |
elements: str |
| 36 |
description: The allowed HTTP methods that will be sent to ICAP server for further processing. |
| 37 |
choices: ['delete', 'get', 'head', 'options', 'post', 'put', 'trace', 'other', |
| 38 |
'connect'] |
| 39 |
name: |
| 40 |
type: str |
| 41 |
description: ICAP profile name. |
| 42 |
required: true |
| 43 |
replacemsg_group: |
| 44 |
aliases: ['replacemsg-group'] |
| 45 |
type: str |
| 46 |
description: Replacement message group. |
| 47 |
request: |
| 48 |
type: str |
| 49 |
description: Enable/disable whether an HTTP request is passed to an ICAP server. |
| 50 |
choices: ['disable', 'enable'] |
| 51 |
request_failure: |
| 52 |
aliases: ['request-failure'] |
| 53 |
type: str |
| 54 |
description: Action to take if the ICAP server cannot be contacted when processing an HTTP request. |
| 55 |
choices: ['error', 'bypass'] |
| 56 |
request_path: |
| 57 |
aliases: ['request-path'] |
| 58 |
type: str |
| 59 |
description: Path component of the ICAP URI that identifies the HTTP request processing service. |
| 60 |
request_server: |
| 61 |
aliases: ['request-server'] |
| 62 |
type: str |
| 63 |
description: ICAP server to use for an HTTP request. |
| 64 |
response: |
| 65 |
type: str |
| 66 |
description: Enable/disable whether an HTTP response is passed to an ICAP server. |
| 67 |
choices: ['disable', 'enable'] |
| 68 |
response_failure: |
| 69 |
aliases: ['response-failure'] |
| 70 |
type: str |
| 71 |
description: Action to take if the ICAP server cannot be contacted when processing an HTTP response. |
| 72 |
choices: ['error', 'bypass'] |
| 73 |
response_path: |
| 74 |
aliases: ['response-path'] |
| 75 |
type: str |
| 76 |
description: Path component of the ICAP URI that identifies the HTTP response processing service. |
| 77 |
response_server: |
| 78 |
aliases: ['response-server'] |
| 79 |
type: str |
| 80 |
description: ICAP server to use for an HTTP response. |
| 81 |
streaming_content_bypass: |
| 82 |
aliases: ['streaming-content-bypass'] |
| 83 |
type: str |
| 84 |
description: Enable/disable bypassing of ICAP server for streaming content. |
| 85 |
choices: ['disable', 'enable'] |
| 86 |
icap_headers: |
| 87 |
aliases: ['icap-headers'] |
| 88 |
type: list |
| 89 |
elements: dict |
| 90 |
description: Icap headers. |
| 91 |
suboptions: |
| 92 |
base64_encoding: |
| 93 |
aliases: ['base64-encoding'] |
| 94 |
type: str |
| 95 |
description: Enable/disable use of base64 encoding of HTTP content. |
| 96 |
choices: ['disable', 'enable'] |
| 97 |
content: |
| 98 |
type: str |
| 99 |
description: HTTP header content. |
| 100 |
id: |
| 101 |
type: int |
| 102 |
description: HTTP forwarded header ID. |
| 103 |
name: |
| 104 |
type: str |
| 105 |
description: HTTP forwarded header name. |
| 106 |
http_header: |
| 107 |
aliases: ['http-header'] |
| 108 |
type: str |
| 109 |
description: Http header. |
| 110 |
sesson_info_type: |
| 111 |
aliases: ['sesson-info-type'] |
| 112 |
type: str |
| 113 |
description: Sesson info type. |
| 114 |
choices: ['client-ip', 'user', 'upn', 'domain', 'local-grp', 'remote-grp', |
| 115 |
'proxy-name', 'auth-user-uri', 'auth-group-uri'] |
| 116 |
source: |
| 117 |
type: str |
| 118 |
description: Source. |
| 119 |
choices: ['content', 'http-header', 'session'] |
| 120 |
preview: |
| 121 |
type: str |
| 122 |
description: Enable/disable preview of data to ICAP server. |
| 123 |
choices: ['disable', 'enable'] |
| 124 |
preview_data_length: |
| 125 |
aliases: ['preview-data-length'] |
| 126 |
type: int |
| 127 |
description: Preview data length to be sent to ICAP server. |
| 128 |
response_req_hdr: |
| 129 |
aliases: ['response-req-hdr'] |
| 130 |
type: str |
| 131 |
description: Enable/disable addition of req-hdr for ICAP response modification |
| 132 |
choices: ['disable', 'enable'] |
| 133 |
respmod_default_action: |
| 134 |
aliases: ['respmod-default-action'] |
| 135 |
type: str |
| 136 |
description: Default action to ICAP response modification |
| 137 |
choices: ['bypass', 'forward'] |
| 138 |
respmod_forward_rules: |
| 139 |
aliases: ['respmod-forward-rules'] |
| 140 |
type: list |
| 141 |
elements: dict |
| 142 |
description: Respmod forward rules. |
| 143 |
suboptions: |
| 144 |
action: |
| 145 |
type: str |
| 146 |
description: Action to be taken for ICAP server. |
| 147 |
choices: ['bypass', 'forward'] |
| 148 |
header_group: |
| 149 |
aliases: ['header-group'] |
| 150 |
type: list |
| 151 |
elements: dict |
| 152 |
description: Header group. |
| 153 |
suboptions: |
| 154 |
case_sensitivity: |
| 155 |
aliases: ['case-sensitivity'] |
| 156 |
type: str |
| 157 |
description: Enable/disable case sensitivity when matching header. |
| 158 |
choices: ['disable', 'enable'] |
| 159 |
header: |
| 160 |
type: str |
| 161 |
description: HTTP header regular expression. |
| 162 |
header_name: |
| 163 |
aliases: ['header-name'] |
| 164 |
type: str |
| 165 |
description: HTTP header. |
| 166 |
id: |
| 167 |
type: int |
| 168 |
description: ID. |
| 169 |
host: |
| 170 |
type: str |
| 171 |
description: Address object for the host. |
| 172 |
http_resp_status_code: |
| 173 |
aliases: ['http-resp-status-code'] |
| 174 |
type: raw |
| 175 |
description: (list) HTTP response status code. |
| 176 |
name: |
| 177 |
type: str |
| 178 |
description: Address name. |
| 179 |
204_response: |
| 180 |
aliases: ['204-response'] |
| 181 |
type: str |
| 182 |
description: Enable/disable allowance of 204 response from ICAP server. |
| 183 |
choices: ['disable', 'enable'] |
| 184 |
204_size_limit: |
| 185 |
aliases: ['204-size-limit'] |
| 186 |
type: int |
| 187 |
description: 204 response size limit to be saved by ICAP client in megabytes |
| 188 |
chunk_encap: |
| 189 |
aliases: ['chunk-encap'] |
| 190 |
type: str |
| 191 |
description: Enable/disable chunked encapsulation |
| 192 |
choices: ['disable', 'enable'] |
| 193 |
extension_feature: |
| 194 |
aliases: ['extension-feature'] |
| 195 |
type: list |
| 196 |
elements: str |
| 197 |
description: Enable/disable ICAP extension features. |
| 198 |
choices: ['scan-progress'] |
| 199 |
file_transfer: |
| 200 |
aliases: ['file-transfer'] |
| 201 |
type: list |
| 202 |
elements: str |
| 203 |
description: Configure the file transfer protocols to pass transferred files to an ICAP server as REQMOD. |
| 204 |
choices: ['ssh', 'ftp'] |
| 205 |
file_transfer_failure: |
| 206 |
aliases: ['file-transfer-failure'] |
| 207 |
type: str |
| 208 |
description: Action to take if the ICAP server cannot be contacted when processing a file transfer. |
| 209 |
choices: ['error', 'bypass'] |
| 210 |
file_transfer_path: |
| 211 |
aliases: ['file-transfer-path'] |
| 212 |
type: str |
| 213 |
description: Path component of the ICAP URI that identifies the file transfer processing service. |
| 214 |
file_transfer_server: |
| 215 |
aliases: ['file-transfer-server'] |
| 216 |
type: str |
| 217 |
description: ICAP server to use for a file transfer. |
| 218 |
icap_block_log: |
| 219 |
aliases: ['icap-block-log'] |
| 220 |
type: str |
| 221 |
description: Enable/disable UTM log when infection found |
| 222 |
choices: ['disable', 'enable'] |
| 223 |
scan_progress_interval: |
| 224 |
aliases: ['scan-progress-interval'] |
| 225 |
type: int |
| 226 |
description: Scan progress interval value. |
| 227 |
timeout: |
| 228 |
type: int |
| 229 |
description: Time |
| 230 |
comment: |
| 231 |
type: str |
| 232 |
description: Comment. |
| 233 |
ocr-only: |
| 234 |
type: str |
| 235 |
description: Deprecated, please rename it to ocr_only. Enable/disable this FortiGate unit to submit only OCR interested content to the ... |
| 236 |
choices: ['disable', 'enable'] |
| 237 |
ocr_only: |
| 238 |
type: str |
| 239 |
description: Ocr only. |
| 240 |
choices: ['disable', 'enable'] |
| 241 |
scan_oversize_log: |
| 242 |
aliases: ['scan-oversize-log'] |
| 243 |
type: str |
| 244 |
description: Scan oversize log. |
| 245 |
choices: ['disable', 'enable'] |
| 246 |
scan_size_limit: |
| 247 |
aliases: ['scan-size-limit'] |
| 248 |
type: int |
| 249 |
description: Scan size limit. |
| 250 |
allow_204_response: |
| 251 |
aliases: ['allow-204-response'] |
| 252 |
type: str |
| 253 |
description: Enable/disable allowing of 204 response from icap server. |
| 254 |
choices: ['disable', 'enable'] |
| 255 |
''' |
| 256 |
|
| 257 |
EXAMPLES = ''' |
| 258 |
- name: Example playbook (generated based on argument schema) |
| 259 |
hosts: fortimanagers |
| 260 |
connection: httpapi |
| 261 |
gather_facts: false |
| 262 |
tasks: |
| 263 |
- name: Configure ICAP profiles. |
| 264 |
fortinet.fortimanager.fmgr_icap_profile: |
| 265 |
# workspace_locking_adom: <global or your adom name> |
| 266 |
adom: <your own value> |
| 267 |
state: present # <value in [present, absent]> |
| 268 |
icap_profile: |
| 269 |
name: "your value" # Required variable, string |
| 270 |
# methods: ["delete", "get", "head", "options", "post", "put", "trace", "other", |
| 271 |
# "connect"] |
| 272 |
# replacemsg_group: <string> |
| 273 |
# request: <value in [disable, enable]> |
| 274 |
# request_failure: <value in [error, bypass]> |
| 275 |
# request_path: <string> |
| 276 |
# request_server: <string> |
| 277 |
# response: <value in [disable, enable]> |
| 278 |
# response_failure: <value in [error, bypass]> |
| 279 |
# response_path: <string> |
| 280 |
# response_server: <string> |
| 281 |
# streaming_content_bypass: <value in [disable, enable]> |
| 282 |
# icap_headers: |
| 283 |
# - base64_encoding: <value in [disable, enable]> |
| 284 |
# content: <string> |
| 285 |
# id: <integer> |
| 286 |
# name: <string> |
| 287 |
# http_header: <string> |
| 288 |
# sesson_info_type: <value in [client-ip, user, upn, ...]> |
| 289 |
# source: <value in [content, http-header, session]> |
| 290 |
# preview: <value in [disable, enable]> |
| 291 |
# preview_data_length: <integer> |
| 292 |
# response_req_hdr: <value in [disable, enable]> |
| 293 |
# respmod_default_action: <value in [bypass, forward]> |
| 294 |
# respmod_forward_rules: |
| 295 |
# - action: <value in [bypass, forward]> |
| 296 |
# header_group: |
| 297 |
# - case_sensitivity: <value in [disable, enable]> |
| 298 |
# header: <string> |
| 299 |
# header_name: <string> |
| 300 |
# id: <integer> |
| 301 |
# host: <string> |
| 302 |
# http_resp_status_code: <list or integer> |
| 303 |
# name: <string> |
| 304 |
# 204_response: <value in [disable, enable]> |
| 305 |
# 204_size_limit: <integer> |
| 306 |
# chunk_encap: <value in [disable, enable]> |
| 307 |
# extension_feature: ["scan-progress"] |
| 308 |
# file_transfer: ["ssh", "ftp"] |
| 309 |
# file_transfer_failure: <value in [error, bypass]> |
| 310 |
# file_transfer_path: <string> |
| 311 |
# file_transfer_server: <string> |
| 312 |
# icap_block_log: <value in [disable, enable]> |
| 313 |
# scan_progress_interval: <integer> |
| 314 |
# timeout: <integer> |
| 315 |
# comment: <string> |
| 316 |
# ocr_only: <value in [disable, enable]> |
| 317 |
# ocr_only: <value in [disable, enable]> |
| 318 |
# scan_oversize_log: <value in [disable, enable]> |
| 319 |
# scan_size_limit: <integer> |
| 320 |
# allow_204_response: <value in [disable, enable]> |
| 321 |
''' |
| 322 |
|
| 323 |
RETURN = ''' |
| 324 |
meta: |
| 325 |
description: The result of the request. |
| 326 |
type: dict |
| 327 |
returned: always |
| 328 |
contains: |
| 329 |
request_url: |
| 330 |
description: The full url requested. |
| 331 |
returned: always |
| 332 |
type: str |
| 333 |
sample: /sys/login/user |
| 334 |
response_code: |
| 335 |
description: The status of api request. |
| 336 |
returned: always |
| 337 |
type: int |
| 338 |
sample: 0 |
| 339 |
response_data: |
| 340 |
description: The api response. |
| 341 |
type: list |
| 342 |
returned: always |
| 343 |
response_message: |
| 344 |
description: The descriptive message of the api response. |
| 345 |
type: str |
| 346 |
returned: always |
| 347 |
sample: OK. |
| 348 |
system_information: |
| 349 |
description: The information of the target system. |
| 350 |
type: dict |
| 351 |
returned: always |
| 352 |
rc: |
| 353 |
description: The status the request. |
| 354 |
type: int |
| 355 |
returned: always |
| 356 |
sample: 0 |
| 357 |
version_check_warning: |
| 358 |
description: Warning if the parameters used in the playbook are not supported by the current FortiManager version. |
| 359 |
type: list |
| 360 |
returned: complex |
| 361 |
''' |
| 362 |
from ansible.module_utils.basic import AnsibleModule |
| 363 |
from ansible.module_utils.connection import Connection |
| 364 |
from ansible_collections.fortinet.fortimanager.plugins.module_utils.napi import NAPIManager, check_galaxy_version, check_parameter_bypass |
| 365 |
from ansible_collections.fortinet.fortimanager.plugins.module_utils.common import get_module_arg_spec |
| 366 |
|
| 367 |
|
| 368 |
def main(): |
| 369 |
urls_list = [ |
| 370 |
'/pm/config/adom/{adom}/obj/icap/profile', |
| 371 |
'/pm/config/global/obj/icap/profile' |
| 372 |
] |
| 373 |
module_arg_spec = { |
| 374 |
'adom': {'required': True, 'type': 'str'}, |
| 375 |
'revision_note': {'type': 'str'}, |
| 376 |
'icap_profile': { |
| 377 |
'type': 'dict', 'v_range': [['6.0.0', '']], |
| 378 |
'options': { |
| 379 |
'methods': { |
| 380 |
'type': 'list', |
| 381 |
'choices': ['delete', 'get', 'head', 'options', 'post', 'put', 'trace', 'other', 'connect'], |
| 382 |
'elements': 'str' |
| 383 |
}, |
| 384 |
'name': {'required': True, 'type': 'str'}, |
| 385 |
'replacemsg-group': {'type': 'str'}, |
| 386 |
'request': {'choices': ['disable', 'enable'], 'type': 'str'}, |
| 387 |
'request-failure': {'choices': ['error', 'bypass'], 'type': 'str'}, |
| 388 |
'request-path': {'type': 'str'}, |
| 389 |
'request-server': {'type': 'str'}, |
| 390 |
'response': {'choices': ['disable', 'enable'], 'type': 'str'}, |
| 391 |
'response-failure': {'choices': ['error', 'bypass'], 'type': 'str'}, |
| 392 |
'response-path': {'type': 'str'}, |
| 393 |
'response-server': {'type': 'str'}, |
| 394 |
'streaming-content-bypass': {'choices': ['disable', 'enable'], 'type': 'str'}, |
| 395 |
'icap-headers': { |
| 396 |
'v_range': [['6.2.0', '']], |
| 397 |
'type': 'list', |
| 398 |
'options': { |
| 399 |
'base64-encoding': {'v_range': [['6.2.0', '']], 'choices': ['disable', 'enable'], 'type': 'str'}, |
| 400 |
'content': {'v_range': [['6.2.0', '']], 'type': 'str'}, |
| 401 |
'id': {'v_range': [['6.2.0', '']], 'type': 'int'}, |
| 402 |
'name': {'v_range': [['6.2.0', '']], 'type': 'str'}, |
| 403 |
'http-header': {'v_range': [['7.4.8', '7.4.10'], ['7.6.4', '']], 'type': 'str'}, |
| 404 |
'sesson-info-type': { |
| 405 |
'v_range': [['7.4.8', '7.4.10'], ['7.6.4', '']], |
| 406 |
'choices': ['client-ip', 'user', 'upn', 'domain', 'local-grp', 'remote-grp', 'proxy-name', 'auth-user-uri', 'auth-group-uri'], |
| 407 |
'type': 'str' |
| 408 |
}, |
| 409 |
'source': {'v_range': [['7.4.8', '7.4.10'], ['7.6.4', '']], 'choices': ['content', 'http-header', 'session'], 'type': 'str'} |
| 410 |
}, |
| 411 |
'elements': 'dict' |
| 412 |
}, |
| 413 |
'preview': {'v_range': [['6.2.0', '']], 'choices': ['disable', 'enable'], 'type': 'str'}, |
| 414 |
'preview-data-length': {'v_range': [['6.2.0', '']], 'type': 'int'}, |
| 415 |
'response-req-hdr': {'v_range': [['6.2.0', '']], 'choices': ['disable', 'enable'], 'type': 'str'}, |
| 416 |
'respmod-default-action': {'v_range': [['6.4.0', '']], 'choices': ['bypass', 'forward'], 'type': 'str'}, |
| 417 |
'respmod-forward-rules': { |
| 418 |
'v_range': [['6.4.0', '']], |
| 419 |
'type': 'list', |
| 420 |
'options': { |
| 421 |
'action': {'v_range': [['6.4.0', '']], 'choices': ['bypass', 'forward'], 'type': 'str'}, |
| 422 |
'header-group': { |
| 423 |
'v_range': [['6.4.0', '']], |
| 424 |
'type': 'list', |
| 425 |
'options': { |
| 426 |
'case-sensitivity': {'v_range': [['6.4.0', '']], 'choices': ['disable', 'enable'], 'type': 'str'}, |
| 427 |
'header': {'v_range': [['6.4.0', '']], 'type': 'str'}, |
| 428 |
'header-name': {'v_range': [['6.4.0', '']], 'type': 'str'}, |
| 429 |
'id': {'v_range': [['6.4.0', '']], 'type': 'int'} |
| 430 |
}, |
| 431 |
'elements': 'dict' |
| 432 |
}, |
| 433 |
'host': {'v_range': [['6.4.0', '']], 'type': 'str'}, |
| 434 |
'http-resp-status-code': {'v_range': [['6.4.0', '']], 'type': 'raw'}, |
| 435 |
'name': {'v_range': [['6.4.0', '']], 'type': 'str'} |
| 436 |
}, |
| 437 |
'elements': 'dict' |
| 438 |
}, |
| 439 |
'204-response': {'v_range': [['7.2.0', '']], 'choices': ['disable', 'enable'], 'type': 'str'}, |
| 440 |
'204-size-limit': {'v_range': [['7.2.0', '']], 'type': 'int'}, |
| 441 |
'chunk-encap': {'v_range': [['7.0.2', '']], 'choices': ['disable', 'enable'], 'type': 'str'}, |
| 442 |
'extension-feature': {'v_range': [['7.0.2', '']], 'type': 'list', 'choices': ['scan-progress'], 'elements': 'str'}, |
| 443 |
'file-transfer': {'v_range': [['7.2.0', '']], 'type': 'list', 'choices': ['ssh', 'ftp'], 'elements': 'str'}, |
| 444 |
'file-transfer-failure': {'v_range': [['7.2.0', '']], 'choices': ['error', 'bypass'], 'type': 'str'}, |
| 445 |
'file-transfer-path': {'v_range': [['7.2.0', '']], 'type': 'str'}, |
| 446 |
'file-transfer-server': {'v_range': [['7.2.0', '']], 'type': 'str'}, |
| 447 |
'icap-block-log': {'v_range': [['7.0.1', '']], 'choices': ['disable', 'enable'], 'type': 'str'}, |
| 448 |
'scan-progress-interval': {'v_range': [['7.0.2', '']], 'type': 'int'}, |
| 449 |
'timeout': {'v_range': [['7.2.0', '']], 'type': 'int'}, |
| 450 |
'comment': {'v_range': [['7.2.2', '']], 'type': 'str'}, |
| 451 |
'ocr-only': {'v_range': [['7.6.2', '']], 'choices': ['disable', 'enable'], 'type': 'str'}, |
| 452 |
'ocr_only': {'v_range': [['7.4.8', '7.4.10'], ['7.6.4', '']], 'choices': ['disable', 'enable'], 'type': 'str'}, |
| 453 |
'scan-oversize-log': {'v_range': [['7.4.8', '7.4.10'], ['7.6.4', '']], 'choices': ['disable', 'enable'], 'type': 'str'}, |
| 454 |
'scan-size-limit': {'v_range': [['7.4.8', '7.4.10'], ['7.6.4', '']], 'type': 'int'}, |
| 455 |
'allow-204-response': {'v_range': [['7.4.8', '7.4.10'], ['7.6.4', '']], 'choices': ['disable', 'enable'], 'type': 'str'} |
| 456 |
} |
| 457 |
} |
| 458 |
} |
| 459 |
|
| 460 |
module_option_spec = get_module_arg_spec('full crud') |
| 461 |
module_arg_spec.update(module_option_spec) |
| 462 |
check_galaxy_version(module_arg_spec) |
| 463 |
module = AnsibleModule(argument_spec=check_parameter_bypass(module_arg_spec, 'icap_profile'), |
| 464 |
supports_check_mode=True) |
| 465 |
if not module._socket_path: |
| 466 |
module.fail_json(msg='MUST RUN IN HTTPAPI MODE') |
| 467 |
connection = Connection(module._socket_path) |
| 468 |
fmgr = NAPIManager('full crud', module_arg_spec, urls_list, |
| 469 |
'name', 'data', module, connection) |
| 470 |
fmgr.process_crud() |
| 471 |
module.exit_json(meta=module.params) |
| 472 |
|
| 473 |
|
| 474 |
if __name__ == '__main__': |
| 475 |
main() |