~bigbes/sr-ht-spec

6e59bf0ffc7d16f509dad40063d35bf8f6fb98a7 — Eugene Blikh 8 days ago cb60d4f
api: advertise an empty scope list, not null

core-go serves the second argument of WithSchema verbatim at
/query/api-meta.json, so a nil slice reaches the wire as `"scopes": null`.
meta.sr.ht discovers every *.sr.ht service at import time and iterates that
field when rendering /oauth2/personal-token, so the null turned the whole
instance's personal-token page into a 500 — no token could be minted at all
while spec.sr.ht was up. The other custom services answer 404 there and are
skipped, which is why only this one broke it.

Empty is the accurate value: the service is owner-only and defines no
AccessScope enum to grant against.
1 files changed, 8 insertions(+), 1 deletions(-)

M cmd/specsrht/main.go
M cmd/specsrht/main.go => cmd/specsrht/main.go +8 -1
@@ 357,11 357,18 @@ func run(conf ini.File, log *slog.Logger) error {
	// WithQueues starts the webhook delivery worker with a context carrying that
	// same stack; the queue executes a subscription's stored query against the
	// shared schema at delivery time.
	// The scope list must be an empty slice and not nil. core-go serves it
	// verbatim at /query/api-meta.json, where a nil slice marshals to
	// `"scopes": null` — and meta.sr.ht's OAuth page iterates that field for
	// every service it discovers, so one null there is a 500 on
	// /oauth2/personal-token for the whole instance, not a degraded entry.
	// Empty is also the honest answer: this service is owner-only (see
	// ownerOnly above) and defines no AccessScope enum to grant against.
	webhookQueue := webhooks.NewQueue(surf.schema, conf)
	srv := coreserver.New(serviceName, defaultBind, conf, os.Args).
		WithDefaultMiddleware().
		WithMiddleware(ownerOnly(cfg.Instance.OwnerName)).
		WithSchema(surf.schema, nil).
		WithSchema(surf.schema, []string{}).
		WithQueues(webhookQueue.Queue)
	mountRoutes(srv.AnonRouter(), conf, surf)