This commit is contained in:
hashbro
2026-08-09 02:42:45 +08:00
parent e730bba4a5
commit 9153a4f557
9 changed files with 155 additions and 6 deletions
+18
View File
@@ -26,11 +26,16 @@ CHANNEL_PATH = Path(
bearer_scheme = HTTPBearer(auto_error=False)
SUPPORT_TEMPLATES = ("test", "blank")
DEFAULT_SUPPORT_TEMPLATE = "test"
class BuildRequest(BaseModel):
model_config = ConfigDict(extra="forbid")
deployment_domains: List[str] = Field(min_length=1, max_length=8)
reporting_domains: List[str] = Field(min_length=1, max_length=8)
support_template: str = Field(default=DEFAULT_SUPPORT_TEMPLATE)
force: bool = Field(default=False, strict=True)
@field_validator("deployment_domains", "reporting_domains")
@@ -41,6 +46,16 @@ class BuildRequest(BaseModel):
raise ValueError("domain entries must be non-empty strings")
return value
@field_validator("support_template")
@classmethod
def support_template_must_be_known(cls, value: str) -> str:
template = value.strip().lower()
if template not in SUPPORT_TEMPLATES:
raise ValueError(
f"support_template must be one of: {', '.join(SUPPORT_TEMPLATES)}"
)
return template
def _error_response(status: int, code: str, message: str) -> JSONResponse:
return JSONResponse(
@@ -67,6 +82,8 @@ def _validation_message(exc: RequestValidationError) -> str:
return f"unknown fields: {loc[-1]}"
if "force" in loc and error_type.startswith("bool"):
return "force must be a boolean"
if "support_template" in loc:
return f"support_template must be one of: {', '.join(SUPPORT_TEMPLATES)}"
if any(part == "channel_id" for part in first.get("loc", ())):
return "channel id must be 32 lowercase alphanumeric characters"
if loc and loc[-1] in {"deployment_domains", "reporting_domains"}:
@@ -182,6 +199,7 @@ def create_application(
"reporting_domains": BuildService.normalize_domains(
body.reporting_domains, "reporting_domains"
),
"support_template": body.support_template,
}
status, payload, headers = service.build(
channel_id, request_input, force=body.force