2525)
2626from .custom import acr_update_custom
2727
28+
2829class ConnectedRegistryModes (Enum ):
2930 READONLY = 'readonly'
3031 READWRITE = 'readwrite'
@@ -146,6 +147,7 @@ def acr_connected_registry_create(cmd, # pylint: disable=too-many-locals, too-m
146147
147148def acr_connected_registry_update (cmd , # pylint: disable=too-many-locals, too-many-statements
148149 client ,
150+ instance ,
149151 registry_name ,
150152 connected_registry_name ,
151153 add_client_token_list = None ,
@@ -164,7 +166,7 @@ def acr_connected_registry_update(cmd, # pylint: disable=too-many-locals, too-m
164166 current_connected_registry = acr_connected_registry_show (
165167 cmd , client , connected_registry_name , registry_name , resource_group_name )
166168
167- # Add or remove from the current client token id list
169+ # create add client token set and remove client token set
168170 if add_client_token_list is not None :
169171 for i , client_token_name in enumerate (add_client_token_list ):
170172 add_client_token_list [i ] = build_token_id (
@@ -179,61 +181,76 @@ def acr_connected_registry_update(cmd, # pylint: disable=too-many-locals, too-m
179181 remove_client_token_set = set (remove_client_token_list )
180182 else :
181183 remove_client_token_set = set ()
182-
184+ # check for interesaction between add and remove.
183185 duplicate_client_token = set .intersection (add_client_token_set , remove_client_token_set )
184186 if duplicate_client_token :
185187 errors = sorted (map (lambda action : action [action .rfind ('/' ) + 1 :], duplicate_client_token ))
186188 raise CLIError (
187189 'Update ambiguity. Duplicate client token ids were provided with ' +
188190 '--add-client-tokens and --remove-client-tokens arguments.\n {}' .format (errors ))
189-
191+ # get updated client token list
190192 current_client_token_set = set (current_connected_registry .client_token_ids ) \
191193 if current_connected_registry .client_token_ids else set ()
192194 client_token_set = current_client_token_set .union (add_client_token_set ).difference (remove_client_token_set )
193-
194195 client_token_list = list (client_token_set ) if client_token_set != current_client_token_set else None
196+ # update client token properties
197+ instance .client_token_ids = client_token_list
195198
196- # Add or remove from the current notifications list
199+ # create add notifications set and remove notifications set
197200 add_notifications_set = set (list (add_notifications )) \
198201 if add_notifications else set ()
199-
200202 remove_notifications_set = set (list (remove_notifications )) \
201203 if remove_notifications else set ()
202-
204+ # check for interesaction between add and remove.
203205 duplicate_notifications = set .intersection (add_notifications_set , remove_notifications_set )
204206 if duplicate_notifications :
205207 errors = sorted (duplicate_notifications )
206208 raise ArgumentUsageError (
207209 'Update ambiguity. Duplicate notifications list were provided with ' +
208210 '--add-notifications and --remove-notifications arguments.\n {}' .format (errors ))
209-
211+ # get updated notifications list
210212 current_notifications_set = set (current_connected_registry .notifications_list ) \
211213 if current_connected_registry .notifications_list else set ()
212214 notifications_set = current_notifications_set .union (add_notifications_set ).difference (remove_notifications_set )
213-
214215 notifications_list = list (notifications_set ) if notifications_set != current_notifications_set else None
216+ # update notifications properties
217+ instance .notifications_list = notifications_list
215218
216- ConnectedRegistryUpdateParameters , SyncUpdateProperties , LoggingProperties = cmd . get_models (
217- 'ConnectedRegistryUpdateParameters' , 'SyncUpdateProperties' , 'LoggingProperties' )
218- connected_registry_update_parameters = ConnectedRegistryUpdateParameters (
219- sync_properties = SyncUpdateProperties (
219+ # update sync properties and logging properties
220+ SyncUpdateProperties , LoggingProperties = cmd . get_models ( 'SyncUpdateProperties' , 'LoggingProperties' )
221+ if bool ( sync_schedule ) or bool ( sync_window ) or bool ( sync_message_ttl ):
222+ instance . sync_properties = SyncUpdateProperties (
220223 schedule = sync_schedule ,
221224 message_ttl = sync_message_ttl ,
222225 sync_window = sync_window
223- ),
224- logging = LoggingProperties (
226+ )
227+ if bool (log_level ) or bool (sync_audit_logs_enabled ):
228+ instance .logging = LoggingProperties (
225229 log_level = log_level ,
226230 audit_log_status = sync_audit_logs_enabled
227- ),
228- client_token_ids = client_token_list ,
229- notifications_list = notifications_list
230- )
231+ )
232+ return instance
233+
231234
235+ def acr_connected_registry_update_get (cmd ):
236+ """Returns an empty RegistryUpdateParameters object.
237+ """
238+ ConnectedRegistryUpdateParameters = cmd .get_models ('ConnectedRegistryUpdateParameters' )
239+ return ConnectedRegistryUpdateParameters ()
240+
241+
242+ def acr_connected_registry_update_set (cmd ,
243+ client ,
244+ registry_name ,
245+ connected_registry_name ,
246+ resource_group_name = None ,
247+ parameters = None ):
248+ _ , resource_group_name = get_registry_by_name (cmd .cli_ctx , registry_name , resource_group_name )
232249 try :
233250 return client .begin_update (resource_group_name = resource_group_name ,
234251 registry_name = registry_name ,
235252 connected_registry_name = connected_registry_name ,
236- connected_registry_update_parameters = connected_registry_update_parameters )
253+ connected_registry_update_parameters = parameters )
237254 except ValidationError as e :
238255 raise CLIError (e )
239256
0 commit comments