email: remove content headers of passed-in message
The email has already been parsed according to the headers, but they are
still present. However, signing or encrypting the email will change the
content format, so remove any such headers before continuing.
server: register SQL collector
Missed this step
Add prometheus SQL connection stats
Also updates the prometheus client_go library
auth: fix invalid json tag in InternalAuth
email: handle error from Enqueue() in EnqueueStd()
Update pq (Postgres driver) to latest version
auth: Use canonical user IDs
When adding users to the database, use the canonical user ID from
meta.sr.ht.
email/worker: add more context to errors
For instance, failure to open the private PGP key would just fail
with an unhelpful "panic: open : no such file or directory" error.
database: add helpers to fetch all columns
The current solution of fetching columns based on the GraphQL context
has some limits. While probably not the solution for all use-cases, it
sometimes can be desirable to simply fetch all columns from the database
when retrieving objects.
This commit adds two simple functions doing just that. They can be used
when building SQL queries, like
query := database.SelectAll(new(model.Email))
and
rows.Scan(database.ScanAll(&email)...)
auth: Use canonical user IDs
When adding users to the database, use the canonical user ID from
meta.sr.ht.
webhooks.FilterWebhooks: Filter by user_id
Normalize remote address before saving to context
One cause for https://todo.sr.ht/~sircmpwn/meta.sr.ht/193 was that code
performing this sanitization was in multiple places, and a fix was not
applied in all places. There is no reasonable expectation for the port
to be present anyways, e.g. if the address is taken from a trusted
reverse proxy's header. Hence, perform the normalization here, so that
the code doing this in applications can be simplified.
Note that this does not yet fix the below ticket, it will just make the
fix easier.
References: https://todo.sr.ht/~sircmpwn/meta.sr.ht/193
email.EnqueueStd: Don't overwrite headers
Sometimes we need to specify the Message-Id, From, and Reply-To headers
(e.g. for todo.sr.ht ticket notifications). Don't overwrite these
headers if they are present.
email: handle failure to encrypt notifications
Currently, failure to encrypt the notification email - e.g. due to an
expired key - will make the entire request fail. Instead, fall back to
sending an unencrypted email and let the request succeed (unless that
fails also, which is unlikely).
valid: Add Error function
Add an Error function which is similar to Errorf except that it does not
take a format specifier.
webhooks: Execute GraphQL queries synchronously
Execute GraphQL webhook queries synchronously instead of in a background
task to avoid race conditions.