-
Couldn't load subscription status.
- Fork 353
Feat/2976 snowpark container auth #2984
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
Open
mohamedmeqlad99
wants to merge
3
commits into
dlt-hub:devel
Choose a base branch
from
mohamedmeqlad99:feat/2976-snowpark-container-auth
base: devel
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| # Snowflake Configuration | ||
|
|
||
| ## Authentication Methods | ||
|
|
||
| Snowflake destination supports several authentication methods: | ||
|
|
||
| ### Username and Password | ||
| ```python | ||
| pipeline = dlt.pipeline( | ||
| pipeline_name="my_pipeline", | ||
| destination="snowflake", | ||
| credentials={ | ||
| "username": "my_user", | ||
| "password": "my_password", | ||
| "account": "my_account" | ||
| } | ||
| ) | ||
| ``` | ||
|
|
||
| ### Private Key | ||
| ```python | ||
| pipeline = dlt.pipeline( | ||
| pipeline_name="my_pipeline", | ||
| destination="snowflake", | ||
| credentials={ | ||
| "username": "my_user", | ||
| "private_key_path": "path/to/rsa_key.p8", | ||
| "account": "my_account" | ||
| } | ||
| ) | ||
| ``` | ||
|
|
||
| ### Snowpark Container Services | ||
|
|
||
| When running inside Snowpark Container Services, dlt will automatically detect and use the mounted OAuth token and environment variables: | ||
|
|
||
| ```python | ||
| pipeline = dlt.pipeline( | ||
| pipeline_name="my_pipeline", | ||
| destination="snowflake", | ||
| dataset_name="my_dataset" | ||
| ) | ||
|
|
||
| # No credentials needed - dlt will automatically use: | ||
| # - Token from /snowflake/session/token | ||
| # - Account from SNOWFLAKE_HOST or SNOWFLAKE_ACCOUNT env vars | ||
| ``` | ||
|
|
||
| You can still provide explicit credentials to override the auto-detection: | ||
|
|
||
| ```python | ||
| pipeline = dlt.pipeline( | ||
| pipeline_name="my_pipeline", | ||
| destination="snowflake", | ||
| credentials={ | ||
| "token": "my_token", # Override container token | ||
| "account": "my_account" # Override SNOWFLAKE_HOST | ||
| } | ||
| ) | ||
| ``` | ||
|
|
||
| ## Additional Configuration | ||
| # ...existing documentation... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import os | ||
| import tempfile | ||
| from pathlib import Path | ||
| from dlt.destinations.impl.snowflake.configuration import SnowflakeCredentials | ||
|
|
||
| def test_snowpark_token(monkeypatch): | ||
| """Test Snowpark Container Services token authentication""" | ||
| with tempfile.NamedTemporaryFile("w+", delete=False) as tf: | ||
| tf.write("test-token") | ||
| tf.flush() | ||
| token_path = tf.name | ||
|
|
||
| # Set up test environment | ||
| monkeypatch.setenv("SNOWFLAKE_HOST", "test-account") | ||
| monkeypatch.setenv("SNOWFLAKE_ACCOUNT", "test-account") | ||
|
|
||
| # Mock token path existence and file reading | ||
| monkeypatch.setattr("os.path.exists", lambda p: p == token_path) | ||
| monkeypatch.setattr("builtins.open", lambda p, mode="r": open(token_path, mode)) | ||
|
|
||
| # Test credentials resolution | ||
| creds = SnowflakeCredentials() | ||
| creds.on_resolved.__globals__["token_path"] = token_path | ||
| creds.on_resolved() | ||
|
|
||
| assert creds.token == "test-token" | ||
| assert creds.host == "test-account" | ||
| assert creds.authenticator == "oauth" | ||
|
|
||
| # Test connector parameters | ||
| params = creds.to_connector_params() | ||
| assert params["token"] == "test-token" | ||
| assert params["account"] == "test-account" | ||
| assert params["authenticator"] == "oauth" | ||
| assert "user" not in params | ||
| assert "password" not in params | ||
|
|
||
| # Cleanup | ||
| Path(token_path).unlink() | ||
|
|
||
| def test_explicit_credentials_preferred(monkeypatch): | ||
| """Test that explicit credentials are preferred over Snowpark token""" | ||
| with tempfile.NamedTemporaryFile("w+", delete=False) as tf: | ||
| tf.write("test-token") | ||
| tf.flush() | ||
| token_path = tf.name | ||
|
|
||
| # Test with explicit credentials | ||
| creds = SnowflakeCredentials( | ||
| token="explicit-token", | ||
| host="explicit-account" | ||
| ) | ||
| creds.on_resolved.__globals__["token_path"] = token_path | ||
| creds.on_resolved() | ||
|
|
||
| assert creds.token == "explicit-token" | ||
| assert creds.host == "explicit-account" | ||
|
|
||
| # Cleanup | ||
| Path(token_path).unlink() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may break other oauth flows https://docs.snowflake.com/en/developer-guide/python-connector/python-connector-connect#connecting-with-oauth where
useris actually required.