Azure Databricks 秘密范围:Azure Key Vault 支持或 Databricks 支持

Azure Databricks Secret Scope: Azure Key Vault-backed or Databricks-backed

有没有办法通过 python 笔记本确定现有的 Azure Databricks Secret Scope 是否由 Key Vault 或 Databricks 支持? dbutils.secrets.listScopes() 不输出这个。假设我对范围具有管理权限。 (不幸的是,Google 没有帮助)

您可以通过 Secrets REST API 执行此操作 - 如果您使用 List Secret Scopes API,则 backend_type 字段显示后端 - Datbricks 或 KeyVault。在笔记本中,您可以使用以下代码完成此操作:

import requests
ctx = dbutils.notebook.entry_point.getDbutils().notebook().getContext()
host_name = ctx.tags().get("browserHostName").get()
host_token = ctx.apiToken().get()
cluster_id = ctx.tags().get("clusterId").get()

response = requests.get(
    f'https://{host_name}/api/2.0/secrets/scopes/list',
    headers={'Authorization': f'Bearer {host_token}'}
  ).json()
scopes = dict([(s['name'], s.get('backend_type', 'DATABRICKS')) 
               for s in response['scopes']])
backend = scopes['scope-name']

或者您可以使用 databricks secrets list-scopes 命令通过 databricks-cli 执行相同的操作(参见 docs