Zanzana: Refactor stores listing (#99098)

Zanzana: Refactor store loading
pull/99009/head
Alexander Zobnin 4 months ago committed by GitHub
parent 5e23b2c07f
commit c5f14407cc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 35
      pkg/services/authz/zanzana/server/server_store.go

@ -40,40 +40,25 @@ func (s *Server) getStoreInfo(ctx context.Context, namespace string) (*storeInfo
}
func (s *Server) getOrCreateStore(ctx context.Context, namespace string) (*openfgav1.Store, error) {
var continuationToken string
for {
res, err := s.openfga.ListStores(ctx, &openfgav1.ListStoresRequest{
PageSize: &wrapperspb.Int32Value{Value: 100},
ContinuationToken: continuationToken,
})
if err != nil {
return nil, fmt.Errorf("failed to load zanzana stores: %w", err)
}
for _, s := range res.GetStores() {
if s.GetName() == namespace {
return s, nil
}
}
res, err := s.openfga.ListStores(ctx, &openfgav1.ListStoresRequest{Name: namespace})
if err != nil {
return nil, fmt.Errorf("failed to load zanzana stores: %w", err)
}
// we have no more stores to check
if res.GetContinuationToken() == "" {
break
for _, s := range res.GetStores() {
if s.GetName() == namespace {
return s, nil
}
continuationToken = res.GetContinuationToken()
}
res, err := s.openfga.CreateStore(ctx, &openfgav1.CreateStoreRequest{Name: namespace})
createStoreRes, err := s.openfga.CreateStore(ctx, &openfgav1.CreateStoreRequest{Name: namespace})
if err != nil {
return nil, err
}
return &openfgav1.Store{
Id: res.GetId(),
Name: res.GetName(),
Id: createStoreRes.GetId(),
Name: createStoreRes.GetName(),
}, nil
}

Loading…
Cancel
Save