Debian Codegraph @

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

raw symbols SCIP
1 #!/usr/bin/python
2 #
3 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
4
5 from __future__ import absolute_import, division, print_function
6 __metaclass__ = type
7
8
9 DOCUMENTATION = '''
10 ---
11 module: azure_rm_containerregistrytoken_info
12 version_added: "3.7.0"
13 short_description: Get Azure Container Registry Token facts
14 description:
15 - Get or list facts for Container Registry Token.
16
17 options:
18 resource_group:
19 description:
20 - The name of the resource group to which the container registry belongs.
21 type: str
22 required: true
23 registry_name:
24 description:
25 - The name of the container registry.
26 type: str
27 required: true
28 name:
29 description:
30 - The name of the container registry token.
31 type: str
32
33 extends_documentation_fragment:
34 - azure.azcollection.azure
35
36 author:
37 - magodo (@magodo)
38 - Fred-sun (@Fred-sun)
39
40 '''
41
42 EXAMPLES = '''
43 - name: Get instance of Registry Token
44 azure_rm_containerregistrytoken_info:
45 resource_group: myResourceGroup
46 registry_name: myRegistry
47 name: myToken
48
49 - name: List instances of Registry Token
50 azure_rm_containerregistrytoken_info:
51 resource_group: myResourceGroup
52 registry_name: myRegistry
53 '''
54
55 RETURN = '''
56 registry_tokens:
57 description:
58 - A list of dictionaries containing facts for token.
59 returned: always
60 type: complex
61 contains:
62 id:
63 description:
64 - The resource ID.
65 returned: always
66 type: str
67 sample: "/subscriptions/xxx-xxx/resourceGroups/myRG/providers/Microsoft.ContainerRegistry/registries/registry01/tokens/token01"
68 name:
69 description:
70 - The name of the resource.
71 returned: always
72 type: str
73 sample: token01
74 registry_name:
75 description:
76 - The name of the container registry.
77 type: str
78 returned: always
79 sample: registry01
80 resource_group:
81 description:
82 - The name fo the resource group.
83 type: str
84 returned: always
85 sample: myRG
86 creation_date:
87 description:
88 - The creation date of scope map.
89 type: str
90 returned: always
91 sample: '2025-07-21T03:16:03.828541Z'
92 credentials:
93 description:
94 - The credentials that can be used for authenticating the token.
95 type: str
96 returned: always
97 sample: {
98 "passwords": [
99 {
100 "creation_time": "2025-07-21T03:17:14.528612Z",
101 "expiry": "2026-07-22T03:17:00.551Z",
102 "name": "password1"
103 }
104 ]
105 }
106 provisioning_state:
107 description:
108 - Provisioning state of the container registry token.
109 returned: always
110 type: str
111 sample: Succeeded
112 scope_map_id:
113 description:
114 - The resource ID of the scope map to which the token will be associated with.
115 type: str
116 returned: always
117 sample: "/subscriptions/xxx-xxx/resourceGroups/myRG/providers/Microsoft.ContainerRegistry/registries/registry01/scopeMaps/map01"
118 status:
119 description:
120 - The status of the token example enabled or disabled.
121 type: str
122 returned: always
123 sample: enabled
124 system_data:
125 description:
126 - Metadata pertaining to creation and last modification of the resource.
127 type: dict
128 returned: always
129 sample: {
130 "created_at": "2025-07-21T03:16:50.586036Z",
131 "created_by": "[email protected]",
132 "created_by_type": "User",
133 "last_modified_at": "2025-07-21T03:16:50.586036Z",
134 "last_modified_by": "[email protected]",
135 "last_modified_by_type": "User"
136 }
137 type:
138 description:
139 - The type of the resource.
140 type: str
141 returned: always
142 sample: 'Microsoft.ContainerRegistry/registries/tokens'
143 '''
144
145 from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase
146
147
148 class AzureRMContainerRegistryTokenInfo(AzureRMModuleBase):
149 def __init__(self):
150 # define user inputs into argument
151 self.module_arg_spec = dict(
152 resource_group=dict(
153 type='str',
154 required=True,
155 ),
156 registry_name=dict(
157 type='str',
158 required=True
159 ),
160 name=dict(
161 type='str'
162 )
163 )
164 # store the results of the module operation
165 self.results = dict(
166 changed=False
167 )
168 self.resource_group = None
169 self.registry_name = None
170 self.name = None
171
172 super(AzureRMContainerRegistryTokenInfo, self).__init__(self.module_arg_spec, supports_check_mode=True, supports_tags=False, facts_module=True)
173
174 def exec_module(self, **kwargs):
175
176 for key in list(self.module_arg_spec):
177 setattr(self, key, kwargs[key])
178
179 if self.name:
180 self.results['registry_tokens'] = self.get()
181 else:
182 self.results['registry_tokens'] = self.list()
183
184 return self.results
185
186 def get(self):
187 try:
188 response = self.containerregistrytoken_client.tokens.get(resource_group_name=self.resource_group,
189 registry_name=self.registry_name,
190 token_name=self.name)
191 self.log("Response : {0}".format(response))
192 except Exception as e:
193 self.log("Could not get facts for Registry Token: {0}".format(str(e)))
194 return []
195
196 if response:
197 return [self.format_item(response)]
198
199 def list(self):
200 response = None
201 try:
202 response = self.containerregistrytoken_client.tokens.list(resource_group_name=self.resource_group,
203 registry_name=self.registry_name)
204 self.log("Response : {0}".format(response))
205 except Exception as e:
206 self.log("Could not list facts for Registry Token: {0}".format(str(e)))
207
208 return [self.format_item(item) for item in response if response]
209
210 def format_item(self, item):
211 result = item.as_dict()
212 result['resource_group'] = self.resource_group
213 result['registry_name'] = self.registry_name
214
215 return result
216
217
218 def main():
219 AzureRMContainerRegistryTokenInfo()
220
221
222 if __name__ == '__main__':
223 main()