forked from baron/baron-sso
kratos SSOT 재설계
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-redis/redis/v8"
|
||||
@@ -199,6 +200,39 @@ func (s *RedisService) FlushIdentityCache(ctx context.Context) (domain.IdentityC
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *RedisService) ListIdentityMirrors(ctx context.Context) ([]KratosIdentity, error) {
|
||||
if s == nil || s.Client == nil {
|
||||
return nil, os.ErrInvalid
|
||||
}
|
||||
|
||||
keys, err := s.identityCacheKeys(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
identities := make([]KratosIdentity, 0, len(keys))
|
||||
for _, key := range keys {
|
||||
if key == "identity:mirror:state" || !strings.HasPrefix(key, "identity:mirror:") {
|
||||
continue
|
||||
}
|
||||
raw, err := s.Client.Get(ctx, key).Result()
|
||||
if err == redis.Nil {
|
||||
continue
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var identity KratosIdentity
|
||||
if err := json.Unmarshal([]byte(raw), &identity); err != nil {
|
||||
continue
|
||||
}
|
||||
if strings.TrimSpace(identity.ID) == "" {
|
||||
continue
|
||||
}
|
||||
identities = append(identities, identity)
|
||||
}
|
||||
return identities, nil
|
||||
}
|
||||
|
||||
func (s *RedisService) countIdentityCacheKeys(ctx context.Context) (int64, error) {
|
||||
keys, err := s.identityCacheKeys(ctx)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user