Skip to content

Commit 80cf4d4

Browse files
authored
[ACR] az acr connected-registry: Add --notifications argument to support the list of artifact pattern for which notifications need to be generated (#20763)
* [Acr] az acr connected-registry: Add --notifications-list argument Add notifications list to acr connected-registry create and update commands * Rerun tests * Address review comments and run other module tests in live * Address failures during test run * Revert linter exclusions * Change API version manually on test_acr_image_import.yaml
1 parent b421a9b commit 80cf4d4

32 files changed

Lines changed: 11859 additions & 9160 deletions

src/azure-cli-core/azure/cli/core/profiles/_shared.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def default_api_version(self):
174174
'role_definitions': '2018-01-01-preview',
175175
'provider_operations_metadata': '2018-01-01-preview'
176176
}),
177-
ResourceType.MGMT_CONTAINERREGISTRY: SDKProfile('2021-06-01-preview', {
177+
ResourceType.MGMT_CONTAINERREGISTRY: SDKProfile('2021-08-01-preview', {
178178
'agent_pools': '2019-06-01-preview',
179179
'tasks': '2019-06-01-preview',
180180
'task_runs': '2019-06-01-preview',

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ def load_arguments(self, _): # pylint: disable=too-many-statements
423423
c.argument('sync_window', options_list=['--sync-window', '-w'], help='Required parameter if --sync-schedule is present. Used to determine the schedule duration. Uses ISO 8601 duration format.')
424424
c.argument('sync_schedule', options_list=['--sync-schedule', '-s'], help='Optional parameter to define the sync schedule. Uses cron expression to determine the schedule. If not specified, the instance is considered always online and attempts to sync every minute.', required=False, default="* * * * *")
425425
c.argument('sync_message_ttl', help='Determine how long the sync messages will be kept in the cloud. Uses ISO 8601 duration format.', required=False, default="P2D")
426+
c.argument('notifications', options_list=['--notifications'], nargs='+', help='List of artifact pattern for which notifications need to be generated. Use the format "--notifications [PATTERN1 PATTERN2 ...]".')
426427

427428
with self.argument_context('acr connected-registry update') as c:
428429
c.argument('log_level', help='Set the log level for logging on the instance. Accepted log levels are Debug, Information, Warning, Error, and None.')
@@ -433,6 +434,10 @@ def load_arguments(self, _): # pylint: disable=too-many-statements
433434
c.argument('sync_window', options_list=['--sync-window', '-w'], help='Used to determine the schedule duration. Uses ISO 8601 duration format.')
434435
c.argument('sync_schedule', options_list=['--sync-schedule', '-s'], help='Optional parameter to define the sync schedule. Uses cron expression to determine the schedule. If not specified, the instance is considered always online and attempts to sync every minute.')
435436
c.argument('sync_message_ttl', help='Determine how long the sync messages will be kept in the cloud. Uses ISO 8601 duration format.')
437+
c.argument('add_notifications', options_list=['--add-notifications'], nargs='*',
438+
help='List of artifact pattern to be added to notifications list. Use the format "--add-notifications [PATTERN1 PATTERN2 ...]".')
439+
c.argument('remove_notifications', options_list=['--remove-notifications'], nargs='*',
440+
help='List of artifact pattern to be removed from notifications list. Use the format "--remove-notifications [PATTERN1 PATTERN2 ...]".')
436441

437442
with self.argument_context('acr connected-registry permissions') as c:
438443
c.argument('add_repos', options_list=['--add'], nargs='*',

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

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from msrest.exceptions import ValidationError
88
from knack.log import get_logger
99
from knack.util import CLIError
10+
from azure.cli.core.azclierror import ArgumentUsageError
1011
from azure.cli.core.commands import LongRunningOperation
1112
from azure.cli.core.commands.client_factory import get_subscription_id
1213
from azure.cli.core.util import user_confirmation
@@ -56,7 +57,8 @@ def acr_connected_registry_create(cmd, # pylint: disable=too-many-locals, too-m
5657
sync_message_ttl=None,
5758
sync_window=None,
5859
log_level=None,
59-
sync_audit_logs_enabled=False):
60+
sync_audit_logs_enabled=False,
61+
notifications=None):
6062

6163
if bool(sync_token_name) == bool(repositories):
6264
raise CLIError("usage error: you must provide either --sync-token-name or --repository, but not both.")
@@ -104,6 +106,9 @@ def acr_connected_registry_create(cmd, # pylint: disable=too-many-locals, too-m
104106
client_token_list[i] = build_token_id(
105107
subscription_id, resource_group_name, registry_name, client_token_name)
106108

109+
notifications_set = set(list(notifications)) \
110+
if notifications else set()
111+
107112
ConnectedRegistry, LoggingProperties, SyncProperties, ParentProperties = cmd.get_models(
108113
'ConnectedRegistry', 'LoggingProperties', 'SyncProperties', 'ParentProperties')
109114
connected_registry_create_parameters = ConnectedRegistry(
@@ -122,7 +127,8 @@ def acr_connected_registry_create(cmd, # pylint: disable=too-many-locals, too-m
122127
logging=LoggingProperties(
123128
log_level=log_level,
124129
audit_log_status='Enabled' if sync_audit_logs_enabled else 'Disabled'
125-
)
130+
),
131+
notifications_list=list(notifications_set) if notifications_set else None
126132
)
127133

128134
try:
@@ -145,7 +151,9 @@ def acr_connected_registry_update(cmd, # pylint: disable=too-many-locals, too-m
145151
sync_window=None,
146152
log_level=None,
147153
sync_message_ttl=None,
148-
sync_audit_logs_enabled=None):
154+
sync_audit_logs_enabled=None,
155+
add_notifications=None,
156+
remove_notifications=None):
149157
_, resource_group_name = validate_managed_registry(
150158
cmd, registry_name, resource_group_name)
151159
subscription_id = get_subscription_id(cmd.cli_ctx)
@@ -181,11 +189,30 @@ def acr_connected_registry_update(cmd, # pylint: disable=too-many-locals, too-m
181189

182190
client_token_list = list(client_token_set) if client_token_set != current_client_token_set else None
183191

192+
# Add or remove from the current notifications list
193+
add_notifications_set = set(list(add_notifications)) \
194+
if add_notifications else set()
195+
196+
remove_notifications_set = set(list(remove_notifications)) \
197+
if remove_notifications else set()
198+
199+
duplicate_notifications = set.intersection(add_notifications_set, remove_notifications_set)
200+
if duplicate_notifications:
201+
errors = sorted(duplicate_notifications)
202+
raise ArgumentUsageError(
203+
'Update ambiguity. Duplicate notifications list were provided with ' +
204+
'--add-notifications and --remove-notifications arguments.\n{}'.format(errors))
205+
206+
current_notifications_set = set(current_connected_registry.notifications_list) \
207+
if current_connected_registry.notifications_list else set()
208+
notifications_set = current_notifications_set.union(add_notifications_set).difference(remove_notifications_set)
209+
210+
notifications_list = list(notifications_set) if notifications_set != current_notifications_set else None
211+
184212
ConnectedRegistryUpdateParameters, SyncUpdateProperties, LoggingProperties = cmd.get_models(
185213
'ConnectedRegistryUpdateParameters', 'SyncUpdateProperties', 'LoggingProperties')
186214
connected_registry_update_parameters = ConnectedRegistryUpdateParameters(
187215
sync_properties=SyncUpdateProperties(
188-
token_id=current_connected_registry.parent.sync_properties.token_id,
189216
schedule=sync_schedule,
190217
message_ttl=sync_message_ttl,
191218
sync_window=sync_window
@@ -194,7 +221,8 @@ def acr_connected_registry_update(cmd, # pylint: disable=too-many-locals, too-m
194221
log_level=log_level,
195222
audit_log_status=sync_audit_logs_enabled
196223
),
197-
client_token_ids=client_token_list
224+
client_token_ids=client_token_list,
225+
notifications_list=notifications_list
198226
)
199227

200228
try:
@@ -548,12 +576,13 @@ def _update_repo_permissions(cmd,
548576
actions=current_actions
549577
)
550578

551-
return scope_map_client.begin_update(
579+
poller = scope_map_client.begin_update(
552580
resource_group_name,
553581
registry_name,
554582
sync_scope_map_name,
555583
scope_map_update_parameters
556584
)
585+
return LongRunningOperation(cmd.cli_ctx)(poller)
557586

558587

559588
def _get_scope_map_actions_set(repos, actions):

0 commit comments

Comments
 (0)