worker: add SAMS notifications subscriber#63051
Conversation
65cad0a to
b163d1f
Compare
b163d1f to
a014c8b
Compare
| credentialsJSON, err := os.ReadFile(s.config.GCP.CredentialsFile) | ||
| if err != nil { | ||
| return nil, errors.Wrap(err, "read GCP credentials file") | ||
| } | ||
| credentials, err := google.CredentialsFromJSON(ctx, credentialsJSON, pubsub.ScopePubSub) | ||
| if err != nil { | ||
| return nil, errors.Wrap(err, "parse GCP credentials JSON") | ||
| } |
There was a problem hiding this comment.
Should this happen up-front in config load instead?
There was a problem hiding this comment.
I think all of config init steps here equally crucial, and CredentialsFromJSON doesn't really do any validation other than expecting valid JSON format. Thus prefer init them in the same order as the fields of notificationsv1.SubscriberOptions.
| c.GCP.SubscriptionID = c.Get("SOURCEGRAPH_ACCOUNTS_NOTIFICATIONS_SUBSCRIPTION", "sams-notifications", "GCP Pub/Sub subscription ID to receive SAMS notifications from") | ||
| } | ||
|
|
||
| func handleOnUserDeleted( |
There was a problem hiding this comment.
IMO the handlers deserve their own file for readability and expansion - e.g. in the future, we might have:
user_deletion.go
user_rename.go
etc.
There was a problem hiding this comment.
I ended up restructuring the files a bit in https://github.com/sourcegraph/sourcegraph/pull/63051/commits/f7ab03a3a8ebcad6e69670bf6e95cfd23ddf87c8, PTAL!
I do want anything notifications-related visually and structurally grouped, since this package is generic "sourcegraphaccounts", who knows if we gonna add more workers here 😁
| - filename: cmd/worker/internal/sourcegraphaccounts/mocks_test.go | ||
| path: github.com/sourcegraph/sourcegraph/cmd/worker/internal/sourcegraphaccounts | ||
| interfaces: | ||
| - notificationsSubscriberStore |
…er.go Co-authored-by: Robert Lin <robert@bobheadxi.dev>
Part of CORE-92
This PR add a new worker for subscribing to SAMS notifications. The current use case is to automatically (hard-)delete users on Sourcegraph.com when the corresponding user is deleted from SAMS.
This worker is only started when running in the Sourcegraph.com mode and the credentials file (
service_account.json) is provided, which has been configured since https://github.com/sourcegraph/deploy-sourcegraph-cloud/pull/18591.Test plan
Tested locally end-to-end using my test GCP project.
curl -X DELETE -H "Authorization: Bearer foolmeifyoucan" http://localhost:9991/api/management/v1/users/018d21f2-10ba-7f83-84b9-615678d6b383