Skip to content
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

notifications/v1: add user metadata change event #79

Merged
merged 2 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions notifications/v1/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,13 @@ type SubscriberHandlers struct {
// revoked. If the service's roles are relevant to the subscriber the user's
// current roles can be retrieved from the SAMS API.
OnUserRolesUpdated func(ctx context.Context, data *UserRolesUpdatedData) error
// OnUserMetadataUpdated is called when a "UserMetadataUpdated" notification
// is received.
//
// It indicates that a user's metadata has been updated for a particular namespace.
// The notification data does not specify the updated metadata - the current
// metadata must be retrieved from the SAMS API.
OnUserMetadataUpdated func(ctx context.Context, data *UserMetadataUpdatedData) error
// OnSessionInvalidated is called when a "SessionInvalidated" notification is
// received.
//
Expand All @@ -208,13 +215,12 @@ func (s *subscriber) handleReceive(ctx context.Context, name string, metadata js
if s.handlers.OnUserDeleted == nil {
return "skipped", nil
}

var data UserDeletedData
if err := json.Unmarshal(metadata, &data); err != nil {
return "malformed_message", errors.Wrap(err, "unmarshal metadata")
}

return "handled", s.handlers.OnUserDeleted(ctx, &data)

case nameUserRolesUpdated:
if s.handlers.OnUserRolesUpdated == nil {
return "skipped", nil
Expand All @@ -223,8 +229,18 @@ func (s *subscriber) handleReceive(ctx context.Context, name string, metadata js
if err := json.Unmarshal(metadata, &data); err != nil {
return "malformed_message", errors.Wrap(err, "unmarshal metadata")
}

return "handled", s.handlers.OnUserRolesUpdated(ctx, &data)

case nameUserMetadataUpdated:
if s.handlers.OnUserMetadataUpdated == nil {
return "skipped", nil
}
var data UserMetadataUpdatedData
if err := json.Unmarshal(metadata, &data); err != nil {
return "malformed_message", errors.Wrap(err, "unmarshal metadata")
}
return "handled", s.handlers.OnUserMetadataUpdated(ctx, &data)

case nameSessionInvalidated:
if s.handlers.OnSessionInvalidated == nil {
return "skipped", nil
Expand Down
15 changes: 12 additions & 3 deletions notifications/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import (
// backend/internal/notification/types.go

const (
nameUserDeleted = "UserDeleted"
nameUserRolesUpdated = "UserRolesUpdated"
nameSessionInvalidated = "SessionInvalidated"
nameUserDeleted = "UserDeleted"
nameUserRolesUpdated = "UserRolesUpdated"
nameUserMetadataUpdated = "UserMetadataUpdated"
nameSessionInvalidated = "SessionInvalidated"
)

// UserDeletedData contains information of a "UserDeleted" notification.
Expand Down Expand Up @@ -47,6 +48,14 @@ type UserRolesUpdatedData struct {
ResourceType roles.ResourceType `json:"resource_type,omitempty"`
}

type UserMetadataUpdatedData struct {
// AccountID is the SAMS external ID of the user whose metadata has been
// updated.
AccountID string `json:"account_id"`
// Namespace is the metadata scope that the user's roles have been updated in.
Namespace string `json:"namespace"`
Comment on lines +55 to +56
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

// SessionInvalidatedData contains information of a "SessionInvalidated"
// notification.
type SessionInvalidatedData struct {
Expand Down
Loading