Debian Codegraph @

ansible_collections/community/general/plugins/modules/utm_aaa_group.py

raw
1 #!/usr/bin/python
2
3 # Copyright (c) 2018, Johannes Brunswicker <[email protected]>
4 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
5 # SPDX-License-Identifier: GPL-3.0-or-later
6 from __future__ import annotations
7
8 DOCUMENTATION = r"""
9 module: utm_aaa_group
10
11 author:
12 - Johannes Brunswicker (@MatrixCrawler)
13
14 short_description: Create, update or destroy an aaa group object in Sophos UTM
15
16 description:
17 - Create, update or destroy an aaa group object in Sophos UTM.
18 - This module needs to have the REST Ability of the UTM to be activated.
19 attributes:
20 check_mode:
21 support: none
22 diff_mode:
23 support: none
24
25 options:
26 name:
27 description:
28 - The name of the object that identifies the entry.
29 type: str
30 required: true
31 adirectory_groups:
32 description:
33 - List of adirectory group strings.
34 type: list
35 elements: str
36 default: []
37 adirectory_groups_sids:
38 description:
39 - Dictionary of group sids.
40 type: dict
41 default: {}
42 backend_match:
43 description:
44 - The backend for the group.
45 type: str
46 choices:
47 - none
48 - adirectory
49 - edirectory
50 - radius
51 - tacacs
52 - ldap
53 default: none
54 comment:
55 description:
56 - Comment that describes the AAA group.
57 type: str
58 default: ''
59 dynamic:
60 description:
61 - Group type. Is static if none is selected.
62 type: str
63 default: none
64 choices:
65 - none
66 - ipsec_dn
67 - directory_groups
68 edirectory_groups:
69 description:
70 - List of edirectory group strings.
71 type: list
72 elements: str
73 default: []
74 ipsec_dn:
75 description:
76 - The ipsec dn string.
77 type: str
78 default: ''
79 ldap_attribute:
80 description:
81 - The ldap attribute to check against.
82 type: str
83 default: ''
84 ldap_attribute_value:
85 description:
86 - The ldap attribute value to check against.
87 type: str
88 default: ''
89 members:
90 description:
91 - A list of user ref names (aaa/user).
92 type: list
93 elements: str
94 default: []
95 network:
96 description:
97 - The network reference name. The objects contains the known IP addresses for the authentication object (network/aaa).
98 type: str
99 default: ""
100 radius_groups:
101 description:
102 - A list of radius group strings.
103 type: list
104 elements: str
105 default: []
106 tacacs_groups:
107 description:
108 - A list of tacacs group strings.
109 type: list
110 elements: str
111 default: []
112
113 extends_documentation_fragment:
114 - community.general._utm
115 - community.general._attributes
116 """
117
118 EXAMPLES = r"""
119 - name: Create UTM aaa_group
120 community.general.utm_aaa_group:
121 utm_host: sophos.host.name
122 utm_token: abcdefghijklmno1234
123 name: TestAAAGroupEntry
124 backend_match: ldap
125 dynamic: directory_groups
126 ldap_attributes: memberof
127 ldap_attributes_value: "cn=groupname,ou=Groups,dc=mydomain,dc=com"
128 network: REF_OBJECT_STRING
129 state: present
130
131 - name: Remove UTM aaa_group
132 community.general.utm_aaa_group:
133 utm_host: sophos.host.name
134 utm_token: abcdefghijklmno1234
135 name: TestAAAGroupEntry
136 state: absent
137 """
138
139 RETURN = r"""
140 result:
141 description: The utm object that was created.
142 returned: success
143 type: complex
144 contains:
145 _ref:
146 description: The reference name of the object.
147 type: str
148 _locked:
149 description: Whether or not the object is currently locked.
150 type: bool
151 _type:
152 description: The type of the object.
153 type: str
154 name:
155 description: The name of the object.
156 type: str
157 adirectory_groups:
158 description: List of Active Directory Groups.
159 type: str
160 adirectory_groups_sids:
161 description: List of Active Directory Groups SIDS.
162 type: list
163 backend_match:
164 description: The backend to use.
165 type: str
166 comment:
167 description: The comment string.
168 type: str
169 dynamic:
170 description: Whether the group match is ipsec_dn or directory_group.
171 type: str
172 edirectory_groups:
173 description: List of eDirectory Groups.
174 type: str
175 ipsec_dn:
176 description: Ipsec_dn identifier to match.
177 type: str
178 ldap_attribute:
179 description: The LDAP Attribute to match against.
180 type: str
181 ldap_attribute_value:
182 description: The LDAP Attribute Value to match against.
183 type: str
184 members:
185 description: List of member identifiers of the group.
186 type: list
187 network:
188 description: The identifier of the network (network/aaa).
189 type: str
190 radius_group:
191 description: The radius group identifier.
192 type: str
193 tacacs_group:
194 description: The tacacs group identifier.
195 type: str
196 """
197
198 from ansible_collections.community.general.plugins.module_utils._utm_utils import UTM, UTMModule
199
200
201 def main():
202 endpoint = "aaa/group"
203 key_to_check_for_changes = [
204 "comment",
205 "adirectory_groups",
206 "adirectory_groups_sids",
207 "backend_match",
208 "dynamic",
209 "edirectory_groups",
210 "ipsec_dn",
211 "ldap_attribute",
212 "ldap_attribute_value",
213 "members",
214 "network",
215 "radius_groups",
216 "tacacs_groups",
217 ]
218 module = UTMModule(
219 argument_spec=dict(
220 name=dict(type="str", required=True),
221 adirectory_groups=dict(type="list", elements="str", default=[]),
222 adirectory_groups_sids=dict(type="dict", default={}),
223 backend_match=dict(
224 type="str", default="none", choices=["none", "adirectory", "edirectory", "radius", "tacacs", "ldap"]
225 ),
226 comment=dict(type="str", default=""),
227 dynamic=dict(type="str", default="none", choices=["none", "ipsec_dn", "directory_groups"]),
228 edirectory_groups=dict(type="list", elements="str", default=[]),
229 ipsec_dn=dict(type="str", default=""),
230 ldap_attribute=dict(type="str", default=""),
231 ldap_attribute_value=dict(type="str", default=""),
232 members=dict(type="list", elements="str", default=[]),
233 network=dict(type="str", default=""),
234 radius_groups=dict(type="list", elements="str", default=[]),
235 tacacs_groups=dict(type="list", elements="str", default=[]),
236 )
237 )
238 try:
239 UTM(module, endpoint, key_to_check_for_changes).execute()
240 except Exception as e:
241 module.fail_json(msg=f"{e}")
242
243
244 if __name__ == "__main__":
245 main()