Skip to content

Commit 650165f

Browse files
author
octavia-squidington-iii
committed
Auto-fix lint and format issues
1 parent 739c429 commit 650165f

5 files changed

Lines changed: 197 additions & 123 deletions

File tree

airbyte_cdk/sources/declarative/checks/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
from pydantic.v1 import BaseModel
88

99
from airbyte_cdk.sources.declarative.checks.check_dynamic_stream import CheckDynamicStream
10-
from airbyte_cdk.sources.declarative.checks.check_stream import CheckStream, DynamicStreamCheckConfig
10+
from airbyte_cdk.sources.declarative.checks.check_stream import (
11+
CheckStream,
12+
DynamicStreamCheckConfig,
13+
)
1114
from airbyte_cdk.sources.declarative.checks.connection_checker import ConnectionChecker
1215
from airbyte_cdk.sources.declarative.models import (
1316
CheckDynamicStream as CheckDynamicStreamModel,

airbyte_cdk/sources/declarative/checks/check_stream.py

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ def check_connection(
4444
try:
4545
streams = source.streams(config=config)
4646
except Exception as error:
47-
error_message = (
48-
f"Encountered an error trying to connect to streams. Error: {error}"
49-
)
47+
error_message = f"Encountered an error trying to connect to streams. Error: {error}"
5048
logger.error(error_message, exc_info=True)
5149
return False, error_message
5250

@@ -73,27 +71,47 @@ def check_connection(
7371
)
7472
return False, f"Unable to connect to stream {stream_name} - {error}"
7573

76-
if hasattr(source, "resolved_manifest") and hasattr(source, "dynamic_streams") and self.dynamic_streams_check_configs:
77-
dynamic_stream_name_to_dynamic_stream = {dynamic_stream.get("name", f"dynamic_stream_{i}"): dynamic_stream for i, dynamic_stream in enumerate(source.resolved_manifest.get("dynamic_streams", []))}
74+
if (
75+
hasattr(source, "resolved_manifest")
76+
and hasattr(source, "dynamic_streams")
77+
and self.dynamic_streams_check_configs
78+
):
79+
dynamic_stream_name_to_dynamic_stream = {
80+
dynamic_stream.get("name", f"dynamic_stream_{i}"): dynamic_stream
81+
for i, dynamic_stream in enumerate(
82+
source.resolved_manifest.get("dynamic_streams", [])
83+
)
84+
}
7885

7986
dynamic_stream_name_to_generated_streams = {}
8087
for stream in source.dynamic_streams:
81-
dynamic_stream_name_to_generated_streams[
82-
stream["dynamic_stream_name"]] = dynamic_stream_name_to_generated_streams.setdefault(
83-
stream["dynamic_stream_name"], []) + [stream]
88+
dynamic_stream_name_to_generated_streams[stream["dynamic_stream_name"]] = (
89+
dynamic_stream_name_to_generated_streams.setdefault(
90+
stream["dynamic_stream_name"], []
91+
)
92+
+ [stream]
93+
)
8494

8595
for dynamic_streams_check_config in self.dynamic_streams_check_configs:
86-
dynamic_stream = dynamic_stream_name_to_dynamic_stream.get(dynamic_streams_check_config.dynamic_stream_name)
96+
dynamic_stream = dynamic_stream_name_to_dynamic_stream.get(
97+
dynamic_streams_check_config.dynamic_stream_name
98+
)
8799

88-
is_config_depend = dynamic_stream["components_resolver"]["type"] == "ConfigComponentsResolver"
100+
is_config_depend = (
101+
dynamic_stream["components_resolver"]["type"] == "ConfigComponentsResolver"
102+
)
89103

90104
if not is_config_depend and not bool(dynamic_streams_check_config.stream_count):
91105
continue
92106

93-
generated_streams = dynamic_stream_name_to_generated_streams.get(dynamic_streams_check_config.dynamic_stream_name)
107+
generated_streams = dynamic_stream_name_to_generated_streams.get(
108+
dynamic_streams_check_config.dynamic_stream_name
109+
)
94110
availability_strategy = HttpAvailabilityStrategy()
95111

96-
for declarative_stream in generated_streams[: min(dynamic_streams_check_config.stream_count, len(generated_streams))]:
112+
for declarative_stream in generated_streams[
113+
: min(dynamic_streams_check_config.stream_count, len(generated_streams))
114+
]:
97115
stream = stream_name_to_stream.get(declarative_stream["name"])
98116
try:
99117
stream_is_available, reason = availability_strategy.check_availability(
@@ -103,9 +121,7 @@ def check_connection(
103121
logger.warning(f"Stream {stream.name} is not available: {reason}")
104122
return False, reason
105123
except Exception as error:
106-
error_message = (
107-
f"Encountered an error trying to connect to stream {stream.name}. Error: {error}"
108-
)
124+
error_message = f"Encountered an error trying to connect to stream {stream.name}. Error: {error}"
109125
logger.error(error_message, exc_info=True)
110126
return False, error_message
111127

airbyte_cdk/sources/declarative/models/declarative_component_schema.py

Lines changed: 27 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -611,9 +611,7 @@ class OAuthAuthenticator(BaseModel):
611611
scopes: Optional[List[str]] = Field(
612612
None,
613613
description="List of scopes that should be granted to the access token.",
614-
examples=[
615-
["crm.list.read", "crm.objects.contacts.read", "crm.schema.contacts.read"]
616-
],
614+
examples=[["crm.list.read", "crm.objects.contacts.read", "crm.schema.contacts.read"]],
617615
title="Scopes",
618616
)
619617
token_expiry_date: Optional[str] = Field(
@@ -1087,28 +1085,24 @@ class OAuthConfigSpecification(BaseModel):
10871085
class Config:
10881086
extra = Extra.allow
10891087

1090-
oauth_user_input_from_connector_config_specification: Optional[Dict[str, Any]] = (
1091-
Field(
1092-
None,
1093-
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 }",
1094-
examples=[
1095-
{"app_id": {"type": "string", "path_in_connector_config": ["app_id"]}},
1096-
{
1097-
"app_id": {
1098-
"type": "string",
1099-
"path_in_connector_config": ["info", "app_id"],
1100-
}
1101-
},
1102-
],
1103-
title="OAuth user input",
1104-
)
1088+
oauth_user_input_from_connector_config_specification: Optional[Dict[str, Any]] = Field(
1089+
None,
1090+
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 }",
1091+
examples=[
1092+
{"app_id": {"type": "string", "path_in_connector_config": ["app_id"]}},
1093+
{
1094+
"app_id": {
1095+
"type": "string",
1096+
"path_in_connector_config": ["info", "app_id"],
1097+
}
1098+
},
1099+
],
1100+
title="OAuth user input",
11051101
)
1106-
oauth_connector_input_specification: Optional[OauthConnectorInputSpecification] = (
1107-
Field(
1108-
None,
1109-
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 }',
1110-
title="DeclarativeOAuth Connector Specification",
1111-
)
1102+
oauth_connector_input_specification: Optional[OauthConnectorInputSpecification] = Field(
1103+
None,
1104+
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 }',
1105+
title="DeclarativeOAuth Connector Specification",
11121106
)
11131107
complete_oauth_output_specification: Optional[Dict[str, Any]] = Field(
11141108
None,
@@ -1126,9 +1120,7 @@ class Config:
11261120
complete_oauth_server_input_specification: Optional[Dict[str, Any]] = Field(
11271121
None,
11281122
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 }",
1129-
examples=[
1130-
{"client_id": {"type": "string"}, "client_secret": {"type": "string"}}
1131-
],
1123+
examples=[{"client_id": {"type": "string"}, "client_secret": {"type": "string"}}],
11321124
title="OAuth input specification",
11331125
)
11341126
complete_oauth_server_output_specification: Optional[Dict[str, Any]] = Field(
@@ -1802,9 +1794,7 @@ class RecordSelector(BaseModel):
18021794
description="Responsible for filtering records to be emitted by the Source.",
18031795
title="Record Filter",
18041796
)
1805-
schema_normalization: Optional[
1806-
Union[SchemaNormalization, CustomSchemaNormalization]
1807-
] = Field(
1797+
schema_normalization: Optional[Union[SchemaNormalization, CustomSchemaNormalization]] = Field(
18081798
SchemaNormalization.None_,
18091799
description="Responsible for normalization according to the schema.",
18101800
title="Schema Normalization",
@@ -2031,9 +2021,7 @@ class Config:
20312021
description="Component used to fetch data incrementally based on a time field in the data.",
20322022
title="Incremental Sync",
20332023
)
2034-
name: Optional[str] = Field(
2035-
"", description="The stream name.", example=["Users"], title="Name"
2036-
)
2024+
name: Optional[str] = Field("", description="The stream name.", example=["Users"], title="Name")
20372025
primary_key: Optional[PrimaryKey] = Field(
20382026
"", description="The primary key of the stream.", title="Primary Key"
20392027
)
@@ -2291,9 +2279,7 @@ class ParentStreamConfig(BaseModel):
22912279

22922280
class StateDelegatingStream(BaseModel):
22932281
type: Literal["StateDelegatingStream"]
2294-
name: str = Field(
2295-
..., description="The stream name.", example=["Users"], title="Name"
2296-
)
2282+
name: str = Field(..., description="The stream name.", example=["Users"], title="Name")
22972283
full_refresh_stream: DeclarativeStream = Field(
22982284
...,
22992285
description="Component used to coordinate how records are extracted across stream slices and request pages when the state is empty or not provided.",
@@ -2382,9 +2368,7 @@ class AsyncRetriever(BaseModel):
23822368
)
23832369
download_extractor: Optional[
23842370
Union[CustomRecordExtractor, DpathExtractor, ResponseToFileExtractor]
2385-
] = Field(
2386-
None, description="Responsible for fetching the records from provided urls."
2387-
)
2371+
] = Field(None, description="Responsible for fetching the records from provided urls.")
23882372
creation_requester: Union[CustomRequester, HttpRequester] = Field(
23892373
...,
23902374
description="Requester component that describes how to prepare HTTP requests to send to the source API to create the async server-side job.",
@@ -2524,12 +2508,10 @@ class DynamicDeclarativeStream(BaseModel):
25242508
stream_template: DeclarativeStream = Field(
25252509
..., description="Reference to the stream template.", title="Stream Template"
25262510
)
2527-
components_resolver: Union[HttpComponentsResolver, ConfigComponentsResolver] = (
2528-
Field(
2529-
...,
2530-
description="Component resolve and populates stream templates with components values.",
2531-
title="Components Resolver",
2532-
)
2511+
components_resolver: Union[HttpComponentsResolver, ConfigComponentsResolver] = Field(
2512+
...,
2513+
description="Component resolve and populates stream templates with components values.",
2514+
title="Components Resolver",
25332515
)
25342516

25352517

0 commit comments

Comments
 (0)