python - 使用 Python、Azure Key Vault Secret Client 以编程方式连接

标签 python python-3.x azure azure-keyvault azure-secrets

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

最佳答案

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)

关于python - 使用 Python、Azure Key Vault Secret Client 以编程方式连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69884235/

相关文章:

使用 API 获取 json 中的 xml 数据的 python 脚本

multithreading - "RuntimeError: Calling Tcl from different appartment"tkinter 和线程

c# - Azure 搜索文档添加自定义分析器、分词器和分词过滤器

c# - 如何配置 WCF 来处理大量并发用户?

azure - 如何使用 .Net 客户端列出 Azure Blob 快照

python - 如何使用 numpy 或 tensorflow 更快地将图像平均分成 N 个部分?

python - 导入错误 : No module named prop2part (TuLiP)

linux - Python PATH .is_file() 将符号链接(symbolic link)评估为文件

python - 展平包含列表和元组列表的字典

python - 运行 pyCOMPSs 应用程序的 SCP 失败