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: [2.4] optional db for grant/revoke v2 #856

Merged
merged 1 commit into from
Dec 10, 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
8 changes: 4 additions & 4 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,10 @@ type Client interface {
Grant(ctx context.Context, role string, objectType entity.PriviledgeObjectType, object string, privilege string, options ...entity.OperatePrivilegeOption) error
// Revoke removes privilege from role.
Revoke(ctx context.Context, role string, objectType entity.PriviledgeObjectType, object string, privilege string, options ...entity.OperatePrivilegeOption) error
// GrantV2 adds privilege for role.
GrantV2(ctx context.Context, role string, privilege string, dbName string, colName string) error
// RevokeV2 removes privilege from role.
RevokeV2(ctx context.Context, role string, privilege string, dbName string, colName string) error
// GrantV2 adds privilege for role. It will use default database if the option is not provided.
GrantV2(ctx context.Context, role string, colName string, privilege string, options ...entity.OperatePrivilegeOption) error
// RevokeV2 removes privilege from role. It will use default database if the option is not provided.
RevokeV2(ctx context.Context, role string, colName string, privilege string, options ...entity.OperatePrivilegeOption) error

// GetLoadingProgress get the collection or partitions loading progress
GetLoadingProgress(ctx context.Context, collectionName string, partitionNames []string) (int64, error)
Expand Down
16 changes: 12 additions & 4 deletions client/rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,11 +394,15 @@ func (c *GrpcClient) Revoke(ctx context.Context, role string, objectType entity.
}

// GrantV2 adds object privilege for role without object type
func (c *GrpcClient) GrantV2(ctx context.Context, role string, privilege string, dbName string, colName string) error {
func (c *GrpcClient) GrantV2(ctx context.Context, role string, colName string, privilege string, options ...entity.OperatePrivilegeOption) error {
if c.Service == nil {
return ErrClientNotReady
}

grantOpt := &entity.OperatePrivilegeOpt{}
for _, opt := range options {
opt(grantOpt)
}
req := &milvuspb.OperatePrivilegeV2Request{
Role: &milvuspb.RoleEntity{
Name: role,
Expand All @@ -409,7 +413,7 @@ func (c *GrpcClient) GrantV2(ctx context.Context, role string, privilege string,
},
},
Type: milvuspb.OperatePrivilegeType_Grant,
DbName: dbName,
DbName: grantOpt.Database,
CollectionName: colName,
}

Expand All @@ -422,11 +426,15 @@ func (c *GrpcClient) GrantV2(ctx context.Context, role string, privilege string,
}

// Revoke removes privilege from role without object type
func (c *GrpcClient) RevokeV2(ctx context.Context, role string, privilege string, dbName string, colName string) error {
func (c *GrpcClient) RevokeV2(ctx context.Context, role string, colName string, privilege string, options ...entity.OperatePrivilegeOption) error {
if c.Service == nil {
return ErrClientNotReady
}

revokeOpt := &entity.OperatePrivilegeOpt{}
for _, opt := range options {
opt(revokeOpt)
}
req := &milvuspb.OperatePrivilegeV2Request{
Role: &milvuspb.RoleEntity{
Name: role,
Expand All @@ -437,7 +445,7 @@ func (c *GrpcClient) RevokeV2(ctx context.Context, role string, privilege string
},
},
Type: milvuspb.OperatePrivilegeType_Revoke,
DbName: dbName,
DbName: revokeOpt.Database,
CollectionName: colName,
}

Expand Down
Loading