As a Module

There are two ways to give in the Azure KeyVault credentials, either set environment variables for:

AZURE_VAULT_BASE_URL=***
AZURE_CLIENT_ID=***
AZURE_SECRET_KEY=***
AZURE_TENANT_ID=***

or set them while calling the object.

Get a Single Secret

You can get a single secret with the following example:

from azsecrets import AzureSecrets

secrets = AzureSecrets('https://', 'client id', 'secret key', 'tenant id')
print(secrets.get_secret('secret-name'))
# secret-value

Get All Secrets

from azsecrets import AzureSecrets

secrets = AzureSecrets('https://', 'client id', 'secret key', 'tenant id')
print(secrets.get_secret())
# {
#     'secret-name-1' : 'secret-value-1',
#     'secret-name-2': 'secret-value-2'
#      ...
# }

Get Specific Set of Secretes

You can also get a specific set of secrets present in your Azure KeyVault by doing:

from azsecrets import AzureSecrets

secrets = AzureSecrets('https://', 'client id', 'secret key', 'tenant id')
print(secrets.get_secret(['secret-name-1', 'secret-name-2']))
# {
#     'secret-name-1' : 'secret-value-1',
#     'secret-name-2': 'secret-value-2'
# }

Package Contents

class azsecrets.AzureSecrets(vault_base_url: str = None, client_id: str = None, secret: str = None, tenant: str = None)[source]

Azure secrets object that can be used for CLI and as a module.

env_bash(secret_names: list = None, except_names: list = None)[source]

Prints environment variable for Bash

env_cmd(secret_names: list = None, except_names: list = None)[source]

Prints environment variable for CMD

env_powershell(secret_names: list = None, except_names: list = None)[source]

Prints environment variable for PowerShell

get_secret(secret_name: str, secret_version: str = None) → str[source]

Get the value for the secret key.

Parameters
  • secret_name (str) – Name of the secret key.

  • secret_version (str) – The version string of the secret key.

Returns

The secret value.

Return type

str

>>> secrets = AzureSecrets('https://', 'client id', 'secret key', 'tenant id')
>>> print(secrets.get_secret('secret-name'))
secret-value
get_secrets(env_names: list = None) → dict[source]

A dictionary of secret name and it’s value.

Parameters

env_names (list) – A list of secret names.

Return type

dict

Returns

Dictionary of secrets.

>>> secrets = AzureSecrets('https://', 'client id', 'secret key', 'tenant id')
>>> print(secrets.get_secrets(['secret-name-1', 'secret-name-2']))
{
    'secret-name-1' : 'secret-value-1',
    'secret-name-2': 'secret-value-2'
}