Skip to content

Commit 33eda51

Browse files
committed
Add imterpolation for limit field in Rate
1 parent e1a182c commit 33eda51

File tree

4 files changed

+67
-36
lines changed

4 files changed

+67
-36
lines changed

airbyte_cdk/sources/declarative/declarative_component_schema.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1490,7 +1490,11 @@ definitions:
14901490
limit:
14911491
title: Limit
14921492
description: The maximum number of calls allowed within the interval.
1493-
type: integer
1493+
anyOf:
1494+
- type: integer
1495+
- type: string
1496+
interpolation_context:
1497+
- config
14941498
interval:
14951499
title: Interval
14961500
description: The time interval for the rate limit.

airbyte_cdk/sources/declarative/models/declarative_component_schema.py

Lines changed: 59 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,9 @@ class OAuthAuthenticator(BaseModel):
609609
scopes: Optional[List[str]] = Field(
610610
None,
611611
description="List of scopes that should be granted to the access token.",
612-
examples=[["crm.list.read", "crm.objects.contacts.read", "crm.schema.contacts.read"]],
612+
examples=[
613+
["crm.list.read", "crm.objects.contacts.read", "crm.schema.contacts.read"]
614+
],
613615
title="Scopes",
614616
)
615617
token_expiry_date: Optional[str] = Field(
@@ -646,7 +648,7 @@ class Rate(BaseModel):
646648
class Config:
647649
extra = Extra.allow
648650

649-
limit: int = Field(
651+
limit: Union[int, str] = Field(
650652
...,
651653
description="The maximum number of calls allowed within the interval.",
652654
title="Limit",
@@ -1078,24 +1080,28 @@ class OAuthConfigSpecification(BaseModel):
10781080
class Config:
10791081
extra = Extra.allow
10801082

1081-
oauth_user_input_from_connector_config_specification: Optional[Dict[str, Any]] = Field(
1082-
None,
1083-
description="OAuth specific blob. This is a Json Schema used to validate Json configurations used as input to OAuth.\nMust be a valid non-nested JSON that refers to properties from ConnectorSpecification.connectionSpecification\nusing special annotation 'path_in_connector_config'.\nThese are input values the user is entering through the UI to authenticate to the connector, that might also shared\nas inputs for syncing data via the connector.\nExamples:\nif no connector values is shared during oauth flow, oauth_user_input_from_connector_config_specification=[]\nif connector values such as 'app_id' inside the top level are used to generate the API url for the oauth flow,\n oauth_user_input_from_connector_config_specification={\n app_id: {\n type: string\n path_in_connector_config: ['app_id']\n }\n }\nif connector values such as 'info.app_id' nested inside another object are used to generate the API url for the oauth flow,\n oauth_user_input_from_connector_config_specification={\n app_id: {\n type: string\n path_in_connector_config: ['info', 'app_id']\n }\n }",
1084-
examples=[
1085-
{"app_id": {"type": "string", "path_in_connector_config": ["app_id"]}},
1086-
{
1087-
"app_id": {
1088-
"type": "string",
1089-
"path_in_connector_config": ["info", "app_id"],
1090-
}
1091-
},
1092-
],
1093-
title="OAuth user input",
1083+
oauth_user_input_from_connector_config_specification: Optional[Dict[str, Any]] = (
1084+
Field(
1085+
None,
1086+
description="OAuth specific blob. This is a Json Schema used to validate Json configurations used as input to OAuth.\nMust be a valid non-nested JSON that refers to properties from ConnectorSpecification.connectionSpecification\nusing special annotation 'path_in_connector_config'.\nThese are input values the user is entering through the UI to authenticate to the connector, that might also shared\nas inputs for syncing data via the connector.\nExamples:\nif no connector values is shared during oauth flow, oauth_user_input_from_connector_config_specification=[]\nif connector values such as 'app_id' inside the top level are used to generate the API url for the oauth flow,\n oauth_user_input_from_connector_config_specification={\n app_id: {\n type: string\n path_in_connector_config: ['app_id']\n }\n }\nif connector values such as 'info.app_id' nested inside another object are used to generate the API url for the oauth flow,\n oauth_user_input_from_connector_config_specification={\n app_id: {\n type: string\n path_in_connector_config: ['info', 'app_id']\n }\n }",
1087+
examples=[
1088+
{"app_id": {"type": "string", "path_in_connector_config": ["app_id"]}},
1089+
{
1090+
"app_id": {
1091+
"type": "string",
1092+
"path_in_connector_config": ["info", "app_id"],
1093+
}
1094+
},
1095+
],
1096+
title="OAuth user input",
1097+
)
10941098
)
1095-
oauth_connector_input_specification: Optional[OauthConnectorInputSpecification] = Field(
1096-
None,
1097-
description='The DeclarativeOAuth specific blob.\nPertains to the fields defined by the connector relating to the OAuth flow.\n\nInterpolation capabilities:\n- The variables placeholders are declared as `{{my_var}}`.\n- The nested resolution variables like `{{ {{my_nested_var}} }}` is allowed as well.\n\n- The allowed interpolation context is:\n + base64Encoder - encode to `base64`, {{ {{my_var_a}}:{{my_var_b}} | base64Encoder }}\n + base64Decorer - decode from `base64` encoded string, {{ {{my_string_variable_or_string_value}} | base64Decoder }}\n + urlEncoder - encode the input string to URL-like format, {{ https://test.host.com/endpoint | urlEncoder}}\n + urlDecorer - decode the input url-encoded string into text format, {{ urlDecoder:https%3A%2F%2Fairbyte.io | urlDecoder}}\n + codeChallengeS256 - get the `codeChallenge` encoded value to provide additional data-provider specific authorisation values, {{ {{state_value}} | codeChallengeS256 }}\n\nExamples:\n - The TikTok Marketing DeclarativeOAuth spec:\n {\n "oauth_connector_input_specification": {\n "type": "object",\n "additionalProperties": false,\n "properties": {\n "consent_url": "https://ads.tiktok.com/marketing_api/auth?{{client_id_key}}={{client_id_value}}&{{redirect_uri_key}}={{ {{redirect_uri_value}} | urlEncoder}}&{{state_key}}={{state_value}}",\n "access_token_url": "https://business-api.tiktok.com/open_api/v1.3/oauth2/access_token/",\n "access_token_params": {\n "{{ auth_code_key }}": "{{ auth_code_value }}",\n "{{ client_id_key }}": "{{ client_id_value }}",\n "{{ client_secret_key }}": "{{ client_secret_value }}"\n },\n "access_token_headers": {\n "Content-Type": "application/json",\n "Accept": "application/json"\n },\n "extract_output": ["data.access_token"],\n "client_id_key": "app_id",\n "client_secret_key": "secret",\n "auth_code_key": "auth_code"\n }\n }\n }',
1098-
title="DeclarativeOAuth Connector Specification",
1099+
oauth_connector_input_specification: Optional[OauthConnectorInputSpecification] = (
1100+
Field(
1101+
None,
1102+
description='The DeclarativeOAuth specific blob.\nPertains to the fields defined by the connector relating to the OAuth flow.\n\nInterpolation capabilities:\n- The variables placeholders are declared as `{{my_var}}`.\n- The nested resolution variables like `{{ {{my_nested_var}} }}` is allowed as well.\n\n- The allowed interpolation context is:\n + base64Encoder - encode to `base64`, {{ {{my_var_a}}:{{my_var_b}} | base64Encoder }}\n + base64Decorer - decode from `base64` encoded string, {{ {{my_string_variable_or_string_value}} | base64Decoder }}\n + urlEncoder - encode the input string to URL-like format, {{ https://test.host.com/endpoint | urlEncoder}}\n + urlDecorer - decode the input url-encoded string into text format, {{ urlDecoder:https%3A%2F%2Fairbyte.io | urlDecoder}}\n + codeChallengeS256 - get the `codeChallenge` encoded value to provide additional data-provider specific authorisation values, {{ {{state_value}} | codeChallengeS256 }}\n\nExamples:\n - The TikTok Marketing DeclarativeOAuth spec:\n {\n "oauth_connector_input_specification": {\n "type": "object",\n "additionalProperties": false,\n "properties": {\n "consent_url": "https://ads.tiktok.com/marketing_api/auth?{{client_id_key}}={{client_id_value}}&{{redirect_uri_key}}={{ {{redirect_uri_value}} | urlEncoder}}&{{state_key}}={{state_value}}",\n "access_token_url": "https://business-api.tiktok.com/open_api/v1.3/oauth2/access_token/",\n "access_token_params": {\n "{{ auth_code_key }}": "{{ auth_code_value }}",\n "{{ client_id_key }}": "{{ client_id_value }}",\n "{{ client_secret_key }}": "{{ client_secret_value }}"\n },\n "access_token_headers": {\n "Content-Type": "application/json",\n "Accept": "application/json"\n },\n "extract_output": ["data.access_token"],\n "client_id_key": "app_id",\n "client_secret_key": "secret",\n "auth_code_key": "auth_code"\n }\n }\n }',
1103+
title="DeclarativeOAuth Connector Specification",
1104+
)
10991105
)
11001106
complete_oauth_output_specification: Optional[Dict[str, Any]] = Field(
11011107
None,
@@ -1113,7 +1119,9 @@ class Config:
11131119
complete_oauth_server_input_specification: Optional[Dict[str, Any]] = Field(
11141120
None,
11151121
description="OAuth specific blob. This is a Json Schema used to validate Json configurations persisted as Airbyte Server configurations.\nMust be a valid non-nested JSON describing additional fields configured by the Airbyte Instance or Workspace Admins to be used by the\nserver when completing an OAuth flow (typically exchanging an auth code for refresh token).\nExamples:\n complete_oauth_server_input_specification={\n client_id: {\n type: string\n },\n client_secret: {\n type: string\n }\n }",
1116-
examples=[{"client_id": {"type": "string"}, "client_secret": {"type": "string"}}],
1122+
examples=[
1123+
{"client_id": {"type": "string"}, "client_secret": {"type": "string"}}
1124+
],
11171125
title="OAuth input specification",
11181126
)
11191127
complete_oauth_server_output_specification: Optional[Dict[str, Any]] = Field(
@@ -1744,7 +1752,9 @@ class RecordSelector(BaseModel):
17441752
description="Responsible for filtering records to be emitted by the Source.",
17451753
title="Record Filter",
17461754
)
1747-
schema_normalization: Optional[Union[SchemaNormalization, CustomSchemaNormalization]] = Field(
1755+
schema_normalization: Optional[
1756+
Union[SchemaNormalization, CustomSchemaNormalization]
1757+
] = Field(
17481758
SchemaNormalization.None_,
17491759
description="Responsible for normalization according to the schema.",
17501760
title="Schema Normalization",
@@ -1948,12 +1958,16 @@ class Config:
19481958
description="Component used to coordinate how records are extracted across stream slices and request pages.",
19491959
title="Retriever",
19501960
)
1951-
incremental_sync: Optional[Union[CustomIncrementalSync, DatetimeBasedCursor]] = Field(
1952-
None,
1953-
description="Component used to fetch data incrementally based on a time field in the data.",
1954-
title="Incremental Sync",
1961+
incremental_sync: Optional[Union[CustomIncrementalSync, DatetimeBasedCursor]] = (
1962+
Field(
1963+
None,
1964+
description="Component used to fetch data incrementally based on a time field in the data.",
1965+
title="Incremental Sync",
1966+
)
1967+
)
1968+
name: Optional[str] = Field(
1969+
"", description="The stream name.", example=["Users"], title="Name"
19551970
)
1956-
name: Optional[str] = Field("", description="The stream name.", example=["Users"], title="Name")
19571971
primary_key: Optional[PrimaryKey] = Field(
19581972
"", description="The primary key of the stream.", title="Primary Key"
19591973
)
@@ -2225,7 +2239,11 @@ class SimpleRetriever(BaseModel):
22252239
CustomPartitionRouter,
22262240
ListPartitionRouter,
22272241
SubstreamPartitionRouter,
2228-
List[Union[CustomPartitionRouter, ListPartitionRouter, SubstreamPartitionRouter]],
2242+
List[
2243+
Union[
2244+
CustomPartitionRouter, ListPartitionRouter, SubstreamPartitionRouter
2245+
]
2246+
],
22292247
]
22302248
] = Field(
22312249
[],
@@ -2269,7 +2287,9 @@ class AsyncRetriever(BaseModel):
22692287
)
22702288
download_extractor: Optional[
22712289
Union[CustomRecordExtractor, DpathExtractor, ResponseToFileExtractor]
2272-
] = Field(None, description="Responsible for fetching the records from provided urls.")
2290+
] = Field(
2291+
None, description="Responsible for fetching the records from provided urls."
2292+
)
22732293
creation_requester: Union[CustomRequester, HttpRequester] = Field(
22742294
...,
22752295
description="Requester component that describes how to prepare HTTP requests to send to the source API to create the async server-side job.",
@@ -2303,7 +2323,11 @@ class AsyncRetriever(BaseModel):
23032323
CustomPartitionRouter,
23042324
ListPartitionRouter,
23052325
SubstreamPartitionRouter,
2306-
List[Union[CustomPartitionRouter, ListPartitionRouter, SubstreamPartitionRouter]],
2326+
List[
2327+
Union[
2328+
CustomPartitionRouter, ListPartitionRouter, SubstreamPartitionRouter
2329+
]
2330+
],
23072331
]
23082332
] = Field(
23092333
[],
@@ -2371,10 +2395,12 @@ class DynamicDeclarativeStream(BaseModel):
23712395
stream_template: DeclarativeStream = Field(
23722396
..., description="Reference to the stream template.", title="Stream Template"
23732397
)
2374-
components_resolver: Union[HttpComponentsResolver, ConfigComponentsResolver] = Field(
2375-
...,
2376-
description="Component resolve and populates stream templates with components values.",
2377-
title="Components Resolver",
2398+
components_resolver: Union[HttpComponentsResolver, ConfigComponentsResolver] = (
2399+
Field(
2400+
...,
2401+
description="Component resolve and populates stream templates with components values.",
2402+
title="Components Resolver",
2403+
)
23782404
)
23792405

23802406

airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3024,8 +3024,9 @@ def create_unlimited_call_rate_policy(
30243024
)
30253025

30263026
def create_rate(self, model: RateModel, config: Config, **kwargs: Any) -> Rate:
3027+
interpolated_limit = InterpolatedString.create(str(model.limit), parameters={})
30273028
return Rate(
3028-
limit=model.limit,
3029+
limit=int(interpolated_limit.eval(config=config)),
30293030
interval=parse_duration(model.interval),
30303031
)
30313032

unit_tests/sources/declarative/requesters/test_http_requester.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ def test_backoff_strategy_from_manifest_is_respected(http_requester_factory: Any
946946
)
947947

948948

949-
def test_http_requester_with_mock_apibudget(http_requester_factory, monkeypatch):
949+
def test_http_requester_with_mock_api_budget(http_requester_factory, monkeypatch):
950950
mock_budget = MagicMock(spec=HttpAPIBudget)
951951

952952
requester = http_requester_factory(

0 commit comments

Comments
 (0)