I created a secret on databricks using the secrets API.
Code :
Scope_name : {"scope": "dbtest", "initial_manage_principal":"user"}
Resp= requests.post('https://instancename.net/mynoteid/api/2.0/secrets/scopes/create',json=Scope_name)
Similar way, I added the user and password
Code:
Content = {"scope":"dbtest","key":"user","string_value":"Vidyasekar"}
requests.post('https://instancename.net/mynoteid/api/2.0/secrets/put', json=content)
After the execution I got response : <Response [200]>
Which means secrets stored successfully.
While listing the same using the list API call or dbutils.secrets.get()
, its shows 'Secret does not exist with scope
Here my doubt is, How to get the databricks intance name? Where the secrets stored in the DBFS location?
The creation of a secret scope (sample on Azure) in python would look like this:
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)
Store a credential in the scope via:
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)