Skip to content

Commit

Permalink
Merge branch 'main' into aldogonzalez8/changes-for-custom-retriever
Browse files Browse the repository at this point in the history
  • Loading branch information
aldogonzalez8 authored Jan 6, 2025
2 parents 513a533 + f8cb659 commit c18f0d7
Show file tree
Hide file tree
Showing 62 changed files with 2,326 additions and 746 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pypi_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ name: Packaging and Publishing
on:
push:
tags:
- 'v*'
- "v*"
workflow_dispatch:
inputs:
version:
Expand Down Expand Up @@ -146,7 +146,7 @@ jobs:
(github.event_name == 'push' &&
startsWith(github.ref, 'refs/tags/v')
) || github.event.inputs.publish_to_pypi == 'true'
uses: pypa/[email protected].2
uses: pypa/[email protected].3

publish_sdm:
name: Publish SDM to DockerHub
Expand Down
127 changes: 93 additions & 34 deletions airbyte_cdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,27 +48,46 @@
# Once those issues are resolved, the below can be sorted with isort.
import dunamai as _dunamai

from .destinations import Destination
from .models import AirbyteConnectionStatus, AirbyteMessage, ConfiguredAirbyteCatalog, Status, Type, FailureType, AirbyteStream, AdvancedAuth, DestinationSyncMode, ConnectorSpecification, OAuthConfigSpecification, OrchestratorType, ConfiguredAirbyteStream, SyncMode, AirbyteLogMessage, Level, AirbyteRecordMessage

from .sources import Source
from .config_observation import create_connector_config_control_message, emit_configuration_as_airbyte_control_message
from .config_observation import (
create_connector_config_control_message,
emit_configuration_as_airbyte_control_message,
)
from .connector import BaseConnector, Connector

from .entrypoint import launch, AirbyteEntrypoint

from .destinations import Destination
from .entrypoint import AirbyteEntrypoint, launch
from .logger import AirbyteLogFormatter, init_logger
from .sources import AbstractSource
from .models import (
AdvancedAuth,
AirbyteConnectionStatus,
AirbyteLogMessage,
AirbyteMessage,
AirbyteRecordMessage,
AirbyteStream,
ConfiguredAirbyteCatalog,
ConfiguredAirbyteStream,
ConnectorSpecification,
DestinationSyncMode,
FailureType,
Level,
OAuthConfigSpecification,
OrchestratorType,
Status,
SyncMode,
Type,
)
from .sources import AbstractSource, Source
from .sources.concurrent_source.concurrent_source import ConcurrentSource
from .sources.concurrent_source.concurrent_source_adapter import ConcurrentSourceAdapter
from .sources.config import BaseConfig
from .sources.types import Config, Record, StreamSlice
from .sources.connector_state_manager import ConnectorStateManager
from .sources.declarative.auth import DeclarativeOauth2Authenticator
from .sources.declarative.auth.declarative_authenticator import DeclarativeAuthenticator
from .sources.declarative.auth.declarative_authenticator import NoAuth
from .sources.declarative.auth.declarative_authenticator import DeclarativeAuthenticator, NoAuth
from .sources.declarative.auth.oauth import DeclarativeSingleUseRefreshTokenOauth2Authenticator
from .sources.declarative.auth.token import BasicHttpAuthenticator, BearerAuthenticator, ApiKeyAuthenticator
from .sources.declarative.auth.token import (
ApiKeyAuthenticator,
BasicHttpAuthenticator,
BearerAuthenticator,
)
from .sources.declarative.datetime.min_max_datetime import MinMaxDatetime
from .sources.declarative.declarative_stream import DeclarativeStream
from .sources.declarative.decoders import Decoder, JsonDecoder
Expand All @@ -77,48 +96,89 @@
from .sources.declarative.extractors.record_extractor import RecordExtractor
from .sources.declarative.extractors.record_filter import RecordFilter
from .sources.declarative.incremental import DatetimeBasedCursor
from .sources.declarative.interpolation import InterpolatedString, InterpolatedBoolean
from .sources.declarative.interpolation import InterpolatedBoolean, InterpolatedString
from .sources.declarative.manifest_declarative_source import ManifestDeclarativeSource
from .sources.declarative.migrations.legacy_to_per_partition_state_migration import LegacyToPerPartitionStateMigration

from .sources.declarative.partition_routers import CartesianProductStreamSlicer, SinglePartitionRouter, SubstreamPartitionRouter
from .sources.declarative.migrations.legacy_to_per_partition_state_migration import (
LegacyToPerPartitionStateMigration,
)
from .sources.declarative.partition_routers import (
CartesianProductStreamSlicer,
SinglePartitionRouter,
SubstreamPartitionRouter,
)
from .sources.declarative.partition_routers.substream_partition_router import ParentStreamConfig
from .sources.declarative.requesters import Requester, HttpRequester

from .sources.declarative.requesters import HttpRequester, Requester
from .sources.declarative.requesters.error_handlers import BackoffStrategy
from .sources.declarative.requesters.paginators import DefaultPaginator, PaginationStrategy
from .sources.declarative.requesters.paginators.strategies import OffsetIncrement, CursorPaginationStrategy, PageIncrement, StopConditionPaginationStrategyDecorator

from .sources.declarative.requesters.paginators.strategies import (
CursorPaginationStrategy,
OffsetIncrement,
PageIncrement,
StopConditionPaginationStrategyDecorator,
)
from .sources.declarative.requesters.request_option import RequestOption, RequestOptionType

from .sources.declarative.requesters.request_options.default_request_options_provider import DefaultRequestOptionsProvider
from .sources.declarative.requesters.request_options.interpolated_request_input_provider import InterpolatedRequestInputProvider
from .sources.declarative.requesters.request_options.default_request_options_provider import (
DefaultRequestOptionsProvider,
)
from .sources.declarative.requesters.request_options.interpolated_request_input_provider import (
InterpolatedRequestInputProvider,
)
from .sources.declarative.requesters.requester import HttpMethod
from .sources.declarative.retrievers import SimpleRetriever
from .sources.declarative.schema import JsonFileSchemaLoader
from .sources.declarative.transformations.add_fields import AddFields, AddedFieldDefinition
from .sources.declarative.transformations.add_fields import AddedFieldDefinition, AddFields
from .sources.declarative.transformations.transformation import RecordTransformation
from .sources.declarative.types import FieldPointer
from .sources.declarative.yaml_declarative_source import YamlDeclarativeSource
from .sources.message import InMemoryMessageRepository, MessageRepository
from .sources.source import TState
from .sources.streams.availability_strategy import AvailabilityStrategy
from .sources.streams.call_rate import AbstractAPIBudget, HttpAPIBudget, HttpRequestMatcher, MovingWindowCallRatePolicy, Rate, CachedLimiterSession, LimiterSession
from .sources.streams.call_rate import (
AbstractAPIBudget,
CachedLimiterSession,
HttpAPIBudget,
HttpRequestMatcher,
LimiterSession,
MovingWindowCallRatePolicy,
Rate,
)
from .sources.streams.checkpoint import Cursor as LegacyCursor
from .sources.streams.checkpoint import ResumableFullRefreshCursor
from .sources.streams.concurrent.adapters import StreamFacade
from .sources.streams.concurrent.cursor import ConcurrentCursor, CursorField, FinalStateCursor
from .sources.streams.concurrent.cursor import Cursor
from .sources.streams.concurrent.state_converters.datetime_stream_state_converter import EpochValueConcurrentStreamStateConverter, IsoMillisConcurrentStreamStateConverter
from .sources.streams.core import Stream, IncrementalMixin, package_name_from_class
from .sources.streams.concurrent.cursor import (
ConcurrentCursor,
Cursor,
CursorField,
FinalStateCursor,
)
from .sources.streams.concurrent.state_converters.datetime_stream_state_converter import (
EpochValueConcurrentStreamStateConverter,
IsoMillisConcurrentStreamStateConverter,
)
from .sources.streams.core import IncrementalMixin, Stream, package_name_from_class
from .sources.streams.http import HttpStream, HttpSubStream
from .sources.streams.http.availability_strategy import HttpAvailabilityStrategy
from .sources.streams.http.exceptions import BaseBackoffException, DefaultBackoffException, UserDefinedBackoffException
from .sources.streams.http.exceptions import (
BaseBackoffException,
DefaultBackoffException,
UserDefinedBackoffException,
)
from .sources.streams.http.rate_limiting import default_backoff_handler
from .sources.streams.http.requests_native_auth import Oauth2Authenticator, TokenAuthenticator, SingleUseRefreshTokenOauth2Authenticator
from .sources.streams.http.requests_native_auth import (
Oauth2Authenticator,
SingleUseRefreshTokenOauth2Authenticator,
TokenAuthenticator,
)
from .sources.streams.http.requests_native_auth.abstract_token import AbstractHeaderAuthenticator
from .sources.types import Config, Record, StreamSlice
from .sources.utils import casing
from .sources.utils.schema_helpers import InternalConfig, ResourceSchemaLoader, check_config_against_spec_or_exit, split_config, expand_refs
from .sources.utils.schema_helpers import (
InternalConfig,
ResourceSchemaLoader,
check_config_against_spec_or_exit,
expand_refs,
split_config,
)
from .sources.utils.transform import TransformConfig, TypeTransformer
from .utils import AirbyteTracedException, is_cloud_environment
from .utils.constants import ENV_REQUEST_CACHE_PATH
Expand All @@ -127,7 +187,6 @@
from .utils.spec_schema_transformations import resolve_refs
from .utils.stream_status_utils import as_airbyte_message


__all__ = [
# Availability strategy
"AvailabilityStrategy",
Expand Down
1 change: 0 additions & 1 deletion airbyte_cdk/cli/source_declarative_manifest/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from airbyte_cdk.cli.source_declarative_manifest._run import run


__all__ = [
"run",
]
21 changes: 10 additions & 11 deletions airbyte_cdk/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
# of airbyte-cdk rather than a standalone package.
from .airbyte_protocol import (
AdvancedAuth,
AirbyteStateStats,
AirbyteAnalyticsTraceMessage,
AirbyteCatalog,
AirbyteConnectionStatus,
Expand All @@ -22,13 +21,14 @@
AirbyteRecordMessage,
AirbyteStateBlob,
AirbyteStateMessage,
AirbyteStateStats,
AirbyteStateType,
AirbyteStream,
AirbyteStreamState,
AirbyteStreamStatus,
AirbyteStreamStatusTraceMessage,
AirbyteStreamStatusReason,
AirbyteStreamStatusReasonType,
AirbyteStreamStatusTraceMessage,
AirbyteTraceMessage,
AuthFlowType,
ConfiguredAirbyteCatalog,
Expand All @@ -48,6 +48,14 @@
TraceType,
Type,
)
from .airbyte_protocol_serializers import (
AirbyteMessageSerializer,
AirbyteStateMessageSerializer,
AirbyteStreamStateSerializer,
ConfiguredAirbyteCatalogSerializer,
ConfiguredAirbyteStreamSerializer,
ConnectorSpecificationSerializer,
)
from .well_known_types import (
BinaryData,
Boolean,
Expand All @@ -61,12 +69,3 @@
TimeWithoutTimezone,
TimeWithTimezone,
)

from .airbyte_protocol_serializers import (
AirbyteStreamStateSerializer,
AirbyteStateMessageSerializer,
AirbyteMessageSerializer,
ConfiguredAirbyteCatalogSerializer,
ConfiguredAirbyteStreamSerializer,
ConnectorSpecificationSerializer,
)
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
TypeVar,
)

from airbyte_cdk import StreamSlice
from airbyte_cdk.logger import lazy_log
from airbyte_cdk.models import FailureType
from airbyte_cdk.sources.declarative.async_job.job import AsyncJob
Expand All @@ -31,6 +30,7 @@
from airbyte_cdk.sources.declarative.async_job.repository import AsyncJobRepository
from airbyte_cdk.sources.declarative.async_job.status import AsyncJobStatus
from airbyte_cdk.sources.message import MessageRepository
from airbyte_cdk.sources.types import StreamSlice
from airbyte_cdk.utils.airbyte_secrets_utils import filter_secrets
from airbyte_cdk.utils.traced_exception import AirbyteTracedException

Expand Down
7 changes: 2 additions & 5 deletions airbyte_cdk/sources/declarative/auth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
#

from airbyte_cdk.sources.declarative.auth.oauth import DeclarativeOauth2Authenticator
from airbyte_cdk.sources.declarative.auth.jwt import JwtAuthenticator
from airbyte_cdk.sources.declarative.auth.oauth import DeclarativeOauth2Authenticator

__all__ = [
"DeclarativeOauth2Authenticator",
"JwtAuthenticator"
]
__all__ = ["DeclarativeOauth2Authenticator", "JwtAuthenticator"]
39 changes: 27 additions & 12 deletions airbyte_cdk/sources/declarative/auth/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,32 @@ class DeclarativeOauth2Authenticator(AbstractOauth2Authenticator, DeclarativeAut
message_repository (MessageRepository): the message repository used to emit logs on HTTP requests
"""

token_refresh_endpoint: Union[InterpolatedString, str]
client_id: Union[InterpolatedString, str]
client_secret: Union[InterpolatedString, str]
config: Mapping[str, Any]
parameters: InitVar[Mapping[str, Any]]
token_refresh_endpoint: Optional[Union[InterpolatedString, str]] = None
refresh_token: Optional[Union[InterpolatedString, str]] = None
scopes: Optional[List[str]] = None
token_expiry_date: Optional[Union[InterpolatedString, str]] = None
_token_expiry_date: Optional[pendulum.DateTime] = field(init=False, repr=False, default=None)
token_expiry_date_format: Optional[str] = None
token_expiry_is_time_of_expiration: bool = False
access_token_name: Union[InterpolatedString, str] = "access_token"
access_token_value: Optional[Union[InterpolatedString, str]] = None
expires_in_name: Union[InterpolatedString, str] = "expires_in"
refresh_request_body: Optional[Mapping[str, Any]] = None
grant_type: Union[InterpolatedString, str] = "refresh_token"
message_repository: MessageRepository = NoopMessageRepository()

def __post_init__(self, parameters: Mapping[str, Any]) -> None:
super().__init__()
self._token_refresh_endpoint = InterpolatedString.create(
self.token_refresh_endpoint, parameters=parameters
)
if self.token_refresh_endpoint is not None:
self._token_refresh_endpoint: Optional[InterpolatedString] = InterpolatedString.create(
self.token_refresh_endpoint, parameters=parameters
)
else:
self._token_refresh_endpoint = None
self._client_id = InterpolatedString.create(self.client_id, parameters=parameters)
self._client_secret = InterpolatedString.create(self.client_secret, parameters=parameters)
if self.refresh_token is not None:
Expand Down Expand Up @@ -92,20 +96,31 @@ def __post_init__(self, parameters: Mapping[str, Any]) -> None:
if self.token_expiry_date
else pendulum.now().subtract(days=1) # type: ignore # substract does not have type hints
)
self._access_token: Optional[str] = None # access_token is initialized by a setter
if self.access_token_value is not None:
self._access_token_value = InterpolatedString.create(
self.access_token_value, parameters=parameters
).eval(self.config)
else:
self._access_token_value = None

self._access_token: Optional[str] = (
self._access_token_value if self.access_token_value else None
)

if self.get_grant_type() == "refresh_token" and self._refresh_token is None:
raise ValueError(
"OAuthAuthenticator needs a refresh_token parameter if grant_type is set to `refresh_token`"
)

def get_token_refresh_endpoint(self) -> str:
refresh_token: str = self._token_refresh_endpoint.eval(self.config)
if not refresh_token:
raise ValueError(
"OAuthAuthenticator was unable to evaluate token_refresh_endpoint parameter"
)
return refresh_token
def get_token_refresh_endpoint(self) -> Optional[str]:
if self._token_refresh_endpoint is not None:
refresh_token_endpoint: str = self._token_refresh_endpoint.eval(self.config)
if not refresh_token_endpoint:
raise ValueError(
"OAuthAuthenticator was unable to evaluate token_refresh_endpoint parameter"
)
return refresh_token_endpoint
return None

def get_client_id(self) -> str:
client_id: str = self._client_id.eval(self.config)
Expand Down
Loading

0 comments on commit c18f0d7

Please sign in to comment.