-
Notifications
You must be signed in to change notification settings - Fork 3.3k
{Core} Fix random_config_dir when AZURE_CONFIG_DIR is set
#28673
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ class DummyCli(AzCli): | |
| """A dummy CLI instance can be used to facilitate automation""" | ||
| def __init__(self, commands_loader_cls=None, random_config_dir=False, **kwargs): | ||
| import os | ||
| from unittest.mock import patch | ||
|
|
||
| from azure.cli.core import MainCommandsLoader | ||
| from azure.cli.core.commands import AzCliCommandInvoker | ||
|
|
@@ -26,6 +27,10 @@ def __init__(self, commands_loader_cls=None, random_config_dir=False, **kwargs): | |
|
|
||
| if random_config_dir: | ||
| config_dir = os.path.join(GLOBAL_CONFIG_DIR, 'dummy_cli_config_dir', random_string()) | ||
| # Knack prioritizes the AZURE_CONFIG_DIR env over the config_dir param, and other functions may call | ||
| # get_config_dir directly. We need to set the env to make sure the config_dir is used. | ||
| self.env_patch = patch.dict(os.environ, {'AZURE_CONFIG_DIR': config_dir}) | ||
| self.env_patch.start() | ||
|
|
||
| # In recording mode, copy login credentials from global config dir to the dummy config dir | ||
| if os.getenv(ENV_VAR_TEST_LIVE, '').lower() == 'true': | ||
|
|
@@ -38,12 +43,10 @@ def __init__(self, commands_loader_cls=None, random_config_dir=False, **kwargs): | |
| shutil.copy(os.path.join(GLOBAL_CONFIG_DIR, file), config_dir) | ||
| except FileNotFoundError: | ||
| pass | ||
| else: | ||
| config_dir = GLOBAL_CONFIG_DIR | ||
|
|
||
| super(DummyCli, self).__init__( | ||
| cli_name='az', | ||
| config_dir=config_dir, | ||
| config_dir=GLOBAL_CONFIG_DIR, | ||
|
Member
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. This is what it looks like before #25689. As we are already overriding |
||
| config_env_var_prefix=ENV_VAR_PREFIX, | ||
| commands_loader_cls=commands_loader_cls or MainCommandsLoader, | ||
| parser_cls=AzCliCommandParser, | ||
|
|
||
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.
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.
https://github.com/microsoft/knack/blob/e0c14114aea5e4416c70a77623e403773aba73a8/knack/config.py#L44