-
Notifications
You must be signed in to change notification settings - Fork 4.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
Alex/lowcode referencedocs #14973
Alex/lowcode referencedocs #14973
Changes from all commits
70b3a33
39a8969
69ef7af
268ca35
96344c0
5fa2780
ff53477
2987444
dd3a0a5
7e73174
adc5032
835ccd2
8002ed4
6a8fc70
b2755f4
ce8eae2
8afdecd
2b29847
d2912a8
4634999
eb4a118
4e44305
8295789
c01d93e
045776b
4f9932c
2368893
1e650cc
272e584
d32b453
1a7cb23
863a470
c31b586
205880c
e4090a4
499b4e8
cac95dd
dca0bae
6b507c0
2e0d806
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
# Copyright (c) 2022 Airbyte, Inc., all rights reserved. | ||
# | ||
|
||
from typing import Any, List, Mapping | ||
from typing import Any, List, Mapping, Optional, Union | ||
|
||
import pendulum | ||
from airbyte_cdk.sources.declarative.interpolation.interpolated_mapping import InterpolatedMapping | ||
|
@@ -19,29 +19,41 @@ class DeclarativeOauth2Authenticator(AbstractOauth2Authenticator): | |
|
||
def __init__( | ||
self, | ||
token_refresh_endpoint: str, | ||
client_id: str, | ||
client_secret: str, | ||
refresh_token: str, | ||
token_refresh_endpoint: Union[InterpolatedString, str], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Union is what we actually accept |
||
client_id: Union[InterpolatedString, str], | ||
client_secret: Union[InterpolatedString, str], | ||
refresh_token: Union[InterpolatedString, str], | ||
config: Mapping[str, Any], | ||
scopes: List[str] = None, | ||
token_expiry_date: str = None, | ||
access_token_name: str = "access_token", | ||
expires_in_name: str = "expires_in", | ||
refresh_request_body: Mapping[str, Any] = None, | ||
scopes: Optional[List[str]] = None, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. optional because default is None |
||
token_expiry_date: Optional[Union[InterpolatedString, str]] = None, | ||
access_token_name: Union[InterpolatedString, str] = InterpolatedString("access_token"), | ||
expires_in_name: Union[InterpolatedString, str] = InterpolatedString("expires_in"), | ||
refresh_request_body: Optional[Mapping[str, Any]] = None, | ||
): | ||
""" | ||
:param token_refresh_endpoint: The endpoint to refresh the access token | ||
:param client_id: The client id | ||
:param client_secret: Client secret | ||
:param refresh_token: The token used to refresh the access token | ||
:param config: The user-provided configuration as specified by the source's spec | ||
:param scopes: The scopes to request | ||
:param token_expiry_date: The access token expiration date | ||
:param access_token_name: THe field to extract access token from in the response | ||
:param expires_in_name:The field to extract expires_in from in the response | ||
:param refresh_request_body: The request body to send in the refresh request | ||
""" | ||
self.config = config | ||
self.token_refresh_endpoint = InterpolatedString(token_refresh_endpoint) | ||
self.client_secret = InterpolatedString(client_secret) | ||
self.client_id = InterpolatedString(client_id) | ||
self.refresh_token = InterpolatedString(refresh_token) | ||
self.token_refresh_endpoint = InterpolatedString.create(token_refresh_endpoint) | ||
self.client_secret = InterpolatedString.create(client_secret) | ||
self.client_id = InterpolatedString.create(client_id) | ||
self.refresh_token = InterpolatedString.create(refresh_token) | ||
self.scopes = scopes | ||
self.access_token_name = InterpolatedString(access_token_name) | ||
self.expires_in_name = InterpolatedString(expires_in_name) | ||
self.refresh_request_body = InterpolatedMapping(refresh_request_body) | ||
self.access_token_name = InterpolatedString.create(access_token_name) | ||
self.expires_in_name = InterpolatedString.create(expires_in_name) | ||
self.refresh_request_body = InterpolatedMapping(refresh_request_body or {}) | ||
|
||
self.token_expiry_date = ( | ||
pendulum.parse(InterpolatedString(token_expiry_date).eval(self.config)) | ||
pendulum.parse(InterpolatedString.create(token_expiry_date).eval(self.config)) | ||
if token_expiry_date | ||
else pendulum.now().subtract(days=1) | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,10 @@ | |
import inspect | ||
|
||
from airbyte_cdk.sources.declarative.interpolation.interpolated_mapping import InterpolatedMapping | ||
from airbyte_cdk.sources.declarative.interpolation.jinja import JinjaInterpolation | ||
|
||
""" | ||
|
||
def create(func, /, *args, **keywords): | ||
""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move docstring within the method |
||
Create a partial on steroids. | ||
Returns a partial object which when called will behave like func called with the arguments supplied. | ||
Parameters will be interpolated before the creation of the object | ||
|
@@ -20,10 +21,7 @@ | |
:return: partially created object | ||
""" | ||
|
||
|
||
def create(func, /, *args, **keywords): | ||
def newfunc(*fargs, **fkeywords): | ||
interpolation = JinjaInterpolation() | ||
all_keywords = {**keywords} | ||
all_keywords.update(fkeywords) | ||
|
||
|
@@ -40,7 +38,7 @@ def newfunc(*fargs, **fkeywords): | |
fully_created = _create_inner_objects(all_keywords, options) | ||
|
||
# interpolate the parameters | ||
interpolated_keywords = InterpolatedMapping(fully_created, interpolation).eval(config, **{"options": options}) | ||
interpolated_keywords = InterpolatedMapping(fully_created).eval(config, **{"options": options}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we always use a |
||
interpolated_keywords = {k: v for k, v in interpolated_keywords.items() if v} | ||
|
||
all_keywords.update(interpolated_keywords) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,16 @@ | |
# Copyright (c) 2022 Airbyte, Inc., all rights reserved. | ||
# | ||
|
||
from typing import Any, Mapping | ||
from typing import Any, List, Mapping, Union | ||
|
||
import requests | ||
from airbyte_cdk.sources.declarative.decoders.decoder import Decoder | ||
|
||
|
||
class JsonDecoder(Decoder): | ||
def decode(self, response: requests.Response) -> Mapping[str, Any]: | ||
return response.json() | ||
""" | ||
Decoder strategy that returns the json-encoded content of a response, if any. | ||
""" | ||
|
||
def decode(self, response: requests.Response) -> Union[Mapping[str, Any], List]: | ||
return response.json() or {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fwiw I believe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added |
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.
we accept a union, not just a str