Skip to content

Commit

Permalink
chore: raise error with documentation link - find_secret (#2180)
Browse files Browse the repository at this point in the history
* raise error with documentation link

* minor format

* add raise error on other platforms
  • Loading branch information
JessicaXYWang authored Mar 18, 2024
1 parent ce5cc5c commit 59f8250
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions core/src/main/python/synapse/ml/core/platform/Platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,35 +47,40 @@ def running_on_databricks():


def find_secret(secret_name, keyvault):
if running_on_synapse():
from notebookutils.mssparkutils.credentials import getSecret

return getSecret(keyvault, secret_name)
elif running_on_synapse_internal():
from notebookutils.mssparkutils.credentials import getSecret

keyVaultURL = f"https://{keyvault}.vault.azure.net/"
return getSecret(keyVaultURL, secret_name)
elif running_on_databricks():
from pyspark.sql import SparkSession
from pyspark.dbutils import DBUtils

spark = SparkSession.builder.getOrCreate()
dbutils = DBUtils(spark)
return dbutils.secrets.get(scope=keyvault, key=secret_name)
else:
try:
if running_on_synapse():
from notebookutils.mssparkutils.credentials import getSecret

return getSecret(keyvault, secret_name)
elif running_on_synapse_internal():
from notebookutils.mssparkutils.credentials import getSecret

keyVaultURL = f"https://{keyvault}.vault.azure.net/"
return getSecret(keyVaultURL, secret_name)
elif running_on_databricks():
from pyspark.sql import SparkSession
from pyspark.dbutils import DBUtils

spark = SparkSession.builder.getOrCreate()
dbutils = DBUtils(spark)
return dbutils.secrets.get(scope=keyvault, key=secret_name)
else:
raise RuntimeError("get secret is not supported on this platform.")
except:
raise RuntimeError(
f"Could not find {secret_name} in keyvault {keyvault}. "
f"If you are trying to use the mmlspark-buil-keys keyvault, you cant! "
f"You need to make your own keyvaukt with secrets or replace this call with a string. "
f"You need to make your own keyvault with secrets or replace this call with a string. "
f"Make sure your notebook has access to a "
f"keyvault named {keyvault} which contains a secret named {secret_name}. "
f"On synapse, use a linked service keyvault, "
f"on databricks use their secrets management sdk, "
f"on fabric make sure your azure identity can access your azure keyvault. "
f"If you want to avoid making a keyvault, replace this call to find secret with your secret as a string "
f"like my_secret = 'jdiej38dnal.....'. Note that this has "
f"security implications for publishing and sharing notebooks!"
f"security implications for publishing and sharing notebooks! "
f"Please see the documentation for more information. "
f"https://microsoft.github.io/SynapseML/docs/Get%20Started/Set%20up%20Cognitive%20Services/"
)


Expand Down

0 comments on commit 59f8250

Please sign in to comment.