feat(api): M4.2 — REST surface + pgx Postgres store + OpenAPI 3.1
Full M4.2 deliverable: 16 endpoints (tenants CRUD + lifecycle, catalog, entitlements, API keys with argon2 hashing, audit append + filter), Store interface with pgx-backed Postgres + in-memory parallel implementations exercised by the same eachStore harness, openapi.yaml at 3.1 with kin-openapi contract test. M4.3 adds auth. Refs: M4.2
This commit was merged in pull request #7.
This commit is contained in:
@@ -43,28 +43,38 @@ Env vars (override at the shell):
|
||||
|
||||
## Endpoints
|
||||
|
||||
| Method | Path | Returns |
|
||||
Authoritative spec: [`openapi.yaml`](./openapi.yaml). Summary:
|
||||
|
||||
| Method | Path | Purpose |
|
||||
|---|---|---|
|
||||
| GET | `/healthz` | `{"status":"ok"}` — liveness probe |
|
||||
| GET | `/v1/tenants/by-slug/{slug}` | 200 with tenant JSON, 404 if missing |
|
||||
| GET | `/v1/tenants/{id}` | 200 with tenant JSON, 404 if missing |
|
||||
| GET | `/healthz` | Liveness |
|
||||
| GET | `/readyz` | Pings the store |
|
||||
| POST | `/v1/tenants` | Create a tenant |
|
||||
| GET | `/v1/tenants/{id}` | Read by id |
|
||||
| GET | `/v1/tenants/by-slug/{slug}` | Read by slug (portal middleware uses this) |
|
||||
| POST | `/v1/tenants/{id}/activate` | trial → active |
|
||||
| POST | `/v1/tenants/{id}/cancel` | active → frozen |
|
||||
| GET | `/v1/entitlements?tenant_id={id}` | List product entitlements |
|
||||
| GET | `/v1/catalog` | List requestable products |
|
||||
| POST | `/v1/catalog/request` | Customer requests a product (sales follow-up) |
|
||||
| POST | `/v1/catalog/trial-request` | Self-serve 14-day trial |
|
||||
| GET | `/v1/api-keys?tenant_id={id}` | List keys |
|
||||
| POST | `/v1/api-keys` | Create key (plaintext shown once) |
|
||||
| DELETE | `/v1/api-keys/{id}` | Revoke |
|
||||
| POST | `/v1/internal/api-keys/verify` | Used by headless products to validate inbound keys |
|
||||
| POST | `/v1/audit` | Append an audit event |
|
||||
| GET | `/v1/audit` | Query (cursor-paginated) |
|
||||
|
||||
The skeleton's store is in-memory and pre-seeded with one tenant:
|
||||
State-changing endpoints emit audit events automatically. The OpenAPI contract test (`openapi_test.go`) asserts every listed path resolves against the committed spec.
|
||||
|
||||
```json
|
||||
{
|
||||
"id": "00000000-0000-0000-0000-000000000001",
|
||||
"slug": "acme",
|
||||
"name": "Acme Inc.",
|
||||
"status": "active",
|
||||
"plan": "professional",
|
||||
"products": ["certifai", "compliance"]
|
||||
}
|
||||
```
|
||||
## Storage
|
||||
|
||||
So `curl http://localhost:8090/v1/tenants/by-slug/acme` works the moment `make dev` is up.
|
||||
The service picks its store based on `DATABASE_URL`:
|
||||
|
||||
The full schema (6 tables: `tenants`, `tenant_projects`, `tenant_products`, `tenant_idp_config`, `api_keys`, `audit_log` — per `PLATFORM_ARCHITECTURE.md §5c`) lives at `migrations/0001_init.up.sql`. The handler-layer in-memory store is still wired in by default; the pgx-backed store + the full REST surface lands in **M4.2**.
|
||||
- **empty** → in-memory store, pre-seeded with the `acme` tenant (`id: 00000000-0000-0000-0000-000000000001`). Useful for portal dev without spinning Postgres.
|
||||
- **set** → pgx-backed Postgres. Run `make migrate-up` against the same DSN first.
|
||||
|
||||
Both implementations pass the same test harness (`internal/server/server_test.go` → `eachStore`).
|
||||
|
||||
## Schema migrations (M4.1)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user