Skip to content

Instantly share code, notes, and snippets.

@snobu
Last active June 25, 2020 12:43
Show Gist options
  • Select an option

  • Save snobu/e196ed41c3e9640b36ce62b56ef5c8ad to your computer and use it in GitHub Desktop.

Select an option

Save snobu/e196ed41c3e9640b36ce62b56ef5c8ad to your computer and use it in GitHub Desktop.
Get secret from Azure Key Vault in Python
#!/usr/bin/env python3
# pip install azure-keyvault-secrets azure-identity
from blessings import Terminal
t = Terminal()
import json
from azure.identity import DefaultAzureCredential, InteractiveBrowserCredential
from azure.keyvault.secrets import SecretClient
credential = InteractiveBrowserCredential()
secret_client = SecretClient(vault_url="https://alice.vault.azure.net/", credential=credential)
secret = secret_client.get_secret("secret1")
print(f' {t.green}Name: {secret.name} {t.normal}')
print(f' {t.magenta}Value: {secret.value} {t.normal}')
print(f' Enabled: {secret.properties.enabled}')
print(f' Content type: {secret.properties.content_type}')
print(f' Expires: {secret.properties.expires_on}')
print(f' Version: {secret.properties.version}')
print(f' Vault URL: {secret.properties.vault_url}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment