~bigbes/sr-ht-spec

ref: 3cb1c03d8078d5748cc13a2e9bd7ba7d078e1b37 sr-ht-spec/cmd/specsrht/graphql.go -rw-r--r-- 2.4 KiB
3cb1c03d — Eugene Blikh go.mod: take the shared libraries' current heads 2 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main

import (
	"strconv"

	"github.com/vaughan0/go-ini"
)

// queryRoute is where the GraphQL schema answers. It is core-go's own path,
// because that is where every SourceHut client — hut, api.sr.ht, meta's
// personal-token page — already looks. The file beside it is served by
// sr-ht-ecore's apimeta, at apimeta.Path, because a service that mounts its own
// /query is the one thing core-go does not serve that file for.
const queryRoute = "/query"

// apiScopes is what this service publishes at apimeta.Path: nothing.
//
// A scope is the part after the service name in a meta.sr.ht personal-token
// grant, and spec.sr.ht defines none — no AccessScope enum, no @access directive
// on any field, and no code path that reads one. Its grant vocabulary is
// tokens.sr.ht's (authn.ActionRead, authn.ActionPropose), which meta neither
// mints nor advertises, so the honest list is empty and not a placeholder.
//
// It is a variable so that what the daemon serves and what its test asserts are
// one value rather than two spellings of an intention. apimeta marshals it as []
// and never as null; see the test for why that distinction is instance-wide.
var apiScopes []string

// defaultMaxComplexity is the bound core-go's server.WithSchema would have
// applied. It is repeated here because this daemon does not call WithSchema —
// /query is mounted on the anonymous router with spec's own credential plane in
// front of it — and the value has a second reader that has nothing to do with
// HTTP: the webhook delivery worker runs a subscriber's stored query through
// corewebhooks.Exec, which compares its complexity against Server.MaxComplexity
// and refuses everything above it. Leaving the field at its zero value would
// therefore not mean "no limit"; it would mean every webhook delivery fails.
const defaultMaxComplexity = 250

// maxComplexity is [spec.sr.ht::api] max-complexity, or defaultMaxComplexity
// when the instance does not set it.
//
// An unparseable value is a configuration error and is reported as one, rather
// than being read as "the operator meant the default": a limit somebody wrote
// down and got wrong must not be silently replaced by a different limit.
func maxComplexity(conf ini.File) (int, error) {
	raw, ok := conf.Get(serviceName+"::api", "max-complexity")
	if !ok || raw == "" {
		return defaultMaxComplexity, nil
	}
	limit, err := strconv.Atoi(raw)
	if err != nil {
		return 0, err
	}
	return limit, nil
}