Skip to content

Conversation

@vdonato
Copy link
Collaborator

@vdonato vdonato commented Apr 12, 2023

📚 Context

Another small-ish thing on our TODO list was to merge the connection config params we receive
from various sources. This PR does this for both our SQL and Snowpark first party connections, and
we additionally write a few small helper functions to help with this that are likely to be useful for many
other connections.

@vdonato vdonato added the security-assessment-completed Security assessment has been completed for PR label Apr 12, 2023
@vdonato vdonato requested review from kajarenc and lukasmasuch April 12, 2023 22:55
@vdonato vdonato marked this pull request as ready for review April 12, 2023 23:54
Copy link
Collaborator

@lukasmasuch lukasmasuch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@kajarenc
Copy link
Collaborator

Hey, @vdonato !
these changes look good, and we could merge them

A potential improvement could be the usage of ChainMaps instead of merge_dicts

It is one of the main usages for ChainMaps to merge config options, so they fit here perfectly.
https://docs.python.org/3/library/collections.html#chainmap-examples-and-recipes

Feel free to refactor this with ChainMaps usage or keep it as is.

database=conn_params.get("database"),
)

eng = sqlalchemy.create_engine(url, **kwargs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

snowflake-sqlalchemy uses a connect_args kwarg outside the URL to specify common behaviors like non-password based authentication (rough cite - this is also what I found when I tried it out).

Similarly, bigquery-sqlalchemy uses a credentials_info kwarg which seems to be required for any usage (cite).

It seems like there's no way to get that passed into create_engine directly from secrets with this implementation. So to use these dialects (which are pretty important!) I still have to do something like:
conn = st.connection('sql', connect_args=dict(st.secrets.snowflakeargs))

I would love to be able to just specify a secrets section like [connections.sql.connect_args] and have it get passed through.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Should I move this comment to the main feature PR? Since I guess it doesn't need to be addressed in this PR)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack -- will see if I can address this early next week

@sfc-gh-jcarroll
Copy link
Contributor

Good by me to merge and address the other comment in a separate PR if desired.

@vdonato vdonato merged this pull request into feature/st.experimental_connection Apr 15, 2023
@vdonato vdonato deleted the vdonato/better-secrets-merging branch April 15, 2023 01:41
vdonato added a commit that referenced this pull request Apr 15, 2023
…ons (#6486)

* Add some utility functions for manipulating dicts

* Teach the SQL connection to merge params set via secrets.toml and kwargs

* Merge secrets from various sources in Snowpark connection

* Add a @pytest.mark.require_snowflake decorator

* Remove "password" from required params

* Use ChainMap instead of custom helper function
vdonato added a commit that referenced this pull request Apr 17, 2023
…ons (#6486)

* Add some utility functions for manipulating dicts

* Teach the SQL connection to merge params set via secrets.toml and kwargs

* Merge secrets from various sources in Snowpark connection

* Add a @pytest.mark.require_snowflake decorator

* Remove "password" from required params

* Use ChainMap instead of custom helper function
vdonato added a commit that referenced this pull request Apr 19, 2023
…ons (#6486)

* Add some utility functions for manipulating dicts

* Teach the SQL connection to merge params set via secrets.toml and kwargs

* Merge secrets from various sources in Snowpark connection

* Add a @pytest.mark.require_snowflake decorator

* Remove "password" from required params

* Use ChainMap instead of custom helper function
vdonato added a commit that referenced this pull request Apr 20, 2023
…ons (#6486)

* Add some utility functions for manipulating dicts

* Teach the SQL connection to merge params set via secrets.toml and kwargs

* Merge secrets from various sources in Snowpark connection

* Add a @pytest.mark.require_snowflake decorator

* Remove "password" from required params

* Use ChainMap instead of custom helper function
vdonato added a commit that referenced this pull request Apr 21, 2023
…ons (#6486)

* Add some utility functions for manipulating dicts

* Teach the SQL connection to merge params set via secrets.toml and kwargs

* Merge secrets from various sources in Snowpark connection

* Add a @pytest.mark.require_snowflake decorator

* Remove "password" from required params

* Use ChainMap instead of custom helper function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

security-assessment-completed Security assessment has been completed for PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants