Skip to main content

GrantPrivilegeV2

This operation grants a privilege to a role using the v2 API with simplified parameters.

go
func (c *Client) GrantPrivilegeV2(ctx context.Context, option GrantPrivilegeV2Option, callOptions ...grpc.CallOption) error

Request Syntax​

Creates the request for GrantPrivilegeV2().

go
option := milvusclient.NewGrantPrivilegeV2Option(roleName, privilegeName, collectionName).
WithDbName(dbName)

err := client.GrantPrivilegeV2(ctx, option)

PARAMETERS:

  • roleName (string) -

    [REQUIRED]

    The name of the role.

  • privilegeName (string) -

    [REQUIRED]

    The name of the privilege.

  • collectionName (string) -

    [REQUIRED]

    The name of the target collection.

BUILDER METHODS:

  • NewGrantPrivilegeV2Option(roleName string, privilegeName string, collectionName string)

    Creates the request for GrantPrivilegeV2().

  • WithDbName(dbName string)

    Specifies the database to use for the operation.

RETURN TYPE:

error

RETURNS:

Returns nil on success, or an error describing what went wrong.

ERROR HANDLING:

  • error

    The operation fails. Check err != nil for failure details.

Example​

Demonstrates GrantPrivilegeV2() usage.

go
import (
"context"

"github.com/milvus-io/milvus/client/v3/milvusclient"
)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

cli, err := milvusclient.New(ctx, &milvusclient.ClientConfig{
Address: milvusAddr,
})
if err != nil {
// handle error
}

defer cli.Close(ctx)

err = cli.GrantPrivilegeV2(ctx, milvusclient.NewGrantPrivilegeV2Option("my_role", "Search", "quick_setup"))
if err != nil {
// handle error
}
Minimum SDK versionv3.0.x
Was this page helpful?