Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix broken Grant() call #784

Merged
merged 1 commit into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ type Client interface {
// ListGrants lists all assigned privileges and objects for the role.
ListGrants(ctx context.Context, role string, dbName string) ([]entity.RoleGrants, error)
// Grant adds privilege for role.
Grant(ctx context.Context, role string, objectType entity.PriviledgeObjectType, object string) error
Grant(ctx context.Context, role string, objectType entity.PriviledgeObjectType, object string, privilege string) error
// Revoke removes privilege from role.
Revoke(ctx context.Context, role string, objectType entity.PriviledgeObjectType, object string) error

Expand Down
7 changes: 6 additions & 1 deletion client/rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ func (c *GrpcClient) ListGrant(ctx context.Context, role string, object string,
}

// Grant adds object privileged for role.
func (c *GrpcClient) Grant(ctx context.Context, role string, objectType entity.PriviledgeObjectType, object string) error {
func (c *GrpcClient) Grant(ctx context.Context, role string, objectType entity.PriviledgeObjectType, object string, privilege string) error {
if c.Service == nil {
return ErrClientNotReady
}
Expand All @@ -333,6 +333,11 @@ func (c *GrpcClient) Grant(ctx context.Context, role string, objectType entity.P
Object: &milvuspb.ObjectEntity{
Name: commonpb.ObjectType_name[int32(objectType)],
},
Grantor: &milvuspb.GrantorEntity{
Privilege: &milvuspb.PrivilegeEntity{
Name: privilege,
},
},
ObjectName: object,
},
Type: milvuspb.OperatePrivilegeType_Grant,
Expand Down
9 changes: 5 additions & 4 deletions client/rbac_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,7 @@ func (s *RBACSuite) TestGrant() {
roleName := "testRole"
objectName := testCollectionName
objectType := entity.PriviledegeObjectTypeCollection
privilegeName := "testPrivilege"

s.Run("normal run", func() {
ctx, cancel := context.WithCancel(ctx)
Expand All @@ -641,7 +642,7 @@ func (s *RBACSuite) TestGrant() {
s.Equal(milvuspb.OperatePrivilegeType_Grant, req.GetType())
}).Return(&commonpb.Status{ErrorCode: commonpb.ErrorCode_Success}, nil)

err := s.client.Grant(ctx, roleName, objectType, objectName)
err := s.client.Grant(ctx, roleName, objectType, objectName, privilegeName)

s.NoError(err)
})
Expand All @@ -652,7 +653,7 @@ func (s *RBACSuite) TestGrant() {
defer s.resetMock()
s.mock.EXPECT().OperatePrivilege(mock.Anything, mock.Anything).Return(nil, errors.New("mock error"))

err := s.client.Grant(ctx, roleName, objectType, objectName)
err := s.client.Grant(ctx, roleName, objectType, objectName, privilegeName)
s.Error(err)
})

Expand All @@ -662,7 +663,7 @@ func (s *RBACSuite) TestGrant() {
defer s.resetMock()
s.mock.EXPECT().OperatePrivilege(mock.Anything, mock.Anything).Return(&commonpb.Status{ErrorCode: commonpb.ErrorCode_UnexpectedError}, nil)

err := s.client.Grant(ctx, roleName, objectType, objectName)
err := s.client.Grant(ctx, roleName, objectType, objectName, privilegeName)
s.Error(err)
})

Expand All @@ -671,7 +672,7 @@ func (s *RBACSuite) TestGrant() {
defer cancel()

c := &GrpcClient{}
err := c.Grant(ctx, roleName, objectType, objectName)
err := c.Grant(ctx, roleName, objectType, objectName, privilegeName)
s.Error(err)
s.ErrorIs(err, ErrClientNotReady)
})
Expand Down
Loading