-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSecretsAPI.py
57 lines (35 loc) · 1.22 KB
/
SecretsAPI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Databricks notebook source
# MAGIC %md ## Install Databricks CLI to access APIs
# COMMAND ----------
# MAGIC %pip install databricks_cli
# COMMAND ----------
# MAGIC %md ## Instantiate API client
# COMMAND ----------
from databricks_cli.sdk.api_client import ApiClient
apiclient = ApiClient(token = dbutils.entry_point.getDbutils().notebook().getContext().apiToken().get(),
host = dbutils.entry_point.getDbutils().notebook().getContext().apiUrl().get())
# COMMAND ----------
# MAGIC %md ## Create Secret Scope
# COMMAND ----------
apiclient.perform_query("POST","/secrets/scopes/create",
{
"scope": "my_secret_SCOPE",
"initial_manage_principal": "users"
})
# COMMAND ----------
# MAGIC %md ## Lists Secret Scopes to confirm created
# COMMAND ----------
apiclient.perform_query("GET", "/secrets/scopes/list")
# COMMAND ----------
# MAGIC %md ## Put secret in scope
# COMMAND ----------
apiclient.perform_query("POST","/secrets/put",
{
"scope": "my_secret_SCOPE",
"key": "my_secret_KEY",
"string_value": "my_super_secret_token"
})
# COMMAND ----------
# MAGIC %md ## Retrieve secret using DBUTILS
# COMMAND ----------
token = dbutils.secrets.get(scope="my_secret_SCOPE", key="my_secret_KEY")