coverage~bigbes/sr-ht-spec3cb1c03dcmd/specsrht/graphql.go

Coverage
100.0% 7/7 statements
Δ
Blob
548dd97
Uncovered nothing — every instrumented line ran
1 package main
2
3 import (
4 "strconv"
5
6 "github.com/vaughan0/go-ini"
7 )
8
9 // queryRoute is where the GraphQL schema answers. It is core-go's own path,
10 // because that is where every SourceHut client — hut, api.sr.ht, meta's
11 // personal-token page — already looks. The file beside it is served by
12 // sr-ht-ecore's apimeta, at apimeta.Path, because a service that mounts its own
13 // /query is the one thing core-go does not serve that file for.
14 const queryRoute = "/query"
15
16 // apiScopes is what this service publishes at apimeta.Path: nothing.
17 //
18 // A scope is the part after the service name in a meta.sr.ht personal-token
19 // grant, and spec.sr.ht defines none — no AccessScope enum, no @access directive
20 // on any field, and no code path that reads one. Its grant vocabulary is
21 // tokens.sr.ht's (authn.ActionRead, authn.ActionPropose), which meta neither
22 // mints nor advertises, so the honest list is empty and not a placeholder.
23 //
24 // It is a variable so that what the daemon serves and what its test asserts are
25 // one value rather than two spellings of an intention. apimeta marshals it as []
26 // and never as null; see the test for why that distinction is instance-wide.
27 var apiScopes []string
28
29 // defaultMaxComplexity is the bound core-go's server.WithSchema would have
30 // applied. It is repeated here because this daemon does not call WithSchema —
31 // /query is mounted on the anonymous router with spec's own credential plane in
32 // front of it — and the value has a second reader that has nothing to do with
33 // HTTP: the webhook delivery worker runs a subscriber's stored query through
34 // corewebhooks.Exec, which compares its complexity against Server.MaxComplexity
35 // and refuses everything above it. Leaving the field at its zero value would
36 // therefore not mean "no limit"; it would mean every webhook delivery fails.
37 const defaultMaxComplexity = 250
38
39 // maxComplexity is [spec.sr.ht::api] max-complexity, or defaultMaxComplexity
40 // when the instance does not set it.
41 //
42 // An unparseable value is a configuration error and is reported as one, rather
43 // than being read as "the operator meant the default": a limit somebody wrote
44 // down and got wrong must not be silently replaced by a different limit.
45 4 func maxComplexity(conf ini.File) (int, error) {
46 4 raw, ok := conf.Get(serviceName+"::api", "max-complexity")
47 4 if !ok || raw == "" {
48 2 return defaultMaxComplexity, nil
49 2 }
50 2 limit, err := strconv.Atoi(raw)
51 2 if err != nil {
52 1 return 0, err
53 1 }
54 1 return limit, nil
55 }