Skip to content

Commit 5465460

Browse files
committed
Update Airbyte models
1 parent 40520f7 commit 5465460

1 file changed

Lines changed: 89 additions & 18 deletions

File tree

splitgraph/ingestion/airbyte/models.py

Lines changed: 89 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from __future__ import annotations
77

88
from enum import Enum
9-
from typing import Any, Dict, List, Optional
9+
from typing import Any, Dict, List, Optional, Union
1010

1111
from pydantic import AnyUrl, BaseModel, Extra, Field
1212

@@ -81,25 +81,57 @@ class DestinationSyncMode(Enum):
8181
append_dedup = "append_dedup"
8282

8383

84-
class ConnectorSpecification(BaseModel):
84+
class OAuth2Specification(BaseModel):
8585
class Config:
8686
extra = Extra.allow
8787

88-
documentationUrl: Optional[AnyUrl] = None
89-
changelogUrl: Optional[AnyUrl] = None
90-
connectionSpecification: Dict[str, Any] = Field(
91-
...,
92-
description="ConnectorDefinition specific blob. Must be a valid JSON string.",
88+
rootObject: Optional[List[Union[str, int]]] = Field(
89+
None,
90+
description="A list of strings representing a pointer to the root object which contains any oauth parameters in the ConnectorSpecification.\nExamples:\nif oauth parameters were contained inside the top level, rootObject=[] If they were nested inside another object {'credentials': {'app_id' etc...}, rootObject=['credentials'] If they were inside a oneOf {'switch': {oneOf: [{client_id...}, {non_oauth_param]}}, rootObject=['switch', 0] ",
9391
)
94-
supportsIncremental: Optional[bool] = Field(
95-
None, description="If the connector supports incremental mode or not."
92+
oauthFlowInitParameters: Optional[List[List[str]]] = Field(
93+
None,
94+
description="Pointers to the fields in the rootObject needed to obtain the initial refresh/access tokens for the OAuth flow. Each inner array represents the path in the rootObject of the referenced field. For example. Assume the rootObject contains params 'app_secret', 'app_id' which are needed to get the initial refresh token. If they are not nested in the rootObject, then the array would look like this [['app_secret'], ['app_id']] If they are nested inside an object called 'auth_params' then this array would be [['auth_params', 'app_secret'], ['auth_params', 'app_id']]",
9695
)
97-
supportsNormalization: Optional[bool] = Field(
98-
False, description="If the connector supports normalization or not."
96+
oauthFlowOutputParameters: Optional[List[List[str]]] = Field(
97+
None,
98+
description="Pointers to the fields in the rootObject which can be populated from successfully completing the oauth flow using the init parameters. This is typically a refresh/access token. Each inner array represents the path in the rootObject of the referenced field.",
9999
)
100-
supportsDBT: Optional[bool] = Field(False, description="If the connector supports DBT or not.")
101-
supported_destination_sync_modes: Optional[List[DestinationSyncMode]] = Field(
102-
None, description="List of destination sync modes supported by the connector"
100+
101+
102+
class AuthType(Enum):
103+
oauth2_0 = "oauth2.0"
104+
105+
106+
class AuthSpecification(BaseModel):
107+
auth_type: Optional[AuthType] = None
108+
oauth2Specification: Optional[OAuth2Specification] = Field(
109+
None,
110+
description="If the connector supports OAuth, this field should be non-null.",
111+
)
112+
113+
114+
class AuthFlowType(Enum):
115+
oauth2_0 = "oauth2.0"
116+
oauth1_0 = "oauth1.0"
117+
118+
119+
class OAuthConfigSpecification(BaseModel):
120+
oauth_user_input_from_connector_config_specification: Optional[Dict[str, Any]] = Field(
121+
None,
122+
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.\n\nExamples:\n\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 }",
123+
)
124+
complete_oauth_output_specification: Optional[Dict[str, Any]] = Field(
125+
None,
126+
description="OAuth specific blob. This is a Json Schema used to validate Json configurations produced by the OAuth flows as they are\nreturned by the distant OAuth APIs.\nMust be a valid JSON describing the fields to merge back to `ConnectorSpecification.connectionSpecification`.\nFor each field, a special annotation `path_in_connector_config` can be specified to determine where to merge it,\n\nExamples:\n\n complete_oauth_output_specification={\n refresh_token: {\n type: string,\n path_in_connector_config: ['credentials', 'refresh_token']\n }\n }",
127+
)
128+
complete_oauth_server_input_specification: Optional[Dict[str, Any]] = Field(
129+
None,
130+
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).\n\nExamples:\n\n complete_oauth_server_input_specification={\n client_id: {\n type: string\n },\n client_secret: {\n type: string\n }\n }",
131+
)
132+
complete_oauth_server_output_specification: Optional[Dict[str, Any]] = Field(
133+
None,
134+
description="OAuth specific blob. This is a Json Schema used to validate Json configurations persisted as Airbyte Server configurations that\nalso need to be merged back into the connector configuration at runtime.\nThis is a subset configuration of `complete_oauth_server_input_specification` that filters fields out to retain only the ones that\nare necessary for the connector to function with OAuth. (some fields could be used during oauth flows but not needed afterwards, therefore\nthey would be listed in the `complete_oauth_server_input_specification` but not `complete_oauth_server_output_specification`)\nMust be a valid non-nested JSON describing additional fields configured by the Airbyte Instance or Workspace Admins to be used by the\nconnector when using OAuth flow APIs.\nThese fields are to be merged back to `ConnectorSpecification.connectionSpecification`.\nFor each field, a special annotation `path_in_connector_config` can be specified to determine where to merge it,\n\nExamples:\n\n complete_oauth_server_output_specification={\n client_id: {\n type: string,\n path_in_connector_config: ['credentials', 'client_id']\n },\n client_secret: {\n type: string,\n path_in_connector_config: ['credentials', 'client_secret']\n }\n }",
103135
)
104136

105137

@@ -145,6 +177,48 @@ class Config:
145177
)
146178

147179

180+
class AdvancedAuth(BaseModel):
181+
auth_flow_type: Optional[AuthFlowType] = None
182+
predicate_key: Optional[List[str]] = Field(
183+
None,
184+
description="Json Path to a field in the connectorSpecification that should exist for the advanced auth to be applicable.",
185+
)
186+
predicate_value: Optional[str] = Field(
187+
None,
188+
description="Value of the predicate_key fields for the advanced auth to be applicable.",
189+
)
190+
oauth_config_specification: Optional[OAuthConfigSpecification] = None
191+
192+
193+
class ConnectorSpecification(BaseModel):
194+
class Config:
195+
extra = Extra.allow
196+
197+
documentationUrl: Optional[AnyUrl] = None
198+
changelogUrl: Optional[AnyUrl] = None
199+
connectionSpecification: Dict[str, Any] = Field(
200+
...,
201+
description="ConnectorDefinition specific blob. Must be a valid JSON string.",
202+
)
203+
supportsIncremental: Optional[bool] = Field(
204+
None, description="If the connector supports incremental mode or not."
205+
)
206+
supportsNormalization: Optional[bool] = Field(
207+
False, description="If the connector supports normalization or not."
208+
)
209+
supportsDBT: Optional[bool] = Field(False, description="If the connector supports DBT or not.")
210+
supported_destination_sync_modes: Optional[List[DestinationSyncMode]] = Field(
211+
None, description="List of destination sync modes supported by the connector"
212+
)
213+
authSpecification: Optional[AuthSpecification] = Field(
214+
None, description="deprecated, switching to advanced_auth instead"
215+
)
216+
advanced_auth: Optional[AdvancedAuth] = Field(
217+
None,
218+
description="Additional and optional specification object to describe what an 'advanced' Auth flow would need to function.\n - A connector should be able to fully function with the configuration as described by the ConnectorSpecification in a 'basic' mode.\n - The 'advanced' mode provides easier UX for the user with UI improvements and automations. However, this requires further setup on the\n server side by instance or workspace admins beforehand. The trade-off is that the user does not have to provide as many technical\n inputs anymore and the auth process is faster and easier to complete.",
219+
)
220+
221+
148222
class AirbyteCatalog(BaseModel):
149223
class Config:
150224
extra = Extra.allow
@@ -170,10 +244,7 @@ class Config:
170244
)
171245
spec: Optional[ConnectorSpecification] = None
172246
connectionStatus: Optional[AirbyteConnectionStatus] = None
173-
catalog: Optional[AirbyteCatalog] = Field(
174-
None,
175-
description="log message: any kind of logging you want the platform to know about.",
176-
)
247+
catalog: Optional[AirbyteCatalog] = Field(None, description="catalog message: the catalog")
177248
record: Optional[AirbyteRecordMessage] = Field(None, description="record message: the record")
178249
state: Optional[AirbyteStateMessage] = Field(
179250
None,

0 commit comments

Comments
 (0)