|
| 1 | +"""Pydantic configuration schema for ArcGIS Hub plugin.""" |
| 2 | + |
| 3 | +from typing import Optional |
| 4 | +from urllib.parse import urlparse |
| 5 | + |
| 6 | +from pydantic import BaseModel, ConfigDict, Field, field_validator |
| 7 | + |
| 8 | + |
| 9 | +class ArcGISPluginConfig(BaseModel): |
| 10 | + """Configuration schema for ArcGIS Hub plugin. |
| 11 | +
|
| 12 | + This schema validates ArcGIS Hub plugin configuration from config.yaml. |
| 13 | + """ |
| 14 | + |
| 15 | + enabled: bool = Field(default=False, description="Whether plugin is enabled") |
| 16 | + portal_url: str = Field( |
| 17 | + default="https://hub.arcgis.com", |
| 18 | + description="Base URL of ArcGIS Hub portal (e.g., https://hub.arcgis.com)", |
| 19 | + ) |
| 20 | + city_name: str = Field(..., description="Name of the city/organization") |
| 21 | + timeout: int = Field( |
| 22 | + default=120, ge=1, le=300, description="HTTP request timeout in seconds" |
| 23 | + ) |
| 24 | + token: Optional[str] = Field( |
| 25 | + None, description="Optional Bearer token for authenticated requests" |
| 26 | + ) |
| 27 | + |
| 28 | + @field_validator("portal_url") |
| 29 | + @classmethod |
| 30 | + def validate_url(cls, v: str) -> str: |
| 31 | + """Validate that URL is well-formed.""" |
| 32 | + if not v: |
| 33 | + raise ValueError("URL cannot be empty") |
| 34 | + try: |
| 35 | + result = urlparse(v) |
| 36 | + if not result.scheme or not result.netloc: |
| 37 | + raise ValueError("URL must include scheme (http/https) and hostname") |
| 38 | + if result.scheme not in ("http", "https"): |
| 39 | + raise ValueError("URL scheme must be http or https") |
| 40 | + except Exception as e: |
| 41 | + raise ValueError(f"Invalid URL format: {e}") |
| 42 | + return v.rstrip("/") |
| 43 | + |
| 44 | + model_config = ConfigDict(extra="forbid") |
0 commit comments