-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new InterpolatedRequestOptionsProvider that encapsulates all vari…
…ations of request arguments (#13472) * write out new request options provider and refactor components and parts of the YAML config * fix formatting * pr feedback to consolidate body_data_provider to simplify the code * pr feedback get rid of extraneous optional
- Loading branch information
Showing
21 changed files
with
297 additions
and
393 deletions.
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
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
3 changes: 3 additions & 0 deletions
3
airbyte-cdk/python/airbyte_cdk/sources/declarative/requesters/request_options/__init__.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,3 @@ | ||
# | ||
# Copyright (c) 2022 Airbyte, Inc., all rights reserved. | ||
# |
50 changes: 50 additions & 0 deletions
50
...k/sources/declarative/requesters/request_options/interpolated_request_options_provider.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,50 @@ | ||
# | ||
# Copyright (c) 2022 Airbyte, Inc., all rights reserved. | ||
# | ||
|
||
from typing import Any, Mapping, MutableMapping, Optional, Union | ||
|
||
from airbyte_cdk.sources.declarative.requesters.interpolated_request_input_provider import InterpolatedRequestInputProvider | ||
from airbyte_cdk.sources.declarative.requesters.request_options.request_options_provider import RequestOptionsProvider | ||
|
||
|
||
class InterpolatedRequestOptionsProvider(RequestOptionsProvider): | ||
def __init__(self, *, config, request_parameters=None, request_body_data=None, request_body_json=None): | ||
if request_parameters is None: | ||
request_parameters = {} | ||
if request_body_data is None: | ||
request_body_data = "" | ||
if request_body_json is None: | ||
request_body_json = {} | ||
|
||
if request_body_json and request_body_data: | ||
raise ValueError("RequestOptionsProvider should only contain either 'request_body_data' or 'request_body_json' not both") | ||
|
||
self._parameter_interpolator = InterpolatedRequestInputProvider(config=config, request_inputs=request_parameters) | ||
self._body_data_interpolator = InterpolatedRequestInputProvider(config=config, request_inputs=request_body_data) | ||
self._body_json_interpolator = InterpolatedRequestInputProvider(config=config, request_inputs=request_body_json) | ||
|
||
def request_params( | ||
self, stream_state: Mapping[str, Any], stream_slice: Mapping[str, Any] = None, next_page_token: Mapping[str, Any] = None | ||
) -> MutableMapping[str, Any]: | ||
interpolated_value = self._parameter_interpolator.request_inputs(stream_state, stream_slice, next_page_token) | ||
if isinstance(interpolated_value, dict): | ||
return interpolated_value | ||
return {} | ||
|
||
def request_body_data( | ||
self, stream_state: Mapping[str, Any], stream_slice: Mapping[str, Any] = None, next_page_token: Mapping[str, Any] = None | ||
) -> Optional[Union[Mapping, str]]: | ||
return self._body_data_interpolator.request_inputs(stream_state, stream_slice, next_page_token) | ||
|
||
def request_body_json( | ||
self, stream_state: Mapping[str, Any], stream_slice: Mapping[str, Any] = None, next_page_token: Mapping[str, Any] = None | ||
) -> Optional[Mapping]: | ||
return self._body_json_interpolator.request_inputs(stream_state, stream_slice, next_page_token) | ||
|
||
def request_kwargs( | ||
self, stream_state: Mapping[str, Any], stream_slice: Mapping[str, Any] = None, next_page_token: Mapping[str, Any] = None | ||
) -> Mapping[str, Any]: | ||
# todo: there are a few integrations that override the request_kwargs() method, but the use case for why kwargs over existing | ||
# constructs is a little unclear. We may revisit this, but for now lets leave it out of the DSL | ||
return {} |
32 changes: 32 additions & 0 deletions
32
...on/airbyte_cdk/sources/declarative/requesters/request_options/request_options_provider.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,32 @@ | ||
# | ||
# Copyright (c) 2022 Airbyte, Inc., all rights reserved. | ||
# | ||
|
||
from abc import ABC, abstractmethod | ||
from typing import Any, Mapping, MutableMapping, Optional, Union | ||
|
||
|
||
class RequestOptionsProvider(ABC): | ||
@abstractmethod | ||
def request_params( | ||
self, stream_state: Mapping[str, Any], stream_slice: Mapping[str, Any] = None, next_page_token: Mapping[str, Any] = None | ||
) -> MutableMapping[str, Any]: | ||
pass | ||
|
||
@abstractmethod | ||
def request_body_data( | ||
self, stream_state: Mapping[str, Any], stream_slice: Mapping[str, Any] = None, next_page_token: Mapping[str, Any] = None | ||
) -> Optional[Union[Mapping, str]]: | ||
pass | ||
|
||
@abstractmethod | ||
def request_body_json( | ||
self, stream_state: Mapping[str, Any], stream_slice: Mapping[str, Any] = None, next_page_token: Mapping[str, Any] = None | ||
) -> Optional[Mapping]: | ||
pass | ||
|
||
@abstractmethod | ||
def request_kwargs( | ||
self, stream_state: Mapping[str, Any], stream_slice: Mapping[str, Any] = None, next_page_token: Mapping[str, Any] = None | ||
) -> Mapping[str, Any]: | ||
pass |
3 changes: 0 additions & 3 deletions
3
airbyte-cdk/python/airbyte_cdk/sources/declarative/requesters/request_params/__init__.py
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
.../sources/declarative/requesters/request_params/interpolated_request_parameter_provider.py
This file was deleted.
Oops, something went wrong.
14 changes: 0 additions & 14 deletions
14
.../airbyte_cdk/sources/declarative/requesters/request_params/request_parameters_provider.py
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
|
||
class HttpMethod(Enum): | ||
GET = "GET" | ||
POST = "POST" | ||
|
||
|
||
class Requester(ABC): | ||
|
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
78 changes: 0 additions & 78 deletions
78
...t_tests/sources/declarative/interpolation/test_interpolated_request_parameter_provider.py
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.