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

add listGrant alias #324

Merged
merged 1 commit into from
Jun 11, 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
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
Loading