"""Configuration loader — YAML + environment variables."""
from __future__ import annotations
from pathlib import Path
import yaml
from pydantic import BaseModel, SecretStr
[docs]
class SourceConfig(BaseModel):
type: str # oracle, postgres, databricks, unity_catalog
host: str = "localhost"
port: int = 1521
service_name: str = ""
sid: str = ""
username: str = ""
password: SecretStr = SecretStr("")
schema_name: str = ""
# Databricks/Azure
workspace_url: str = ""
token: SecretStr = SecretStr("")
catalog: str = ""
# Timeout (seconds) for individual probe queries
timeout: int = 120
def __repr__(self) -> str:
return f"SourceConfig(type={self.type!r}, host={self.host!r}, schema_name={self.schema_name!r})"
[docs]
class TargetConfig(BaseModel):
url: str = ""
api_key: SecretStr = SecretStr("")
project: str = "default"
def __repr__(self) -> str:
return f"TargetConfig(url={self.url!r}, project={self.project!r})"
[docs]
class ProbeConfig(BaseModel):
source: SourceConfig
target: TargetConfig = TargetConfig()
output_dir: str = "./output"
probes: list[str] = ["*"]
schedule: str = ""
[docs]
def load_config(path: str | Path) -> ProbeConfig:
"""Load config from YAML file with environment variable substitution.
Supports ${VAR_NAME} syntax in string values.
"""
import os
p = Path(path)
if not p.exists():
raise FileNotFoundError(f"Config not found: {p}")
raw = p.read_text()
raw = os.path.expandvars(raw)
data = yaml.safe_load(raw)
return ProbeConfig(**data)