我使用secrets API在databricks上创建了一个秘密。
代码:
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_valur":"Vidyasekar"}
requests.post('https://instancename.net/mynoteid/api/2.0/secrets/put', json=content)
执行后,我得到了响应:
Whcih表示秘密已成功存储。
使用列表API调用或dbutils.secrets.get()列出sam时,其显示'秘密范围不存在
我的疑问是, 如何获取数据块实例名称? 机密存储在DBFS的位置在哪里?
答案 0 :(得分:2)
在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)