Murugaraju Perumalla
Murugaraju Perumalla

Reputation: 435

Using Python, Azure KeyVault Secret Client connecting programatically

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

enter image description here

enter image description here

Wanted those to be injected manually, instead setting them as Env Variable

Upvotes: 2

Views: 1994

Answers (1)

Murugaraju Perumalla
Murugaraju Perumalla

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

Related Questions