-
Notifications
You must be signed in to change notification settings - Fork 3.3k
{Core} Refactor code for passing arguments #30300
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -362,12 +362,10 @@ def logout_all(self): | |||
| identity.logout_all_users() | ||||
| identity.logout_all_service_principal() | ||||
|
|
||||
| def get_login_credentials(self, resource=None, client_id=None, subscription_id=None, aux_subscriptions=None, | ||||
| aux_tenants=None): | ||||
| def get_login_credentials(self, resource=None, subscription_id=None, aux_subscriptions=None, aux_tenants=None): | ||||
| """Get a CredentialAdaptor instance to be used with both Track 1 and Track 2 SDKs. | ||||
|
|
||||
| :param resource: The resource ID to acquire an access token. Only provide it for Track 1 SDKs. | ||||
| :param client_id: | ||||
| :param subscription_id: | ||||
| :param aux_subscriptions: | ||||
| :param aux_tenants: | ||||
|
|
@@ -410,10 +408,10 @@ def get_login_credentials(self, resource=None, client_id=None, subscription_id=N | |||
| if sub[_TENANT_ID] != account[_TENANT_ID]: | ||||
| external_tenants.append(sub[_TENANT_ID]) | ||||
|
|
||||
| credential = self._create_credential(account, client_id=client_id) | ||||
| credential = self._create_credential(account) | ||||
| external_credentials = [] | ||||
| for external_tenant in external_tenants: | ||||
| external_credentials.append(self._create_credential(account, external_tenant, client_id=client_id)) | ||||
| external_credentials.append(self._create_credential(account, tenant_id=external_tenant)) | ||||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Calling |
||||
| from azure.cli.core.auth.credential_adaptor import CredentialAdaptor | ||||
| cred = CredentialAdaptor(credential, | ||||
| auxiliary_credentials=external_credentials, | ||||
|
|
@@ -460,7 +458,7 @@ def get_raw_token(self, resource=None, scopes=None, subscription=None, tenant=No | |||
| scopes_to_resource(scopes)) | ||||
|
|
||||
| else: | ||||
| cred = self._create_credential(account, tenant) | ||||
| cred = self._create_credential(account, tenant_id=tenant) | ||||
|
|
||||
| sdk_token = cred.get_token(*scopes) | ||||
| # Convert epoch int 'expires_on' to datetime string 'expiresOn' for backward compatibility | ||||
|
|
@@ -658,14 +656,14 @@ def _try_parse_msi_account_name(account): | |||
| def _create_credential(self, account, tenant_id=None, client_id=None): | ||||
| """Create a credential object driven by MSAL | ||||
|
|
||||
| :param account: | ||||
| :param account: The CLI account to create credential for | ||||
| :param tenant_id: If not None, override tenantId from 'account' | ||||
| :param client_id: | ||||
| :param client_id: Client ID of another public client application | ||||
| :return: | ||||
| """ | ||||
| user_type = account[_USER_ENTITY][_USER_TYPE] | ||||
| username_or_sp_id = account[_USER_ENTITY][_USER_NAME] | ||||
| tenant_id = tenant_id if tenant_id else account[_TENANT_ID] | ||||
| tenant_id = tenant_id or account[_TENANT_ID] | ||||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://docs.python.org/3/library/stdtypes.html#boolean-operations-and-or-not
|
||||
| identity = _create_identity_instance(self.cli_ctx, self._authority, tenant_id=tenant_id, client_id=client_id) | ||||
|
|
||||
| # User | ||||
|
|
@@ -694,7 +692,7 @@ def refresh_accounts(self): | |||
| tenant = s[_TENANT_ID] | ||||
| subscriptions = [] | ||||
| try: | ||||
| identity_credential = self._create_credential(s, tenant) | ||||
| identity_credential = self._create_credential(s, tenant_id=tenant) | ||||
| if is_service_principal: | ||||
| subscriptions = subscription_finder.find_using_specific_tenant(tenant, identity_credential) | ||||
| else: | ||||
|
|
@@ -938,7 +936,7 @@ def _transform_subscription_for_multiapi(s, s_dict): | |||
| s_dict[_MANAGED_BY_TENANTS] = [{_TENANT_ID: t.tenant_id} for t in s.managed_by_tenants] | ||||
|
|
||||
|
|
||||
| def _create_identity_instance(cli_ctx, *args, **kwargs): | ||||
| def _create_identity_instance(cli_ctx, authority, tenant_id=None, client_id=None): | ||||
| """Lazily import and create Identity instance to avoid unnecessary imports.""" | ||||
| from .auth.identity import Identity | ||||
| from .util import should_encrypt_token_cache | ||||
|
|
@@ -955,9 +953,11 @@ def _create_identity_instance(cli_ctx, *args, **kwargs): | |||
| # PREVIEW: In Azure Stack environment, use core.instance_discovery=false to disable MSAL's instance discovery. | ||||
| instance_discovery = cli_ctx.config.getboolean('core', 'instance_discovery', True) | ||||
|
|
||||
| return Identity(*args, encrypt=encrypt, use_msal_http_cache=use_msal_http_cache, | ||||
| return Identity(authority, tenant_id=tenant_id, client_id=client_id, | ||||
| encrypt=encrypt, | ||||
| use_msal_http_cache=use_msal_http_cache, | ||||
| enable_broker_on_windows=enable_broker_on_windows, | ||||
| instance_discovery=instance_discovery, **kwargs) | ||||
| instance_discovery=instance_discovery) | ||||
|
|
||||
|
|
||||
| def _on_azure_arc_windows(): | ||||
|
|
||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
client_idshould not be supported byget_login_credentials().