Skip to content

Commit

Permalink
Fix: return empty when get users/groups if not specify tenantID (tkes…
Browse files Browse the repository at this point in the history
  • Loading branch information
yadzhang committed Feb 13, 2020
1 parent 684df86 commit 9fa27cb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
7 changes: 3 additions & 4 deletions pkg/auth/registry/group/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package storage

import (
"context"
"fmt"

"github.com/casbin/casbin/v2"
"tkestack.io/tke/pkg/auth/util"
Expand Down Expand Up @@ -117,19 +116,19 @@ func (r *REST) List(ctx context.Context, options *metainternal.ListOptions) (run
if tenantID == "" {
tenantID, _ = options.FieldSelector.RequiresExactMatch("spec.tenantID")
if tenantID == "" {
return nil, apierrors.NewBadRequest("List groups must specify tenantID")
return &auth.GroupList{}, nil
}
}
idp, ok := identityprovider.IdentityProvidersStore[tenantID]
if !ok {
log.Error("Tenant has no related identity providers", log.String("tenantID", tenantID))
return nil, apierrors.NewInternalError(fmt.Errorf("tenant %s has no related identity providers", tenantID))
return &auth.GroupList{}, nil
}

groupLister, ok := idp.(identityprovider.GroupLister)
if !ok {
log.Info("tenant %s related idp not implement UserLister interface", log.String("tenantID", tenantID))
return nil, apierrors.NewInternalError(fmt.Errorf("tenant must implement UserLister interface"))
return &auth.GroupList{}, nil
}

users, err := groupLister.ListGroups(ctx, options)
Expand Down
2 changes: 1 addition & 1 deletion pkg/auth/registry/user/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (r *REST) List(ctx context.Context, options *metainternal.ListOptions) (run
if tenantID == "" {
tenantID, _ = options.FieldSelector.RequiresExactMatch("spec.tenantID")
if tenantID == "" {
return nil, apierrors.NewBadRequest("List groups must specify tenantID")
return &auth.UserList{}, nil
}
}

Expand Down

0 comments on commit 9fa27cb

Please sign in to comment.