-
Notifications
You must be signed in to change notification settings - Fork 126
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
adding privatekey auth param #1190
base: main
Are you sure you want to change the base?
Changes from 7 commits
25a7992
f2c15d1
cd2658f
adbfef5
63a2eeb
8de2b06
3f7a045
0492dc4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,6 +69,8 @@ def __init__( | |
user: str, | ||
account: str, | ||
api_key: Secret = Secret.from_env_var("SNOWFLAKE_API_KEY"), # noqa: B008 | ||
private_key_file: Optional[str] = None, | ||
private_key_file_pwd: Optional[str] = None, | ||
database: Optional[str] = None, | ||
db_schema: Optional[str] = None, | ||
warehouse: Optional[str] = None, | ||
|
@@ -82,11 +84,16 @@ def __init__( | |
:param db_schema: Name of the schema to use. | ||
:param warehouse: Name of the warehouse to use. | ||
:param login_timeout: Timeout in seconds for login. By default, 60 seconds. | ||
:param private_key_file: Location of private key | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this docstring is very confusing - what's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I chose to match the snowflake connector params to keep it consistent with the snowflake documentation, see sample code here: I've added some further comments to the docstring to include a note to the following link: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't see your changes - also my comment was not about the params names themselves, rather the docstring explaining what they are used for. |
||
mutually exclusive to password, if key_file is provided this auth method will be used. | ||
:param private_key_file_pwd: Password for private key file | ||
""" | ||
|
||
self.user = user | ||
self.account = account | ||
self.api_key = api_key | ||
self.private_key_file = private_key_file | ||
self.private_key_file_pwd = private_key_file_pwd | ||
self.database = database | ||
self.db_schema = db_schema | ||
self.warehouse = warehouse | ||
|
@@ -104,6 +111,8 @@ def to_dict(self) -> Dict[str, Any]: | |
user=self.user, | ||
account=self.account, | ||
api_key=self.api_key.to_dict(), | ||
private_key_file=self.private_key_file, | ||
private_key_file_pwd=self.private_key_file_pwd, | ||
database=self.database, | ||
db_schema=self.db_schema, | ||
warehouse=self.warehouse, | ||
|
@@ -275,18 +284,22 @@ def _fetch_data( | |
if not query: | ||
return df | ||
try: | ||
# Build up param connection | ||
connect_params = { | ||
"user": self.user, | ||
"account": self.account, | ||
"private_key_file": self.private_key_file, | ||
"private_key_file_pwd": self.private_key_file_pwd, | ||
"database": self.database, | ||
"schema": self.db_schema, | ||
"warehouse": self.warehouse, | ||
"login_timeout": self.login_timeout, | ||
} | ||
# Check if private key has been provided | ||
if self.private_key_file is None: | ||
connect_params["password"] = self.api_key.resolve_value() | ||
# Create a new connection with every run | ||
conn = self._snowflake_connector( | ||
connect_params={ | ||
"user": self.user, | ||
"account": self.account, | ||
"password": self.api_key.resolve_value(), | ||
"database": self.database, | ||
"schema": self.db_schema, | ||
"warehouse": self.warehouse, | ||
"login_timeout": self.login_timeout, | ||
} | ||
) | ||
conn = self._snowflake_connector(connect_params=connect_params) | ||
if conn is None: | ||
return df | ||
except (ForbiddenError, ProgrammingError) as e: | ||
|
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 should be using the
Secret
- check above how it was done forapi_key