-
Notifications
You must be signed in to change notification settings - Fork 16
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
Add support for connecting to snowpark container services #100
Comments
I believe you're referencing this check: django-snowflake/django_snowflake/base.py Lines 108 to 111 in e2962b3
Do you have a suggestion for how to modify the check? I'm not sure we should remove it completely. For example, we have logic not to require a password if any of these options are specified: `'private_key', 'private_key_file', 'authenticator'. |
@punitchauhan771 Can you clarify your question/request? |
Hi @timgraham I have an application that i want to host in snowpark container service, so if i am using external communication i.e. egress based AUTH then the container is able to connect to the snowflake warehouse and everything works fine (inside the container), but if i try to use internal network i.e. snowflake_host , token etc it Fails, also I tried modifying this code base, even if i make the username field optional it still tries to connect to the host URL rather than the proxy URL created by snowflake for the connectivity.
The only challenge in the egress based AUTH is it creates additional latency for each of my request, so I was hoping we might have some way to connect to internal network like how we do in Flask/python: Flask/python example code:
Hope this helps. |
I tried to replicate the logic in the example code you provided. Can you test it? The example code also omits diff --git a/django_snowflake/base.py b/django_snowflake/base.py
index e2c4fcd..7e2a8ec 100644
--- a/django_snowflake/base.py
+++ b/django_snowflake/base.py
@@ -99,21 +99,26 @@ class DatabaseWrapper(BaseDatabaseWrapper):
'interpolate_empty_sequences': True,
**settings_dict['OPTIONS'],
}
+ if use_token := os.path.exists("/snowflake/session/token"):
+ conn_params["token"] = self.get_login_token()
+
if os.environ.get('RUNNING_DJANGOS_TEST_SUITE') != 'true':
conn_params['application'] = 'Django_SnowflakeConnector_%s' % __version__
if settings_dict['NAME']:
conn_params['database'] = self.ops.quote_name(settings_dict['NAME'])
- if settings_dict['USER']:
- conn_params['user'] = settings_dict['USER']
- else:
- raise ImproperlyConfigured(self.settings_is_missing % 'USER')
+ # Omit USER/PASSWORD if using token.
+ if not use_token:
+ if settings_dict['USER']:
+ conn_params['user'] = settings_dict['USER']
+ else:
+ raise ImproperlyConfigured(self.settings_is_missing % 'USER')
- if settings_dict['PASSWORD']:
- conn_params['password'] = settings_dict['PASSWORD']
- elif all(x not in conn_params for x in self.password_not_required_options):
- raise ImproperlyConfigured(self.settings_is_missing % 'PASSWORD')
+ if settings_dict['PASSWORD']:
+ conn_params['password'] = settings_dict['PASSWORD']
+ elif all(x not in conn_params for x in self.password_not_required_options):
+ raise ImproperlyConfigured(self.settings_is_missing % 'PASSWORD')
if settings_dict.get('ACCOUNT'):
conn_params['account'] = settings_dict['ACCOUNT']
@@ -132,6 +137,15 @@ class DatabaseWrapper(BaseDatabaseWrapper):
return conn_params
+ def get_login_token():
+ """
+ Read the login token supplied automatically by Snowflake. These tokens
+ are short lived and should always be read right before creating any new
+ connection.
+ """
+ with open("/snowflake/session/token", "r") as f:
+ return f.read()
+
@async_unsafe
def get_new_connection(self, conn_params):
return Database.connect(**conn_params) |
Hi @timgraham, I made the above changes, now I am getting this error:
also I noticed that when I am connecting via external network the url/host is account-name.reigon.snowflakecomputing.com for additional info: |
I'm unsure if I can take this any further since I don't have a way to test it. If you have some Python code that works, I can try to blindly adapt it, or else you'll have to debug what I provided and make corrections. |
Hi @timgraham , Does this reference help spcs_python |
Hi @timgraham , |
I'm facing issues connecting my Django application to a Snowflake warehouse using Snowpark Container Service and OAuth authentication. While the application can connect via the external network using username and password, it requires username when using OAuth within the internal network. I'm using Django-snowflake version 4.1 and would like to establish a connection without external network access.
The text was updated successfully, but these errors were encountered: