Skip to content

Commit

Permalink
Fix oauth in snowflake ibis plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik4949 authored and fnikolai committed Dec 17, 2024
1 parent 06c3c24 commit 93e51db
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Deprecate vanilla `DataType`
- Remove `_Encodable` from project
- Connect to Snowflake using the incluster oauth token

#### New Features & Functionality

Expand Down
13 changes: 7 additions & 6 deletions plugins/ibis/superduper_ibis/data_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,17 @@ def _snowflake_connection_callback():

logging.info('Using env variables and OAuth to connect!')

import snowflake
import snowflake.connector

conn = snowflake.connector.connect(
account=os.environ['SNOWFLAKE_ACCOUNT'],
host=os.environ['SNOWFLAKE_HOST'],
schema=os.environ['SUPERDUPER_DATA_SCHEMA'],
database=os.environ['SNOWFLAKE_DATABASE'],
port=int(os.environ['SNOWFLAKE_PORT']),
token=open('/snowflake/session/token').read(),
account=os.environ['SNOWFLAKE_ACCOUNT'],
authenticator='oauth',
token=open('/snowflake/session/token').read(),
warehouse=os.environ['SNOWFLAKE_WAREHOUSE'],
database=os.environ['SNOWFLAKE_DATABASE'],
schema=os.environ['SUPERDUPER_DATA_SCHEMA'],
)

return ibis.snowflake.from_connection(conn)
Expand All @@ -68,7 +69,7 @@ def _connection_callback(uri, flavour):
in_memory = True
return ibis_conn, dir_name, in_memory
elif uri == 'snowflake://':
return _snowflake_connection_callback(uri), 'snowflake', False
return _snowflake_connection_callback(), 'snowflake', False
else:
name = uri.split("//")[0]
in_memory = False
Expand Down
11 changes: 6 additions & 5 deletions plugins/sqlalchemy/superduper_sqlalchemy/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,20 @@ def _connect_snowflake():
# mounted token. In this case, as a convention
# we connect with `"snowflake://"`

import snowflake
import snowflake.connector

def creator():
import os

return snowflake.connector.connect(
account=os.environ['SNOWFLAKE_ACCOUNT'],
host=os.environ['SNOWFLAKE_HOST'],
schema=os.environ['SUPERDUPER_DATA_SCHEMA'],
database=os.environ['SNOWFLAKE_DATABASE'],
port=int(os.environ['SNOWFLAKE_PORT']),
token=open('/snowflake/session/token').read(),
account=os.environ['SNOWFLAKE_ACCOUNT'],
authenticator='oauth',
token=open('/snowflake/session/token').read(),
warehouse=os.environ['SNOWFLAKE_WAREHOUSE'],
database=os.environ['SNOWFLAKE_DATABASE'],
schema=os.environ['SUPERDUPER_DATA_SCHEMA'],
)

return create_engine("snowflake://not@used/db", creator=creator)
Expand Down
4 changes: 2 additions & 2 deletions templates/pdf_rag/component.json
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@
"blobs": null,
"files": null,
"requirements": null,
"default_table": "?table:sample_pdf_rag",
"default_tables": ["?table:sample_pdf_rag"],
"queries": null,
"_literals": [
"template"
Expand Down Expand Up @@ -392,4 +392,4 @@
}
},
"_files": {}
}
}

0 comments on commit 93e51db

Please sign in to comment.