Debian Codegraph @

ansible_collections/community/aws/plugins/modules/waf_info.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright (c) 2017 Ansible Project
5 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 DOCUMENTATION = r"""
8 module: waf_info
9 short_description: Retrieve information for WAF ACLs, Rules, Conditions and Filters
10 version_added: 1.0.0
11
12 description:
13 - Retrieve information for WAF ACLs, Rules, Conditions and Filters.
14 - Prior to release 5.0.0 this module was called C(community.aws.aws_waf_info).
15 The usage did not change.
16
17 author:
18 - Mike Mochan (@mmochan)
19 - Will Thames (@willthames)
20
21 deprecated:
22 removed_in: 12.0.0
23 why: Amazon has retired the "WAF Classic" service.
24 alternative: Please use the "AWS WAF (WAFv2)" service and modules instead.
25
26 options:
27 name:
28 description:
29 - The name of a Web Application Firewall.
30 type: str
31 waf_regional:
32 description: Whether to use the C(waf-regional) module.
33 default: false
34 required: false
35 type: bool
36
37 extends_documentation_fragment:
38 - amazon.aws.common.modules
39 - amazon.aws.region.modules
40 - amazon.aws.boto3
41 """
42
43 EXAMPLES = r"""
44 - name: obtain all WAF information
45 community.aws.waf_info:
46
47 - name: obtain all information for a single WAF
48 community.aws.waf_info:
49 name: test_waf
50
51 - name: obtain all information for a single WAF Regional
52 community.aws.waf_info:
53 name: test_waf
54 waf_regional: true
55 """
56
57 RETURN = r"""
58 wafs:
59 description: The WAFs that match the passed arguments.
60 returned: success
61 type: complex
62 contains:
63 name:
64 description: A friendly name or description of the WebACL.
65 returned: always
66 type: str
67 sample: test_waf
68 default_action:
69 description: The action to perform if none of the Rules contained in the WebACL match.
70 returned: always
71 type: int
72 sample: BLOCK
73 metric_name:
74 description: A friendly name or description for the metrics for this WebACL.
75 returned: always
76 type: str
77 sample: test_waf_metric
78 rules:
79 description: An array that contains the action for each Rule in a WebACL , the priority of the Rule.
80 returned: always
81 type: complex
82 contains:
83 action:
84 description: The action to perform if the Rule matches.
85 returned: always
86 type: str
87 sample: BLOCK
88 metric_name:
89 description: A friendly name or description for the metrics for this Rule.
90 returned: always
91 type: str
92 sample: ipblockrule
93 name:
94 description: A friendly name or description of the Rule.
95 returned: always
96 type: str
97 sample: ip_block_rule
98 predicates:
99 description: The Predicates list contains a Predicate for each
100 ByteMatchSet, IPSet, SizeConstraintSet, SqlInjectionMatchSet or XssMatchSet
101 object in a Rule.
102 returned: always
103 type: list
104 sample:
105 [
106 {
107 "byte_match_set_id": "47b822b5-abcd-1234-faaf-1234567890",
108 "byte_match_tuples": [
109 {
110 "field_to_match": {
111 "type": "QUERY_STRING"
112 },
113 "positional_constraint": "STARTS_WITH",
114 "target_string": "bobbins",
115 "text_transformation": "NONE"
116 }
117 ],
118 "name": "bobbins",
119 "negated": false,
120 "type": "ByteMatch"
121 }
122 ]
123 """
124
125 from ansible_collections.amazon.aws.plugins.module_utils.waf import get_web_acl
126 from ansible_collections.amazon.aws.plugins.module_utils.waf import list_web_acls
127
128 from ansible_collections.community.aws.plugins.module_utils.modules import AnsibleCommunityAWSModule as AnsibleAWSModule
129
130
131 def main():
132 argument_spec = dict(
133 name=dict(required=False),
134 waf_regional=dict(type="bool", default=False),
135 )
136 module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True)
137
138 resource = "waf" if not module.params["waf_regional"] else "waf-regional"
139 client = module.client(resource)
140 web_acls = list_web_acls(client, module)
141 name = module.params["name"]
142 if name:
143 web_acls = [web_acl for web_acl in web_acls if web_acl["Name"] == name]
144 if not web_acls:
145 module.fail_json(msg=f"WAF named {name} not found")
146 module.exit_json(wafs=[get_web_acl(client, module, web_acl["WebACLId"]) for web_acl in web_acls])
147
148
149 if __name__ == "__main__":
150 main()