Skip to content
Open
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
62 changes: 52 additions & 10 deletions milvus/grpc/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
ListUsersReq,
UpdateUserReq,
CreateRoleReq,
AlterRoleReq,
DropRoleReq,
AddUserToRoleReq,
RemoveUserFromRoleReq,
Expand Down Expand Up @@ -73,6 +74,7 @@ export class User extends Resource {
{
username: data.username,
password: encryptedPassword,
description: data.description,
},
data.timeout || this.timeout
);
Expand Down Expand Up @@ -102,24 +104,31 @@ export class User extends Resource {
* ```
*/
async updateUser(data: UpdateUserReq): Promise<ResStatus> {
const hasDescription = data.description !== undefined;
const hasPassword = data.newPassword !== undefined;

if (
data.username === undefined ||
data.newPassword === undefined ||
data.oldPassword === undefined
(!hasDescription && !hasPassword) ||
(hasPassword && data.oldPassword === undefined)
) {
throw new Error(ERROR_REASONS.USERNAME_PWD_ARE_REQUIRED);
}
const encryptedOldPwd = stringToBase64(data.oldPassword);
const encryptedNewPwd = stringToBase64(data.newPassword);

const req: any = {
username: data.username,
...(hasDescription ? { description: data.description } : {}),
};

if (hasPassword) {
req.oldPassword = stringToBase64(data.oldPassword!);
req.newPassword = stringToBase64(data.newPassword!);
}

const promise = await promisify(
this.channelPool,
'UpdateCredential',
{
username: data.username,
oldPassword: encryptedOldPwd,
newPassword: encryptedNewPwd,
},
req,
data.timeout || this.timeout
);
return promise;
Expand Down Expand Up @@ -210,7 +219,40 @@ export class User extends Resource {
this.channelPool,
'CreateRole',
{
entity: { name: data.roleName },
entity: { name: data.roleName, description: data.description },
},
data.timeout || this.timeout
);
return promise;
}

/**
* Alters a role in Milvus.
*
* @param {AlterRoleReq} data - The role data.
* @param {string} data.roleName - The name of the role to alter.
* @param {string} data.description - The new role description.
* @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<ResStatus>} The response status.
* @returns {number} ResStatus.error_code - The error code number.
* @returns {string} ResStatus.reason - The cause of the error, if any.
*
* @example
* ```javascript
* milvusClient.alterRole({
* roleName: 'exampleRole',
* description: 'example role description',
* });
* ```
*/
async alterRole(data: AlterRoleReq): Promise<ResStatus> {
const promise = await promisify(
this.channelPool,
'AlterRole',
{
role_name: data.roleName,
description: data.description,
},
data.timeout || this.timeout
);
Expand Down
Loading
Loading