Debian Codegraph @

ansible_collections/azure/azcollection/plugins/modules/azure_rm_applicationfirewallpolicy_info.py

raw symbols SCIP
1 #!/usr/bin/python
2 #
3 # Copyright (c) 2024 xuzhang3 (@xuzhang3), Fred-sun (@Fred-sun)
4 #
5 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 from __future__ import absolute_import, division, print_function
8 __metaclass__ = type
9
10
11 DOCUMENTATION = '''
12 ---
13 module: azure_rm_applicationfirewallpolicy_info
14 version_added: "3.1.0"
15 short_description: Retrieve Application firewall policy instance facts
16 description:
17 - Get or list the application firewall facts.
18 options:
19 name:
20 description:
21 - The name of the application firewall policy's name.
22 type: str
23 resource_group:
24 description:
25 - The name of the resource group.,
26 type: str
27 tags:
28 description:
29 - The application firewall policy's tags key.
30 - For filter the resource.
31 type: list
32 elements: str
33
34 extends_documentation_fragment:
35 - azure.azcollection.azure
36
37 author:
38 - xuzhang3 (@xuzhang3)
39 - Fred-sun (@Fred-sun)
40 '''
41
42 EXAMPLES = '''
43 - name: Get the application firewall policy by name
44 azure_rm_applicationfirewallpolicy_info:
45 name: Myfirewallpolicy01
46 resource_group: MyResourceGroup
47
48 - name: List the application firewall policy by resource group
49 azure_rm_applicationfirewallpolicy_info:
50 resource_group: MyResourceGroup
51
52 - name: List all application firewall policy
53 azure_rm_applicationfirewallpolicy_info:
54 '''
55
56 RETURN = '''
57 firewall_policy:
58 description:
59 - A list of the application firewall policy facts
60 returned: always
61 type: complex
62 contains:
63 id:
64 description:
65 - The application firewall policy's ID.
66 returned: always
67 type: str
68 sample: "/subscriptions/xxx-xxx/resourceGroups/v-xisuRG/providers/Microsoft.Network/ApplicationGatewayWebApplicationFirewallPolicies/firewallpolicy"
69 name:
70 description:
71 - Name of application firewall policy.
72 returned: always
73 type: str
74 sample: firewallpolicy
75 resource_group:
76 description:
77 - Name of resource group.
78 returned: always
79 type: str
80 sample: myResourceGroup
81 location:
82 description:
83 - Location of application firewall policy.
84 returned: always
85 type: str
86 sample: eastus
87 provisioning_state:
88 description:
89 - Provisioning state of application firewall policy.
90 returned: always
91 type: str
92 sample: Succeeded
93 type:
94 description:
95 - The type of the application firewall policy.
96 returned: always
97 type: str
98 sample: Microsoft.Network/ApplicationGatewayWebApplicationFirewallPolicies
99 tags:
100 description:
101 - The application firewall policy tags.
102 type: dict
103 returned: always
104 sample: {"key1": "value1"}
105 custom_rules:
106 description:
107 - The custom rules inside the policy.
108 type: complex
109 returned: when used
110 contains:
111 action:
112 description:
113 - The name of the resource that is unique within a policy.
114 - This name can be used to access the resource.
115 type: str
116 returned: always
117 sample: Block
118 match_conditions:
119 description:
120 - List of match conditions.
121 type: list
122 returned: always
123 sample: [{'match_values': ['10.1.0.4'], 'match_variables': [{'variable_name': 'RemoteAddr'}],
124 'negation_condition': false, 'operator': 'IPMatch', 'transforms': []}]
125 name:
126 description:
127 - The name of the resource that is unique within a policy.
128 - This name can be used to access the resource.
129 type: str
130 returned: always
131 sample: testrule01
132 priority:
133 description:
134 - Priority of the rule.
135 - Rules with a lower value will be evaluated before rules with a higher value.
136 type: int
137 returned: always
138 sample: 33
139 rule_type:
140 description:
141 - The rule type.
142 type: str
143 returned: always
144 sample: MatchRule
145 state:
146 description:
147 - Describes if the custom rule is in enabled or disabled state.
148 type: str
149 returned: always
150 sample: Enabled
151 managed_rules:
152 description:
153 - Describes the managedRules structure.
154 type: complex
155 returned: when used
156 contains:
157 exclusions:
158 description:
159 - The exceptions that are applied on the policy.
160 type: list
161 returned: always
162 sample: []
163 managed_rule_sets:
164 description:
165 - The managed rule sets that are associated with the policy.
166 type: list
167 returned: always
168 sample: [{"rule_group_overrides": [],
169 "rule_set_type": "Microsoft_DefaultRuleSet",
170 "rule_set_version": "2.1"
171 }]
172 policy_settings:
173 description:
174 - The PolicySettings for policy.
175 type: complex
176 returned: when used
177 contains:
178 file_upload_enforcement:
179 description:
180 - Whether allow WAF to enforce file upload limits.
181 type: bool
182 returned: always
183 sample: true
184 file_upload_limit_in_mb:
185 description:
186 - Maximum file upload size in Mb for WAF.
187 type: int
188 returned: always
189 sample: 100
190 js_challenge_cookie_expiration_in_mins:
191 description:
192 - Web Application Firewall JavaScript Challenge Cookie Expiration time in minutes.
193 type: int
194 returned: always
195 sample: 30
196 max_request_body_size_in_kb:
197 description:
198 - Maximum request body size in Kb for WAF.
199 type: int
200 returned: always
201 sample: 128
202 mode:
203 description:
204 - The mode of the policy.
205 type: str
206 returned: always
207 sample: Detection
208 request_body_check:
209 description:
210 - Whether to allow WAF to check request Body.
211 type: bool
212 returned: always
213 sample: false
214 request_body_enforcement:
215 description:
216 - Whether allow WAF to enforce request body limits.
217 type: bool
218 returned: always
219 sample: false
220 state:
221 description:
222 - The state of the policy.
223 type: str
224 returned: always
225 sample: Enabled
226 '''
227
228 from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase
229
230 try:
231 from azure.core.exceptions import ResourceNotFoundError
232 from azure.mgmt.core.tools import parse_resource_id
233 except ImportError:
234 # This is handled in azure_rm_common
235 pass
236
237
238 class AzureRMApplicationFirewallPolicyInfo(AzureRMModuleBase):
239
240 def __init__(self):
241
242 self.module_arg_spec = dict(
243 name=dict(type='str'),
244 resource_group=dict(type='str'),
245 tags=dict(type='list', elements='str')
246 )
247
248 self.results = dict(
249 changed=False,
250 )
251
252 self.name = None
253 self.resource_group = None
254 self.tags = None
255
256 super(AzureRMApplicationFirewallPolicyInfo, self).__init__(self.module_arg_spec,
257 supports_check_mode=True,
258 supports_tags=False,
259 facts_module=True)
260
261 def exec_module(self, **kwargs):
262 for key in self.module_arg_spec:
263 setattr(self, key, kwargs[key])
264
265 if self.name is not None:
266 if self.resource_group is not None:
267 response = self.get()
268 else:
269 self.fail("Missing resource_group when configed name")
270 elif self.resource_group is not None:
271 response = self.list_by_rg()
272 else:
273 response = self.list_all()
274 self.results["firewall_policy"] = [item for item in response if self.has_tags(item.get('tags'), self.tags)]
275 return self.results
276
277 def get(self):
278 response = None
279 results = []
280 try:
281 response = self.network_client.web_application_firewall_policies.get(resource_group_name=self.resource_group, policy_name=self.name)
282 except ResourceNotFoundError:
283 pass
284
285 if response is not None:
286 results.append(self.format_response(response))
287
288 return results
289
290 def list_by_rg(self):
291 response = None
292 results = []
293 try:
294 response = self.network_client.web_application_firewall_policies.list(resource_group_name=self.resource_group)
295 except Exception as exc:
296 self.fail("Error listing web application firewall policy in resource groups {0}: {1}".format(self.resource_group, str(exc)))
297
298 for item in response:
299 results.append(self.format_response(item))
300
301 return results
302
303 def list_all(self):
304 response = None
305 results = []
306 try:
307 response = self.network_client.web_application_firewall_policies.list_all()
308 except Exception as exc:
309 self.fail("Error listing all web application firewall policy: {0}".format(str(exc)))
310
311 for item in response:
312 results.append(self.format_response(item))
313
314 return results
315
316 def format_response(self, item):
317 d = item.as_dict()
318 id_dict = parse_resource_id(item.id)
319 d['resource_group'] = id_dict.get('resource_group')
320
321 return d
322
323
324 def main():
325 AzureRMApplicationFirewallPolicyInfo()
326
327
328 if __name__ == '__main__':
329 main()