Debian Codegraph @

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