-
Notifications
You must be signed in to change notification settings - Fork 875
feat(coderd): add webpush package #17091
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
1fdf10c
to
86c481e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want to call this a notification of any kind because this will confuse with our existing notification targets. Instead we should call this something like PushMessage
c44bdca
to
1274623
Compare
8dde95a
to
449f882
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First round done. I skipped "site" changes for now.
|
||
defer cancel() | ||
|
||
if regenVapidKeypairDBURL == "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm quite sure I have seen this pattern in other CLI commands:
startBuiltinPostgres - codersdk.PostgresAuth - ConnectToPostgres
we may consider some base pattern for all commands using the database
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep there are a few commands that do this. I'll create a follow-up. (EDIT: coder/internal#541)
|
||
// Ensure the push subscriptions were deleted. | ||
var count int64 | ||
rows, err := sqlDB.QueryContext(ctx, "SELECT COUNT(*) FROM webpush_subscriptions") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just confirming - is there a chance that there will be another testrun operating on this table (flakiness risk?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There shouldn't be. It operates entirely in its own transaction, and each test should be operating on its own database.
postgres-builtin-serve Run the built-in PostgreSQL deployment. | ||
postgres-builtin-url Output the connection URL for the built-in | ||
PostgreSQL deployment. | ||
create-admin-user Create a new admin user with the given username, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: unrelated change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm actually not sure what's causing these changes, but the command to update these golden files is convinced that this is how it should be now.
assert.Len(t, subscriptions, 0, "No subscriptions should be returned") | ||
}) | ||
|
||
t.Run("FailedDelivery", func(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we want to implement retry mechanism at some point?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we will need to do this later if we make it a first-class notifciation target.
} | ||
|
||
type WebpushMessage struct { | ||
Icon string `json:"icon"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the notification payload we use version for potential schema changes. Should we adopt this pattern too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a bad idea! It might be slightly premature right now, but I could see this being useful down the line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cosmetics
/cherry-pick release/2.21 |
Extracted from https://github.com/coder/coder/tree/kyle/tasks
This PR adds a
webpush
package undercoderd
to allow sending push notifications to browsers from coderd using Web Push and VAPID.Why VAPID? Why not just dial the agent directly?
It is not yet hooked up to the wider notifications ecosystem inside Coder, and is therefore hidden behind an experiment
web-push
. This simply adds the package and a minimal service worker + button in the UI. Later PRs will build further upon this.Adds
codersdk.ExperimentWebPush
(web-push
)Adds a
coderd/webpush
package that allows sending native push notifications viagithub.com/SherClockHolmes/webpush-go
Adds database tables to store push notification subscriptions.
Adds an API endpoint that allows users to subscribe/unsubscribe, and send a test notification
Adds server CLI command to regenerate VAPID keys (note: regenerating the VAPID keypair requires deleting all existing subscriptions)
* Adds a service worker to display push notificationsEDIT: moved to feat(site): add webpush notification serviceworker #17123