|
23 | 23 | author: |
24 | 24 | - "Webster Mudge (@wmudge)" |
25 | 25 | - "Dan Chaffelson (@chaffelson)" |
| 26 | + - "Ronald Suplina (@rsuplina)" |
26 | 27 | version_added: "1.0.0" |
27 | 28 | options: |
28 | 29 | name: |
|
36 | 37 | aliases: |
37 | 38 | - group_name |
38 | 39 | extends_documentation_fragment: |
39 | | - - cloudera.cloud.cdp_sdk_options |
40 | | - - cloudera.cloud.cdp_auth_options |
| 40 | + - cloudera.cloud.cdp_client |
41 | 41 | """ |
42 | 42 |
|
43 | 43 | EXAMPLES = r""" |
44 | 44 | # Note: These examples do not set authentication details. |
45 | 45 |
|
46 | | -# Gather information about all Groups |
47 | | -- cloudera.cloud.iam_group_info: |
| 46 | + - name: Gather information about all Groups |
| 47 | + cloudera.cloud.iam_group_info: |
48 | 48 |
|
49 | | -# Gather information about a named Group |
50 | | -- cloudera.cloud.iam_group_info: |
51 | | - name: example-01 |
| 49 | + - name: Gather information about a named Group |
| 50 | + cloudera.cloud.iam_group_info: |
| 51 | + name: example-01 |
| 52 | +
|
| 53 | + - name: Gather information about several named Groups |
| 54 | + cloudera.cloud.iam_group_info: |
| 55 | + name: |
| 56 | + - example-01 |
| 57 | + - example-02 |
| 58 | + - example-03 |
52 | 59 |
|
53 | | -# Gather information about several named Groups |
54 | 60 | - cloudera.cloud.iam_group_info: |
55 | 61 | name: |
56 | 62 | - example-01 |
|
60 | 66 |
|
61 | 67 | RETURN = r""" |
62 | 68 | groups: |
63 | | - description: The information about the named Group or Groups |
| 69 | + description: |
| 70 | + - Returns a list of group records. |
| 71 | + - Each record represents a CDP IAM group and its details. |
64 | 72 | type: list |
65 | 73 | returned: always |
66 | 74 | elements: dict |
67 | 75 | contains: |
68 | 76 | creationDate: |
| 77 | + # creation_date: |
69 | 78 | description: The date when this group record was created. |
70 | 79 | returned: on success |
71 | 80 | type: str |
|
75 | 84 | returned: on success |
76 | 85 | type: str |
77 | 86 | groupName: |
| 87 | + # group_name: |
78 | 88 | description: The group name. |
79 | 89 | returned: on success |
80 | 90 | type: str |
81 | 91 | sample: example-01 |
82 | | - users: |
83 | | - description: List of User CRNs which are members of the group. |
84 | | - returned: on success |
85 | | - type: list |
86 | | - elements: str |
87 | | - roles: |
88 | | - description: List of Role CRNs assigned to the group. |
89 | | - returned: on success |
90 | | - type: list |
91 | | - elements: str |
92 | | - resource_roles: |
93 | | - description: List of Resource-to-Role assignments, by CRN, that are associated with the group. |
94 | | - returned: on success |
95 | | - type: list |
96 | | - elements: dict |
97 | | - contains: |
98 | | - resourceCrn: |
99 | | - description: The CRN of the resource granted the rights of the role. |
100 | | - returned: on success |
101 | | - type: str |
102 | | - resourceRoleCrn: |
103 | | - description: The CRN of the CDP Role. |
104 | | - returned: on success |
105 | | - type: str |
106 | 92 | syncMembershipOnUserLogin: |
107 | | - description: Flag indicating whether group membership is synced when a user logs in. The default is to sync group |
108 | | - membership. |
| 93 | + # sync_membership_on_user_login: |
| 94 | + description: Flag indicating whether group membership is synced when a user logs in. The default is to sync group membership. |
109 | 95 | returned: when supported |
110 | 96 | type: bool |
111 | 97 | sdk_out: |
112 | | - description: Returns the captured CDP SDK log. |
| 98 | + description: Returns the captured API HTTP log. |
113 | 99 | returned: when supported |
114 | 100 | type: str |
115 | 101 | sdk_out_lines: |
116 | | - description: Returns a list of each line of the captured CDP SDK log. |
| 102 | + description: Returns a list of each line of the captured API HTTP log. |
117 | 103 | returned: when supported |
118 | 104 | type: list |
119 | 105 | elements: str |
120 | 106 | """ |
121 | 107 |
|
122 | | -from ansible.module_utils.basic import AnsibleModule |
123 | | -from ansible_collections.cloudera.cloud.plugins.module_utils.cdp_common import CdpModule |
| 108 | +from typing import Any |
124 | 109 |
|
| 110 | +# from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict |
125 | 111 |
|
126 | | -class IAMGroupInfo(CdpModule): |
127 | | - def __init__(self, module): |
128 | | - super(IAMGroupInfo, self).__init__(module) |
| 112 | +from ansible_collections.cloudera.cloud.plugins.module_utils.common import ( |
| 113 | + ServicesModule, |
| 114 | +) |
| 115 | +from ansible_collections.cloudera.cloud.plugins.module_utils.cdp_iam import ( |
| 116 | + CdpIamClient, |
| 117 | +) |
129 | 118 |
|
130 | | - # Set variables |
131 | | - self.name = self._get_param("name") |
132 | 119 |
|
133 | | - # Initialize the return values |
134 | | - self.info = [] |
| 120 | +class IAMGroupInfo(ServicesModule): |
| 121 | + def __init__(self): |
| 122 | + super().__init__( |
| 123 | + argument_spec=dict( |
| 124 | + name=dict( |
| 125 | + required=False, |
| 126 | + type="list", |
| 127 | + elements="str", |
| 128 | + aliases=["group_name"], |
| 129 | + ), |
| 130 | + ), |
| 131 | + supports_check_mode=True, |
| 132 | + ) |
135 | 133 |
|
136 | | - # Execute logic process |
137 | | - self.process() |
| 134 | + # Set parameters |
| 135 | + self.name = self.get_param("name") |
| 136 | + |
| 137 | + # Initialize the return values |
| 138 | + self.groups = [] |
138 | 139 |
|
139 | | - @CdpModule._Decorators.process_debug |
140 | 140 | def process(self): |
141 | | - self.info = self.cdpy.iam.gather_groups(self.name) |
| 141 | + client = CdpIamClient(api_client=self.api_client) |
| 142 | + result = client.list_groups(group_names=self.name) |
| 143 | + self.groups = result.get("groups", []) |
142 | 144 |
|
143 | 145 |
|
144 | | -def main(): |
145 | | - module = AnsibleModule( |
146 | | - argument_spec=CdpModule.argument_spec( |
147 | | - name=dict( |
148 | | - required=False, |
149 | | - type="list", |
150 | | - elements="str", |
151 | | - aliases=["group_name"], |
152 | | - ), |
153 | | - ), |
154 | | - supports_check_mode=True, |
155 | | - ) |
| 146 | +# NOTE: Snake_case conversion deferred until 4.0 to maintain backward compatibility. |
| 147 | +# self.groups = [ |
| 148 | +# camel_dict_to_snake_dict(group) for group in result.get("groups", []) |
| 149 | +# ] |
| 150 | + |
156 | 151 |
|
157 | | - result = IAMGroupInfo(module) |
| 152 | +def main(): |
| 153 | + result = IAMGroupInfo() |
158 | 154 |
|
159 | | - output = dict( |
| 155 | + output: dict[str, Any] = dict( |
160 | 156 | changed=False, |
161 | | - groups=result.info, |
| 157 | + groups=result.groups, |
162 | 158 | ) |
163 | 159 |
|
164 | | - if result.debug: |
165 | | - output.update(sdk_out=result.log_out, sdk_out_lines=result.log_lines) |
| 160 | + if result.debug_log: |
| 161 | + output.update( |
| 162 | + sdk_out=result.log_out, |
| 163 | + sdk_out_lines=result.log_lines, |
| 164 | + ) |
166 | 165 |
|
167 | | - module.exit_json(**output) |
| 166 | + result.module.exit_json(**output) |
168 | 167 |
|
169 | 168 |
|
170 | 169 | if __name__ == "__main__": |
|
0 commit comments