-
Notifications
You must be signed in to change notification settings - Fork 150
Snow 2324796 secrets api migration 1 #3781
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
Changes from all commits
ead2e79
2c279a0
582b9f7
3a1ebaf
a2b262e
d154a30
07cb3da
9cb690d
06a5c53
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ Snowpark APIs | |
| udf | ||
| udaf | ||
| udtf | ||
| secrets | ||
| observability | ||
| files | ||
| catalog | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| ============================= | ||
| Snowpark Secrets | ||
| ============================= | ||
|
|
||
| .. currentmodule:: snowflake.snowpark.secrets | ||
|
|
||
| .. rubric:: Classes | ||
|
|
||
| .. autosummary:: | ||
| :toctree: api/ | ||
|
|
||
| UsernamePassword | ||
| CloudProviderToken | ||
|
|
||
| .. rubric:: Functions | ||
|
|
||
| .. autosummary:: | ||
| :toctree: api/ | ||
|
|
||
| get_generic_secret_string | ||
| get_oauth_access_token | ||
| get_secret_type | ||
| get_username_password | ||
| get_cloud_provider_token | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| # | ||
| # Copyright (c) 2012-2025 Snowflake Computing Inc. All rights reserved. | ||
| # | ||
| from snowflake.snowpark._internal.utils import publicapi | ||
|
|
||
| # Reference for Python API for Secret Access: | ||
| # https://docs.snowflake.com/en/developer-guide/external-network-access/secret-api-reference#python-api-for-secret-access | ||
|
|
||
|
|
||
| class UsernamePassword: | ||
| def __init__(self, username, password) -> None: | ||
| self.username = username | ||
| self.password = password | ||
|
|
||
|
|
||
| class CloudProviderToken: | ||
| def __init__(self, id, key, token) -> None: | ||
| self.access_key_id = id | ||
| self.secret_access_key = key | ||
| self.token = token | ||
|
|
||
|
|
||
| @publicapi | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sfc-gh-heshah do we need
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not necessary because the API doesn't interact with AST or have an |
||
| def get_generic_secret_string(secret_name: str) -> str: | ||
| """Get a generic token string from Snowflake. | ||
| Note: | ||
| Require a Snowflake environment with generic secret strings configured | ||
| Returns: | ||
| The secret value as a string. | ||
| Raises: | ||
| NotImplementedError: If the _snowflake module cannot be imported. | ||
| """ | ||
| try: | ||
| import _snowflake | ||
|
|
||
| return _snowflake.get_generic_secret_string(secret_name) | ||
|
sfc-gh-mayliu marked this conversation as resolved.
|
||
| except ImportError: | ||
| raise NotImplementedError( | ||
|
sfc-gh-mayliu marked this conversation as resolved.
|
||
| "Cannot import _snowflake module. Secret API is only supported on Snowflake server environment." | ||
| ) | ||
|
|
||
|
|
||
| @publicapi | ||
| def get_oauth_access_token(secret_name: str) -> str: | ||
| """Get an OAuth2 access token from Snowflake. | ||
| Note: | ||
| Require a Snowflake environment with OAuth secrets configured | ||
| Returns: | ||
| The OAuth2 access token as a string. | ||
| Raises: | ||
| NotImplementedError: If the _snowflake module cannot be imported. | ||
| """ | ||
| try: | ||
| import _snowflake | ||
|
|
||
| return _snowflake.get_oauth_access_token(secret_name) | ||
| except ImportError: | ||
| raise NotImplementedError( | ||
| "Cannot import _snowflake module. Secret API is only supported on Snowflake server environment." | ||
| ) | ||
|
|
||
|
|
||
| @publicapi | ||
| def get_secret_type(secret_name: str) -> str: | ||
| """Get the type of a secret from Snowflake. | ||
| Note: | ||
| Require a Snowflake environment with secrets configured | ||
| Returns: | ||
| The type of the secret as a string. | ||
| Raises: | ||
| NotImplementedError: If the _snowflake module cannot be imported. | ||
| """ | ||
| try: | ||
| import _snowflake | ||
|
|
||
| return str(_snowflake.get_secret_type(secret_name)) | ||
| except ImportError: | ||
| raise NotImplementedError( | ||
| "Cannot import _snowflake module. Secret API is only supported on Snowflake server environment." | ||
| ) | ||
|
|
||
|
|
||
| @publicapi | ||
| def get_username_password(secret_name: str) -> UsernamePassword: | ||
| """Get a username and password secret from Snowflake. | ||
| Note: | ||
| Require a Snowflake environment with username/password secrets configured | ||
| Returns: | ||
| UsernamePassword: An object with attributes ``username`` and ``password``. | ||
| Raises: | ||
| NotImplementedError: If the _snowflake module cannot be imported. | ||
| """ | ||
| try: | ||
| import _snowflake | ||
|
|
||
| secret_object = _snowflake.get_username_password(secret_name) | ||
| return UsernamePassword(secret_object.username, secret_object.password) | ||
| except ImportError: | ||
| raise NotImplementedError( | ||
| "Cannot import _snowflake module. Secret API is only supported on Snowflake server environment." | ||
| ) | ||
|
|
||
|
|
||
| @publicapi | ||
| def get_cloud_provider_token(secret_name: str) -> CloudProviderToken: | ||
| """Get a cloud provider token secret from Snowflake. | ||
| Note: | ||
| Require a Snowflake environment with cloud provider secrets configured | ||
| Returns: | ||
| CloudProviderToken: An object with attributes ``access_key_id``, | ||
| ``secret_access_key``, and ``token``. | ||
| Raises: | ||
| NotImplementedError: If the _snowflake module cannot be imported. | ||
| """ | ||
| try: | ||
| import _snowflake | ||
|
|
||
| secret_object = _snowflake.get_cloud_provider_token(secret_name) | ||
|
sfc-gh-mayliu marked this conversation as resolved.
|
||
| return CloudProviderToken( | ||
| secret_object.access_key_id, | ||
| secret_object.secret_access_key, | ||
| secret_object.token, | ||
| ) | ||
| except ImportError: | ||
| raise NotImplementedError( | ||
| "Cannot import _snowflake module. Secret API is only supported on Snowflake server environment." | ||
| ) | ||
Uh oh!
There was an error while loading. Please reload this page.