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.

1004 B
Raw Blame
"""The warehouse sources that use an integration row. The integrations SDK loads this module."""

from posthog.integrations import IntegrationUsage

from products.warehouse_sources.backend.facade.contracts import (
    UNREADABLE_WAREHOUSE_SOURCE_USAGE_TYPE,
    WAREHOUSE_SOURCE_USAGE_TYPE,
    SourceReferencingIntegration,
)
from products.warehouse_sources.backend.logic.integration_references import list_sources_using_integration


def integration_usages(team_id: int, integration_id: int) -> list[IntegrationUsage]:
    return [
        IntegrationUsage(
            type=UNREADABLE_WAREHOUSE_SOURCE_USAGE_TYPE if source.unreadable else WAREHOUSE_SOURCE_USAGE_TYPE,
            id=str(source.id),
            name=_name(source),
        )
        for source in list_sources_using_integration(team_id=team_id, integration_pk=integration_id)
    ]


def _name(source: SourceReferencingIntegration) -> str:
    return f"{source.source_type} ({source.prefix})" if source.prefix else source.source_type