Skip to content

Commit aa16bbe

Browse files
committed
notification -> webpush
1 parent e726290 commit aa16bbe

File tree

14 files changed

+77
-77
lines changed

14 files changed

+77
-77
lines changed

cli/server.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -779,18 +779,18 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
779779
// Manage push notifications.
780780
experiments := coderd.ReadExperiments(options.Logger, options.DeploymentValues.Experiments.Value())
781781
if experiments.Enabled(codersdk.ExperimentWebPush) {
782-
pushNotifier, err := push.New(ctx, &options.Logger, options.Database)
782+
webpusher, err := push.New(ctx, &options.Logger, options.Database)
783783
if err != nil {
784-
options.Logger.Error(ctx, "failed to create push notifier", slog.Error(err))
785-
options.Logger.Warn(ctx, "push notifications will not work until the VAPID keys are regenerated")
786-
pushNotifier = &push.NoopNotifier{
787-
Msg: "Push notifications are disabled due to a system error. Please contact your Coder administrator.",
784+
options.Logger.Error(ctx, "failed to create web push dispatcher", slog.Error(err))
785+
options.Logger.Warn(ctx, "web push notifications will not work until the VAPID keys are regenerated")
786+
webpusher = &push.NoopWebpusher{
787+
Msg: "Web Push notifications are disabled due to a system error. Please contact your Coder administrator.",
788788
}
789789
}
790-
options.PushNotifier = pushNotifier
790+
options.WebpushDispatcher = webpusher
791791
} else {
792-
options.PushNotifier = &push.NoopNotifier{
793-
Msg: "Push notifications are disabled. Enable the 'web-push' experiment to use this feature.",
792+
options.WebpushDispatcher = &push.NoopWebpusher{
793+
Msg: "Web Push notifications are an experimental feature and are disabled by default. Enable the 'web-push' experiment to use this feature.",
794794
}
795795
}
796796

cli/server_regenerate_vapid_keypair.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func (r *RootCmd) newRegenerateVapidKeypairCommand() *serpent.Command {
2525
)
2626
regenerateVapidKeypairCommand := &serpent.Command{
2727
Use: "regenerate-vapid-keypair",
28-
Short: "Regenerate the VAPID keypair used for push notifications.",
28+
Short: "Regenerate the VAPID keypair used for web push notifications.",
2929
Hidden: true, // Hide this command as it's an experimental feature
3030
Handler: func(inv *serpent.Invocation) error {
3131
var (
@@ -71,7 +71,7 @@ func (r *RootCmd) newRegenerateVapidKeypairCommand() *serpent.Command {
7171

7272
// Confirm that the user really wants to regenerate the VAPID keypair.
7373
cliui.Infof(inv.Stdout, "Regenerating VAPID keypair...")
74-
cliui.Infof(inv.Stdout, "This will delete all existing push notification subscriptions.")
74+
cliui.Infof(inv.Stdout, "This will delete all existing webpush subscriptions.")
7575
cliui.Infof(inv.Stdout, "Are you sure you want to continue? (y/N)")
7676

7777
if resp, err := cliui.Prompt(inv, cliui.PromptOptions{

coderd/apidoc/docs.go

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/coderd.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,8 @@ type Options struct {
262262
OIDCConvertKeyCache cryptokeys.SigningKeycache
263263
Clock quartz.Clock
264264

265-
// PushNotifier is a way to send push notifications to users.
266-
PushNotifier push.NotificationDispatcher
265+
// WebpushDispatcher is a way to send notifications over Web Push.
266+
WebpushDispatcher push.Dispatcher
267267
}
268268

269269
// @title Coder API
@@ -550,7 +550,7 @@ func New(options *Options) *API {
550550
UserQuietHoursScheduleStore: options.UserQuietHoursScheduleStore,
551551
AccessControlStore: options.AccessControlStore,
552552
Experiments: experiments,
553-
PushNotifier: options.PushNotifier,
553+
PushNotifier: options.WebpushDispatcher,
554554
healthCheckGroup: &singleflight.Group[string, *healthsdk.HealthcheckReport]{},
555555
Acquirer: provisionerdserver.NewAcquirer(
556556
ctx,
@@ -1506,7 +1506,7 @@ type API struct {
15061506
NetworkTelemetryBatcher *tailnet.NetworkTelemetryBatcher
15071507
TailnetClientService *tailnet.ClientService
15081508
// PushNotifier is a way to send push notifications to users.
1509-
PushNotifier push.NotificationDispatcher
1509+
PushNotifier push.Dispatcher
15101510
QuotaCommitter atomic.Pointer[proto.QuotaCommitter]
15111511
AppearanceFetcher atomic.Pointer[appearance.Fetcher]
15121512
// WorkspaceProxyHostsFn returns the hosts of healthy workspace proxies

coderd/coderdtest/coderdtest.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ type Options struct {
162162
Logger *slog.Logger
163163
StatsBatcher workspacestats.Batcher
164164

165-
PushNotifier push.NotificationDispatcher
165+
PushNotifier push.Dispatcher
166166
WorkspaceAppsStatsCollectorOptions workspaceapps.StatsCollectorOptions
167167
AllowWorkspaceRenames bool
168168
NewTicker func(duration time.Duration) (<-chan time.Time, func())
@@ -541,7 +541,7 @@ func NewOptions(t testing.TB, options *Options) (func(http.Handler), context.Can
541541
TrialGenerator: options.TrialGenerator,
542542
RefreshEntitlements: options.RefreshEntitlements,
543543
TailnetCoordinator: options.Coordinator,
544-
PushNotifier: options.PushNotifier,
544+
WebpushDispatcher: options.PushNotifier,
545545
BaseDERPMap: derpMap,
546546
DERPMapUpdateFrequency: 150 * time.Millisecond,
547547
CoordinatorResumeTokenProvider: options.CoordinatorResumeTokenProvider,

coderd/notifications.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,8 @@ func (api *API) putUserNotificationPreferences(rw http.ResponseWriter, r *http.R
327327
httpapi.Write(ctx, rw, http.StatusOK, out)
328328
}
329329

330-
// @Summary Create user push notification subscription
331-
// @ID create-user-push-notification-subscription
330+
// @Summary Create user webpush notification subscription
331+
// @ID create-user-webpush-notification-subscription
332332
// @Security CoderSessionToken
333333
// @Accept json
334334
// @Tags Notifications
@@ -404,8 +404,8 @@ func (api *API) postUserWebpushSubscription(rw http.ResponseWriter, r *http.Requ
404404
rw.WriteHeader(http.StatusNoContent)
405405
}
406406

407-
// @Summary Delete user push notification subscription
408-
// @ID delete-user-push-notification-subscription
407+
// @Summary Delete user webpush notification subscription
408+
// @ID delete-user-webpush-notification-subscription
409409
// @Security CoderSessionToken
410410
// @Accept json
411411
// @Tags Notifications

coderd/notifications/push/push.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,23 @@ import (
2121
"github.com/coder/coder/v2/codersdk"
2222
)
2323

24-
// NotificationDispatcher is an interface that can be used to dispatch
25-
// push notifications.
26-
type NotificationDispatcher interface {
24+
// Dispatcher is an interface that can be used to dispatch
25+
// push notifications over Web Push.
26+
type Dispatcher interface {
2727
Dispatch(ctx context.Context, userID uuid.UUID, notification codersdk.WebpushMessage) error
2828
PublicKey() string
2929
PrivateKey() string
3030
}
3131

32-
// New creates a new push manager to dispatch push notifications.
32+
// New creates a new Dispatcher to dispatch notifications via Web Push.
3333
//
3434
// This is *not* integrated into the enqueue system unfortunately.
3535
// That's because the notifications system has a enqueue system,
3636
// and push notifications at time of implementation are being used
3737
// for updates inside of a workspace, which we want to be immediate.
3838
//
3939
// See: https://github.com/coder/internal/issues/528
40-
func New(ctx context.Context, log *slog.Logger, db database.Store) (NotificationDispatcher, error) {
40+
func New(ctx context.Context, log *slog.Logger, db database.Store) (Dispatcher, error) {
4141
keys, err := db.GetWebpushVAPIDKeys(ctx)
4242
if err != nil {
4343
if !errors.Is(err, sql.ErrNoRows) {
@@ -57,23 +57,23 @@ func New(ctx context.Context, log *slog.Logger, db database.Store) (Notification
5757
keys.VapidPrivateKey = newPrivateKey
5858
}
5959

60-
return &Notifier{
60+
return &Webpusher{
6161
store: db,
6262
log: log,
6363
VAPIDPublicKey: keys.VapidPublicKey,
6464
VAPIDPrivateKey: keys.VapidPrivateKey,
6565
}, nil
6666
}
6767

68-
type Notifier struct {
68+
type Webpusher struct {
6969
store database.Store
7070
log *slog.Logger
7171

7272
VAPIDPublicKey string
7373
VAPIDPrivateKey string
7474
}
7575

76-
func (n *Notifier) Dispatch(ctx context.Context, userID uuid.UUID, notification codersdk.WebpushMessage) error {
76+
func (n *Webpusher) Dispatch(ctx context.Context, userID uuid.UUID, notification codersdk.WebpushMessage) error {
7777
subscriptions, err := n.store.GetWebpushSubscriptionsByUserID(ctx, userID)
7878
if err != nil {
7979
return xerrors.Errorf("get notification push subscriptions by user ID: %w", err)
@@ -122,7 +122,7 @@ func (n *Notifier) Dispatch(ctx context.Context, userID uuid.UUID, notification
122122
if resp.StatusCode > http.StatusAccepted {
123123
// It's likely the subscription failed to deliver for some reason.
124124
body, _ := io.ReadAll(resp.Body)
125-
return xerrors.Errorf("push notification failed with status code %d: %s", resp.StatusCode, string(body))
125+
return xerrors.Errorf("web push dispatch failed with status code %d: %s", resp.StatusCode, string(body))
126126
}
127127

128128
return nil
@@ -145,30 +145,30 @@ func (n *Notifier) Dispatch(ctx context.Context, userID uuid.UUID, notification
145145
return nil
146146
}
147147

148-
func (n *Notifier) PublicKey() string {
148+
func (n *Webpusher) PublicKey() string {
149149
return n.VAPIDPublicKey
150150
}
151151

152-
func (n *Notifier) PrivateKey() string {
152+
func (n *Webpusher) PrivateKey() string {
153153
return n.VAPIDPrivateKey
154154
}
155155

156-
// NoopNotifier is a Notifier that does nothing except return an error.
156+
// NoopWebpusher is a Dispatcher that does nothing except return an error.
157157
// This is returned when push notifications are disabled, or if there was an
158158
// error generating the VAPID keys.
159-
type NoopNotifier struct {
159+
type NoopWebpusher struct {
160160
Msg string
161161
}
162162

163-
func (n *NoopNotifier) Dispatch(context.Context, uuid.UUID, codersdk.WebpushMessage) error {
163+
func (n *NoopWebpusher) Dispatch(context.Context, uuid.UUID, codersdk.WebpushMessage) error {
164164
return xerrors.New(n.Msg)
165165
}
166166

167-
func (*NoopNotifier) PublicKey() string {
167+
func (*NoopWebpusher) PublicKey() string {
168168
return ""
169169
}
170170

171-
func (*NoopNotifier) PrivateKey() string {
171+
func (*NoopWebpusher) PrivateKey() string {
172172
return ""
173173
}
174174

coderd/notifications/push/push_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ func TestPush(t *testing.T) {
243243
}
244244

245245
// setupPushTest creates a common test setup for push notification tests
246-
func setupPushTest(ctx context.Context, t *testing.T, handlerFunc func(w http.ResponseWriter, r *http.Request)) (push.NotificationDispatcher, database.Store, string) {
246+
func setupPushTest(ctx context.Context, t *testing.T, handlerFunc func(w http.ResponseWriter, r *http.Request)) (push.Dispatcher, database.Store, string) {
247247
logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}).Leveled(slog.LevelDebug)
248248
db, _ := dbtestutil.NewDB(t)
249249

coderd/notifications_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ func TestNotificationTest(t *testing.T) {
379379
}
380380

381381
const (
382-
// These are valid keys for a push notification subscription.
382+
// These are valid keys for a web push subscription.
383383
// DO NOT REUSE THESE IN ANY REAL CODE.
384384
validEndpointAuthKey = "zqbxT6JKstKSY9JKibZLSQ=="
385385
validEndpointP256dhKey = "BNNL5ZaTfK81qhXOx23+wewhigUeFb632jN6LvRWCFH1ubQr77FE/9qV1FuojuRmHP42zmf34rXgW80OvUVDgTk="
@@ -413,7 +413,7 @@ func TestPushNotificationSubscription(t *testing.T) {
413413
require.True(t, <-handlerCalled, "handler should have been called")
414414

415415
err = memberClient.PostTestWebpushMessage(ctx)
416-
require.NoError(t, err, "test push notification")
416+
require.NoError(t, err, "test web push notification")
417417
require.True(t, <-handlerCalled, "handler should have been called again")
418418

419419
err = memberClient.DeleteWebpushSubscription(ctx, "me", codersdk.DeleteWebpushSubscription{

codersdk/deployment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3149,7 +3149,7 @@ type BuildInfoResponse struct {
31493149
// DeploymentID is the unique identifier for this deployment.
31503150
DeploymentID string `json:"deployment_id"`
31513151

3152-
// WebPushPublicKey is the public key for push notifications.
3152+
// WebPushPublicKey is the public key for push notifications via Web Push.
31533153
WebPushPublicKey string `json:"webpush_public_key,omitempty"`
31543154
}
31553155

docs/reference/api/notifications.md

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/api/schemas.md

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)