Debian Codegraph @

ansible_collections/azure/azcollection/plugins/modules/azure_rm_containerregistrytokenpassword.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_containerregistrytokenpassword
12 version_added: "3.7.0"
13 short_description: Generate or renegenerate the Azure Container Registry Token Password
14 description:
15 - Generate or renegenerate the Azure Container Registry Token Password.
16 - Note that the generated password cannot be retrieved. Please store your credentials safely after generation.
17
18 options:
19 resource_group:
20 description:
21 - The name of the resource group to which the container registry belongs.
22 type: str
23 required: true
24 registry_name:
25 description:
26 - The name of the container registry.
27 type: str
28 required: true
29 token_id:
30 description:
31 - The ID of the container registry token.
32 type: str
33 required: true
34 expiry:
35 description:
36 - The expiry datetime of the password.
37 - Sample as 2025/07/25.
38 - If not configured, it will never expire.
39 type: str
40 name:
41 description:
42 - The name of the password.
43 - If not configured, both passwords will be regenerated.
44 type: str
45 choices:
46 - password1
47 - password2
48
49 extends_documentation_fragment:
50 - azure.azcollection.azure
51
52 author:
53 - magodo (@magodo)
54 - Fred-sun (@Fred-sun)
55
56 '''
57
58 EXAMPLES = '''
59 - name: Generate a new password for container registry token
60 azure_rm_containerregistrytokenpassword:
61 resource_group: myResourceGroup
62 registry_name: myRegistry
63 name: mytoken
64 expiry: 2025/08/01
65 token_id: token_id
66 '''
67
68 RETURN = '''
69 passwords:
70 description:
71 - A list of dictionaries containing facts for token passwords facts.
72 returned: always
73 type: list
74 sample: [
75 {
76 "creation_time": "2025-07-24T08:28:50.569062Z",
77 "expiry": "2025-08-01T00:00:00.000Z",
78 "name": "password1"
79 },
80 {
81 "creation_time": "2025-07-24T08:29:19.12587Z",
82 "expiry": "2025-08-01T00:00:00.000Z",
83 "name": "password2",
84 "value": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
85 }
86 ]
87 '''
88
89 try:
90 from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase
91 from azure.core.polling import LROPoller
92 from datetime import datetime
93 except ImportError:
94 # This is handled in azure_rm_common
95 pass
96
97
98 class AzureRMContainerRegistryTokenPassword(AzureRMModuleBase):
99 def __init__(self):
100 # define user inputs into argument
101 self.module_arg_spec = dict(
102 resource_group=dict(
103 type='str',
104 required=True,
105 ),
106 registry_name=dict(
107 type='str',
108 required=True
109 ),
110 name=dict(
111 type='str',
112 choices=['password1', 'password2']
113 ),
114 token_id=dict(
115 type='str',
116 required=True
117 ),
118 expiry=dict(
119 type='str'
120 )
121 )
122 # store the results of the module operation
123 self.results = dict(
124 changed=False,
125 passwords=None,
126 )
127 self.resource_group = None
128 self.registry_name = None
129 self.name = None
130 self.expiry = None
131 self.token_id = None
132
133 super(AzureRMContainerRegistryTokenPassword, self).__init__(self.module_arg_spec, supports_check_mode=True, supports_tags=False, facts_module=False)
134
135 def exec_module(self, **kwargs):
136
137 for key in list(self.module_arg_spec):
138 setattr(self, key, kwargs[key])
139
140 # Create dict form input, without None value
141 password_template = dict(name=self.name,
142 token_id=self.token_id,
143 expiry=datetime.strptime(self.expiry, "%Y/%m/%d") if self.expiry else None)
144 try:
145 response = self.containerregistrytoken_client.registries.begin_generate_credentials(resource_group_name=self.resource_group,
146 registry_name=self.registry_name,
147 generate_credentials_parameters=password_template)
148
149 except Exception as ec:
150 self.fail("Generate token password occur exception, Exception as {0}".format(str(ec)))
151
152 if isinstance(response, LROPoller):
153 response = self.get_poller_result(response)
154
155 self.results = response.as_dict()
156 self.results['changed'] = True
157 return self.results
158
159
160 def main():
161 AzureRMContainerRegistryTokenPassword()
162
163
164 if __name__ == '__main__':
165 main()