mirror of
https://github.com/netbirdio/netbird.git
synced 2025-06-24 11:41:35 +02:00
Get cache from external cache when refresh fails (#1537)
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
This commit is contained in:
parent
62bacee8dc
commit
a7547b9990
@ -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
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user