def _CheckAzureCliCredentials() -> Optional[str]:
  """Test if AzureCliCredentials are configured, returning the subscription
  id if successful.

  Returns:
    str: the subscription_id of the credentials if properly configured or else
      None.

  Raises:
    CredentialsConfigurationError: If AzureCliCredentials are configured but
      the active subscription could not be determined.
  """
  tokens = None

  config_dir = os.getenv('AZURE_CONFIG_DIR')
  if not config_dir:
    config_dir = os.path.expanduser('~/.azure/')

  tokens_path = os.path.join(config_dir, 'accessTokens.json')
  profile_path = os.path.join(config_dir, 'azureProfile.json')

  if not os.path.exists(tokens_path) or not os.path.exists(profile_path):
    return None

  with open(tokens_path, encoding='utf-8-sig') as tokens_fd:
    tokens = json.load(tokens_fd)

  # If tokens are not found then Azure CLI auth is not configured.
  if not tokens:
    return None

  with open(profile_path, encoding='utf-8-sig') as profile_fd:
    profile = json.load(profile_fd)

    for subscription in profile['subscriptions']:
      if subscription['isDefault']:
        return str(subscription["id"])

    raise errors.CredentialsConfigurationError(
        'AzureCliCredentials tokens found but could not determine active '
        'subscription. No "isDefault" set in "{0:s}"'.format(config_dir),
        __name__)
Test if AzureCliCredentials are configured, returning the subscription
id if successful.

Returns:
str: the subscription_id of the credentials if properly configured or else
None.

Raises:
CredentialsConfigurationError: If AzureCliCredentials are configured but
the active subscription could not be determined.
libcloudforensics/providers/azure/internal/common.py