Compare commits

..

1 Commits

Author SHA1 Message Date
Maycon Santos
a7547b9990 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
2024-02-07 16:14:30 +01:00
2 changed files with 15 additions and 12 deletions

View File

@@ -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
}

View File

@@ -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)