Skip to content

Instantly share code, notes, and snippets.

@slopp
Created November 28, 2022 22:18
Show Gist options
  • Select an option

  • Save slopp/7793615632e0021a57713ed8984d7fd9 to your computer and use it in GitHub Desktop.

Select an option

Save slopp/7793615632e0021a57713ed8984d7fd9 to your computer and use it in GitHub Desktop.
Snowflake Resource with OAuth
from dagster_snowflake import SnowflakeConnection
from typing import Mapping
from dagster._annotations import public
from dagster import resource, StringSource
class SnowflakeOAuthConnection(SnowflakeConnection):
def __init__(self, config: Mapping[str, str], log):
self.conn_args = {
k: config.get(k)
for k in (
"account",
"user",
"host",
"database",
"schema",
"role",
"warehouse",
"autocommit"
)
if config.get(k) is not None
}
self.conn_args['authenticator'] = 'oauth'
self.autocommit = self.conn_args.get("autocommit", False)
self.log = log
@public
def get_connection(self, raw_conn: bool = True):
self.conn_args['token'] = token_generator(...)
return super().get_connection(raw_conn)
@resource(
config_schema = {
"account": StringSource,
"user": StringSource,
"host": StringSource,
"database": StringSource,
"schema": StringSource,
"role": StringSource,
"warehouse": StringSource,
"autocommit": bool
}
)
def snowflake_oauth_resource(context):
return SnowflakeOAuthConnection(context.resource_config, context.log)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment