Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
Signed-off-by: shaoting-huang <[email protected]>
  • Loading branch information
shaoting-huang committed Nov 18, 2024
1 parent 1d7bdc8 commit 5cfbba0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 47 deletions.
28 changes: 11 additions & 17 deletions internal/rootcoord/meta_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ type IMetaTable interface {
BackupRBAC(ctx context.Context, tenant string) (*milvuspb.RBACMeta, error)
RestoreRBAC(ctx context.Context, tenant string, meta *milvuspb.RBACMeta) error
IsCustomPrivilegeGroup(groupName string) (bool, error)
CreatePrivilegeGroup(groupName string, options ...bool) error
CreatePrivilegeGroup(groupName string) error
DropPrivilegeGroup(groupName string) error
ListPrivilegeGroups() ([]*milvuspb.PrivilegeGroupInfo, error)
OperatePrivilegeGroup(groupName string, privileges []*milvuspb.PrivilegeEntity, operateType milvuspb.OperatePrivilegeGroupType) error
Expand Down Expand Up @@ -1477,28 +1477,22 @@ func (mt *MetaTable) IsCustomPrivilegeGroup(groupName string) (bool, error) {
return false, nil
}

func (mt *MetaTable) CreatePrivilegeGroup(groupName string, options ...bool) error {
func (mt *MetaTable) CreatePrivilegeGroup(groupName string) error {
if funcutil.IsEmptyString(groupName) {
return fmt.Errorf("the privilege group name is empty")
}
skipValidation := false
if len(options) > 0 {
skipValidation = options[0]
}
mt.permissionLock.Lock()
defer mt.permissionLock.Unlock()

if !skipValidation {
definedByUsers, err := mt.IsCustomPrivilegeGroup(groupName)
if err != nil {
return err
}
if definedByUsers {
return merr.WrapErrParameterInvalidMsg("privilege group name [%s] is defined by users", groupName)
}
if util.IsPrivilegeNameDefined(groupName) {
return merr.WrapErrParameterInvalidMsg("privilege group name [%s] is defined by built in privileges or privilege groups in system", groupName)
}
definedByUsers, err := mt.IsCustomPrivilegeGroup(groupName)
if err != nil {
return err
}
if definedByUsers {
return merr.WrapErrParameterInvalidMsg("privilege group name [%s] is defined by users", groupName)
}
if util.IsPrivilegeNameDefined(groupName) {
return merr.WrapErrParameterInvalidMsg("privilege group name [%s] is defined by built in privileges or privilege groups in system", groupName)
}
data := &milvuspb.PrivilegeGroupInfo{
GroupName: groupName,
Expand Down
8 changes: 4 additions & 4 deletions internal/rootcoord/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ type mockMetaTable struct {
ListPolicyFunc func(tenant string) ([]string, error)
ListUserRoleFunc func(tenant string) ([]string, error)
DescribeDatabaseFunc func(ctx context.Context, dbName string) (*model.Database, error)
CreatePrivilegeGroupFunc func(groupName string, options ...bool) error
CreatePrivilegeGroupFunc func(groupName string) error
DropPrivilegeGroupFunc func(groupName string) error
ListPrivilegeGroupsFunc func() ([]*milvuspb.PrivilegeGroupInfo, error)
OperatePrivilegeGroupFunc func(groupName string, privileges []*milvuspb.PrivilegeEntity, operateType milvuspb.OperatePrivilegeGroupType) error
Expand Down Expand Up @@ -256,8 +256,8 @@ func (m mockMetaTable) ListUserRole(tenant string) ([]string, error) {
return m.ListUserRoleFunc(tenant)
}

func (m mockMetaTable) CreatePrivilegeGroup(groupName string, options ...bool) error {
return m.CreatePrivilegeGroupFunc(groupName, options...)
func (m mockMetaTable) CreatePrivilegeGroup(groupName string) error {
return m.CreatePrivilegeGroupFunc(groupName)
}

func (m mockMetaTable) DropPrivilegeGroup(groupName string) error {
Expand Down Expand Up @@ -552,7 +552,7 @@ func withInvalidMeta() Opt {
meta.DescribeDatabaseFunc = func(ctx context.Context, dbName string) (*model.Database, error) {
return nil, errors.New("error mock DescribeDatabase")
}
meta.CreatePrivilegeGroupFunc = func(groupName string, options ...bool) error {
meta.CreatePrivilegeGroupFunc = func(groupName string) error {
return errors.New("error mock CreatePrivilegeGroup")
}
meta.DropPrivilegeGroupFunc = func(groupName string) error {
Expand Down
35 changes: 10 additions & 25 deletions internal/rootcoord/mocks/meta_table.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/rootcoord/root_coord_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1792,7 +1792,7 @@ func TestRootCoord_RBACError(t *testing.T) {
mockMeta.ListPrivilegeGroupsFunc = func() ([]*milvuspb.PrivilegeGroupInfo, error) {
return nil, errors.New("mock error")
}
mockMeta.CreatePrivilegeGroupFunc = func(groupName string, options ...bool) error {
mockMeta.CreatePrivilegeGroupFunc = func(groupName string) error {
return errors.New("mock error")
}
mockMeta.GetPrivilegeGroupRolesFunc = func(groupName string) ([]*milvuspb.RoleEntity, error) {
Expand Down

0 comments on commit 5cfbba0

Please sign in to comment.