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 }