-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnotificationsv1.go
More file actions
41 lines (36 loc) · 1.79 KB
/
notificationsv1.go
File metadata and controls
41 lines (36 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package sams
import (
"github.com/sourcegraph/log"
"github.com/sourcegraph/sourcegraph/lib/background"
"github.com/sourcegraph/sourcegraph/lib/pointers"
notificationsv1 "github.com/sourcegraph/sourcegraph-accounts-sdk-go/notifications/v1"
)
// NotificationsV1SubscriberConfig holds configuration for the SAMS
// notifications that are derived from the environment variables, HOWEVER, this
// is not a complete configuration to create a notification subscriber.
type NotificationsV1SubscriberConfig struct {
// ProjectID is the GCP project ID that the Pub/Sub subscription belongs to. It
// is almost always the same GCP project that the Cloud Run service is deployed
// to.
ProjectID string
// SubscriptionID is the GCP Pub/Sub subscription ID to receive SAMS
// notifications from.
SubscriptionID string
}
// NewNotificationsV1SubscriberConfigFromEnv initializes configuration based on
// environment variables.
func NewNotificationsV1SubscriberConfigFromEnv(env envGetter) NotificationsV1SubscriberConfig {
projectID := env.GetOptional("SAMS_NOTIFICATION_PROJECT", "GCP project ID that the Pub/Sub subscription belongs to")
if pointers.DerefZero(projectID) == "" {
projectID = env.GetOptional("GOOGLE_CLOUD_PROJECT", "The GCP project that the service is running in")
}
return NotificationsV1SubscriberConfig{
ProjectID: pointers.DerefZero(projectID),
SubscriptionID: env.Get("SAMS_NOTIFICATION_SUBSCRIPTION", "sams-notifications", "GCP Pub/Sub subscription ID to receive SAMS notifications from"),
}
}
// NewNotificationsV1Subscriber returns a new background routine for receiving
// SAMS notifications with v1 protocol.
func NewNotificationsV1Subscriber(logger log.Logger, opts notificationsv1.SubscriberOptions) (background.Routine, error) {
return notificationsv1.NewSubscriber(logger, opts)
}