Files
Nguyen Minh Phuc c53734d2bc
ci / lint (push) Successful in 33s
ci / types (push) Successful in 43s
ci / unit (push) Successful in 32s
ci / security (push) Successful in 57s
ci / dockerfile (push) Successful in 7s
ci / chart (push) Successful in 8s
ci / integration (push) Successful in 55s
ci / image (api) (push) Successful in 3m39s
ci / image (reconciler) (push) Successful in 2m53s
ci / image (worker) (push) Successful in 2m14s
ci / bump (push) Successful in 16s
docs: add USER_GUIDE.md, tighten comments, fix CLI needing a DSN
The comment pass is prose-only: every distinct "why" is kept, the
narration around it is not. Verified by AST-comparing each changed file
against HEAD with docstrings stripped — only the two files below differ
in executable code.

Two real fixes fell out of the read-through:

* The CLI documented itself as never touching the database, then called
  load_settings(), which requires SVCFORGE_PG_DSN. It refused to start
  without a Postgres URL it never opens. It now has its own two-field
  ClientSettings; the orphaned api_url/api_token are dropped from
  Settings, where nothing else read them.
* repo/db.py had the DictRow alias comment and the ERROR_MAX_CHARS
  comment run together above the wrong symbol.

USER_GUIDE.md is the caller-facing guide the README only gestured at:
auth, catalog, every endpoint with curl, the lifecycle, the error table,
rate limiting, the CLI, client generation, an end-to-end poll loop.

It records two facts about the live deployment rather than documenting a
flow nobody can run. SVCFORGE_JWKS_URL points at a realm with no IdP
behind it, so the API logs "JWKS warm-up failed" at startup and every
/v1 request is a 401. And `helm repo list` in the worker returns no
repositories, so the three bitnamilegacy/ catalog entries cannot resolve
at provision time; only the oci:// entries can.

make lint clean, 76 unit + 111 integration tests pass.
2026-07-21 14:51:26 +00:00

93 lines
3.2 KiB
Python

"""Wire types, deliberately not the domain models.
`Instance` carries `team`, `namespace` and `release_name` — placement details a tenant has
no business seeing or setting. The response model is the allow-list that keeps them off the
wire, which is why it is written by hand instead of derived from `Instance`.
"""
from __future__ import annotations
from uuid import UUID
from pydantic import BaseModel, ConfigDict, Field
from svcforge_core.domain.states import InstanceState
class CreateInstanceRequest(BaseModel):
"""What a tenant may ask for.
`service_type` and `size` are plain strings, not enums: the catalog is data loaded at
runtime, so baking its keys into a type would mean a redeploy to add a service type and
a 422 where the spec wants a 404. The handler validates them against the catalog.
"""
model_config = ConfigDict(
extra="forbid",
json_schema_extra={"examples": [{"service_type": "redis", "size": "small", "ttl_days": 7}]},
)
service_type: str = Field(
min_length=1,
description=(
"A service type in the catalog, e.g. `elasticsearch`, `redis`, `postgres`, "
"`podinfo`, `nginx`. "
"Unknown values return 404."
),
)
size: str = Field(
description=(
"A size the catalog defines for that service type, e.g. `small`. Unknown values return 422."
),
)
ttl_days: int | None = Field(
default=None,
ge=1,
le=30,
description="Delete the instance automatically after this many days. Omit for no expiry.",
)
class InstanceResponse(BaseModel):
"""What a tenant gets back. A subset of Instance, on purpose."""
model_config = ConfigDict(
from_attributes=True,
json_schema_extra={
"examples": [
{
"id": "0f8b7d3e-1c2a-4f5b-9e6d-7a8b9c0d1e2f",
"state": "ready",
"service_type": "redis",
"size": "small",
"endpoint": "http://acme-redis-0f8b7d3e.tenant-acme.svc.cluster.local",
"chart_version": "20.6.2",
"error": None,
}
]
},
)
id: UUID = Field(description="Poll `GET /v1/instances/{id}` with this to watch the state change.")
state: InstanceState = Field(description="Lifecycle state. Only `ready` carries a usable endpoint.")
service_type: str
size: str
endpoint: str | None = Field(description="In-cluster DNS name. Null until the instance is `ready`.")
chart_version: str = Field(
description="The chart version actually deployed, written only after helm succeeds."
)
error: str | None = Field(description="Why the last attempt failed. Null unless `state` is `failed`.")
class ErrorBody(BaseModel):
"""Every non-2xx body. `code` is for machines, `message` is for humans."""
model_config = ConfigDict(
json_schema_extra={
"examples": [{"code": "unknown_service_type", "message": "no such service_type: mongodb"}]
}
)
code: str = Field(description="Stable machine-readable identifier for the failure.")
message: str = Field(description="Human-readable detail. Do not parse this.")