148 lines
4.0 KiB
Go
148 lines
4.0 KiB
Go
// Code generated by sdkgen. DO NOT EDIT.
|
|
|
|
//nolint
|
|
package clickhouse
|
|
|
|
import (
|
|
"context"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
clickhouse "github.com/yandex-cloud/go-genproto/yandex/cloud/mdb/clickhouse/v1"
|
|
"github.com/yandex-cloud/go-genproto/yandex/cloud/operation"
|
|
)
|
|
|
|
//revive:disable
|
|
|
|
// UserServiceClient is a clickhouse.UserServiceClient with
|
|
// lazy GRPC connection initialization.
|
|
type UserServiceClient struct {
|
|
getConn func(ctx context.Context) (*grpc.ClientConn, error)
|
|
}
|
|
|
|
// Create implements clickhouse.UserServiceClient
|
|
func (c *UserServiceClient) Create(ctx context.Context, in *clickhouse.CreateUserRequest, opts ...grpc.CallOption) (*operation.Operation, error) {
|
|
conn, err := c.getConn(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return clickhouse.NewUserServiceClient(conn).Create(ctx, in, opts...)
|
|
}
|
|
|
|
// Delete implements clickhouse.UserServiceClient
|
|
func (c *UserServiceClient) Delete(ctx context.Context, in *clickhouse.DeleteUserRequest, opts ...grpc.CallOption) (*operation.Operation, error) {
|
|
conn, err := c.getConn(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return clickhouse.NewUserServiceClient(conn).Delete(ctx, in, opts...)
|
|
}
|
|
|
|
// Get implements clickhouse.UserServiceClient
|
|
func (c *UserServiceClient) Get(ctx context.Context, in *clickhouse.GetUserRequest, opts ...grpc.CallOption) (*clickhouse.User, error) {
|
|
conn, err := c.getConn(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return clickhouse.NewUserServiceClient(conn).Get(ctx, in, opts...)
|
|
}
|
|
|
|
// GrantPermission implements clickhouse.UserServiceClient
|
|
func (c *UserServiceClient) GrantPermission(ctx context.Context, in *clickhouse.GrantUserPermissionRequest, opts ...grpc.CallOption) (*operation.Operation, error) {
|
|
conn, err := c.getConn(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return clickhouse.NewUserServiceClient(conn).GrantPermission(ctx, in, opts...)
|
|
}
|
|
|
|
// List implements clickhouse.UserServiceClient
|
|
func (c *UserServiceClient) List(ctx context.Context, in *clickhouse.ListUsersRequest, opts ...grpc.CallOption) (*clickhouse.ListUsersResponse, error) {
|
|
conn, err := c.getConn(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return clickhouse.NewUserServiceClient(conn).List(ctx, in, opts...)
|
|
}
|
|
|
|
type UserIterator struct {
|
|
ctx context.Context
|
|
opts []grpc.CallOption
|
|
|
|
err error
|
|
started bool
|
|
|
|
client *UserServiceClient
|
|
request *clickhouse.ListUsersRequest
|
|
|
|
items []*clickhouse.User
|
|
}
|
|
|
|
func (c *UserServiceClient) UserIterator(ctx context.Context, clusterId string, opts ...grpc.CallOption) *UserIterator {
|
|
return &UserIterator{
|
|
ctx: ctx,
|
|
opts: opts,
|
|
client: c,
|
|
request: &clickhouse.ListUsersRequest{
|
|
ClusterId: clusterId,
|
|
PageSize: 1000,
|
|
},
|
|
}
|
|
}
|
|
|
|
func (it *UserIterator) Next() bool {
|
|
if it.err != nil {
|
|
return false
|
|
}
|
|
if len(it.items) > 1 {
|
|
it.items[0] = nil
|
|
it.items = it.items[1:]
|
|
return true
|
|
}
|
|
it.items = nil // consume last item, if any
|
|
|
|
if it.started && it.request.PageToken == "" {
|
|
return false
|
|
}
|
|
it.started = true
|
|
|
|
response, err := it.client.List(it.ctx, it.request, it.opts...)
|
|
it.err = err
|
|
if err != nil {
|
|
return false
|
|
}
|
|
|
|
it.items = response.Users
|
|
it.request.PageToken = response.NextPageToken
|
|
return len(it.items) > 0
|
|
}
|
|
|
|
func (it *UserIterator) Value() *clickhouse.User {
|
|
if len(it.items) == 0 {
|
|
panic("calling Value on empty iterator")
|
|
}
|
|
return it.items[0]
|
|
}
|
|
|
|
func (it *UserIterator) Error() error {
|
|
return it.err
|
|
}
|
|
|
|
// RevokePermission implements clickhouse.UserServiceClient
|
|
func (c *UserServiceClient) RevokePermission(ctx context.Context, in *clickhouse.RevokeUserPermissionRequest, opts ...grpc.CallOption) (*operation.Operation, error) {
|
|
conn, err := c.getConn(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return clickhouse.NewUserServiceClient(conn).RevokePermission(ctx, in, opts...)
|
|
}
|
|
|
|
// Update implements clickhouse.UserServiceClient
|
|
func (c *UserServiceClient) Update(ctx context.Context, in *clickhouse.UpdateUserRequest, opts ...grpc.CallOption) (*operation.Operation, error) {
|
|
conn, err := c.getConn(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return clickhouse.NewUserServiceClient(conn).Update(ctx, in, opts...)
|
|
}
|