数据块中的秘密

Secrets in databricks

我使用秘密 API 在数据块上创建了秘密。

代码:

Scope_name : {"scope": "dbtest", "initial_manage_principal":"user"}
Resp= requests.post('https://instancename.net/mynoteid/api/2.0/secrets/scopes/create',json=Scope_name)

类似的方法,我添加了用户和密码

代码:

Content = {"scope":"dbtest","key":"user","string_value":"Vidyasekar"}
requests.post('https://instancename.net/mynoteid/api/2.0/secrets/put', json=content)

执行后得到回复:<Response [200]>

这意味着秘密存储成功。

虽然使用列表 API 调用或 dbutils.secrets.get() 列出相同内容,但它显示'秘密不存在范围

这里我的疑问是, 如何获取数据块实例名称? 秘密存储在 DBFS 位置?

在 python 中创建秘密范围(Azure 示例)如下所示:

import requests
import json

# Set authorization token (token is generated in user settings)
hdr = {"authorization": "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}  

x = json.dumps({'scope': 'lab-a-adls'})

r = requests.post("https://westeurope.azuredatabricks.net/api/2.0/secrets/scopes/create",
    headers = hdr,
    data= x)

通过以下方式在范围内存储凭据:

x = json.dumps({
  "scope": "lab-a-adls",
  "key": "credential",
  "string_value": "*******************************"
})

 r = requests.post("https://westeurope.azuredatabricks.net/api/2.0/secrets/put",
    headers = hdr,
    data= x)