server: log GraphQL queries if running in debug mode
server: handle CORS in server
Currently CORS is handled in nginx in front of the API. That setup is
not very suitable for Kubernetes. Instead, handle CORS here, so we do
not need any intermediaries between the ingress and the APIs.
The CORS settings are taken from sr.ht-nginx/graphql.conf [1]
[1] https://git.sr.ht/~sircmpwn/sr.ht-nginx/tree/master/item/graphql.conf
server: disable logging for release mode
This was partially implemented a while ago but we missed the main point
where it matters.
server: add pprof endpoint
This adds a pprof endpoint to all SourceHut APIs. It picks an
OS-assigned port on localhost to run it on and prints this port to
stdout. This ensures a unique port is selected even if several APIs are
running on a single host.
server: enable request logging only in debug mode
To improve the signal:noise ratio in the production logs.
redis: avoid building UniversalOptions for standard mode
This makes it support all options that go-redis recognizes in ParseURL,
by constructing a standard client directly instead of building
UniversalOptions ourselves.
server/email: print correct var on type assertion failure
Export webhooks public key via api-meta.json
server: add @admin directive implementation
This will be used at least by meta.sr.ht in the near future.
config: factorize integer parsing
Add a new GetInt() function to parse an integer value from a parsed
ini.File. Use that function instead of duplicated code.
Signed-off-by: Robin Jarry <robin@jarry.cc>
treewide: update to new multi worker dowork api
The work.Queue() implementation has changed and now allows scheduling
tasks from multiple goroutines in parallel. Also, it requires a new
argument for limiting the queue buffer size in order to apply back
pressure.
Define new configuration variables to allow tuning the queue sizes and
number of workers per service:
[mail]
# Maximum size of the outgoing email queue (default 512).
egress-queue-size = 512
[$service_name]
# Number of parallel workers per queue (default 1).
# There are multiple queues (for egress email, webhooks, etc.).
# This setting is applied on a per-queue basis.
queue-workers = 1
[webhooks]
# Maximum size of the webhooks queue (default 512).
queue-size = 512
Use these new settings to configure the queues and workers accordingly.
Fix unit tests as well.
Link: https://git.sr.ht/~sircmpwn/dowork/commit/95719cfc0118
Signed-off-by: Robin Jarry <robin@jarry.cc>
server: add AnonRouter function
To expose anonymous (unauthenticated) routing to downstream core-go
users.
server: fix playground on config.Debug
A recent change made it so that the playground required authentication
to access in debug mode; this moves it under the other auth-free
endpoints.
server: use routing groups
Instead of hardcoding some exceptions in the auth middleware, use a
different routing group for routes that do not require auth. Makes the
auth middleware more generic and also removes a lot of unneccessary
middleware processing from routes that don't need it.
For now, the added group is not accessible from outside the module, but
if the need arises, this might be an option.
server/directives: disambiguate AnonInternal error message
AUTH_INTERNAL won't work with AnonInternal.
Migrate to chi v5
v1 is not maintained anymore.
server/email: use go-message for address parsing
No need to additionally depend on net/mail
auth: add AuthContext.Access
Same logic as server.Access, but lower-level. Useful to check for
a permission not covered by the GraphQL schema @access directives
(such as builds.sr.ht secrets).