Skip to content
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

feat!: Implement snowflake auth helpers #268

Merged
merged 4 commits into from
Sep 9, 2024
Merged

feat!: Implement snowflake auth helpers #268

merged 4 commits into from
Sep 9, 2024

Conversation

dbkegley
Copy link
Collaborator

@dbkegley dbkegley commented Sep 5, 2024

  • Reorganize examples into databricks and snowflake sub-directories
  • Add external.snowflake helpers
  • Add snowflake streamlit example
  • Move _is_local to __init__.py

Breaking changes:

  • posit.connect.external.PositCredentialsProvider.__init__() now accepts a Client instead of an OAuthIntegration resource.
  • All fields of posit.connect.external.PositCredentialsProvider and posit.connect.external.PositCredentialsStrategy are now _internal
  • Change order of named kwargs to posit.connect.external.PositCredentialsStrategy.__init__(). Only breaking for callers who use *args instead of **kwargs

closes #269

@dbkegley dbkegley requested a review from zackverham September 5, 2024 20:12
@dbkegley dbkegley requested a review from tdstein as a code owner September 5, 2024 20:12
Copy link

github-actions bot commented Sep 5, 2024

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
1257 1212 96% 0% 🟢

New Files

File Coverage Status
src/posit/connect/external/external.py 100% 🟢
src/posit/connect/external/snowflake.py 92% 🟢
TOTAL 96% 🟢

Modified Files

File Coverage Status
src/posit/connect/external/init.py 100% 🟢
src/posit/connect/external/databricks.py 87% 🟢
TOTAL 94% 🟢

updated for commit: f3b884e by action🐍

def __init__(self, posit_oauth: OAuthIntegration, user_session_token: str):
self.posit_oauth = posit_oauth
self.user_session_token = user_session_token
def __init__(self, client: Client, user_session_token: str):
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

breaking: PositCredentialsProvider now accepts a Client instead of an OAuthIntegration resource. This fits better with the API changes that @zackverham is about to make.

client: Optional[Client] = None,
user_session_token: Optional[str] = None,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

potentially breaking? These are named arguments but I did change the order. Callers who are using args instead of kwargs may break

self.user_session_token = user_session_token
def __init__(self, client: Client, user_session_token: str):
self._client = client
self._user_session_token = user_session_token
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

breaking: These fields are now _internal

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks! If you can capture the breaking changes in the PR description, it will be easy to pull into the release notes.

self.client = client
self._local_strategy = local_strategy
self._client = client
self._user_session_token = user_session_token
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

breaking: These fields are now _internal

@dbkegley dbkegley changed the title Implement snowflake auth helpers feat: Implement snowflake auth helpers Sep 5, 2024
@dbkegley dbkegley changed the title feat: Implement snowflake auth helpers feat!: Implement snowflake auth helpers Sep 5, 2024
@zackverham
Copy link
Collaborator

not sure if this has come up anywhere else - but currently we don't indicate w/ the directory structure that our examples are specifically for the oauth integration pieces of the SDK. As we're breaking out sub-directories for the type of integration (snowflake vs databricks) I wonder if we need to do more to flag exactly what these are examples of?

@tdstein
Copy link
Collaborator

tdstein commented Sep 5, 2024

not sure if this has come up anywhere else - but currently we don't indicate w/ the directory structure that our examples are specifically for the oauth integration pieces of the SDK. As we're breaking out sub-directories for the type of integration (snowflake vs databricks) I wonder if we need to do more to flag exactly what these are examples of?

These are well suited for cookbook recipes or extensions as well.

@dbkegley
Copy link
Collaborator Author

dbkegley commented Sep 6, 2024

These are well suited for cookbook recipes or extensions as well.

I'm happy to start moving these over to cookbooks before the Sept Connect release. I think we should have at least 1 release where they exist in both places and the README in the examples dir should start pointing folks toward the cookbooks ASAP. Next Connect release we can remove the examples from the SDK and just maintain the cookbooks going forward.

@tdstein
Copy link
Collaborator

tdstein commented Sep 6, 2024

These are well suited for cookbook recipes or extensions as well.

I'm happy to start moving these over to cookbooks before the Sept Connect release. I think we should have at least 1 release where they exist in both places and the README in the examples dir should start pointing folks toward the cookbooks ASAP. Next Connect release we can remove the examples from the SDK and just maintain the cookbooks going forward.

Awesome. Yes, I agree. It's best to hold off on deleting them until the recipes make it to docs.posit.co.

Copy link
Collaborator

@tdstein tdstein left a comment

Choose a reason for hiding this comment

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

Looks great overall! I have a few minor questions and comments.

Comment on lines 7 to 14
def _is_local() -> bool:
"""Returns true if called from a piece of content running on a Connect server.

The connect server will always set the environment variable `RSTUDIO_PRODUCT=CONNECT`.
We can use this environment variable to determine if the content is running locally
or on a Connect server.
"""
return not os.getenv("RSTUDIO_PRODUCT") == "CONNECT"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I haven't found a clear answer to best practices, but I've recently started reducing init.py to only include named exports. Then placing any shared module code in a file of the same name; external/external.py here.

This also eliminates the need to mark the method as private since it won't be declared in the init.py file.

self._client = client
self._user_session_token = user_session_token

def authenticator(self) -> Optional[str]:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be a @property?

src/posit/connect/external/snowflake.py Show resolved Hide resolved
self.user_session_token = user_session_token
def __init__(self, client: Client, user_session_token: str):
self._client = client
self._user_session_token = user_session_token
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks! If you can capture the breaking changes in the PR description, it will be easy to pull into the release notes.

- use @Property for getter methods
- move _is_local to external.py module
- remove old .qmd
- add examples README.md pointing to cookbook
@dbkegley dbkegley merged commit 700b118 into main Sep 9, 2024
31 checks passed
@dbkegley dbkegley deleted the kegs-snowflake branch September 9, 2024 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement snowflake helpers
3 participants