-
Notifications
You must be signed in to change notification settings - Fork 3.3k
{Perf} Delay importing MSIAuthenticationWrapper and check_version_compatibility #14331
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,8 +21,6 @@ | |
| is_windows, is_wsl | ||
| from azure.cli.core.cloud import get_active_cloud, set_cloud_subscription | ||
|
|
||
| from .adal_authentication import MSIAuthenticationWrapper | ||
|
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. |
||
|
|
||
| from knack.log import get_logger | ||
| from knack.util import CLIError | ||
|
|
||
|
|
@@ -309,6 +307,7 @@ def find_subscriptions_in_vm_with_msi(self, identity_id=None, allow_no_subscript | |
| import jwt | ||
| from requests import HTTPError | ||
| from msrestazure.tools import is_valid_resource_id | ||
| from azure.cli.core.adal_authentication import MSIAuthenticationWrapper | ||
| resource = self.cli_ctx.cloud.endpoints.active_directory_resource_id | ||
|
|
||
| if identity_id: | ||
|
|
@@ -388,6 +387,7 @@ def find_subscriptions_in_cloud_console(self): | |
| return deepcopy(consolidated) | ||
|
|
||
| def _get_token_from_cloud_shell(self, resource): # pylint: disable=no-self-use | ||
| from azure.cli.core.adal_authentication import MSIAuthenticationWrapper | ||
| auth = MSIAuthenticationWrapper(resource=resource) | ||
| auth.set_token() | ||
| token_entry = auth.token | ||
|
|
@@ -773,6 +773,7 @@ def valid_msi_account_types(): | |
|
|
||
| @staticmethod | ||
| def msi_auth_factory(cli_account_name, identity, resource): | ||
| from azure.cli.core.adal_authentication import MSIAuthenticationWrapper | ||
| if cli_account_name == MsiAccountTypes.system_assigned: | ||
| return MSIAuthenticationWrapper(resource=resource) | ||
| if cli_account_name == MsiAccountTypes.user_assigned_client_id: | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Importing a module in a for loop is not a good practice.
How much can it benefit from importing in this for loop?
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.
You can import module as many times as you want in one Python program, no matter what module it is. Every subsequent import after the first accesses the cached module instead of re-evaluating it. So there is no performance penalty.
In reply to: 454774982 [](ancestors = 454774982)
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.
This is a tricky part. I just want to eliminate an extra
if allowed_extensions:. Python has an import cache which will handle "import in a for loop" nicely.