Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ACR] az acr connected-registry create/update: Add new arguments for enabling and setting interval for garbage collection within a connected registry #30956

Draft
wants to merge 9 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/azure-cli-core/azure/cli/core/profiles/_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def default_api_version(self):
'role_definitions': '2022-05-01-preview',
'provider_operations_metadata': '2018-01-01-preview'
}),
ResourceType.MGMT_CONTAINERREGISTRY: SDKProfile('2023-11-01-preview', {
ResourceType.MGMT_CONTAINERREGISTRY: SDKProfile('2024-11-01-preview', {
'agent_pools': '2019-06-01-preview',
'tasks': '2019-06-01-preview',
'task_runs': '2019-06-01-preview',
Expand Down Expand Up @@ -439,6 +439,7 @@ def default_api_version(self):
'VERSION_2021_08_01_PREVIEW': "2021-08-01-preview",
'VERSION_2022_02_01_PREVIEW': "2022-02-01-preview",
'VERSION_2023_11_01_PREVIEW': "2023-11-01-preview",
'VERSION_2024_11_01_PREVIEW': "2024-11-01-preview",
},
ResourceType.MGMT_CONTAINERSERVICE: {
# src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_custom.py:50
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
VERSION_2021_08_01_PREVIEW = "2021-08-01-preview"
VERSION_2022_02_01_PREVIEW = "2022-02-01-preview"
VERSION_2023_01_01_PREVIEW = "2023-01-01-preview"
VERSION_2024_11_01_PREVIEW = "2024-11-01-preview"


def get_acr_service_client(cli_ctx, api_version=None):
Expand Down Expand Up @@ -81,4 +82,4 @@ def cf_acr_agentpool(cli_ctx, *_):


def cf_acr_connected_registries(cli_ctx, *_):
return get_acr_service_client(cli_ctx, VERSION_2021_08_01_PREVIEW).connected_registries
return get_acr_service_client(cli_ctx, VERSION_2024_11_01_PREVIEW).connected_registries
8 changes: 7 additions & 1 deletion src/azure-cli/azure/cli/command_modules/acr/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,10 @@ def load_arguments(self, _): # pylint: disable=too-many-statements
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="* * * * *")
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")
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 ...]".')
c.argument('garbage_collection_enabled', options_list=['--gc-enabled'],
help='Indicate whether garbage collection is enabled. It is enabled by default.', arg_type=get_three_state_flag(), required=False, default="true")
c.argument('garbage_collection_schedule', options_list=['--gc-schedule'],
help='Used to determine garbage collection schedule. Uses cron expression to determine the schedule. If not specified, garbage collection is set to run once a day.', required=False, default="0 0 * * *")

with self.argument_context('acr connected-registry update') as c:
c.argument('log_level', help='Set the log level for logging on the instance. Accepted log levels are Debug, Information, Warning, Error, and None.')
Expand All @@ -561,7 +565,9 @@ def load_arguments(self, _): # pylint: disable=too-many-statements
help='List of artifact pattern to be added to notifications list. Use the format "--add-notifications [PATTERN1 PATTERN2 ...]".')
c.argument('remove_notifications', options_list=['--remove-notifications'], nargs='*',
help='List of artifact pattern to be removed from notifications list. Use the format "--remove-notifications [PATTERN1 PATTERN2 ...]".')

c.argument('garbage_collection_enabled', options_list=['--gc-enabled'],
help='Indicate whether garbage collection is enabled. It is enabled by default.', arg_type=get_three_state_flag())
c.argument('garbage_collection_schedule', options_list=['--gc-schedule'], help='Used to determine garbage collection schedule. Uses cron expression to determine the schedule. If not specified, garbage collection is set to run once a day.')
with self.argument_context('acr connected-registry permissions') as c:
c.argument('add_repos', options_list=['--add'], nargs='*',
help='repository permissions to be added to the targeted connected registry and it\'s ancestors sync scope maps. Use the format "--add [REPO1 REPO2 ...]" per flag. ' + repo_valid_actions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ def acr_connected_registry_create(cmd, # pylint: disable=too-many-locals, too-m
log_level=None,
sync_audit_logs_enabled=False,
notifications=None,
garbage_collection_enabled=None,
garbage_collection_schedule=None,
yes=False):

if bool(sync_token_name) == bool(repositories):
Expand All @@ -71,7 +73,7 @@ def acr_connected_registry_create(cmd, # pylint: disable=too-many-locals, too-m
registry, resource_group_name = get_registry_by_name(cmd.cli_ctx, registry_name, resource_group_name)

if not registry.data_endpoint_enabled:
user_confirmation("Dedicated data enpoints must be enabled to use connected-registry. Enabling might " +
user_confirmation("Dedicated data endpoints must be enabled to use connected-registry. Enabling might " +
"impact your firewall rules. Are you sure you want to enable it for '{}' registry?".format(
registry_name), yes)
acr_update_custom(cmd, registry, resource_group_name, data_endpoint_enabled=True)
Expand Down Expand Up @@ -111,8 +113,10 @@ def acr_connected_registry_create(cmd, # pylint: disable=too-many-locals, too-m
notifications_set = set(notifications) \
if notifications else set()

ConnectedRegistry, LoggingProperties, SyncProperties, ParentProperties = cmd.get_models(
'ConnectedRegistry', 'LoggingProperties', 'SyncProperties', 'ParentProperties')
ConnectedRegistry, LoggingProperties, SyncProperties, \
ParentProperties, GarbageCollectionProperties = cmd.get_models(
'ConnectedRegistry', 'LoggingProperties', 'SyncProperties',
'ParentProperties', 'GarbageCollectionProperties')
connected_registry_create_parameters = ConnectedRegistry(
provisioning_state=None,
mode=mode,
Expand All @@ -130,6 +134,10 @@ def acr_connected_registry_create(cmd, # pylint: disable=too-many-locals, too-m
log_level=log_level,
audit_log_status='Enabled' if sync_audit_logs_enabled else 'Disabled'
),
garbage_collection=GarbageCollectionProperties(
enabled=garbage_collection_enabled,
schedule=garbage_collection_schedule
),
notifications_list=list(notifications_set) if notifications_set else None
)

Expand All @@ -155,7 +163,9 @@ def acr_connected_registry_update(cmd, # pylint: disable=too-many-locals, too-m
sync_message_ttl=None,
sync_audit_logs_enabled=None,
add_notifications=None,
remove_notifications=None):
remove_notifications=None,
garbage_collection_enabled=None,
garbage_collection_schedule=None):
_, resource_group_name = validate_managed_registry(
cmd, registry_name, resource_group_name)
subscription_id = get_subscription_id(cmd.cli_ctx)
Expand Down Expand Up @@ -211,8 +221,10 @@ def acr_connected_registry_update(cmd, # pylint: disable=too-many-locals, too-m

notifications_list = list(notifications_set) if notifications_set != current_notifications_set else None

ConnectedRegistryUpdateParameters, SyncUpdateProperties, LoggingProperties = cmd.get_models(
'ConnectedRegistryUpdateParameters', 'SyncUpdateProperties', 'LoggingProperties')
ConnectedRegistryUpdateParameters, SyncUpdateProperties, \
LoggingProperties, GarbageCollectionProperties = cmd.get_models(
'ConnectedRegistryUpdateParameters', 'SyncUpdateProperties',
'LoggingProperties', 'GarbageCollectionProperties')
connected_registry_update_parameters = ConnectedRegistryUpdateParameters(
sync_properties=SyncUpdateProperties(
schedule=sync_schedule,
Expand All @@ -223,6 +235,10 @@ def acr_connected_registry_update(cmd, # pylint: disable=too-many-locals, too-m
log_level=log_level,
audit_log_status=sync_audit_logs_enabled
),
garbage_collection=GarbageCollectionProperties(
enabled=garbage_collection_enabled,
schedule=garbage_collection_schedule
),
client_token_ids=client_token_list,
notifications_list=notifications_list
)
Expand Down
Loading