: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
from typing import cast
from products.warehouse_sources.sources.harness._config import HarnessSourceConfig
from products.warehouse_sources.sources.harness.harness import HarnessResumeConfig, harness_source, validate_credentials
from products.warehouse_sources.sources.harness.settings import AUTH_ERROR, ENDPOINTS, PERMISSION_ERROR
from products.warehouse_sources.sources.sdk import (
CanonicalDescriptions,
DataWarehouseSourceCategory,
ExternalDataSourceType,
FieldType,
ReleaseStatus,
ResumableSource,
ResumableSourceManager,
SourceConfig,
SourceFieldInputConfig,
SourceFieldInputConfigType,
SourceFieldSelectConfig,
SourceFieldSelectConfigOption,
SourceInputs,
SourceRegistry,
SourceResponse,
SourceSchema,
build_endpoint_schemas,
detect,
)
@SourceRegistry.register
class HarnessSource(ResumableSource[HarnessSourceConfig, HarnessResumeConfig]):
codebase_detection = detect(
env=("^HARNESS_PLATFORM_API_KEY$", "^HARNESS_API_KEY$", "^HARNESS_ACCOUNT_ID$", "^HARNESS_ENDPOINT$"),
go=(
"github.com/harness/harness-go-sdk",
"github.com/harness/gitness",
"github.com/harness/harness-cli",
"github.com/harness/harness-docker-runner",
"github.com/harness/harness-migrate",
"github.com/harness/terraform-kubernetes-harness-delegate",
),
)
lists_tables_without_credentials = True
api_docs_url = "https://apidocs.harness.io/"
@property
def source_type(self) -> ExternalDataSourceType:
return ExternalDataSourceType.HARNESS
@property
def connection_host_fields(self) -> list[str]:
return ["region"]
def get_non_retryable_errors(self) -> dict[str, str | None]:
return {"401 Client Error": AUTH_ERROR, "403 Client Error": PERMISSION_ERROR}
def get_canonical_descriptions(self) -> CanonicalDescriptions:
from products.warehouse_sources.sources.harness.canonical_descriptions import CANONICAL_DESCRIPTIONS
return CANONICAL_DESCRIPTIONS
def get_schemas(
self,
config: HarnessSourceConfig,
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: HarnessSourceConfig,
team_id: int,
schema_name: str | None = None,
api_version: str | None = None,
) -> tuple[bool, str | None]:
return validate_credentials(config, schema_name)
def get_resumable_source_manager(self, inputs: SourceInputs) -> ResumableSourceManager[HarnessResumeConfig]:
return ResumableSourceManager(inputs, HarnessResumeConfig)
def source_for_pipeline(
self,
config: HarnessSourceConfig,
resumable_source_manager: ResumableSourceManager[HarnessResumeConfig],
inputs: SourceInputs,
) -> SourceResponse:
return harness_source(config, inputs.schema_name, inputs.team_id, inputs.job_id, resumable_source_manager)
@property
def get_source_config(self) -> SourceConfig:
return SourceConfig(
name=ExternalDataSourceType.HARNESS,
category=DataWarehouseSourceCategory.ENGINEERING___MONITORING,
label="Harness",
iconPath="/static/services/harness.png",
releaseStatus=ReleaseStatus.BETA,
caption=(
"In Harness, open **My Profile > My API Keys** to create an API key and token. "
"Paste the token below. Give it view permission for pipelines, executions, services, and environments in your project, "
"and for organizations and projects in your account. "
"The organizations and projects tables list your whole account. The other tables import the selected project. "
"All tables use full refresh."
),
fields=cast(
list[FieldType],
[
SourceFieldInputConfig(
name="api_key",
label="API key token",
type=SourceFieldInputConfigType.PASSWORD,
required=True,
placeholder="",
secret=True,
),
SourceFieldInputConfig(
name="account_id",
label="Account ID",
type=SourceFieldInputConfigType.TEXT,
required=True,
placeholder="Your Harness account ID",
secret=False,
),
SourceFieldInputConfig(
name="organization_id",
label="Organization ID",
type=SourceFieldInputConfigType.TEXT,
required=True,
placeholder="default",
secret=False,
),
SourceFieldInputConfig(
name="project_id",
label="Project ID",
type=SourceFieldInputConfigType.TEXT,
required=True,
placeholder="Your Harness project ID",
secret=False,
),
SourceFieldSelectConfig(
name="region",
label="Region",
required=True,
defaultValue="us",
caption="Select the host shown in your Harness account URL.",
options=[
SourceFieldSelectConfigOption(label="US (app.harness.io)", value="us"),
SourceFieldSelectConfigOption(label="US (app3.harness.io)", value="us3"),
SourceFieldSelectConfigOption(label="US (accounts.harness.io)", value="us_accounts"),
SourceFieldSelectConfigOption(label="EU (accounts.eu.harness.io)", value="eu"),
],
),
],
),
)