-
Notifications
You must be signed in to change notification settings - Fork 4k
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
🐛 Source Pinterest: returns config_error after low-code migration without reset #39559
Merged
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
97eebbc
Ensure Pinterest returns config_error after low-code migration withou…
maxi297 5f942d1
Update release information
maxi297 01c857e
Move from auth to requests_native_auth package for authentication
maxi297 d0a4076
Merge branch 'issue-8257/update-pinterest' of https://github.com/airb…
ChristoGrab 2bf5679
update authenticator package
ChristoGrab 25f414d
use requests library for fetching report data
ChristoGrab 816ee0b
chore: format
ChristoGrab 1c3e150
chore: fix unit test
ChristoGrab 4ab14cb
Merge branch 'master' into issue-8257/update-pinterest
ChristoGrab dd9aaae
Merge branch 'issue-8257/update-pinterest' of https://github.com/airb…
ChristoGrab 7602d54
chore: fix unit tests
ChristoGrab ff8ffb0
chore: format
ChristoGrab 1eb535a
chore: fix last unit tests
ChristoGrab 9b22fa8
add authenticator unit tests
ChristoGrab 9e16001
Merge branch 'master' into issue-8257/update-pinterest
ChristoGrab ec76eac
update configured_catalog for CAT tests
ChristoGrab 74adf82
Merge branch 'issue-8257/update-pinterest' of https://github.com/airb…
ChristoGrab 4178d74
Fix parent stream state issue
maxi297 23df232
Merge branch 'master' into issue-8257/update-pinterest
maxi297 5dade79
Merge branch 'master' into issue-8257/update-pinterest
maxi297 5ae4ad7
Merge branch 'master' into issue-8257/update-pinterest
bazarnov a68b373
Merge branch 'master' into issue-8257/update-pinterest
maxi297 f43b63c
Removing some incremental streams
maxi297 22494b4
Merge branch 'master' into issue-8257/update-pinterest
maxi297 f36ffd2
Migration for airbyte_cdk version 3
maxi297 5fb4f3b
Remove custom BackoffStrategy
maxi297 78fbd03
format
maxi297 7a2e26b
add missing file
maxi297 2dc9bff
Update CDK version to have newest backoffstrategy interface
maxi297 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
228 changes: 156 additions & 72 deletions
228
airbyte-integrations/connectors/source-pinterest/poetry.lock
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
88 changes: 88 additions & 0 deletions
88
airbyte-integrations/connectors/source-pinterest/source_pinterest/python_stream_auth.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# | ||
# Copyright (c) 2024 Airbyte, Inc., all rights reserved. | ||
# | ||
|
||
from typing import Any, List, Mapping, Optional, Tuple | ||
|
||
import pendulum | ||
import requests | ||
from airbyte_cdk.models import FailureType | ||
from airbyte_cdk.sources.streams.http.exceptions import DefaultBackoffException | ||
from airbyte_cdk.sources.streams.http.requests_native_auth import Oauth2Authenticator | ||
from airbyte_cdk.utils import AirbyteTracedException | ||
from airbyte_cdk.utils.airbyte_secrets_utils import add_to_secrets | ||
|
||
|
||
class PinterestOauthAuthenticator(Oauth2Authenticator): | ||
""" | ||
Custom implementation of Oauth2Authenticator that allows injection of auth headers in call to refresh access token | ||
""" | ||
|
||
def __init__( | ||
self, | ||
token_refresh_endpoint: str, | ||
client_id: str, | ||
client_secret: str, | ||
refresh_token: str, | ||
scopes: List[str] = None, | ||
token_expiry_date: pendulum.DateTime = None, | ||
token_expiry_date_format: str = None, | ||
access_token_name: str = "access_token", | ||
expires_in_name: str = "expires_in", | ||
refresh_request_body: Mapping[str, Any] = None, | ||
grant_type: str = "refresh_token", | ||
token_expiry_is_time_of_expiration: bool = False, | ||
refresh_token_error_status_codes: Tuple[int, ...] = (), | ||
refresh_token_error_key: str = "", | ||
refresh_token_error_values: Tuple[str, ...] = (), | ||
refresh_access_token_headers: Optional[Mapping[str, Any]] = None, | ||
): | ||
super().__init__( | ||
token_refresh_endpoint, | ||
client_id, | ||
client_secret, | ||
refresh_token, | ||
scopes, | ||
token_expiry_date, | ||
token_expiry_date_format, | ||
access_token_name, | ||
expires_in_name, | ||
refresh_request_body, | ||
grant_type, | ||
token_expiry_is_time_of_expiration, | ||
refresh_token_error_status_codes, | ||
refresh_token_error_key, | ||
refresh_token_error_values, | ||
) | ||
self._refresh_access_token_headers = refresh_access_token_headers | ||
|
||
def _get_refresh_access_token_response(self) -> Any: | ||
try: | ||
headers = self._refresh_access_token_headers or {} | ||
response = requests.request( | ||
method="POST", | ||
url=self.get_token_refresh_endpoint(), | ||
data=self.build_refresh_request_body(), | ||
headers=headers, | ||
) | ||
if response.ok: | ||
response_json = response.json() | ||
access_key = response_json.get(self.get_access_token_name()) | ||
if not access_key: | ||
raise Exception(f"Token refresh API response was missing access token {self.get_access_token_name()}") | ||
add_to_secrets(access_key) | ||
self._log_response(response) | ||
return response_json | ||
else: | ||
self._log_response(response) | ||
response.raise_for_status() | ||
except requests.exceptions.RequestException as e: | ||
if e.response is not None: | ||
if e.response.status_code == 429 or e.response.status_code >= 500: | ||
raise DefaultBackoffException(request=e.response.request, response=e.response) | ||
if self._wrap_refresh_token_exception(e): | ||
message = "Refresh token is invalid or expired. Please re-authenticate from Sources/<your source>/Settings." | ||
raise AirbyteTracedException(internal_message=message, message=message, failure_type=FailureType.config_error) | ||
raise | ||
except Exception as e: | ||
raise Exception(f"Error while refreshing access token: {e}") from e |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@maxi297 and I discussed this aspect a little bit. Although its not great to have to repeat this action so many times to generate independent streams, it doesn't have an I/O on the network and we only do this at the beginning so the performance impact is minimal.
We did play around with deep copy which didn't quite work on the nested objects among other reasons.
We floated a few ideas on how we might address this for other sources that do have dependencies on the API
either way, this is not worth blocking on, but something we'll need to at some point solve for