41
41
choices:
42
42
- enabled
43
43
- disabled
44
- credentials:
45
- description:
46
- - The credentials that can be used for authenticating the token.
47
- type: dict
48
- suboptions:
49
- certificates:
50
- description:
51
- - The certificate of the token credentials.
52
- type: list
53
- elements: dict
54
- suboptions:
55
- name:
56
- description:
57
- - The certificate name.
58
- type: str
59
- choices:
60
- - certificate1
61
- - certificate2
62
- expiry:
63
- description:
64
- - The expiry datetime of the certificate.
65
- type: str
66
- thumbprint:
67
- description:
68
- - The thumbprint of the certificate.
69
- type: str
70
- encoded_pem_certificate:
71
- description:
72
- - Base 64 encoded string of the public certificate1 in PEM format that will be used for authenticating the token.
73
- type: str
74
- passwords:
75
- description:
76
- - The password of the token credentials.
77
- type: list
78
- elements: dict
79
- suboptions:
80
- expiry:
81
- description:
82
- - The expiry datetime of the password.
83
- type: str
84
- name:
85
- description:
86
- - The password name C(password1) or C(password2).
87
- type: str
88
- choices:
89
- - password1
90
- - password2
91
44
state:
92
45
description:
93
46
- Assert the state of the container registry token.
108
61
'''
109
62
110
63
EXAMPLES = '''
111
- - name: Get instance of Registry Token
64
+ - name: Create a new Container Registry Token
112
65
azure_rm_containerregistrytoken:
113
66
resource_group: myResourceGroup
114
67
registry_name: myRegistry
115
68
name: mytoken
69
+ status: enabled
70
+ scope_map_id: scopemap_id
116
71
117
72
- name: Delete the container registry token
118
73
azure_rm_containerregistrytoken:
122
77
'''
123
78
124
79
RETURN = '''
125
- tokens :
80
+ registry_token :
126
81
description:
127
82
- A list of dictionaries containing facts for token.
128
83
returned: always
@@ -242,22 +197,6 @@ def __init__(self):
242
197
type = 'str' ,
243
198
choices = ['enabled' , 'disabled' ]
244
199
),
245
- cred = dict (
246
- type = 'dict' ,
247
- aliase = ['credentials' ],
248
- options = dict (
249
- certificates = dict (
250
- name = dict (type = 'str' , choices = ['certificate1' , 'certificate2' ]),
251
- expiry = dict (type = 'str' ),
252
- thumbprint = dict (type = 'str' ),
253
- encoded_pem_certificate = dict (type = 'str' )
254
- ),
255
- passwords = dict (
256
- expiry = dict (type = 'str' ),
257
- name = dict (type = 'str' , choices = ['password1' , 'password2' ])
258
- )
259
- )
260
- ),
261
200
state = dict (
262
201
type = 'str' ,
263
202
default = 'present' ,
@@ -267,13 +206,12 @@ def __init__(self):
267
206
# store the results of the module operation
268
207
self .results = dict (
269
208
changed = False ,
270
- diff = None ,
209
+ diff = [] ,
271
210
token = None ,
272
211
)
273
212
self .resource_group = None
274
213
self .registry_name = None
275
214
self .name = None
276
- self .cred = None
277
215
self .status = None
278
216
self .scope_map_id = None
279
217
@@ -288,53 +226,50 @@ def exec_module(self, **kwargs):
288
226
289
227
# Defaults for variables
290
228
result = None
291
- result_compare = dict (compare = [])
292
229
293
230
# Get current container registry token
294
- before_dict = self .get ()
295
-
296
- # Create dict form input, without None value
297
- token_template = dict (scope_map_id = self .scope_map_id ,
298
- credentials = self .cred ,
299
- status = self .status )
300
-
301
- # Filter out all None values
302
- token_input = {key : value for key , value in token_template .items () if value is not None }
231
+ old_response = self .get ()
303
232
304
233
# Create/Update if state==present
305
234
if self .state == 'present' :
306
- if before_dict :
307
- # The container registry already exists, try to update
308
- # Dict for update is the union of existing object over written by input data
309
- token_update = before_dict () | token_input
310
- if not self .default_compare ({}, token_update , before_dict , '' , result_compare ):
235
+ if old_response :
236
+ # The container registry token already exists, try to update
237
+ if self .scope_map_id is not None and self .scope_map_id .lower () != old_response ['scope_map_id' ].lower ():
311
238
self .results ['changed' ] = True
239
+ self .results ['diff' ].append ('scope_map_id' )
240
+ if self .status is not None and self .status != old_response ['status' ].lower ():
241
+ self .results ['changed' ] = True
242
+ self .results ['diff' ].append ('status' )
243
+
244
+ if self .results ['changed' ]:
312
245
if self .check_mode :
313
246
# Check mode, skipping actual creation
314
247
pass
315
248
else :
316
- result = self .update (token_update )
249
+ result = self .update ()
250
+ else :
251
+ result = old_response
317
252
else :
318
253
self .results ['changed' ] = True
319
254
# The container registry token not exist, create
320
255
if self .check_mode :
321
256
# Check mode, Skipping actual creation
322
257
pass
323
258
else :
324
- result = self .create (token_input )
325
- elif self .state == 'absent' and before_dict :
259
+ result = self .create ()
260
+ elif self .state == 'absent' and old_response :
326
261
self .results ['changed' ] = True
327
262
if not self .check_mode :
328
263
self .delete ()
329
264
else :
330
265
# Do not delete in check mode
331
266
pass
332
267
333
- self .results ['diff' ] = result_compare
334
- self .results ['token' ] = result
268
+ self .results ['registry_token' ] = result
335
269
return self .results
336
270
337
271
def get (self ):
272
+ # Gets the properties of the specified token
338
273
try :
339
274
response = self .containerregistrytoken_client .tokens .get (resource_group_name = self .resource_group ,
340
275
registry_name = self .registry_name ,
@@ -344,14 +279,16 @@ def get(self):
344
279
self .log ("Could not get facts for Registry Token: {0}" .format (str (e )))
345
280
return None
346
281
347
- return response . as_dict ( )
282
+ return self . format_item ( response )
348
283
349
- def create (self , body ):
284
+ def create (self ):
285
+ # Creates a token for a container registry with the specified parameters
350
286
try :
351
287
response = self .containerregistrytoken_client .tokens .begin_create (resource_group_name = self .resource_group ,
352
288
registry_name = self .registry_name ,
353
289
token_name = self .name ,
354
- token_create_parameters = body )
290
+ token_create_parameters = dict (scope_map_id = self .scope_map_id ,
291
+ status = self .status ))
355
292
self .log ("Response: {0}" .format (response ))
356
293
except Exception as e :
357
294
self .fail ("Create {0} failed. Abnormal message as {1}" .format (self .name , str (e )))
@@ -361,12 +298,14 @@ def create(self, body):
361
298
362
299
return self .format_item (response )
363
300
364
- def update (self , body ):
301
+ def update (self ):
302
+ # Updates a token with the specified parameters
365
303
try :
366
304
response = self .containerregistrytoken_client .tokens .begin_update (resource_group_name = self .resource_group ,
367
305
registry_name = self .registry_name ,
368
306
token_name = self .name ,
369
- token_update_parameters = body )
307
+ token_update_parameters = dict (scope_map_id = self .scope_map_id ,
308
+ status = self .status ))
370
309
self .log ("Response: {0}" .format (response ))
371
310
except Exception as e :
372
311
self .fail ("Update {0} failed. Abnormal message as {1}" .format (self .name , str (e )))
@@ -377,6 +316,7 @@ def update(self, body):
377
316
return self .format_item (response )
378
317
379
318
def delete (self ):
319
+ # Deletes a token from a container registry
380
320
try :
381
321
response = self .containerregistrytoken_client .tokens .begin_delete (resource_group_name = self .resource_group ,
382
322
registry_name = self .registry_name ,
0 commit comments