client_factory module

Functions

get_client_from_auth_file(client_class, auth_path=None, **kwargs)

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.


   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.

get_client_from_auth_file(client_class, auth_path=None, **kwargs)

Parameters

client_class

A SDK client class

auth_path
str

Path to the file.

default value: None

Returns

An instantiated client

get_client_from_cli_profile(client_class, **kwargs)

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.


   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.

get_client_from_cli_profile(client_class, **kwargs)

Parameters

client_class

A SDK client class

Returns

An instantiated client

get_client_from_json_dict(client_class, config_dict, **kwargs)

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.


   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.

get_client_from_json_dict(client_class, config_dict, **kwargs)

Parameters

client_class

A SDK client class

config_dict
dict

A config dict.

Returns

An instantiated client