updatePermission
updatePermission
function is used to modify an existing permission within the RBAC (Role-Based Access Control) system on the PEAQ network. This function returns the JSON object with permission ID and a new name.
Parameters:
permissionId (string, required)
: ID of the permission to be updated.name (string, required)
: new name for the permission.address (address, optional)
: address associated with the operation (used for authentication).seed (string, optional)
: mnemonic seed used to generate cryptographic keys.
Code example
import { Sdk } from "@peaq-network/sdk";
/**
* Update an existing permission within the RBAC system.
* @param {string} permissionId - The ID of the permission to be updated (required).
* @param {string} name - The new name for the permission (required).
* @param {Address} [address] - The address associated with the operation (not required).
* @param {string} [seed] - The mnemonic seed (not required).
* @returns {Promise<Object>} A promise that resolves to an object with a 'message' field indicating the success of the operation.
*/
const updatePermission = async (permissionId, newName, seed) => {
const sdkInstance = await Sdk.createInstance({
baseUrl: "wss://wsspc1-qa.agung.peaq.network",
seed,
});
try {
await sdkInstance.connect();
const result = await sdkInstance.rbac.updatePermission({
name: newName,
permissionId: permissionId,
});
return result;
} finally {
await sdkInstance.disconnect();
}
};
// Example usage
const permissionId = "18709409-bc06-4444-2222-b4zz0000"; // Replace with the actual permission ID
const newName = "updatedPermissionName"; // Replace with the new name for the permission
const seed = "your-seed-phrase";
updatePermission(permissionId, newName, seed)
.then((result) => {
console.log(result);
})
.catch((error) => {
console.error("Error updating permission:", error);
});
Response object
{
message: "Successfully update permission 18709409-bc06-4444-2222-b4zz0000 with new name: updatedPermissionName"
}