GrantPrivilege()
This operation grants a privilege to a role on a specific object.
Status GrantPrivilege(const GrantPrivilegeRequest& request)
Request Syntax
auto request = GrantPrivilegeRequest()
.WithRoleName(name)
.WithObjectType(object_type)
.WithObjectName(object_name)
.WithPrivilege(privilege)
.WithDatabaseName(db_name);
REQUEST METHODS:
WithRoleName(const std::string& name)Sets the name of the role.
WithObjectType(const std::string& object_type)Sets the type of the target object, such as
CollectionorGlobal.WithObjectName(const std::string& object_name)Sets the name of the target object. Use
*to apply the privilege to all objects of the given type.WithPrivilege(const std::string& privilege)Sets the name of the privilege to grant. For available privileges, refer to Grant Privileges.
WithDatabaseName(const std::string& db_name)Sets the target database name. The default database applies if it is empty.
RETURNS:
Status
Check status.IsOk() to confirm success.
ERROR HANDLING:
Status
Failures are reported through the returned Status. The SDK converts internal exceptions into a non-OK Status; public API calls do not throw. Inspect
status.IsOk()andstatus.Message()for failure details. See Status.
Example
#include "milvus/MilvusClientV2.h"
auto client = milvus::MilvusClientV2::Create();
milvus::ConnectParam connect_param{"http://localhost:19530", "root:Milvus"};
auto status = client->Connect(connect_param);
if (!status.IsOk()) {
std::cout << status.Message() << std::endl;
}
status = client->GrantPrivilege(
milvus::GrantPrivilegeRequest()
.WithRoleName(role_name)
.WithObjectType("Collection")
.WithObjectName(collection_name)
.WithPrivilege("Search")
);
if (!status.IsOk()) {
std::cout << status.Message() << std::endl;
}