81 lines
2.5 KiB
Python
81 lines
2.5 KiB
Python
import json
|
|
from pathlib import Path
|
|
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
|
|
|
|
BASE_DIR = Path(__file__).resolve().parents[2]
|
|
WORKSPACE_DIR = BASE_DIR.parent
|
|
DOMAINCHECK_DIR = WORKSPACE_DIR / "domainCheck"
|
|
API_ENV_FILE = BASE_DIR / ".env"
|
|
ENV_FILE = DOMAINCHECK_DIR / ".env"
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
api_prefix: str = "/api/v1"
|
|
api_host: str = "0.0.0.0"
|
|
api_port: int = 8100
|
|
cors_origins: str = "http://127.0.0.1:3200,http://localhost:3200"
|
|
db_host: str = "127.0.0.1"
|
|
db_port: int = 5432
|
|
db_database: str = "domain"
|
|
db_user: str = "postgres"
|
|
db_password: str = "postgres"
|
|
redis_host: str = "127.0.0.1"
|
|
redis_port: int = 6379
|
|
redis_password: str = ""
|
|
redis_db: int = 0
|
|
domain_root: str = str(DOMAINCHECK_DIR)
|
|
admin_username: str = "admin"
|
|
admin_password: str = "admin"
|
|
worker_mode: str = "windows-local"
|
|
worker_service_name: str = "domaincheck-worker"
|
|
api_service_name: str = "domaincheck-api"
|
|
sync_agent_service_name: str = "domaincheck-sync-agent"
|
|
node_code: str = "overseas-control-01"
|
|
node_region: str = "overseas"
|
|
node_role: str = "control"
|
|
sync_push_enabled: bool = False
|
|
sync_source_region: str = "unknown"
|
|
sync_target_region: str = "overseas"
|
|
sync_target_api_base_url: str = ""
|
|
sync_shared_token: str = ""
|
|
sync_batch_size: int = 200
|
|
sync_poll_interval_seconds: int = 30
|
|
build_manifest_path: str = ""
|
|
build_commit_sha: str = ""
|
|
build_commit_ref: str = ""
|
|
build_generated_at: str = ""
|
|
build_package_name: str = ""
|
|
build_checksum: str = ""
|
|
build_source_label: str = ""
|
|
|
|
@property
|
|
def cors_origins_list(self) -> list[str]:
|
|
value = self.cors_origins
|
|
if isinstance(value, list):
|
|
return [str(item).strip() for item in value if str(item).strip()]
|
|
if not isinstance(value, str):
|
|
return []
|
|
stripped = value.strip()
|
|
if not stripped:
|
|
return []
|
|
if stripped.startswith("["):
|
|
try:
|
|
parsed = json.loads(stripped)
|
|
except json.JSONDecodeError:
|
|
pass
|
|
else:
|
|
if isinstance(parsed, list):
|
|
return [str(item).strip() for item in parsed if str(item).strip()]
|
|
return [item.strip() for item in stripped.split(",") if item.strip()]
|
|
|
|
model_config = SettingsConfigDict(
|
|
env_file=(str(API_ENV_FILE), str(ENV_FILE)),
|
|
env_file_encoding="utf-8",
|
|
extra="ignore",
|
|
)
|
|
|
|
|
|
settings = Settings()
|