Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/azure-cli-core/azure/cli/core/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
CONFIG_FILE_NAME = 'config'
GLOBAL_CONFIG_PATH = os.path.join(GLOBAL_CONFIG_DIR, CONFIG_FILE_NAME)
ENV_VAR_PREFIX = 'AZURE'
ENV_VAR_TEST_LIVE = 'AZURE_TEST_RUN_LIVE'
23 changes: 20 additions & 3 deletions src/azure-cli-core/azure/cli/core/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

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', 'msal_token_cache.json',
'service_principal_entries.json']:
try:
shutil.copy(os.path.join(GLOBAL_CONFIG_DIR, file), config_dir)
except FileNotFoundError:
pass
Comment on lines +39 to +40
Copy link
Contributor

@zhoxing-ms zhoxing-ms Jul 12, 2023

Choose a reason for hiding this comment

The 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 FileNotFoundError?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 ~/.azure. Skip copying them.

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,
Expand Down