-
Notifications
You must be signed in to change notification settings - Fork 3k
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
{Core} Refactor code for passing arguments #30300
Conversation
️✔️AzureCLI-FullTest
|
Hi @jiasli, |
️✔️AzureCLI-BreakingChangeTest
|
Thank you for your contribution! We will review the pull request and get back to you soon. |
@@ -665,7 +666,7 @@ def _create_credential(self, account, tenant_id=None, client_id=None): | |||
""" | |||
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] |
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.
https://docs.python.org/3/library/stdtypes.html#boolean-operations-and-or-not
x or y: if x is true, then x, else y
0f28626
to
d2707ea
Compare
@@ -413,7 +413,7 @@ def get_login_credentials(self, resource=None, client_id=None, subscription_id=N | |||
credential = self._create_credential(account, client_id=client_id) | |||
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)) |
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.
_create_credential()
defines tenant_id
as a keyword argument:
def _create_credential(self, account, tenant_id=None, client_id=None): |
Calling _create_credential()
should follow the same pattern.
@@ -938,7 +938,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): |
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.
Very limited args
(actually only one - authority
) and kwargs
are used:
It's better to be explicit.
https://peps.python.org/pep-0020/
Explicit is better than implicit.
d2707ea
to
b12ac18
Compare
@@ -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): |
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_id
should not be supported by get_login_credentials()
.
@@ -655,18 +653,17 @@ def _try_parse_msi_account_name(account): | |||
return parts[0], (None if len(parts) <= 1 else parts[1]) | |||
return None, None | |||
|
|||
def _create_credential(self, account, tenant_id=None, client_id=None): | |||
def _create_credential(self, account, tenant_id=None): |
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_id
is used in here, need to be reverted in the future: https://github.com/Azure/azure-cli/pull/30302/files#diff-242cdb28a28d3ff1d8467d2416389e39c0d149dab437550d6a6e88cca877c220R461
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.
There is no guarantee when #30302 will be merged. Better to keep the code clean for now.
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.
If there's possibility that client_id
is needed in the future, I agree with Hang that we can keep it for now. There's no harm to leave it as it is, right?
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.
Ok, changed as requested, but client_id
will only be supported by get_raw_token()
, not get_login_credentials()
, so I am still removing it from get_login_credentials()
.
b12ac18
to
5decba3
Compare
5decba3
to
4fc8040
Compare
Related command
az login
Description
Refactor code for passing arguments.
Pave way for
az account get-access-token
: Add--client-id
argument #30301