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

[3/n][dagster-airbyte] Implement base request method in AirbyteCloudClient #26241

Merged
merged 8 commits into from
Dec 5, 2024

Conversation

maximearmstrong
Copy link
Contributor

@maximearmstrong maximearmstrong commented Dec 3, 2024

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

@maximearmstrong maximearmstrong force-pushed the maxime/rework-airbyte-cloud-2 branch from 2930c7f to 8645142 Compare December 4, 2024 05:29
@maximearmstrong maximearmstrong force-pushed the maxime/rework-airbyte-cloud-3 branch from 0ba2ae9 to 6b52f15 Compare December 4, 2024 05:29
@maximearmstrong maximearmstrong force-pushed the maxime/rework-airbyte-cloud-2 branch from 8645142 to f19ad83 Compare December 4, 2024 15:30
@maximearmstrong maximearmstrong force-pushed the maxime/rework-airbyte-cloud-3 branch from 6b52f15 to a22d971 Compare December 4, 2024 15:30
@maximearmstrong maximearmstrong force-pushed the maxime/rework-airbyte-cloud-2 branch from f19ad83 to 8397e6a Compare December 4, 2024 19:16
@maximearmstrong maximearmstrong force-pushed the maxime/rework-airbyte-cloud-3 branch from a22d971 to 29a997b Compare December 4, 2024 19:16
@maximearmstrong maximearmstrong changed the title [3/n][dagster-airbyte] Implement base request method in AirbyteClient [3/n][dagster-airbyte] Implement base request method in AirbyteCloudClient Dec 4, 2024
@@ -801,35 +805,145 @@ def airbyte_cloud_resource(context) -> AirbyteCloudResource:


@experimental
class AirbyteCloudClient:
class AirbyteCloudClient(DagsterModel):
Copy link
Contributor Author

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:
Copy link
Contributor Author

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

@maximearmstrong maximearmstrong marked this pull request as ready for review December 4, 2024 20:36
@maximearmstrong maximearmstrong self-assigned this Dec 4, 2024
"""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").
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Comment on lines 919 to 923
request_args: Dict[str, Any] = dict(
method=method,
url=url,
headers=headers,
timeout=self.request_timeout,
Copy link
Contributor

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

Copy link
Contributor Author

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)
Copy link
Contributor

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}
Copy link
Contributor

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:
Copy link
Contributor

Choose a reason for hiding this comment

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

docstring pls

Copy link
Contributor

@dpeng817 dpeng817 left a 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

@maximearmstrong maximearmstrong force-pushed the maxime/rework-airbyte-cloud-2 branch from 8397e6a to 1df12dd Compare December 5, 2024 20:53
@maximearmstrong maximearmstrong force-pushed the maxime/rework-airbyte-cloud-3 branch from 779d404 to 1e19ef1 Compare December 5, 2024 20:53
Base automatically changed from maxime/rework-airbyte-cloud-2 to master December 5, 2024 21:16
@maximearmstrong maximearmstrong force-pushed the maxime/rework-airbyte-cloud-3 branch from 1e19ef1 to d89aee3 Compare December 5, 2024 21:17
@maximearmstrong maximearmstrong force-pushed the maxime/rework-airbyte-cloud-3 branch from d89aee3 to 4c7c1b9 Compare December 5, 2024 22:13
@maximearmstrong maximearmstrong merged commit e24374c into master Dec 5, 2024
1 check failed
@maximearmstrong maximearmstrong deleted the maxime/rework-airbyte-cloud-3 branch December 5, 2024 22:26
pskinnerthyme pushed a commit to pskinnerthyme/dagster that referenced this pull request Dec 16, 2024
…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
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.

2 participants