Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions src/azure-cli-core/azure/cli/core/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

CLOUD_CONFIG_FILE = os.path.join(GLOBAL_CONFIG_DIR, 'clouds.config')

# Add names of clouds that don't allow telemetry data collection here such as JEDI.
CLOUDS_FORBIDDING_TELEMETRY = []


class CloudNotRegisteredException(Exception):
def __init__(self, cloud_name):
Expand Down
10 changes: 9 additions & 1 deletion src/azure-cli-core/azure/cli/core/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def product_version(self):
def _user_agrees_to_telemetry(func):
@wraps(func)
def _wrapper(*args, **kwargs):
if not _get_config().getboolean('core', 'collect_telemetry', fallback=True):
if not is_telemetry_enabled():
return None
return func(*args, **kwargs)

Expand Down Expand Up @@ -358,6 +358,14 @@ def _add_event(event_name, properties, instrumentation_key=DEFAULT_INSTRUMENTATI
})


@decorators.suppress_all_exceptions()
def is_telemetry_enabled():
from azure.cli.core.cloud import AZURE_PUBLIC_CLOUD, CLOUDS_FORBIDDING_TELEMETRY
if _get_config().get('cloud', 'name', fallback=AZURE_PUBLIC_CLOUD.name) in CLOUDS_FORBIDDING_TELEMETRY:
return False
return _get_config().getboolean('core', 'collect_telemetry', fallback=True)


# definitions

@decorators.call_once
Expand Down
3 changes: 3 additions & 0 deletions src/azure-cli/azure/cli/command_modules/configure/_consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
' $ az vm create --help\n' \
' $ az feedback\n'

MSG_CLOUD_FORBID_TELEMETRY = '\nYour current cloud: {} does not allow data collection.' \
' Telemetry is disabled regardless of the configuration.'

MSG_GLOBAL_SETTINGS_LOCATION = 'Your settings can be found at {}'

MSG_HEADING_CURRENT_CONFIG_INFO = 'Your current configuration is as follows:'
Expand Down
15 changes: 12 additions & 3 deletions src/azure-cli/azure/cli/command_modules/configure/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
MSG_PROMPT_TELEMETRY,
MSG_PROMPT_FILE_LOGGING,
MSG_PROMPT_CACHE_TTL,
MSG_CLOUD_FORBID_TELEMETRY,
DEFAULT_CACHE_TTL)
from azure.cli.command_modules.configure._utils import get_default_from_config

Expand Down Expand Up @@ -96,7 +97,7 @@ def _config_env_public_azure(cli_ctx, _):
logger.error(err)


def _handle_global_configuration(config):
def _handle_global_configuration(config, cloud_forbid_telemetry):
# print location of global configuration
print(MSG_GLOBAL_SETTINGS_LOCATION.format(config.config_path))
# set up the config parsers
Expand All @@ -118,7 +119,10 @@ def _handle_global_configuration(config):
answers['output_type_prompt'] = output_index
answers['output_type_options'] = str(OUTPUT_LIST)
enable_file_logging = prompt_y_n(MSG_PROMPT_FILE_LOGGING, default='n')
allow_telemetry = prompt_y_n(MSG_PROMPT_TELEMETRY, default='y')
if cloud_forbid_telemetry:
allow_telemetry = False
else:
allow_telemetry = prompt_y_n(MSG_PROMPT_TELEMETRY, default='y')
answers['telemetry_prompt'] = allow_telemetry
cache_ttl = None
while not cache_ttl:
Expand All @@ -140,6 +144,7 @@ def _handle_global_configuration(config):

# pylint: disable=inconsistent-return-statements
def handle_configure(cmd, defaults=None, list_defaults=None, scope=None):
from azure.cli.core.cloud import AZURE_PUBLIC_CLOUD, CLOUDS_FORBIDDING_TELEMETRY
if defaults:
defaults_section = cmd.cli_ctx.config.defaults_section_name
with ConfiguredDefaultSetter(cmd.cli_ctx.config, scope.lower() == 'local'):
Expand All @@ -157,8 +162,12 @@ def handle_configure(cmd, defaults=None, list_defaults=None, scope=None):
# if nothing supplied, we go interactively
try:
print(MSG_INTRO)
_handle_global_configuration(cmd.cli_ctx.config)
current_cloud = cmd.cli_ctx.config.get('cloud', 'name', fallback=AZURE_PUBLIC_CLOUD.name)
cloud_forbid_telemetry = current_cloud in CLOUDS_FORBIDDING_TELEMETRY
_handle_global_configuration(cmd.cli_ctx.config, cloud_forbid_telemetry)
print(MSG_CLOSING)
if cloud_forbid_telemetry:
logger.warning(MSG_CLOUD_FORBID_TELEMETRY.format(current_cloud))
# TODO: log_telemetry('configure', **answers)
except NoTTYException:
raise CLIError('This command is interactive and no tty available.')
Expand Down