Skip to content

Commit ebd9d5a

Browse files
committed
Connected registry update to cli format
1 parent 258fa77 commit ebd9d5a

File tree

2 files changed

+43
-20
lines changed

2 files changed

+43
-20
lines changed

src/azure-cli/azure/cli/command_modules/acr/commands.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,12 @@ def _helm_deprecate_message(self):
432432
with self.command_group('acr connected-registry', acr_connected_registry_util, is_preview=True) as g:
433433
g.command('create', 'acr_connected_registry_create')
434434
g.command('update', 'acr_connected_registry_update')
435+
g.generic_update_command('update',
436+
getter_name='acr_connected_registry_update_get',
437+
setter_name='acr_connected_registry_update_set',
438+
custom_func_name='acr_connected_registry_update',
439+
custom_func_type=acr_connected_registry_util,
440+
client_factory=cf_acr_connected_registries)
435441
g.command('delete', 'acr_connected_registry_delete')
436442
g.show_command('show', 'acr_connected_registry_show')
437443
g.command('deactivate', 'acr_connected_registry_deactivate')

src/azure-cli/azure/cli/command_modules/acr/connected_registry.py

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
)
2626
from .custom import acr_update_custom
2727

28+
2829
class 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

147148
def 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

Comments
 (0)