Skip to content

Instantly share code, notes, and snippets.

@dmahugh
Created February 20, 2019 22:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmahugh/873ea34954d1b59582e062824a2e3c27 to your computer and use it in GitHub Desktop.
Save dmahugh/873ea34954d1b59582e062824a2e3c27 to your computer and use it in GitHub Desktop.
Minimal Python code to read secrets from Azure Key Vaults
# dependencies: azure-common, azure-keyvault
from azure.common.credentials import ServicePrincipalCredentials
from azure.keyvault import KeyVaultAuthentication, KeyVaultClient
def get_secret(secret_name, key_vault_uri, client_id, secret, tenant):
"""Get a secret from Key Vault.
"""
credentials = ServicePrincipalCredentials(
client_id=client_id, secret=secret, tenant=tenant)
client = KeyVaultClient(credentials)
try:
secret_bundle = client.get_secret(key_vault_uri, secret_name, "")
secret_value = secret_bundle.value
except:
secret_value = ""
return secret_value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment