azure.common package

Submodules

azure.common.client_factory.get_client_from_auth_file(client_class, auth_path=None, **kwargs)[source]

Return a SDK client initialized with auth file.

The easiest way to obtain this file is to call the following CLI commands:

az ad sp create-for-rbac --sdk-auth

You can specific the file path directly, or fill the environment variable AZURE_AUTH_LOCATION. File must be UTF-8.

This method will fill automatically the following client parameters: - credentials - subscription_id - base_url

Parameters provided in kwargs will override parameters and be passed directly to the client.

Example

from azure.common.client_factory import get_client_from_auth_file
from azure.mgmt.compute import ComputeManagementClient
client = get_client_from_auth_file(ComputeManagementClient)

Example of file:

{
    "clientId": "ad735158-65ca-11e7-ba4d-ecb1d756380e",
    "clientSecret": "b70bb224-65ca-11e7-810c-ecb1d756380e",
    "subscriptionId": "bfc42d3a-65ca-11e7-95cf-ecb1d756380e",
    "tenantId": "c81da1d8-65ca-11e7-b1d1-ecb1d756380e",
    "activeDirectoryEndpointUrl": "https://login.microsoftonline.com",
    "resourceManagerEndpointUrl": "https://management.azure.com/",
    "activeDirectoryGraphResourceId": "https://graph.windows.net/",
    "sqlManagementEndpointUrl": "https://management.core.windows.net:8443/",
    "galleryEndpointUrl": "https://gallery.azure.com/",
    "managementEndpointUrl": "https://management.core.windows.net/"
}

New in version 1.1.7.

Parameters
  • client_class – A SDK client class

  • auth_path (str) – Path to the file.

Returns

An instantiated client

Raises

KeyError if AZURE_AUTH_LOCATION is not an environment variable and no path is provided

Raises

FileNotFoundError if provided file path does not exists

Raises

json.JSONDecodeError if provided file is not JSON valid

Raises

UnicodeDecodeError if file is not UTF8 compliant

azure.common.client_factory.get_client_from_cli_profile(client_class, **kwargs)[source]

Return a SDK client initialized with current CLI credentials, CLI default subscription and CLI default cloud.

This method will fill automatically the following client parameters: - credentials - subscription_id - base_url

Parameters provided in kwargs will override CLI parameters and be passed directly to the client.

Example

from azure.common.client_factory import get_client_from_cli_profile
from azure.mgmt.compute import ComputeManagementClient
client = get_client_from_cli_profile(ComputeManagementClient)

New in version 1.1.6.

Parameters

client_class – A SDK client class

Returns

An instantiated client

Raises

ImportError if azure-cli-core package is not available

azure.common.client_factory.get_client_from_json_dict(client_class, config_dict, **kwargs)[source]

Return a SDK client initialized with a JSON auth dict.

The easiest way to obtain this content is to call the following CLI commands:

az ad sp create-for-rbac --sdk-auth

This method will fill automatically the following client parameters: - credentials - subscription_id - base_url - tenant_id

Parameters provided in kwargs will override parameters and be passed directly to the client.

Example

from azure.common.client_factory import get_client_from_auth_file
from azure.mgmt.compute import ComputeManagementClient
config_dict = {
    "clientId": "ad735158-65ca-11e7-ba4d-ecb1d756380e",
    "clientSecret": "b70bb224-65ca-11e7-810c-ecb1d756380e",
    "subscriptionId": "bfc42d3a-65ca-11e7-95cf-ecb1d756380e",
    "tenantId": "c81da1d8-65ca-11e7-b1d1-ecb1d756380e",
    "activeDirectoryEndpointUrl": "https://login.microsoftonline.com",
    "resourceManagerEndpointUrl": "https://management.azure.com/",
    "activeDirectoryGraphResourceId": "https://graph.windows.net/",
    "sqlManagementEndpointUrl": "https://management.core.windows.net:8443/",
    "galleryEndpointUrl": "https://gallery.azure.com/",
    "managementEndpointUrl": "https://management.core.windows.net/"
}
client = get_client_from_json_dict(ComputeManagementClient, config_dict)

New in version 1.1.7.

Parameters
  • client_class – A SDK client class

  • config_dict (dict) – A config dict.

Returns

An instantiated client

azure.common.credentials.get_azure_cli_credentials(resource=None, with_tenant=False)[source]

Return Credentials and default SubscriptionID of current loaded profile of the CLI.

Credentials will be the “az login” command: https://docs.microsoft.com/cli/azure/authenticate-azure-cli

Default subscription ID is either the only one you have, or you can define it: https://docs.microsoft.com/cli/azure/manage-azure-subscriptions-azure-cli

New in version 1.1.6.

Parameters
  • resource (str) – The alternative resource for credentials if not ARM (GraphRBac, etc.)

  • with_tenant (bool) – If True, return a three-tuple with last as tenant ID

Returns

tuple of Credentials and SubscriptionID (and tenant ID if with_tenant)

Return type

tuple

azure.common.credentials.get_cli_profile()[source]

Return a CLI profile class.

New in version 1.1.6.

Returns

A CLI Profile

Return type

azure.cli.core._profile.Profile

Raises

ImportError if azure-cli-core package is not available

Module contents

exception azure.common.AzureConflictHttpError(message, status_code)[source]

Bases: azure.common.AzureHttpError

exception azure.common.AzureException[source]

Bases: Exception

exception azure.common.AzureHttpError(message, status_code)[source]

Bases: azure.common.AzureException

exception azure.common.AzureMissingResourceHttpError(message, status_code)[source]

Bases: azure.common.AzureHttpError