Created
February 20, 2019 22:34
-
-
Save dmahugh/873ea34954d1b59582e062824a2e3c27 to your computer and use it in GitHub Desktop.
Minimal Python code to read secrets from Azure Key Vaults
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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