Skip to content

Commit

Permalink
add listGrant (#324)
Browse files Browse the repository at this point in the history
Signed-off-by: ryjiang <[email protected]>
  • Loading branch information
shanghaikid authored Jun 11, 2024
1 parent be48e5b commit 5fd43da
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
24 changes: 12 additions & 12 deletions milvus/grpc/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object>} The response object.
Expand All @@ -586,30 +585,31 @@ export class User extends Resource {
* roleName: 'roleName',
* object: '*',
* objectName: 'Collection',
* privilegeName: 'CreateIndex'
* });
* ```
*/
async selectGrant(data: SelectGrantReq): Promise<SelectGrantResponse> {
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.
*
Expand Down
7 changes: 5 additions & 2 deletions milvus/types/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 4 additions & 3 deletions test/grpc/User.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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);
});
Expand All @@ -243,6 +243,7 @@ describe(`User Api`, () => {
objectName: COLLECTION_NAME,
privilegeName: Privileges.Search,
});

expect(res.error_code).toEqual(ErrorCode.SUCCESS);
});

Expand Down

0 comments on commit 5fd43da

Please sign in to comment.