def GetCredentials(profile_name: Optional[str] = None
                   ) -> Tuple[str, DefaultAzureCredential]:
  # pylint: disable=line-too-long
  """Get Azure credentials, trying three different methods:

  1. If profile_name is provided it will attempt to parse credentials from a
     credentials.json file, failing if this raises an exception.
  2. Environment variables as per
     https://docs.microsoft.com/en-us/azure/developer/python/azure-sdk-authenticate
  3. Azure CLI credentials.

  Args:
    profile_name (str): A name for the Azure account information to retrieve.
        If provided, then the library will look into ~/.azure/credentials.json
        for the account information linked to profile_name.

  Returns:
    Tuple[str, DefaultAzureCredential]: Subscription ID and
        corresponding Azure credentials.

  Raises:
    CredentialsConfigurationError: If none of the credential methods work.
  """
  # pylint: enable=line-too-long
  if profile_name:
    account_info = _ParseCredentialsFile(profile_name)
    # Set environment variables for DefaultAzureCredentials.
    os.environ['AZURE_SUBSCRIPTION_ID'] = account_info['subscriptionId']
    os.environ['AZURE_CLIENT_ID'] = account_info['clientId']
    os.environ['AZURE_CLIENT_SECRET'] = account_info['clientSecret']
    os.environ['AZURE_TENANT_ID'] = account_info['tenantId']

  # Check if environment variables are already set for DefaultAzureCredentials.
  subscription_id = os.getenv('AZURE_SUBSCRIPTION_ID')
  client_id = os.getenv("AZURE_CLIENT_ID")
  secret = os.getenv("AZURE_CLIENT_SECRET")
  tenant = os.getenv("AZURE_TENANT_ID")

  if not (subscription_id and client_id and secret and tenant):
    logger.info('EnvironmentCredentials unavailable, falling back to '
          'AzureCliCredentials.')
    # Will be automatically picked up by DefaultAzureCredential if configured.
    subscription_id = _CheckAzureCliCredentials()

  if not subscription_id:
    raise errors.CredentialsConfigurationError(
        'No supported credentials found. If using environment variables '
        'please make sure to define: [AZURE_SUBSCRIPTION_ID, AZURE_CLIENT_ID, '
        'AZURE_CLIENT_SECRET, AZURE_TENANT_ID].', __name__)

  return subscription_id, DefaultAzureCredential()
Get Azure credentials, trying three different methods:

1. If profile_name is provided it will attempt to parse credentials from a
credentials.json file, failing if this raises an exception.
2. Environment variables as per
https://docs.microsoft.com/en-us/azure/developer/python/azure-sdk-authenticate
3. Azure CLI credentials.

Args:
profile_name (str): A name for the Azure account information to retrieve.
If provided, then the library will look into ~/.azure/credentials.json
for the account information linked to profile_name.

Returns:
Tuple[str, DefaultAzureCredential]: Subscription ID and
corresponding Azure credentials.

Raises:
CredentialsConfigurationError: If none of the credential methods work.
libcloudforensics/providers/azure/internal/common.py