-
Notifications
You must be signed in to change notification settings - Fork 3.5k
{Core} Copy login credential when run test with --live and random_config_dir is enabled
#26475
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 6 commits
16fdfbc
1358bd6
a09cae0
c1eed81
31f4403
204858b
5988396
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 |
|---|---|---|
|
|
@@ -17,16 +17,33 @@ def __init__(self, commands_loader_cls=None, random_config_dir=False, **kwargs): | |
| from azure.cli.core.cloud import get_active_cloud | ||
| from azure.cli.core.parser import AzCliCommandParser | ||
| from azure.cli.core.util import random_string | ||
| from azure.cli.core._config import GLOBAL_CONFIG_DIR, ENV_VAR_PREFIX | ||
| from azure.cli.core._config import GLOBAL_CONFIG_DIR, ENV_VAR_PREFIX, ENV_VAR_TEST_LIVE | ||
| from azure.cli.core._help import AzCliHelp | ||
| from azure.cli.core._output import AzOutputProducer | ||
|
|
||
| from knack.completion import ARGCOMPLETE_ENV_NAME | ||
| from knack.util import ensure_dir | ||
|
|
||
| # random_config_dir only takes effects in playback mode | ||
| if random_config_dir: | ||
| config_dir = os.path.join(GLOBAL_CONFIG_DIR, 'dummy_cli_config_dir', random_string()) | ||
|
|
||
| # In recording mode, copy login credentials from global config dir to the dummy config dir | ||
| if os.getenv(ENV_VAR_TEST_LIVE, '').lower() == 'true': | ||
| if os.path.exists(GLOBAL_CONFIG_DIR): | ||
| ensure_dir(config_dir) | ||
| import shutil | ||
| for file in ['azureProfile.json', 'msal_token_cache.bin', 'clouds.config']: | ||
| try: | ||
| shutil.copy(os.path.join(GLOBAL_CONFIG_DIR, file), config_dir) | ||
| except FileNotFoundError: | ||
| pass | ||
|
Comment on lines
+39
to
+40
Contributor
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. I am not very familiar with the knowledge in the auth field, may I ask why do we pass for the
Contributor
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. If the user is not logged in yet, these files do not exist in |
||
| else: | ||
| config_dir = GLOBAL_CONFIG_DIR | ||
|
|
||
| super(DummyCli, self).__init__( | ||
| cli_name='az', | ||
| config_dir=os.path.join(GLOBAL_CONFIG_DIR, 'dummy_cli_config_dir', | ||
| random_string()) if random_config_dir else GLOBAL_CONFIG_DIR, | ||
| config_dir=config_dir, | ||
| config_env_var_prefix=ENV_VAR_PREFIX, | ||
| commands_loader_cls=commands_loader_cls or MainCommandsLoader, | ||
| parser_cls=AzCliCommandParser, | ||
|
|
||
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.
@jiasli Are these files requires as login credential?
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.
Service principal credentials are saved as
service_principal_entries.bin:azure-cli/src/azure-cli-core/azure/cli/core/auth/identity.py
Line 79 in f0c87ca
If token encryption is disabled,
.jsonis used as the file extension:msal_token_cache.jsonservice_principal_entries.json