Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: raise error with documentation link - find_secret #2180

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading