admin
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -208,6 +208,8 @@ class BuildService:
|
||||
command.extend(["--deployment-domains", domain])
|
||||
for domain in request_input["reporting_domains"]:
|
||||
command.extend(["--reporting-domains", domain])
|
||||
support_template = str(request_input.get("support_template") or "test")
|
||||
command.extend(["--support-template", support_template])
|
||||
return subprocess.run(
|
||||
command,
|
||||
cwd=str(Path(__file__).resolve().parent.parent),
|
||||
|
||||
Reference in New Issue
Block a user