| 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_casb_useractivity_match |
| 15 |
short_description: CASB user activity match rules. |
| 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 |
user-activity: |
| 29 |
description: Deprecated, please use "user_activity" |
| 30 |
type: str |
| 31 |
user_activity: |
| 32 |
description: The parameter (user-activity) in requested url. |
| 33 |
type: str |
| 34 |
casb_useractivity_match: |
| 35 |
description: The top level parameters set. |
| 36 |
required: false |
| 37 |
type: dict |
| 38 |
suboptions: |
| 39 |
id: |
| 40 |
type: int |
| 41 |
description: CASB user activity match rules ID. |
| 42 |
required: true |
| 43 |
rules: |
| 44 |
type: list |
| 45 |
elements: dict |
| 46 |
description: Rules. |
| 47 |
suboptions: |
| 48 |
case_sensitive: |
| 49 |
aliases: ['case-sensitive'] |
| 50 |
type: str |
| 51 |
description: CASB user activity match case sensitive. |
| 52 |
choices: ['disable', 'enable'] |
| 53 |
domains: |
| 54 |
type: list |
| 55 |
elements: str |
| 56 |
description: CASB user activity domain list. |
| 57 |
header_name: |
| 58 |
aliases: ['header-name'] |
| 59 |
type: str |
| 60 |
description: CASB user activity rule header name. |
| 61 |
id: |
| 62 |
type: int |
| 63 |
description: CASB user activity rule ID. |
| 64 |
match_pattern: |
| 65 |
aliases: ['match-pattern'] |
| 66 |
type: str |
| 67 |
description: CASB user activity rule match pattern. |
| 68 |
choices: ['simple', 'substr', 'regexp'] |
| 69 |
match_value: |
| 70 |
aliases: ['match-value'] |
| 71 |
type: str |
| 72 |
description: CASB user activity rule match value. |
| 73 |
methods: |
| 74 |
type: list |
| 75 |
elements: str |
| 76 |
description: CASB user activity method list. |
| 77 |
negate: |
| 78 |
type: str |
| 79 |
description: Enable/disable what the matching strategy must not be. |
| 80 |
choices: ['disable', 'enable'] |
| 81 |
type: |
| 82 |
type: str |
| 83 |
description: CASB user activity rule type. |
| 84 |
choices: ['domains', 'host', 'path', 'header', 'header-value', 'method', |
| 85 |
'body'] |
| 86 |
body_type: |
| 87 |
aliases: ['body-type'] |
| 88 |
type: str |
| 89 |
description: CASB user activity match rule body type. |
| 90 |
choices: ['json'] |
| 91 |
jq: |
| 92 |
type: str |
| 93 |
description: CASB user activity rule match jq script. |
| 94 |
strategy: |
| 95 |
type: str |
| 96 |
description: CASB user activity rules strategy. |
| 97 |
choices: ['or', 'and'] |
| 98 |
tenant_extraction: |
| 99 |
aliases: ['tenant-extraction'] |
| 100 |
type: dict |
| 101 |
description: Tenant extraction. |
| 102 |
suboptions: |
| 103 |
filters: |
| 104 |
type: list |
| 105 |
elements: dict |
| 106 |
description: Filters. |
| 107 |
suboptions: |
| 108 |
body_type: |
| 109 |
aliases: ['body-type'] |
| 110 |
type: str |
| 111 |
description: CASB tenant extraction filter body type. |
| 112 |
choices: ['json'] |
| 113 |
direction: |
| 114 |
type: str |
| 115 |
description: CASB tenant extraction filter direction. |
| 116 |
choices: ['request', 'response'] |
| 117 |
header_name: |
| 118 |
aliases: ['header-name'] |
| 119 |
type: str |
| 120 |
description: CASB tenant extraction filter header name. |
| 121 |
id: |
| 122 |
type: int |
| 123 |
description: CASB tenant extraction filter ID. |
| 124 |
place: |
| 125 |
type: str |
| 126 |
description: CASB tenant extraction filter place type. |
| 127 |
choices: ['path', 'header', 'body'] |
| 128 |
jq: |
| 129 |
type: str |
| 130 |
description: CASB user activity tenant extraction jq script. |
| 131 |
status: |
| 132 |
type: str |
| 133 |
description: Enable/disable CASB tenant extraction. |
| 134 |
choices: ['disable', 'enable'] |
| 135 |
type: |
| 136 |
type: str |
| 137 |
description: CASB user activity tenant extraction type. |
| 138 |
choices: ['json-query'] |
| 139 |
''' |
| 140 |
|
| 141 |
EXAMPLES = ''' |
| 142 |
- name: Example playbook (generated based on argument schema) |
| 143 |
hosts: fortimanagers |
| 144 |
connection: httpapi |
| 145 |
gather_facts: false |
| 146 |
tasks: |
| 147 |
- name: CASB user activity match rules. |
| 148 |
fortinet.fortimanager.fmgr_casb_useractivity_match: |
| 149 |
# workspace_locking_adom: <global or your adom name> |
| 150 |
adom: <your own value> |
| 151 |
user_activity: <your own value> |
| 152 |
state: present # <value in [present, absent]> |
| 153 |
casb_useractivity_match: |
| 154 |
id: 0 # Required variable, integer |
| 155 |
# rules: |
| 156 |
# - case_sensitive: <value in [disable, enable]> |
| 157 |
# domains: <list or string> |
| 158 |
# header_name: <string> |
| 159 |
# id: <integer> |
| 160 |
# match_pattern: <value in [simple, substr, regexp]> |
| 161 |
# match_value: <string> |
| 162 |
# methods: <list or string> |
| 163 |
# negate: <value in [disable, enable]> |
| 164 |
# type: <value in [domains, host, path, ...]> |
| 165 |
# body_type: <value in [json]> |
| 166 |
# jq: <string> |
| 167 |
# strategy: <value in [or, and]> |
| 168 |
# tenant_extraction: |
| 169 |
# filters: |
| 170 |
# - body_type: <value in [json]> |
| 171 |
# direction: <value in [request, response]> |
| 172 |
# header_name: <string> |
| 173 |
# id: <integer> |
| 174 |
# place: <value in [path, header, body]> |
| 175 |
# jq: <string> |
| 176 |
# status: <value in [disable, enable]> |
| 177 |
# type: <value in [json-query]> |
| 178 |
''' |
| 179 |
|
| 180 |
RETURN = ''' |
| 181 |
meta: |
| 182 |
description: The result of the request. |
| 183 |
type: dict |
| 184 |
returned: always |
| 185 |
contains: |
| 186 |
request_url: |
| 187 |
description: The full url requested. |
| 188 |
returned: always |
| 189 |
type: str |
| 190 |
sample: /sys/login/user |
| 191 |
response_code: |
| 192 |
description: The status of api request. |
| 193 |
returned: always |
| 194 |
type: int |
| 195 |
sample: 0 |
| 196 |
response_data: |
| 197 |
description: The api response. |
| 198 |
type: list |
| 199 |
returned: always |
| 200 |
response_message: |
| 201 |
description: The descriptive message of the api response. |
| 202 |
type: str |
| 203 |
returned: always |
| 204 |
sample: OK. |
| 205 |
system_information: |
| 206 |
description: The information of the target system. |
| 207 |
type: dict |
| 208 |
returned: always |
| 209 |
rc: |
| 210 |
description: The status the request. |
| 211 |
type: int |
| 212 |
returned: always |
| 213 |
sample: 0 |
| 214 |
version_check_warning: |
| 215 |
description: Warning if the parameters used in the playbook are not supported by the current FortiManager version. |
| 216 |
type: list |
| 217 |
returned: complex |
| 218 |
''' |
| 219 |
from ansible.module_utils.basic import AnsibleModule |
| 220 |
from ansible.module_utils.connection import Connection |
| 221 |
from ansible_collections.fortinet.fortimanager.plugins.module_utils.napi import NAPIManager, check_galaxy_version, check_parameter_bypass |
| 222 |
from ansible_collections.fortinet.fortimanager.plugins.module_utils.common import get_module_arg_spec |
| 223 |
|
| 224 |
|
| 225 |
def main(): |
| 226 |
urls_list = [ |
| 227 |
'/pm/config/adom/{adom}/obj/casb/user-activity/{user-activity}/match', |
| 228 |
'/pm/config/global/obj/casb/user-activity/{user-activity}/match' |
| 229 |
] |
| 230 |
module_arg_spec = { |
| 231 |
'adom': {'required': True, 'type': 'str'}, |
| 232 |
'user-activity': {'type': 'str', 'api_name': 'user_activity'}, |
| 233 |
'user_activity': {'type': 'str'}, |
| 234 |
'revision_note': {'type': 'str'}, |
| 235 |
'casb_useractivity_match': { |
| 236 |
'type': 'dict', 'v_range': [['7.4.1', '']], |
| 237 |
'options': { |
| 238 |
'id': {'v_range': [['7.4.1', '']], 'required': True, 'type': 'int'}, |
| 239 |
'rules': { |
| 240 |
'v_range': [['7.4.1', '']], |
| 241 |
'type': 'list', |
| 242 |
'options': { |
| 243 |
'case-sensitive': {'v_range': [['7.4.1', '']], 'choices': ['disable', 'enable'], 'type': 'str'}, |
| 244 |
'domains': {'v_range': [['7.4.1', '']], 'type': 'list', 'elements': 'str'}, |
| 245 |
'header-name': {'v_range': [['7.4.1', '']], 'type': 'str'}, |
| 246 |
'id': {'v_range': [['7.4.1', '']], 'type': 'int'}, |
| 247 |
'match-pattern': {'v_range': [['7.4.1', '']], 'choices': ['simple', 'substr', 'regexp'], 'type': 'str'}, |
| 248 |
'match-value': {'v_range': [['7.4.1', '']], 'type': 'str'}, |
| 249 |
'methods': {'v_range': [['7.4.1', '']], 'type': 'list', 'elements': 'str'}, |
| 250 |
'negate': {'v_range': [['7.4.1', '']], 'choices': ['disable', 'enable'], 'type': 'str'}, |
| 251 |
'type': { |
| 252 |
'v_range': [['7.4.1', '']], |
| 253 |
'choices': ['domains', 'host', 'path', 'header', 'header-value', 'method', 'body'], |
| 254 |
'type': 'str' |
| 255 |
}, |
| 256 |
'body-type': {'v_range': [['7.6.2', '']], 'choices': ['json'], 'type': 'str'}, |
| 257 |
'jq': {'v_range': [['7.6.2', '']], 'type': 'str'} |
| 258 |
}, |
| 259 |
'elements': 'dict' |
| 260 |
}, |
| 261 |
'strategy': {'v_range': [['7.4.1', '']], 'choices': ['or', 'and'], 'type': 'str'}, |
| 262 |
'tenant-extraction': { |
| 263 |
'v_range': [['7.6.2', '']], |
| 264 |
'type': 'dict', |
| 265 |
'options': { |
| 266 |
'filters': { |
| 267 |
'v_range': [['7.6.2', '']], |
| 268 |
'type': 'list', |
| 269 |
'options': { |
| 270 |
'body-type': {'v_range': [['7.6.2', '']], 'choices': ['json'], 'type': 'str'}, |
| 271 |
'direction': {'v_range': [['7.6.2', '']], 'choices': ['request', 'response'], 'type': 'str'}, |
| 272 |
'header-name': {'v_range': [['7.6.2', '']], 'type': 'str'}, |
| 273 |
'id': {'v_range': [['7.6.2', '']], 'type': 'int'}, |
| 274 |
'place': {'v_range': [['7.6.2', '']], 'choices': ['path', 'header', 'body'], 'type': 'str'} |
| 275 |
}, |
| 276 |
'elements': 'dict' |
| 277 |
}, |
| 278 |
'jq': {'v_range': [['7.6.2', '']], 'type': 'str'}, |
| 279 |
'status': {'v_range': [['7.6.2', '']], 'choices': ['disable', 'enable'], 'type': 'str'}, |
| 280 |
'type': {'v_range': [['7.6.2', '']], 'choices': ['json-query'], 'type': 'str'} |
| 281 |
} |
| 282 |
} |
| 283 |
} |
| 284 |
} |
| 285 |
} |
| 286 |
|
| 287 |
module_option_spec = get_module_arg_spec('full crud') |
| 288 |
module_arg_spec.update(module_option_spec) |
| 289 |
check_galaxy_version(module_arg_spec) |
| 290 |
module = AnsibleModule(argument_spec=check_parameter_bypass(module_arg_spec, 'casb_useractivity_match'), |
| 291 |
supports_check_mode=True) |
| 292 |
if not module._socket_path: |
| 293 |
module.fail_json(msg='MUST RUN IN HTTPAPI MODE') |
| 294 |
connection = Connection(module._socket_path) |
| 295 |
fmgr = NAPIManager('full crud', module_arg_spec, urls_list, |
| 296 |
'id', 'data', module, connection) |
| 297 |
fmgr.process_crud() |
| 298 |
module.exit_json(meta=module.params) |
| 299 |
|
| 300 |
|
| 301 |
if __name__ == '__main__': |
| 302 |
main() |