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

fix: can instantiate connectors without callbacks/secrets-keeper (TCTC-10081) #1894

Merged
merged 4 commits into from
Feb 6, 2025

Conversation

julien-pinchelimouroux
Copy link
Contributor

No description provided.

Copy link
Contributor

@Fanaen Fanaen left a comment

Choose a reason for hiding this comment

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

Ok pour moi 👍

def _call_retrieve_token(self) -> str:
"""Retrieve the access token for Google Sheets

Raise an GoogleSheetsInvalidConfiguration if something missing to retrieve the token
Copy link
Contributor

Choose a reason for hiding this comment

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

Pas compris cette phrase 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@lukapeschke lukapeschke left a comment

Choose a reason for hiding this comment

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

thx

name="test_connector",
auth_id="test_auth_id",
)
assert gsheet_connector
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you make an assertion on the fields here ? For example on the token callback ?

assert gsheet_connector


def test_raise_when_trying_to_retrieve_token_if_callable_missing():
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def test_raise_when_trying_to_retrieve_token_if_callable_missing():
def test_raises_when_trying_to_retrieve_token_if_callable_missing():

@@ -234,3 +246,20 @@ def test_get_refresh_token(mocker, oauth2_connector):
mocked_load.return_value = {"refresh_token": "bla"}
token = oauth2_connector.get_refresh_token()
assert token == "bla"


def test_raise_error_if_secret_keeper_not_set(oauth2_connector_without_secret_keeper: OAuth2Connector):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def test_raise_error_if_secret_keeper_not_set(oauth2_connector_without_secret_keeper: OAuth2Connector):
def test_raises_exception_if_secret_keeper_not_set(oauth2_connector_without_secret_keeper: OAuth2Connector):

Comment on lines 107 to 109
def __init__(self, retrieve_token: Callable[[str, str], str] | None = None, *args, **kwargs):
super().__init__(**kwargs)
self._retrieve_token = retrieve_token # Could be async
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think __init__ should be overloaded on models.. could you please remove it ?

Comment on lines 112 to 116
"""Retrieve the access token for Google Sheets

Raise an GoogleSheetsInvalidConfiguration if retrieve_token callback is not set
Raise an GoogleSheetsRetrieveTokenError if an error is encountered while retrieving the token
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"""Retrieve the access token for Google Sheets
Raise an GoogleSheetsInvalidConfiguration if retrieve_token callback is not set
Raise an GoogleSheetsRetrieveTokenError if an error is encountered while retrieving the token
"""
"""Retrieves the access token for Google Sheets
Raises a GoogleSheetsInvalidConfiguration if retrieve_token callback is not set
Raises a GoogleSheetsRetrieveTokenError if an error is encountered while retrieving the token
"""

Comment on lines 73 to 75
if self.secrets_keeper is None:
raise ValueError("Secret Keeper not initialized.")

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please make a method for that ? + Add a custom exception ?

Comment on lines 73 to 75
def _check_secret_keeper_exists(self) -> None:
if self.secrets_keeper is None:
raise SecretKeeperMissingError("Secret keeper is not set on oauth2 connector.")
Copy link
Contributor

@lukapeschke lukapeschke Feb 5, 2025

Choose a reason for hiding this comment

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

Suggested change
def _check_secret_keeper_exists(self) -> None:
if self.secrets_keeper is None:
raise SecretKeeperMissingError("Secret keeper is not set on oauth2 connector.")
def _secrets_keeper(self) -> SecretsKeeper:
if self.secrets_keeper is None:
raise SecretKeeperMissingError("Secret keeper is not set on oauth2 connector.")
return self.secrets_keeper

It'd allow you to do self._secrets_keeper().something everywhere in the code

@julien-pinchelimouroux julien-pinchelimouroux merged commit 4313dc4 into master Feb 6, 2025
5 checks passed
@julien-pinchelimouroux julien-pinchelimouroux deleted the TCTC-10081/accept_none_fields branch February 6, 2025 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Need Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants