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

adds guard clauses to retrieving bound context #106

Merged
merged 1 commit into from
Mar 14, 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
8 changes: 7 additions & 1 deletion internal/globalservice/event_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (srv *GlobalService) GetTotalSharedCatalogs() (uint64, error) {
return srv.countFilteredEvents(subject)
}

// Retrieves the most recent bound context by loading the account projection
// Retrieves the most recent bound context by loading the account projection, if any
func (srv *GlobalService) GetBoundContext(myAccountKey string) (*models.ContextBoundEvent, error) {
js, _ := jetstream.New(srv.nc)
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
Expand All @@ -62,6 +62,9 @@ func (srv *GlobalService) GetBoundContext(myAccountKey string) (*models.ContextB
slog.Error("Failed to load source account for catalog query", slog.Any("error", err))
return nil, err
}
if myAccount == nil {
return nil, nil
}

return myAccount.BoundContext, nil
}
Expand All @@ -71,6 +74,9 @@ func (srv *GlobalService) GetOAuthIdForAccount(accountKey string) (*string, erro
if err != nil {
return nil, err
}
if discoveredContext == nil {
return nil, nil
}

return &discoveredContext.OAuthIdentity, nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/globalservice/hb.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
func handleHeartbeat(srv *GlobalService) func(m *nats.Msg) {
return func(m *nats.Msg) {
accountKey := extractAccountKey(m.Subject)
slog.Info("Receiving heartbeat", slog.String("account", accountKey))
slog.Debug("Receiving heartbeat", slog.String("account", accountKey))
var hb models.Heartbeat
err := json.Unmarshal(m.Data, &hb)
if err != nil {
Expand Down
10 changes: 3 additions & 7 deletions internal/globalservice/whoami.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,9 @@ func handleWhoAmi(srv *GlobalService) func(m *nats.Msg) {
return
}

// Note: a non-error but nil oauth is valid - just means it hasn't been context
// bound yet
oauth, err := srv.GetOAuthIdForAccount(accountKey)
if err != nil {
slog.Error("Failed to query OAuth ID for account", err)
_ = m.Respond(models.NewApiResultFail("Internal server error", 500))
return
var oauth *string
if act.BoundContext != nil && len(act.BoundContext.OAuthIdentity) > 0 {
oauth = &act.BoundContext.OAuthIdentity
}

resp := models.WhoamiResponse{
Expand Down
Loading