diff --git a/milvus/grpc/User.ts b/milvus/grpc/User.ts index 475c5d5a..9a4abaf7 100644 --- a/milvus/grpc/User.ts +++ b/milvus/grpc/User.ts @@ -572,7 +572,6 @@ export class User extends Resource { * @param {string} data.roleName - The name of the role. * @param {string} data.object - The type of the operational object to which the specified privilege belongs, such as Collection, Index, Partition, etc. This parameter is case-sensitive. * @param {string} data.objectName - The name of the object to which the role is granted the specified privilege. - * @param {string} data.privilegeName - The name of the privilege to be granted to the role. This parameter is case-sensitive. * @param {number} [data.timeout] - An optional duration of time in milliseconds to allow for the RPC. If it is set to undefined, the client keeps waiting until the server responds or error occurs. Default is undefined. * * @returns {Promise} The response object. @@ -586,30 +585,31 @@ export class User extends Resource { * roleName: 'roleName', * object: '*', * objectName: 'Collection', - * privilegeName: 'CreateIndex' * }); * ``` */ async selectGrant(data: SelectGrantReq): Promise { + const params: any = { + entity: { + role: { name: data.roleName }, + object: { name: data.object }, + object_name: data.objectName, + }, + }; + const promise = await promisify( this.channelPool, 'SelectGrant', - { - entity: { - role: { name: data.roleName }, - object: { name: data.object }, - object_name: data.objectName, - grantor: { - privilege: { name: data.privilegeName }, - }, - }, - }, + params, data.timeout || this.timeout ); return promise; } + // alias + listGrant = this.selectGrant; + /** * Lists all grants for a specific role. * diff --git a/milvus/types/User.ts b/milvus/types/User.ts index 1b6d08fd..fba62b3a 100644 --- a/milvus/types/User.ts +++ b/milvus/types/User.ts @@ -37,12 +37,15 @@ export interface listRoleReq extends GrpcTimeOut { export interface SelectUserReq extends usernameReq { includeRoleInfo?: boolean; // optional, include role info, default is false } -export interface OperateRolePrivilegeReq extends roleNameReq { + +export interface BaseGrantReq extends roleNameReq { object: RbacObjects; // Type of the operational object to which the specified privilege belongs, such as Collection, Index, Partition, etc. This parameter is case-sensitive. objectName: string; // Name of the object to which the role is granted the specified prvilege. +} +export interface OperateRolePrivilegeReq extends BaseGrantReq { privilegeName: PrivilegesTypes; // Name of the privilege to be granted to the role. This parameter is case-sensitive. } -export interface SelectGrantReq extends OperateRolePrivilegeReq {} +export interface SelectGrantReq extends BaseGrantReq {} export interface ListGrantsReq extends roleNameReq {} export interface ListCredUsersResponse extends resStatusResponse { diff --git a/test/grpc/User.spec.ts b/test/grpc/User.spec.ts index f6c21f16..6719d5f1 100644 --- a/test/grpc/User.spec.ts +++ b/test/grpc/User.spec.ts @@ -197,14 +197,15 @@ describe(`User Api`, () => { objectName: COLLECTION_NAME, privilegeName: Privileges.Search, }); - const alias = await authClient.grantPrivilege({ + const grant = await authClient.grantPrivilege({ roleName: ROLE_NAME, object: RbacObjects.Collection, objectName: COLLECTION_NAME, privilegeName: Privileges.Search, }); + expect(res.error_code).toEqual(ErrorCode.SUCCESS); - expect(alias.error_code).toEqual(ErrorCode.SUCCESS); + expect(grant.error_code).toEqual(ErrorCode.SUCCESS); }); it(`It should list grants successfully`, async () => { @@ -223,7 +224,6 @@ describe(`User Api`, () => { roleName: ROLE_NAME, object: RbacObjects.Collection, objectName: COLLECTION_NAME, - privilegeName: Privileges.Search, }); expect(res.status.error_code).toEqual(ErrorCode.SUCCESS); }); @@ -243,6 +243,7 @@ describe(`User Api`, () => { objectName: COLLECTION_NAME, privilegeName: Privileges.Search, }); + expect(res.error_code).toEqual(ErrorCode.SUCCESS); });