| 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_waf_profile_method |
| 15 |
short_description: Method restriction. |
| 16 |
version_added: "2.0.0" |
| 17 |
extends_documentation_fragment: |
| 18 |
- fortinet.fortimanager.general |
| 19 |
- fortinet.fortimanager.general.partial_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 |
profile: |
| 29 |
description: The parameter (profile) in requested url. |
| 30 |
type: str |
| 31 |
required: true |
| 32 |
waf_profile_method: |
| 33 |
description: The top level parameters set. |
| 34 |
required: false |
| 35 |
type: dict |
| 36 |
suboptions: |
| 37 |
default_allowed_methods: |
| 38 |
aliases: ['default-allowed-methods'] |
| 39 |
type: list |
| 40 |
elements: str |
| 41 |
description: Methods. |
| 42 |
choices: ['delete', 'get', 'head', 'options', 'post', 'put', 'trace', 'others', |
| 43 |
'connect'] |
| 44 |
log: |
| 45 |
type: str |
| 46 |
description: Enable/disable logging. |
| 47 |
choices: ['disable', 'enable'] |
| 48 |
method_policy: |
| 49 |
aliases: ['method-policy'] |
| 50 |
type: list |
| 51 |
elements: dict |
| 52 |
description: Method policy. |
| 53 |
suboptions: |
| 54 |
address: |
| 55 |
type: str |
| 56 |
description: Host address. |
| 57 |
allowed_methods: |
| 58 |
aliases: ['allowed-methods'] |
| 59 |
type: list |
| 60 |
elements: str |
| 61 |
description: Allowed Methods. |
| 62 |
choices: ['delete', 'get', 'head', 'options', 'post', 'put', 'trace', |
| 63 |
'others', 'connect'] |
| 64 |
id: |
| 65 |
type: int |
| 66 |
description: HTTP method policy ID. |
| 67 |
pattern: |
| 68 |
type: str |
| 69 |
description: URL pattern. |
| 70 |
regex: |
| 71 |
type: str |
| 72 |
description: Enable/disable regular expression based pattern match. |
| 73 |
choices: ['disable', 'enable'] |
| 74 |
severity: |
| 75 |
type: str |
| 76 |
description: Severity. |
| 77 |
choices: ['low', 'medium', 'high'] |
| 78 |
status: |
| 79 |
type: str |
| 80 |
description: Status. |
| 81 |
choices: ['disable', 'enable'] |
| 82 |
''' |
| 83 |
|
| 84 |
EXAMPLES = ''' |
| 85 |
- name: Example playbook (generated based on argument schema) |
| 86 |
hosts: fortimanagers |
| 87 |
connection: httpapi |
| 88 |
gather_facts: false |
| 89 |
tasks: |
| 90 |
- name: Method restriction. |
| 91 |
fortinet.fortimanager.fmgr_waf_profile_method: |
| 92 |
# workspace_locking_adom: <global or your adom name> |
| 93 |
adom: <your own value> |
| 94 |
profile: <your own value> |
| 95 |
waf_profile_method: |
| 96 |
# default_allowed_methods: ["delete", "get", "head", "options", "post", "put", "trace", |
| 97 |
# "others", "connect"] |
| 98 |
# log: <value in [disable, enable]> |
| 99 |
# method_policy: |
| 100 |
# - address: <string> |
| 101 |
# allowed_methods: ["delete", "get", "head", "options", "post", "put", "trace", |
| 102 |
# "others", "connect"] |
| 103 |
# id: <integer> |
| 104 |
# pattern: <string> |
| 105 |
# regex: <value in [disable, enable]> |
| 106 |
# severity: <value in [low, medium, high]> |
| 107 |
# status: <value in [disable, enable]> |
| 108 |
''' |
| 109 |
|
| 110 |
RETURN = ''' |
| 111 |
meta: |
| 112 |
description: The result of the request. |
| 113 |
type: dict |
| 114 |
returned: always |
| 115 |
contains: |
| 116 |
request_url: |
| 117 |
description: The full url requested. |
| 118 |
returned: always |
| 119 |
type: str |
| 120 |
sample: /sys/login/user |
| 121 |
response_code: |
| 122 |
description: The status of api request. |
| 123 |
returned: always |
| 124 |
type: int |
| 125 |
sample: 0 |
| 126 |
response_data: |
| 127 |
description: The api response. |
| 128 |
type: list |
| 129 |
returned: always |
| 130 |
response_message: |
| 131 |
description: The descriptive message of the api response. |
| 132 |
type: str |
| 133 |
returned: always |
| 134 |
sample: OK. |
| 135 |
system_information: |
| 136 |
description: The information of the target system. |
| 137 |
type: dict |
| 138 |
returned: always |
| 139 |
rc: |
| 140 |
description: The status the request. |
| 141 |
type: int |
| 142 |
returned: always |
| 143 |
sample: 0 |
| 144 |
version_check_warning: |
| 145 |
description: Warning if the parameters used in the playbook are not supported by the current FortiManager version. |
| 146 |
type: list |
| 147 |
returned: complex |
| 148 |
''' |
| 149 |
from ansible.module_utils.basic import AnsibleModule |
| 150 |
from ansible.module_utils.connection import Connection |
| 151 |
from ansible_collections.fortinet.fortimanager.plugins.module_utils.napi import NAPIManager, check_galaxy_version, check_parameter_bypass |
| 152 |
from ansible_collections.fortinet.fortimanager.plugins.module_utils.common import get_module_arg_spec |
| 153 |
|
| 154 |
|
| 155 |
def main(): |
| 156 |
urls_list = [ |
| 157 |
'/pm/config/adom/{adom}/obj/waf/profile/{profile}/method', |
| 158 |
'/pm/config/global/obj/waf/profile/{profile}/method' |
| 159 |
] |
| 160 |
module_arg_spec = { |
| 161 |
'adom': {'required': True, 'type': 'str'}, |
| 162 |
'profile': {'required': True, 'type': 'str'}, |
| 163 |
'revision_note': {'type': 'str'}, |
| 164 |
'waf_profile_method': { |
| 165 |
'type': 'dict', 'v_range': [['6.0.0', '']], |
| 166 |
'options': { |
| 167 |
'default-allowed-methods': { |
| 168 |
'type': 'list', |
| 169 |
'choices': ['delete', 'get', 'head', 'options', 'post', 'put', 'trace', 'others', 'connect'], |
| 170 |
'elements': 'str' |
| 171 |
}, |
| 172 |
'log': {'choices': ['disable', 'enable'], 'type': 'str'}, |
| 173 |
'method-policy': { |
| 174 |
'type': 'list', |
| 175 |
'options': { |
| 176 |
'address': {'type': 'str'}, |
| 177 |
'allowed-methods': { |
| 178 |
'type': 'list', |
| 179 |
'choices': ['delete', 'get', 'head', 'options', 'post', 'put', 'trace', 'others', 'connect'], |
| 180 |
'elements': 'str' |
| 181 |
}, |
| 182 |
'id': {'type': 'int'}, |
| 183 |
'pattern': {'type': 'str'}, |
| 184 |
'regex': {'choices': ['disable', 'enable'], 'type': 'str'} |
| 185 |
}, |
| 186 |
'elements': 'dict' |
| 187 |
}, |
| 188 |
'severity': {'choices': ['low', 'medium', 'high'], 'type': 'str'}, |
| 189 |
'status': {'choices': ['disable', 'enable'], 'type': 'str'} |
| 190 |
} |
| 191 |
} |
| 192 |
} |
| 193 |
|
| 194 |
module_option_spec = get_module_arg_spec('partial crud') |
| 195 |
module_arg_spec.update(module_option_spec) |
| 196 |
check_galaxy_version(module_arg_spec) |
| 197 |
module = AnsibleModule(argument_spec=check_parameter_bypass(module_arg_spec, 'waf_profile_method'), |
| 198 |
supports_check_mode=True) |
| 199 |
if not module._socket_path: |
| 200 |
module.fail_json(msg='MUST RUN IN HTTPAPI MODE') |
| 201 |
connection = Connection(module._socket_path) |
| 202 |
fmgr = NAPIManager('partial crud', module_arg_spec, urls_list, |
| 203 |
None, 'data', module, connection) |
| 204 |
fmgr.process_partial_crud() |
| 205 |
module.exit_json(meta=module.params) |
| 206 |
|
| 207 |
|
| 208 |
if __name__ == '__main__': |
| 209 |
main() |