Skip to content

Commit 5d0cf1a

Browse files
authored
{Core} Refactor code for passing arguments (#30300)
1 parent eb55296 commit 5d0cf1a

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -362,12 +362,10 @@ def logout_all(self):
362362
identity.logout_all_users()
363363
identity.logout_all_service_principal()
364364

365-
def get_login_credentials(self, resource=None, client_id=None, subscription_id=None, aux_subscriptions=None,
366-
aux_tenants=None):
365+
def get_login_credentials(self, resource=None, subscription_id=None, aux_subscriptions=None, aux_tenants=None):
367366
"""Get a CredentialAdaptor instance to be used with both Track 1 and Track 2 SDKs.
368367
369368
:param resource: The resource ID to acquire an access token. Only provide it for Track 1 SDKs.
370-
:param client_id:
371369
:param subscription_id:
372370
:param aux_subscriptions:
373371
:param aux_tenants:
@@ -410,10 +408,10 @@ def get_login_credentials(self, resource=None, client_id=None, subscription_id=N
410408
if sub[_TENANT_ID] != account[_TENANT_ID]:
411409
external_tenants.append(sub[_TENANT_ID])
412410

413-
credential = self._create_credential(account, client_id=client_id)
411+
credential = self._create_credential(account)
414412
external_credentials = []
415413
for external_tenant in external_tenants:
416-
external_credentials.append(self._create_credential(account, external_tenant, client_id=client_id))
414+
external_credentials.append(self._create_credential(account, tenant_id=external_tenant))
417415
from azure.cli.core.auth.credential_adaptor import CredentialAdaptor
418416
cred = CredentialAdaptor(credential,
419417
auxiliary_credentials=external_credentials,
@@ -460,7 +458,7 @@ def get_raw_token(self, resource=None, scopes=None, subscription=None, tenant=No
460458
scopes_to_resource(scopes))
461459

462460
else:
463-
cred = self._create_credential(account, tenant)
461+
cred = self._create_credential(account, tenant_id=tenant)
464462

465463
sdk_token = cred.get_token(*scopes)
466464
# Convert epoch int 'expires_on' to datetime string 'expiresOn' for backward compatibility
@@ -658,14 +656,14 @@ def _try_parse_msi_account_name(account):
658656
def _create_credential(self, account, tenant_id=None, client_id=None):
659657
"""Create a credential object driven by MSAL
660658
661-
:param account:
659+
:param account: The CLI account to create credential for
662660
:param tenant_id: If not None, override tenantId from 'account'
663-
:param client_id:
661+
:param client_id: Client ID of another public client application
664662
:return:
665663
"""
666664
user_type = account[_USER_ENTITY][_USER_TYPE]
667665
username_or_sp_id = account[_USER_ENTITY][_USER_NAME]
668-
tenant_id = tenant_id if tenant_id else account[_TENANT_ID]
666+
tenant_id = tenant_id or account[_TENANT_ID]
669667
identity = _create_identity_instance(self.cli_ctx, self._authority, tenant_id=tenant_id, client_id=client_id)
670668

671669
# User
@@ -694,7 +692,7 @@ def refresh_accounts(self):
694692
tenant = s[_TENANT_ID]
695693
subscriptions = []
696694
try:
697-
identity_credential = self._create_credential(s, tenant)
695+
identity_credential = self._create_credential(s, tenant_id=tenant)
698696
if is_service_principal:
699697
subscriptions = subscription_finder.find_using_specific_tenant(tenant, identity_credential)
700698
else:
@@ -938,7 +936,7 @@ def _transform_subscription_for_multiapi(s, s_dict):
938936
s_dict[_MANAGED_BY_TENANTS] = [{_TENANT_ID: t.tenant_id} for t in s.managed_by_tenants]
939937

940938

941-
def _create_identity_instance(cli_ctx, *args, **kwargs):
939+
def _create_identity_instance(cli_ctx, authority, tenant_id=None, client_id=None):
942940
"""Lazily import and create Identity instance to avoid unnecessary imports."""
943941
from .auth.identity import Identity
944942
from .util import should_encrypt_token_cache
@@ -955,9 +953,11 @@ def _create_identity_instance(cli_ctx, *args, **kwargs):
955953
# PREVIEW: In Azure Stack environment, use core.instance_discovery=false to disable MSAL's instance discovery.
956954
instance_discovery = cli_ctx.config.getboolean('core', 'instance_discovery', True)
957955

958-
return Identity(*args, encrypt=encrypt, use_msal_http_cache=use_msal_http_cache,
956+
return Identity(authority, tenant_id=tenant_id, client_id=client_id,
957+
encrypt=encrypt,
958+
use_msal_http_cache=use_msal_http_cache,
959959
enable_broker_on_windows=enable_broker_on_windows,
960-
instance_discovery=instance_discovery, **kwargs)
960+
instance_discovery=instance_discovery)
961961

962962

963963
def _on_azure_arc_windows():

0 commit comments

Comments
 (0)