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.
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.