~bigbes/core-go

ref: ba01be8449eadd60ffae7ae28f27247bbefa8bcc core-go/webhooks d---------
c3d11991 — Drew DeVault 1 year, 6 months ago
webhooks: fix filter for internal auth
d3f7b91a — Drew DeVault 1 year, 6 months ago
webhooks: implement internal webhook users

AUTH_INTERNAL requests previously could not register webhooks. This
commit adds the necessary changes to allow for this.
465a6f71 — Drew DeVault 1 year, 6 months ago
all: pass errors to panic, not strings

GraphQL's recovery middleware can't handle strings so it just logs a
very not useful <nil>
fea51c61 — Drew DeVault 1 year, 6 months ago
webhooks: add User-Agent to outgoing requests
6eae2199 — Drew DeVault 1 year, 7 months ago
auth: use config.IsInternalIP
17315205 — Robin Jarry 1 year, 8 months ago
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>
7457c44b — Robin Jarry 1 year, 8 months ago
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>
2624a28a — Robin Jarry 1 year, 8 months ago
webhooks: do not crash when expire is NULL

This is currently not possible to create a webhook without an expiry
date. But the SQL database schema does not forbid it. If in the future
we would like to allow webhooks to be created without an expiry date, we
shouldn't crash when fetching them.

Check for the validity of the Expiry field before checking its value. If
it is nil, assume that the webhooks has no expiry date.

Signed-off-by: Robin Jarry <robin@jarry.cc>
cd878493 — Conrad Hoffmann 2 years ago
webhooks: skip webhooks with expired credentials

The documentation states [1]:

> When the original authentication method becomes invalid (such as the
> expiration of or revocation of an OAuth 2.0 bearer token), the
> webhook is disabled.

However, this is currently not the case. Expired webhooks are indeed
filtered out in virtually all GraphQL queries (by means of core-go's
FilterWebhooks [2]), so users cannot see or delete them. They are _not_
filtered out upon scheduling, however. This commit fixes that.

The symptoms of this are that active webhooks may simply not be run - if
a user has both an expired and a valid, active webhook for some event,
the scheduling will retrieve both, fail on the expired one, and stop
processing, without any feedback to the user who scheduled the hooks.

This is a problem across all services, so core-go seems like the best
place to fix this.

[1]: https://man.sr.ht/graphql.md#webhook-authentication
[2]: https://git.sr.ht/~sircmpwn/core-go/tree/master/item/webhooks/config.go#L74,81
236879ae — Conrad Hoffmann 3 years ago
Run `go fmt`
d0bf1153 — Adnan Maolood 4 years ago
webhooks.FilterWebhooks: Filter by user_id
ebf93be7 — Adnan Maolood 4 years ago
webhooks: Add middleware
7d6b202a — Adnan Maolood 4 years ago
webhooks: Execute GraphQL queries synchronously

Execute GraphQL webhook queries synchronously instead of in a background
task to avoid race conditions.
87de6649 — Adnan Maolood 4 years ago
webhooks: Add FilterWebhooks function
3b553750 — Drew DeVault 4 years ago
webhooks: fix failing test
46875256 — Drew DeVault 4 years ago
webhooks/legacy: fetch subscriptions upfront

This fixes a race condition when delivering webhooks for resource
deletion events, in which the subscriptions would be removed from the
delete cascade before the task to fetch them executes. This requires the
downstream code to call Queue before committing the delete transaction,
and updates the API to include a context argument for the connection
pool.
f44afb10 — Simon Ser 4 years ago
go fmt
48250772 — Simon Ser 4 years ago
Remove %e formatting verbs

%e is not valid for formatting error values:

> %e	scientific notation, e.g. -1.234456e+78

Instead, use %w when using fmt.Errorf (for error wrapping) and
%v when using log.Printf (%w is not valid in that context).
cdb177bb — Drew DeVault 4 years ago
(*WebhookQueue).deliverPayload: address error nit

This return does not need to be here.
99671f85 — Drew DeVault 4 years ago
webhooks: add comment clarifying field usage
Next