Skip to content

Commit

Permalink
Get cache from external cache when refresh fails (#1537)
Browse files Browse the repository at this point in the history
In some cases, when the refresh cache fails, we should try to get the cache from the external cache obj.

This may happen if the IDP is not responsive between storing metadata and refreshing the cache
  • Loading branch information
mlsmaycon authored Feb 7, 2024
1 parent 62bacee commit a7547b9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
15 changes: 15 additions & 0 deletions management/server/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -1223,6 +1223,21 @@ func (am *DefaultAccountManager) lookupUserInCache(userID string, account *Accou
}
}

user, err := account.FindUser(userID)
if err != nil {
log.Errorf("failed finding user %s in account %s", userID, account.Id)
return nil, err
}

key := user.IntegrationReference.CacheKey(account.Id, userID)
ud, err := am.externalCacheManager.Get(am.ctx, key)
if err == nil {
log.Errorf("failed to get externalCache for key: %s, error: %s", key, err)
return ud, status.Errorf(status.NotFound, "user %s not found in the IdP", userID)
}

log.Infof("user %s not found in any cache", userID)

return nil, nil //nolint:nilnil
}

Expand Down
12 changes: 0 additions & 12 deletions management/server/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -890,18 +890,6 @@ func (am *DefaultAccountManager) SaveOrAddUser(accountID, initiatorUserID string
if err != nil {
return nil, err
}
if userData == nil {
// lets check external cache
key := newUser.IntegrationReference.CacheKey(account.Id, newUser.Id)
log.Debugf("looking up user %s of account %s in external cache", key, account.Id)
info, err := am.externalCacheManager.Get(am.ctx, key)
if err != nil {
log.Infof("Get ExternalCache for key: %s, error: %s", key, err)
return nil, status.Errorf(status.NotFound, "user %s not found in the IdP", newUser.Id)
}

return newUser.ToUserInfo(info)
}
return newUser.ToUserInfo(userData)
}
return newUser.ToUserInfo(nil)
Expand Down

0 comments on commit a7547b9

Please sign in to comment.