-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[3/n][dagster-airbyte] Implement base request method in AirbyteCloudClient #26241
Conversation
python_modules/libraries/dagster-airbyte/dagster_airbyte/resources.py
Outdated
Show resolved
Hide resolved
2dc0534
to
9c0212c
Compare
3b10c92
to
b92ce13
Compare
9c0212c
to
2930c7f
Compare
b92ce13
to
0ba2ae9
Compare
python_modules/libraries/dagster-airbyte/dagster_airbyte/resources.py
Outdated
Show resolved
Hide resolved
2930c7f
to
8645142
Compare
0ba2ae9
to
6b52f15
Compare
8645142
to
f19ad83
Compare
6b52f15
to
a22d971
Compare
f19ad83
to
8397e6a
Compare
a22d971
to
29a997b
Compare
@@ -801,35 +805,145 @@ def airbyte_cloud_resource(context) -> AirbyteCloudResource: | |||
|
|||
|
|||
@experimental | |||
class AirbyteCloudClient: | |||
class AirbyteCloudClient(DagsterModel): |
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.
Using DagsterModel
to handle PrivateAttr
self._access_token_value = str(response["access_token"]) | ||
self._access_token_timestamp = datetime.now().timestamp() | ||
|
||
def _needs_refreshed_access_token(self) -> bool: |
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.
The access token must be refreshed every 3 minutes
"""Creates and sends a request to the desired Airbyte REST API endpoint. | ||
|
||
Args: | ||
method (str): The http method to use for this request (e.g. "POST", "GET", "PATCH"). |
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.
nit: can probably use the requests enum here?
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.
The mock response library provides an enum, but the request library doesn't - the request library still uses strings in the implementation.
request_args: Dict[str, Any] = dict( | ||
method=method, | ||
url=url, | ||
headers=headers, | ||
timeout=self.request_timeout, |
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.
nit; could use a request.Session in a method .get_session(additional_params) instead of including this all inline
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.
Much cleaner, thanks for the suggestion
response.raise_for_status() | ||
return response.json() | ||
except RequestException as e: | ||
self._log.error("Request to Airbyte API failed: %s", 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.
maybe include the url used + method
|
||
# Taken from Airbyte API documentation | ||
# https://reference.airbyte.com/reference/createaccesstoken | ||
SAMPLE_ACCESS_TOKEN = {"access_token": TEST_ACCESS_TOKEN} |
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.
thanks for good comment
) | ||
|
||
|
||
def test_refresh_access_token(base_api_mocks: responses.RequestsMock) -> None: |
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.
docstring pls
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.
some comments but lgtm
8397e6a
to
1df12dd
Compare
779d404
to
1e19ef1
Compare
1e19ef1
to
d89aee3
Compare
d89aee3
to
4c7c1b9
Compare
…lient (dagster-io#26241) ## Summary & Motivation This PR implements the base `_make_request` method for AirbyteCloudClient and the methods that are required to handle the creation of the access token. About the access token, the logic was taken and reworked from this [previous implementation](dagster-io#23451). TL;DR, Airbyte now requires a client ID and secret to generate an access token - this access token expires every 3 minutes. See more [here](https://reference.airbyte.com/reference/portalairbytecom-deprecation). ## How I Tested These Changes Additional tests
Summary & Motivation
This PR implements the base
_make_request
method for AirbyteCloudClient and the methods that are required to handle the creation of the access token.About the access token, the logic was taken and reworked from this previous implementation. TL;DR, Airbyte now requires a client ID and secret to generate an access token - this access token expires every 3 minutes. See more here.
How I Tested These Changes
Additional tests