Skip to content

Commit 2c7d810

Browse files
committed
Merge remote-tracking branch 'azure/dev' into mi
2 parents eb95bdb + cd00c8a commit 2c7d810

38 files changed

Lines changed: 4960 additions & 3070 deletions

src/azure-cli-core/azure/cli/core/_profile.py

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -220,19 +220,20 @@ def login(self,
220220
self._set_subscriptions(consolidated)
221221
return deepcopy(consolidated)
222222

223-
def login_with_managed_identity_msrestazure(
224-
self, identity_id=None, client_id=None, object_id=None, resource_id=None, allow_no_subscriptions=None):
223+
def login_with_managed_identity_msrestazure(self, client_id=None, object_id=None, resource_id=None,
224+
allow_no_subscriptions=None):
225+
# Old way of using msrestazure for managed identity
225226
import jwt
226-
from azure.mgmt.core.tools import is_valid_resource_id
227227
from azure.cli.core.auth.adal_authentication import MSIAuthenticationWrapper
228228
resource = self.cli_ctx.cloud.endpoints.active_directory_resource_id
229229

230-
id_arg_count = len([arg for arg in (client_id, object_id, resource_id, identity_id) if arg])
230+
id_arg_count = len([arg for arg in (client_id, object_id, resource_id) if arg])
231231
if id_arg_count > 1:
232-
raise CLIError('Usage error: Provide only one of --client-id, --object-id, --resource-id, or --username.')
232+
raise CLIError('Usage error: Provide only one of --client-id, --object-id, --resource-id.')
233233

234234
if id_arg_count == 0:
235235
identity_type = MsiAccountTypes.system_assigned
236+
identity_id = None
236237
msi_creds = MSIAuthenticationWrapper(resource=resource)
237238
elif client_id:
238239
identity_type = MsiAccountTypes.user_assigned_client_id
@@ -246,37 +247,6 @@ def login_with_managed_identity_msrestazure(
246247
identity_type = MsiAccountTypes.user_assigned_resource_id
247248
identity_id = resource_id
248249
msi_creds = MSIAuthenticationWrapper(resource=resource, msi_res_id=resource_id)
249-
# The old way of re-using the same --username for 3 types of ID
250-
elif identity_id:
251-
if is_valid_resource_id(identity_id):
252-
msi_creds = MSIAuthenticationWrapper(resource=resource, msi_res_id=identity_id)
253-
identity_type = MsiAccountTypes.user_assigned_resource_id
254-
else:
255-
authenticated = False
256-
from azure.cli.core.azclierror import AzureResponseError
257-
try:
258-
msi_creds = MSIAuthenticationWrapper(resource=resource, client_id=identity_id)
259-
identity_type = MsiAccountTypes.user_assigned_client_id
260-
authenticated = True
261-
except AzureResponseError as ex:
262-
if 'http error: 400, reason: Bad Request' in ex.error_msg:
263-
logger.info('Sniff: not an MSI client id')
264-
else:
265-
raise
266-
267-
if not authenticated:
268-
try:
269-
identity_type = MsiAccountTypes.user_assigned_object_id
270-
msi_creds = MSIAuthenticationWrapper(resource=resource, object_id=identity_id)
271-
authenticated = True
272-
except AzureResponseError as ex:
273-
if 'http error: 400, reason: Bad Request' in ex.error_msg:
274-
logger.info('Sniff: not an MSI object id')
275-
else:
276-
raise
277-
278-
if not authenticated:
279-
raise CLIError('Failed to connect to MSI, check your managed service identity id.')
280250

281251
token_entry = msi_creds.token
282252
token = token_entry['access_token']
@@ -301,7 +271,7 @@ def login_with_managed_identity_msrestazure(
301271
return deepcopy(consolidated)
302272

303273
def login_with_managed_identity(self, client_id=None, object_id=None, resource_id=None,
304-
allow_no_subscriptions=None):
274+
allow_no_subscriptions=None):
305275
if not _use_msal_managed_identity(self.cli_ctx):
306276
return self.login_with_managed_identity_msrestazure(
307277
client_id=client_id, object_id=object_id, resource_id=resource_id,

src/azure-cli-core/azure/cli/core/tests/test_profile.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -639,19 +639,6 @@ def test_login_with_mi_user_assigned_client_id(self, create_subscription_client_
639639
self.assertEqual(s['user']['type'], 'servicePrincipal')
640640
self.assertEqual(s['user']['assignedIdentityInfo'], 'MSIClient-{}'.format(test_client_id))
641641

642-
# Old way of using identity_id
643-
subscriptions = profile.login_with_managed_identity(identity_id=test_client_id)
644-
645-
self.assertEqual(len(subscriptions), 1)
646-
s = subscriptions[0]
647-
self.assertEqual(s['name'], self.display_name1)
648-
self.assertEqual(s['id'], self.id1.split('/')[-1])
649-
self.assertEqual(s['tenantId'], self.test_mi_tenant)
650-
651-
self.assertEqual(s['user']['name'], 'userAssignedIdentity')
652-
self.assertEqual(s['user']['type'], 'servicePrincipal')
653-
self.assertEqual(s['user']['assignedIdentityInfo'], 'MSIClient-{}'.format(test_client_id))
654-
655642
@mock.patch('azure.cli.core.auth.adal_authentication.MSIAuthenticationWrapper', autospec=True)
656643
@mock.patch('azure.cli.core._profile.SubscriptionFinder._create_subscription_client', autospec=True)
657644
@mock.patch.dict('os.environ', {'AZURE_CORE_USE_MSAL_MANAGED_IDENTITY': 'false'})
@@ -693,14 +680,6 @@ def set_token(self):
693680
self.assertEqual(s['user']['type'], 'servicePrincipal')
694681
self.assertEqual(s['user']['assignedIdentityInfo'], 'MSIObject-{}'.format(test_object_id))
695682

696-
# Old way of using identity_id
697-
subscriptions = profile.login_with_managed_identity(identity_id=test_object_id)
698-
699-
s = subscriptions[0]
700-
self.assertEqual(s['user']['name'], 'userAssignedIdentity')
701-
self.assertEqual(s['user']['type'], 'servicePrincipal')
702-
self.assertEqual(s['user']['assignedIdentityInfo'], 'MSIObject-{}'.format(test_object_id))
703-
704683
@mock.patch('requests.get', autospec=True)
705684
@mock.patch('azure.cli.core._profile.SubscriptionFinder._create_subscription_client', autospec=True)
706685
@mock.patch.dict('os.environ', {'AZURE_CORE_USE_MSAL_MANAGED_IDENTITY': 'false'})
@@ -735,14 +714,6 @@ def test_login_with_mi_user_assigned_resource_id(self, create_subscription_clien
735714
self.assertEqual(s['user']['type'], 'servicePrincipal')
736715
self.assertEqual(subscriptions[0]['user']['assignedIdentityInfo'], 'MSIResource-{}'.format(test_res_id))
737716

738-
# Old way of using identity_id
739-
subscriptions = profile.login_with_managed_identity(identity_id=test_res_id)
740-
741-
s = subscriptions[0]
742-
self.assertEqual(s['user']['name'], 'userAssignedIdentity')
743-
self.assertEqual(s['user']['type'], 'servicePrincipal')
744-
self.assertEqual(subscriptions[0]['user']['assignedIdentityInfo'], 'MSIResource-{}'.format(test_res_id))
745-
746717
@mock.patch('azure.cli.core._profile.SubscriptionFinder._create_subscription_client', autospec=True)
747718
@mock.patch('azure.cli.core.auth.msal_credentials.ManagedIdentityCredential', ManagedIdentityCredentialStub)
748719
def test_login_with_mi_system_assigned_msal(self, create_subscription_client_mock):

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,4 @@ def cf_acr_agentpool(cli_ctx, *_):
8282

8383

8484
def cf_acr_connected_registries(cli_ctx, *_):
85-
return get_acr_service_client(cli_ctx, VERSION_2021_08_01_PREVIEW).connected_registries
85+
return get_acr_service_client(cli_ctx, VERSION_2024_11_01_PREVIEW).connected_registries

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,10 @@ def load_arguments(self, _): # pylint: disable=too-many-statements
551551
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="* * * * *")
552552
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")
553553
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 ...]".')
554+
c.argument('garbage_collection_enabled', options_list=['--gc-enabled'],
555+
help='Indicate whether garbage collection is enabled. It is enabled by default.', arg_type=get_three_state_flag(), required=False, default="true")
556+
c.argument('garbage_collection_schedule', options_list=['--gc-schedule'],
557+
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 * * *")
554558

555559
with self.argument_context('acr connected-registry update') as c:
556560
c.argument('log_level', help='Set the log level for logging on the instance. Accepted log levels are Debug, Information, Warning, Error, and None.')
@@ -565,7 +569,9 @@ def load_arguments(self, _): # pylint: disable=too-many-statements
565569
help='List of artifact pattern to be added to notifications list. Use the format "--add-notifications [PATTERN1 PATTERN2 ...]".')
566570
c.argument('remove_notifications', options_list=['--remove-notifications'], nargs='*',
567571
help='List of artifact pattern to be removed from notifications list. Use the format "--remove-notifications [PATTERN1 PATTERN2 ...]".')
568-
572+
c.argument('garbage_collection_enabled', options_list=['--gc-enabled'],
573+
help='Indicate whether garbage collection is enabled. It is enabled by default.', arg_type=get_three_state_flag())
574+
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.')
569575
with self.argument_context('acr connected-registry permissions') as c:
570576
c.argument('add_repos', options_list=['--add'], nargs='*',
571577
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)

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

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ def acr_connected_registry_create(cmd, # pylint: disable=too-many-locals, too-m
6060
log_level=None,
6161
sync_audit_logs_enabled=False,
6262
notifications=None,
63+
garbage_collection_enabled=None,
64+
garbage_collection_schedule=None,
6365
yes=False):
6466

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

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

114-
ConnectedRegistry, LoggingProperties, SyncProperties, ParentProperties = cmd.get_models(
115-
'ConnectedRegistry', 'LoggingProperties', 'SyncProperties', 'ParentProperties')
116+
ConnectedRegistry, LoggingProperties, SyncProperties, \
117+
ParentProperties, GarbageCollectionProperties = cmd.get_models(
118+
'ConnectedRegistry', 'LoggingProperties', 'SyncProperties',
119+
'ParentProperties', 'GarbageCollectionProperties')
116120
connected_registry_create_parameters = ConnectedRegistry(
117121
provisioning_state=None,
118122
mode=mode,
@@ -130,6 +134,10 @@ def acr_connected_registry_create(cmd, # pylint: disable=too-many-locals, too-m
130134
log_level=log_level,
131135
audit_log_status='Enabled' if sync_audit_logs_enabled else 'Disabled'
132136
),
137+
garbage_collection=GarbageCollectionProperties(
138+
enabled=garbage_collection_enabled,
139+
schedule=garbage_collection_schedule
140+
),
133141
notifications_list=list(notifications_set) if notifications_set else None
134142
)
135143

@@ -155,7 +163,9 @@ def acr_connected_registry_update(cmd, # pylint: disable=too-many-locals, too-m
155163
sync_message_ttl=None,
156164
sync_audit_logs_enabled=None,
157165
add_notifications=None,
158-
remove_notifications=None):
166+
remove_notifications=None,
167+
garbage_collection_enabled=None,
168+
garbage_collection_schedule=None):
159169
_, resource_group_name = validate_managed_registry(
160170
cmd, registry_name, resource_group_name)
161171
subscription_id = get_subscription_id(cmd.cli_ctx)
@@ -211,8 +221,10 @@ def acr_connected_registry_update(cmd, # pylint: disable=too-many-locals, too-m
211221

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

214-
ConnectedRegistryUpdateParameters, SyncUpdateProperties, LoggingProperties = cmd.get_models(
215-
'ConnectedRegistryUpdateParameters', 'SyncUpdateProperties', 'LoggingProperties')
224+
ConnectedRegistryUpdateParameters, SyncUpdateProperties, \
225+
LoggingProperties, GarbageCollectionProperties = cmd.get_models(
226+
'ConnectedRegistryUpdateParameters', 'SyncUpdateProperties',
227+
'LoggingProperties', 'GarbageCollectionProperties')
216228
connected_registry_update_parameters = ConnectedRegistryUpdateParameters(
217229
sync_properties=SyncUpdateProperties(
218230
schedule=sync_schedule,
@@ -223,6 +235,10 @@ def acr_connected_registry_update(cmd, # pylint: disable=too-many-locals, too-m
223235
log_level=log_level,
224236
audit_log_status=sync_audit_logs_enabled
225237
),
238+
garbage_collection=GarbageCollectionProperties(
239+
enabled=garbage_collection_enabled,
240+
schedule=garbage_collection_schedule
241+
),
226242
client_token_ids=client_token_list,
227243
notifications_list=notifications_list
228244
)

0 commit comments

Comments
 (0)