admin管理员组

文章数量:1134248

My question is simple: I am on development environment where 3-4 secret value related to api url are stored in key vault, which I can access by passing scope and key. Same thing is there in test and higher environment. But for time being my dev api is not working so I want to point to test api in dev environment to do testing, if it works then we do for higher environment.

Can we do this ? I was going through couple of stack question and blog but didn't found fruitful. Please share your valuable thoughts.

My question is simple: I am on development environment where 3-4 secret value related to api url are stored in key vault, which I can access by passing scope and key. Same thing is there in test and higher environment. But for time being my dev api is not working so I want to point to test api in dev environment to do testing, if it works then we do for higher environment.

Can we do this ? I was going through couple of stack question and blog but didn't found fruitful. Please share your valuable thoughts.

Share Improve this question asked Jan 8 at 3:55 chandra prakash kabrachandra prakash kabra 3391 gold badge3 silver badges14 bronze badges 6
  • please add more details on what you are trying? – JayashankarGS Commented Jan 8 at 4:06
  • dbutils.secrets.get("cumu-akv-adb-secret-scope-cp", "CP-API_URL") let say this api url I wanted to get in dev environemnt which will work and it will give dev url , but I wanted to get test url in dev environment how I can achieve it? – chandra prakash kabra Commented Jan 8 at 8:14
  • You can still get the value similarly. But you need create seceret in dev env with test url. – JayashankarGS Commented Jan 8 at 9:04
  • dbutils.secrets.get("cumu-akv-adb-secret-scope-cp", "Your-test-API_URL") – JayashankarGS Commented Jan 8 at 9:10
  • All this 3-4 secret are common to this envs? check if the required secret available in the scope. – JayashankarGS Commented Jan 8 at 9:13
 |  Show 1 more comment

1 Answer 1

Reset to default 1

Actually, with same key name you cannot retrieve the secret like you asked, unless you are changing the secret value that is URL in key vault but that's not recommended.

Below are some ideas you can work on.

Create multiple keys like CP-API_URL_DEV, CP-API_URL_TEST..

Now based on environment get the secret.

environment = dbutils.widgets.get("environment") 

if environment == "test":
    secret_key = "CP-API_URL_DEV"
else:
    secret_scope = "CP-API_URL_TEST"

api_url = dbutils.secrets.get(secret_scope,secret_key)

OR

Creating multiple scopes and accessing based on environment like test-secret-scope, dev-secret-scope..

environment = dbutils.widgets.get("environment") 

if environment == "test":
    secret_scope = "test-secret-scope"
else:
    secret_scope = "dev-secret-scope"

api_url = dbutils.secrets.get(secret_scope, "CP-API_URL")

Here, key name is same, but scopes is different across environment, being in dev environment access test URL giving test scope name.

OR

save URLs in environment variables and retrieve required one, but this method doesn't use key vault.

At least one of the parameters should be different either scope or secret, both being same across environment can't get the different secret value.

本文标签: azure keyvaultCan we get secret value using dbutil in databricks from across envrionmentStack Overflow