Created
November 28, 2022 22:18
-
-
Save slopp/7793615632e0021a57713ed8984d7fd9 to your computer and use it in GitHub Desktop.
Snowflake Resource with OAuth
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
| 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