Reputation: 435
Need a way to connect to Azure Keyvaluat Secret programatically using Python. Found existing doc from Azure which is pointing to usage of DefaultAzureCredential from azure.identity. Which explicitly seeks the enivironment to set up to have values link to git hub
Wanted those to be injected manually, instead setting them as Env Variable
Upvotes: 2
Views: 1994
Reputation: 435
One can use the below class from azure.identity i.e ClientSecretCredential, find the below code ex: snippet
from azure.identity import ClientSecretCredential
from azure.keyvault.secrets import SecretClient
TENANT= <TenantId-in-string>
CLIENT_ID = <ClientId-in-string>
CLIENT_SECRET= <ClientSecret-in-string>
credential = ClientSecretCredential(TENANT,CLIENT_ID,CLIENT_SECRET)
VAULT_URL= <AzureVault-url-in-string>
client = SecretClient(vault_url=VAULT_URL, credential=credential)
print(client)
example_secret = client.get_secret(<secret_name_in_string>)
print(example_secret.value)
Upvotes: 1