Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

4.0 KB
Raw Blame
from typing import cast

from products.warehouse_sources.sources.catchpoint._config import CatchpointSourceConfig
from products.warehouse_sources.sources.catchpoint.catchpoint import (
    CatchpointResumeConfig,
    catchpoint_source,
    validate_credentials,
)
from products.warehouse_sources.sources.catchpoint.settings import (
    AUTH_ERROR,
    ENDPOINTS,
    INCOMPLETE_ERROR,
    PERMISSION_ERROR,
)
from products.warehouse_sources.sources.sdk import (
    CanonicalDescriptions,
    DataWarehouseSourceCategory,
    ExternalDataSourceType,
    FieldType,
    ReleaseStatus,
    ResumableSource,
    ResumableSourceManager,
    SourceConfig,
    SourceFieldInputConfig,
    SourceFieldInputConfigType,
    SourceInputs,
    SourceRegistry,
    SourceResponse,
    SourceSchema,
    build_endpoint_schemas,
    detect,
)


@SourceRegistry.register
class CatchpointSource(ResumableSource[CatchpointSourceConfig, CatchpointResumeConfig]):
    codebase_detection = detect(env=("^CATCHPOINT_",))

    lists_tables_without_credentials = True
    supported_versions = ("v3",)
    default_version = "v3"
    api_docs_url = "https://io.catchpoint.com/api/swagger/index.html"

    @property
    def source_type(self) -> ExternalDataSourceType:
        return ExternalDataSourceType.CATCHPOINT

    def get_non_retryable_errors(self) -> dict[str, str | None]:
        return {
            "401 Client Error": AUTH_ERROR,
            "403 Client Error": PERMISSION_ERROR,
            INCOMPLETE_ERROR: INCOMPLETE_ERROR,
        }

    def get_canonical_descriptions(self) -> CanonicalDescriptions:
        from products.warehouse_sources.sources.catchpoint.canonical_descriptions import CANONICAL_DESCRIPTIONS

        return CANONICAL_DESCRIPTIONS

    def get_schemas(
        self,
        config: CatchpointSourceConfig,
        team_id: int,
        with_counts: bool = False,
        names: list[str] | None = None,
        force_refresh: bool = False,
        api_version: str | None = None,
    ) -> list[SourceSchema]:
        return build_endpoint_schemas(ENDPOINTS, {}, names)

    def validate_credentials(
        self,
        config: CatchpointSourceConfig,
        team_id: int,
        schema_name: str | None = None,
        api_version: str | None = None,
    ) -> tuple[bool, str | None]:
        return validate_credentials(config.api_key, self.resolve_api_version(api_version), team_id)

    def get_resumable_source_manager(self, inputs: SourceInputs) -> ResumableSourceManager[CatchpointResumeConfig]:
        return ResumableSourceManager(inputs, CatchpointResumeConfig)

    def source_for_pipeline(
        self,
        config: CatchpointSourceConfig,
        resumable_source_manager: ResumableSourceManager[CatchpointResumeConfig],
        inputs: SourceInputs,
    ) -> SourceResponse:
        return catchpoint_source(
            api_key=config.api_key,
            api_version=self.resolve_api_version(inputs.api_version),
            endpoint=inputs.schema_name,
            team_id=inputs.team_id,
            job_id=inputs.job_id,
            resumable_source_manager=resumable_source_manager,
        )

    @property
    def get_source_config(self) -> SourceConfig:
        return SourceConfig(
            name=ExternalDataSourceType.CATCHPOINT,
            category=DataWarehouseSourceCategory.ENGINEERING___MONITORING,
            label="Catchpoint Systems",
            caption="Create an API key in Catchpoint under Settings > Integrations > REST API > Add Consumer.",
            iconPath="/static/services/catchpoint.png",
            releaseStatus=ReleaseStatus.BETA,
            fields=cast(
                list[FieldType],
                [
                    SourceFieldInputConfig(
                        name="api_key",
                        label="API key",
                        type=SourceFieldInputConfigType.PASSWORD,
                        required=True,
                        placeholder="",
                        secret=True,
                    )
                ],
            ),
        )