cloud.google.com/go/aiplatform@v1.106.0/apiv1beta1/index_client.go (about)

     1  // Copyright 2025 Google LLC
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     https://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // Code generated by protoc-gen-go_gapic. DO NOT EDIT.
    16  
    17  package aiplatform
    18  
    19  import (
    20  	"bytes"
    21  	"context"
    22  	"fmt"
    23  	"log/slog"
    24  	"math"
    25  	"net/http"
    26  	"net/url"
    27  	"time"
    28  
    29  	aiplatformpb "cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb"
    30  	iampb "cloud.google.com/go/iam/apiv1/iampb"
    31  	"cloud.google.com/go/longrunning"
    32  	lroauto "cloud.google.com/go/longrunning/autogen"
    33  	longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb"
    34  	gax "github.com/googleapis/gax-go/v2"
    35  	"google.golang.org/api/iterator"
    36  	"google.golang.org/api/option"
    37  	"google.golang.org/api/option/internaloption"
    38  	gtransport "google.golang.org/api/transport/grpc"
    39  	httptransport "google.golang.org/api/transport/http"
    40  	locationpb "google.golang.org/genproto/googleapis/cloud/location"
    41  	"google.golang.org/grpc"
    42  	"google.golang.org/protobuf/encoding/protojson"
    43  	"google.golang.org/protobuf/proto"
    44  )
    45  
    46  var newIndexClientHook clientHook
    47  
    48  // IndexCallOptions contains the retry settings for each method of IndexClient.
    49  type IndexCallOptions struct {
    50  	CreateIndex        []gax.CallOption
    51  	GetIndex           []gax.CallOption
    52  	ImportIndex        []gax.CallOption
    53  	ListIndexes        []gax.CallOption
    54  	UpdateIndex        []gax.CallOption
    55  	DeleteIndex        []gax.CallOption
    56  	UpsertDatapoints   []gax.CallOption
    57  	RemoveDatapoints   []gax.CallOption
    58  	GetLocation        []gax.CallOption
    59  	ListLocations      []gax.CallOption
    60  	GetIamPolicy       []gax.CallOption
    61  	SetIamPolicy       []gax.CallOption
    62  	TestIamPermissions []gax.CallOption
    63  	CancelOperation    []gax.CallOption
    64  	DeleteOperation    []gax.CallOption
    65  	GetOperation       []gax.CallOption
    66  	ListOperations     []gax.CallOption
    67  	WaitOperation      []gax.CallOption
    68  }
    69  
    70  func defaultIndexGRPCClientOptions() []option.ClientOption {
    71  	return []option.ClientOption{
    72  		internaloption.WithDefaultEndpoint("aiplatform.googleapis.com:443"),
    73  		internaloption.WithDefaultEndpointTemplate("aiplatform.UNIVERSE_DOMAIN:443"),
    74  		internaloption.WithDefaultMTLSEndpoint("aiplatform.mtls.googleapis.com:443"),
    75  		internaloption.WithDefaultUniverseDomain("googleapis.com"),
    76  		internaloption.WithDefaultAudience("https://aiplatform.googleapis.com/"),
    77  		internaloption.WithDefaultScopes(DefaultAuthScopes()...),
    78  		internaloption.EnableJwtWithScope(),
    79  		internaloption.EnableNewAuthLibrary(),
    80  		option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
    81  			grpc.MaxCallRecvMsgSize(math.MaxInt32))),
    82  	}
    83  }
    84  
    85  func defaultIndexCallOptions() *IndexCallOptions {
    86  	return &IndexCallOptions{
    87  		CreateIndex: []gax.CallOption{
    88  			gax.WithTimeout(5000 * time.Millisecond),
    89  		},
    90  		GetIndex: []gax.CallOption{
    91  			gax.WithTimeout(5000 * time.Millisecond),
    92  		},
    93  		ImportIndex: []gax.CallOption{},
    94  		ListIndexes: []gax.CallOption{
    95  			gax.WithTimeout(5000 * time.Millisecond),
    96  		},
    97  		UpdateIndex: []gax.CallOption{
    98  			gax.WithTimeout(5000 * time.Millisecond),
    99  		},
   100  		DeleteIndex: []gax.CallOption{
   101  			gax.WithTimeout(5000 * time.Millisecond),
   102  		},
   103  		UpsertDatapoints:   []gax.CallOption{},
   104  		RemoveDatapoints:   []gax.CallOption{},
   105  		GetLocation:        []gax.CallOption{},
   106  		ListLocations:      []gax.CallOption{},
   107  		GetIamPolicy:       []gax.CallOption{},
   108  		SetIamPolicy:       []gax.CallOption{},
   109  		TestIamPermissions: []gax.CallOption{},
   110  		CancelOperation:    []gax.CallOption{},
   111  		DeleteOperation:    []gax.CallOption{},
   112  		GetOperation:       []gax.CallOption{},
   113  		ListOperations:     []gax.CallOption{},
   114  		WaitOperation:      []gax.CallOption{},
   115  	}
   116  }
   117  
   118  func defaultIndexRESTCallOptions() *IndexCallOptions {
   119  	return &IndexCallOptions{
   120  		CreateIndex: []gax.CallOption{
   121  			gax.WithTimeout(5000 * time.Millisecond),
   122  		},
   123  		GetIndex: []gax.CallOption{
   124  			gax.WithTimeout(5000 * time.Millisecond),
   125  		},
   126  		ImportIndex: []gax.CallOption{},
   127  		ListIndexes: []gax.CallOption{
   128  			gax.WithTimeout(5000 * time.Millisecond),
   129  		},
   130  		UpdateIndex: []gax.CallOption{
   131  			gax.WithTimeout(5000 * time.Millisecond),
   132  		},
   133  		DeleteIndex: []gax.CallOption{
   134  			gax.WithTimeout(5000 * time.Millisecond),
   135  		},
   136  		UpsertDatapoints:   []gax.CallOption{},
   137  		RemoveDatapoints:   []gax.CallOption{},
   138  		GetLocation:        []gax.CallOption{},
   139  		ListLocations:      []gax.CallOption{},
   140  		GetIamPolicy:       []gax.CallOption{},
   141  		SetIamPolicy:       []gax.CallOption{},
   142  		TestIamPermissions: []gax.CallOption{},
   143  		CancelOperation:    []gax.CallOption{},
   144  		DeleteOperation:    []gax.CallOption{},
   145  		GetOperation:       []gax.CallOption{},
   146  		ListOperations:     []gax.CallOption{},
   147  		WaitOperation:      []gax.CallOption{},
   148  	}
   149  }
   150  
   151  // internalIndexClient is an interface that defines the methods available from Vertex AI API.
   152  type internalIndexClient interface {
   153  	Close() error
   154  	setGoogleClientInfo(...string)
   155  	Connection() *grpc.ClientConn
   156  	CreateIndex(context.Context, *aiplatformpb.CreateIndexRequest, ...gax.CallOption) (*CreateIndexOperation, error)
   157  	CreateIndexOperation(name string) *CreateIndexOperation
   158  	GetIndex(context.Context, *aiplatformpb.GetIndexRequest, ...gax.CallOption) (*aiplatformpb.Index, error)
   159  	ImportIndex(context.Context, *aiplatformpb.ImportIndexRequest, ...gax.CallOption) (*ImportIndexOperation, error)
   160  	ImportIndexOperation(name string) *ImportIndexOperation
   161  	ListIndexes(context.Context, *aiplatformpb.ListIndexesRequest, ...gax.CallOption) *IndexIterator
   162  	UpdateIndex(context.Context, *aiplatformpb.UpdateIndexRequest, ...gax.CallOption) (*UpdateIndexOperation, error)
   163  	UpdateIndexOperation(name string) *UpdateIndexOperation
   164  	DeleteIndex(context.Context, *aiplatformpb.DeleteIndexRequest, ...gax.CallOption) (*DeleteIndexOperation, error)
   165  	DeleteIndexOperation(name string) *DeleteIndexOperation
   166  	UpsertDatapoints(context.Context, *aiplatformpb.UpsertDatapointsRequest, ...gax.CallOption) (*aiplatformpb.UpsertDatapointsResponse, error)
   167  	RemoveDatapoints(context.Context, *aiplatformpb.RemoveDatapointsRequest, ...gax.CallOption) (*aiplatformpb.RemoveDatapointsResponse, error)
   168  	GetLocation(context.Context, *locationpb.GetLocationRequest, ...gax.CallOption) (*locationpb.Location, error)
   169  	ListLocations(context.Context, *locationpb.ListLocationsRequest, ...gax.CallOption) *LocationIterator
   170  	GetIamPolicy(context.Context, *iampb.GetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
   171  	SetIamPolicy(context.Context, *iampb.SetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
   172  	TestIamPermissions(context.Context, *iampb.TestIamPermissionsRequest, ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error)
   173  	CancelOperation(context.Context, *longrunningpb.CancelOperationRequest, ...gax.CallOption) error
   174  	DeleteOperation(context.Context, *longrunningpb.DeleteOperationRequest, ...gax.CallOption) error
   175  	GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error)
   176  	ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator
   177  	WaitOperation(context.Context, *longrunningpb.WaitOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error)
   178  }
   179  
   180  // IndexClient is a client for interacting with Vertex AI API.
   181  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   182  //
   183  // A service for creating and managing Vertex AI’s Index resources.
   184  type IndexClient struct {
   185  	// The internal transport-dependent client.
   186  	internalClient internalIndexClient
   187  
   188  	// The call options for this service.
   189  	CallOptions *IndexCallOptions
   190  
   191  	// LROClient is used internally to handle long-running operations.
   192  	// It is exposed so that its CallOptions can be modified if required.
   193  	// Users should not Close this client.
   194  	LROClient *lroauto.OperationsClient
   195  }
   196  
   197  // Wrapper methods routed to the internal client.
   198  
   199  // Close closes the connection to the API service. The user should invoke this when
   200  // the client is no longer required.
   201  func (c *IndexClient) Close() error {
   202  	return c.internalClient.Close()
   203  }
   204  
   205  // setGoogleClientInfo sets the name and version of the application in
   206  // the `x-goog-api-client` header passed on each request. Intended for
   207  // use by Google-written clients.
   208  func (c *IndexClient) setGoogleClientInfo(keyval ...string) {
   209  	c.internalClient.setGoogleClientInfo(keyval...)
   210  }
   211  
   212  // Connection returns a connection to the API service.
   213  //
   214  // Deprecated: Connections are now pooled so this method does not always
   215  // return the same resource.
   216  func (c *IndexClient) Connection() *grpc.ClientConn {
   217  	return c.internalClient.Connection()
   218  }
   219  
   220  // CreateIndex creates an Index.
   221  func (c *IndexClient) CreateIndex(ctx context.Context, req *aiplatformpb.CreateIndexRequest, opts ...gax.CallOption) (*CreateIndexOperation, error) {
   222  	return c.internalClient.CreateIndex(ctx, req, opts...)
   223  }
   224  
   225  // CreateIndexOperation returns a new CreateIndexOperation from a given name.
   226  // The name must be that of a previously created CreateIndexOperation, possibly from a different process.
   227  func (c *IndexClient) CreateIndexOperation(name string) *CreateIndexOperation {
   228  	return c.internalClient.CreateIndexOperation(name)
   229  }
   230  
   231  // GetIndex gets an Index.
   232  func (c *IndexClient) GetIndex(ctx context.Context, req *aiplatformpb.GetIndexRequest, opts ...gax.CallOption) (*aiplatformpb.Index, error) {
   233  	return c.internalClient.GetIndex(ctx, req, opts...)
   234  }
   235  
   236  // ImportIndex imports an Index from an external source (e.g., BigQuery).
   237  func (c *IndexClient) ImportIndex(ctx context.Context, req *aiplatformpb.ImportIndexRequest, opts ...gax.CallOption) (*ImportIndexOperation, error) {
   238  	return c.internalClient.ImportIndex(ctx, req, opts...)
   239  }
   240  
   241  // ImportIndexOperation returns a new ImportIndexOperation from a given name.
   242  // The name must be that of a previously created ImportIndexOperation, possibly from a different process.
   243  func (c *IndexClient) ImportIndexOperation(name string) *ImportIndexOperation {
   244  	return c.internalClient.ImportIndexOperation(name)
   245  }
   246  
   247  // ListIndexes lists Indexes in a Location.
   248  func (c *IndexClient) ListIndexes(ctx context.Context, req *aiplatformpb.ListIndexesRequest, opts ...gax.CallOption) *IndexIterator {
   249  	return c.internalClient.ListIndexes(ctx, req, opts...)
   250  }
   251  
   252  // UpdateIndex updates an Index.
   253  func (c *IndexClient) UpdateIndex(ctx context.Context, req *aiplatformpb.UpdateIndexRequest, opts ...gax.CallOption) (*UpdateIndexOperation, error) {
   254  	return c.internalClient.UpdateIndex(ctx, req, opts...)
   255  }
   256  
   257  // UpdateIndexOperation returns a new UpdateIndexOperation from a given name.
   258  // The name must be that of a previously created UpdateIndexOperation, possibly from a different process.
   259  func (c *IndexClient) UpdateIndexOperation(name string) *UpdateIndexOperation {
   260  	return c.internalClient.UpdateIndexOperation(name)
   261  }
   262  
   263  // DeleteIndex deletes an Index.
   264  // An Index can only be deleted when all its
   265  // DeployedIndexes
   266  // had been undeployed.
   267  func (c *IndexClient) DeleteIndex(ctx context.Context, req *aiplatformpb.DeleteIndexRequest, opts ...gax.CallOption) (*DeleteIndexOperation, error) {
   268  	return c.internalClient.DeleteIndex(ctx, req, opts...)
   269  }
   270  
   271  // DeleteIndexOperation returns a new DeleteIndexOperation from a given name.
   272  // The name must be that of a previously created DeleteIndexOperation, possibly from a different process.
   273  func (c *IndexClient) DeleteIndexOperation(name string) *DeleteIndexOperation {
   274  	return c.internalClient.DeleteIndexOperation(name)
   275  }
   276  
   277  // UpsertDatapoints add/update Datapoints into an Index.
   278  func (c *IndexClient) UpsertDatapoints(ctx context.Context, req *aiplatformpb.UpsertDatapointsRequest, opts ...gax.CallOption) (*aiplatformpb.UpsertDatapointsResponse, error) {
   279  	return c.internalClient.UpsertDatapoints(ctx, req, opts...)
   280  }
   281  
   282  // RemoveDatapoints remove Datapoints from an Index.
   283  func (c *IndexClient) RemoveDatapoints(ctx context.Context, req *aiplatformpb.RemoveDatapointsRequest, opts ...gax.CallOption) (*aiplatformpb.RemoveDatapointsResponse, error) {
   284  	return c.internalClient.RemoveDatapoints(ctx, req, opts...)
   285  }
   286  
   287  // GetLocation gets information about a location.
   288  func (c *IndexClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) {
   289  	return c.internalClient.GetLocation(ctx, req, opts...)
   290  }
   291  
   292  // ListLocations lists information about the supported locations for this service.
   293  func (c *IndexClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator {
   294  	return c.internalClient.ListLocations(ctx, req, opts...)
   295  }
   296  
   297  // GetIamPolicy gets the access control policy for a resource. Returns an empty policy
   298  // if the resource exists and does not have a policy set.
   299  func (c *IndexClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   300  	return c.internalClient.GetIamPolicy(ctx, req, opts...)
   301  }
   302  
   303  // SetIamPolicy sets the access control policy on the specified resource. Replaces
   304  // any existing policy.
   305  //
   306  // Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED
   307  // errors.
   308  func (c *IndexClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   309  	return c.internalClient.SetIamPolicy(ctx, req, opts...)
   310  }
   311  
   312  // TestIamPermissions returns permissions that a caller has on the specified resource. If the
   313  // resource does not exist, this will return an empty set of
   314  // permissions, not a NOT_FOUND error.
   315  //
   316  // Note: This operation is designed to be used for building
   317  // permission-aware UIs and command-line tools, not for authorization
   318  // checking. This operation may “fail open” without warning.
   319  func (c *IndexClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
   320  	return c.internalClient.TestIamPermissions(ctx, req, opts...)
   321  }
   322  
   323  // CancelOperation is a utility method from google.longrunning.Operations.
   324  func (c *IndexClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
   325  	return c.internalClient.CancelOperation(ctx, req, opts...)
   326  }
   327  
   328  // DeleteOperation is a utility method from google.longrunning.Operations.
   329  func (c *IndexClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
   330  	return c.internalClient.DeleteOperation(ctx, req, opts...)
   331  }
   332  
   333  // GetOperation is a utility method from google.longrunning.Operations.
   334  func (c *IndexClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
   335  	return c.internalClient.GetOperation(ctx, req, opts...)
   336  }
   337  
   338  // ListOperations is a utility method from google.longrunning.Operations.
   339  func (c *IndexClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
   340  	return c.internalClient.ListOperations(ctx, req, opts...)
   341  }
   342  
   343  // WaitOperation is a utility method from google.longrunning.Operations.
   344  func (c *IndexClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
   345  	return c.internalClient.WaitOperation(ctx, req, opts...)
   346  }
   347  
   348  // indexGRPCClient is a client for interacting with Vertex AI API over gRPC transport.
   349  //
   350  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   351  type indexGRPCClient struct {
   352  	// Connection pool of gRPC connections to the service.
   353  	connPool gtransport.ConnPool
   354  
   355  	// Points back to the CallOptions field of the containing IndexClient
   356  	CallOptions **IndexCallOptions
   357  
   358  	// The gRPC API client.
   359  	indexClient aiplatformpb.IndexServiceClient
   360  
   361  	// LROClient is used internally to handle long-running operations.
   362  	// It is exposed so that its CallOptions can be modified if required.
   363  	// Users should not Close this client.
   364  	LROClient **lroauto.OperationsClient
   365  
   366  	operationsClient longrunningpb.OperationsClient
   367  
   368  	iamPolicyClient iampb.IAMPolicyClient
   369  
   370  	locationsClient locationpb.LocationsClient
   371  
   372  	// The x-goog-* metadata to be sent with each request.
   373  	xGoogHeaders []string
   374  
   375  	logger *slog.Logger
   376  }
   377  
   378  // NewIndexClient creates a new index service client based on gRPC.
   379  // The returned client must be Closed when it is done being used to clean up its underlying connections.
   380  //
   381  // A service for creating and managing Vertex AI’s Index resources.
   382  func NewIndexClient(ctx context.Context, opts ...option.ClientOption) (*IndexClient, error) {
   383  	clientOpts := defaultIndexGRPCClientOptions()
   384  	if newIndexClientHook != nil {
   385  		hookOpts, err := newIndexClientHook(ctx, clientHookParams{})
   386  		if err != nil {
   387  			return nil, err
   388  		}
   389  		clientOpts = append(clientOpts, hookOpts...)
   390  	}
   391  
   392  	connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
   393  	if err != nil {
   394  		return nil, err
   395  	}
   396  	client := IndexClient{CallOptions: defaultIndexCallOptions()}
   397  
   398  	c := &indexGRPCClient{
   399  		connPool:         connPool,
   400  		indexClient:      aiplatformpb.NewIndexServiceClient(connPool),
   401  		CallOptions:      &client.CallOptions,
   402  		logger:           internaloption.GetLogger(opts),
   403  		operationsClient: longrunningpb.NewOperationsClient(connPool),
   404  		iamPolicyClient:  iampb.NewIAMPolicyClient(connPool),
   405  		locationsClient:  locationpb.NewLocationsClient(connPool),
   406  	}
   407  	c.setGoogleClientInfo()
   408  
   409  	client.internalClient = c
   410  
   411  	client.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool))
   412  	if err != nil {
   413  		// This error "should not happen", since we are just reusing old connection pool
   414  		// and never actually need to dial.
   415  		// If this does happen, we could leak connp. However, we cannot close conn:
   416  		// If the user invoked the constructor with option.WithGRPCConn,
   417  		// we would close a connection that's still in use.
   418  		// TODO: investigate error conditions.
   419  		return nil, err
   420  	}
   421  	c.LROClient = &client.LROClient
   422  	return &client, nil
   423  }
   424  
   425  // Connection returns a connection to the API service.
   426  //
   427  // Deprecated: Connections are now pooled so this method does not always
   428  // return the same resource.
   429  func (c *indexGRPCClient) Connection() *grpc.ClientConn {
   430  	return c.connPool.Conn()
   431  }
   432  
   433  // setGoogleClientInfo sets the name and version of the application in
   434  // the `x-goog-api-client` header passed on each request. Intended for
   435  // use by Google-written clients.
   436  func (c *indexGRPCClient) setGoogleClientInfo(keyval ...string) {
   437  	kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
   438  	kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
   439  	c.xGoogHeaders = []string{
   440  		"x-goog-api-client", gax.XGoogHeader(kv...),
   441  	}
   442  }
   443  
   444  // Close closes the connection to the API service. The user should invoke this when
   445  // the client is no longer required.
   446  func (c *indexGRPCClient) Close() error {
   447  	return c.connPool.Close()
   448  }
   449  
   450  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   451  type indexRESTClient struct {
   452  	// The http endpoint to connect to.
   453  	endpoint string
   454  
   455  	// The http client.
   456  	httpClient *http.Client
   457  
   458  	// LROClient is used internally to handle long-running operations.
   459  	// It is exposed so that its CallOptions can be modified if required.
   460  	// Users should not Close this client.
   461  	LROClient **lroauto.OperationsClient
   462  
   463  	// The x-goog-* headers to be sent with each request.
   464  	xGoogHeaders []string
   465  
   466  	// Points back to the CallOptions field of the containing IndexClient
   467  	CallOptions **IndexCallOptions
   468  
   469  	logger *slog.Logger
   470  }
   471  
   472  // NewIndexRESTClient creates a new index service rest client.
   473  //
   474  // A service for creating and managing Vertex AI’s Index resources.
   475  func NewIndexRESTClient(ctx context.Context, opts ...option.ClientOption) (*IndexClient, error) {
   476  	clientOpts := append(defaultIndexRESTClientOptions(), opts...)
   477  	httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
   478  	if err != nil {
   479  		return nil, err
   480  	}
   481  
   482  	callOpts := defaultIndexRESTCallOptions()
   483  	c := &indexRESTClient{
   484  		endpoint:    endpoint,
   485  		httpClient:  httpClient,
   486  		CallOptions: &callOpts,
   487  		logger:      internaloption.GetLogger(opts),
   488  	}
   489  	c.setGoogleClientInfo()
   490  
   491  	lroOpts := []option.ClientOption{
   492  		option.WithHTTPClient(httpClient),
   493  		option.WithEndpoint(endpoint),
   494  	}
   495  	opClient, err := lroauto.NewOperationsRESTClient(ctx, lroOpts...)
   496  	if err != nil {
   497  		return nil, err
   498  	}
   499  	c.LROClient = &opClient
   500  
   501  	return &IndexClient{internalClient: c, CallOptions: callOpts}, nil
   502  }
   503  
   504  func defaultIndexRESTClientOptions() []option.ClientOption {
   505  	return []option.ClientOption{
   506  		internaloption.WithDefaultEndpoint("https://aiplatform.googleapis.com"),
   507  		internaloption.WithDefaultEndpointTemplate("https://aiplatform.UNIVERSE_DOMAIN"),
   508  		internaloption.WithDefaultMTLSEndpoint("https://aiplatform.mtls.googleapis.com"),
   509  		internaloption.WithDefaultUniverseDomain("googleapis.com"),
   510  		internaloption.WithDefaultAudience("https://aiplatform.googleapis.com/"),
   511  		internaloption.WithDefaultScopes(DefaultAuthScopes()...),
   512  		internaloption.EnableNewAuthLibrary(),
   513  	}
   514  }
   515  
   516  // setGoogleClientInfo sets the name and version of the application in
   517  // the `x-goog-api-client` header passed on each request. Intended for
   518  // use by Google-written clients.
   519  func (c *indexRESTClient) setGoogleClientInfo(keyval ...string) {
   520  	kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
   521  	kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
   522  	c.xGoogHeaders = []string{
   523  		"x-goog-api-client", gax.XGoogHeader(kv...),
   524  	}
   525  }
   526  
   527  // Close closes the connection to the API service. The user should invoke this when
   528  // the client is no longer required.
   529  func (c *indexRESTClient) Close() error {
   530  	// Replace httpClient with nil to force cleanup.
   531  	c.httpClient = nil
   532  	return nil
   533  }
   534  
   535  // Connection returns a connection to the API service.
   536  //
   537  // Deprecated: This method always returns nil.
   538  func (c *indexRESTClient) Connection() *grpc.ClientConn {
   539  	return nil
   540  }
   541  func (c *indexGRPCClient) CreateIndex(ctx context.Context, req *aiplatformpb.CreateIndexRequest, opts ...gax.CallOption) (*CreateIndexOperation, error) {
   542  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
   543  
   544  	hds = append(c.xGoogHeaders, hds...)
   545  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   546  	opts = append((*c.CallOptions).CreateIndex[0:len((*c.CallOptions).CreateIndex):len((*c.CallOptions).CreateIndex)], opts...)
   547  	var resp *longrunningpb.Operation
   548  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   549  		var err error
   550  		resp, err = executeRPC(ctx, c.indexClient.CreateIndex, req, settings.GRPC, c.logger, "CreateIndex")
   551  		return err
   552  	}, opts...)
   553  	if err != nil {
   554  		return nil, err
   555  	}
   556  	return &CreateIndexOperation{
   557  		lro: longrunning.InternalNewOperation(*c.LROClient, resp),
   558  	}, nil
   559  }
   560  
   561  func (c *indexGRPCClient) GetIndex(ctx context.Context, req *aiplatformpb.GetIndexRequest, opts ...gax.CallOption) (*aiplatformpb.Index, error) {
   562  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   563  
   564  	hds = append(c.xGoogHeaders, hds...)
   565  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   566  	opts = append((*c.CallOptions).GetIndex[0:len((*c.CallOptions).GetIndex):len((*c.CallOptions).GetIndex)], opts...)
   567  	var resp *aiplatformpb.Index
   568  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   569  		var err error
   570  		resp, err = executeRPC(ctx, c.indexClient.GetIndex, req, settings.GRPC, c.logger, "GetIndex")
   571  		return err
   572  	}, opts...)
   573  	if err != nil {
   574  		return nil, err
   575  	}
   576  	return resp, nil
   577  }
   578  
   579  func (c *indexGRPCClient) ImportIndex(ctx context.Context, req *aiplatformpb.ImportIndexRequest, opts ...gax.CallOption) (*ImportIndexOperation, error) {
   580  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   581  
   582  	hds = append(c.xGoogHeaders, hds...)
   583  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   584  	opts = append((*c.CallOptions).ImportIndex[0:len((*c.CallOptions).ImportIndex):len((*c.CallOptions).ImportIndex)], opts...)
   585  	var resp *longrunningpb.Operation
   586  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   587  		var err error
   588  		resp, err = executeRPC(ctx, c.indexClient.ImportIndex, req, settings.GRPC, c.logger, "ImportIndex")
   589  		return err
   590  	}, opts...)
   591  	if err != nil {
   592  		return nil, err
   593  	}
   594  	return &ImportIndexOperation{
   595  		lro: longrunning.InternalNewOperation(*c.LROClient, resp),
   596  	}, nil
   597  }
   598  
   599  func (c *indexGRPCClient) ListIndexes(ctx context.Context, req *aiplatformpb.ListIndexesRequest, opts ...gax.CallOption) *IndexIterator {
   600  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
   601  
   602  	hds = append(c.xGoogHeaders, hds...)
   603  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   604  	opts = append((*c.CallOptions).ListIndexes[0:len((*c.CallOptions).ListIndexes):len((*c.CallOptions).ListIndexes)], opts...)
   605  	it := &IndexIterator{}
   606  	req = proto.Clone(req).(*aiplatformpb.ListIndexesRequest)
   607  	it.InternalFetch = func(pageSize int, pageToken string) ([]*aiplatformpb.Index, string, error) {
   608  		resp := &aiplatformpb.ListIndexesResponse{}
   609  		if pageToken != "" {
   610  			req.PageToken = pageToken
   611  		}
   612  		if pageSize > math.MaxInt32 {
   613  			req.PageSize = math.MaxInt32
   614  		} else if pageSize != 0 {
   615  			req.PageSize = int32(pageSize)
   616  		}
   617  		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   618  			var err error
   619  			resp, err = executeRPC(ctx, c.indexClient.ListIndexes, req, settings.GRPC, c.logger, "ListIndexes")
   620  			return err
   621  		}, opts...)
   622  		if err != nil {
   623  			return nil, "", err
   624  		}
   625  
   626  		it.Response = resp
   627  		return resp.GetIndexes(), resp.GetNextPageToken(), nil
   628  	}
   629  	fetch := func(pageSize int, pageToken string) (string, error) {
   630  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
   631  		if err != nil {
   632  			return "", err
   633  		}
   634  		it.items = append(it.items, items...)
   635  		return nextPageToken, nil
   636  	}
   637  
   638  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
   639  	it.pageInfo.MaxSize = int(req.GetPageSize())
   640  	it.pageInfo.Token = req.GetPageToken()
   641  
   642  	return it
   643  }
   644  
   645  func (c *indexGRPCClient) UpdateIndex(ctx context.Context, req *aiplatformpb.UpdateIndexRequest, opts ...gax.CallOption) (*UpdateIndexOperation, error) {
   646  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "index.name", url.QueryEscape(req.GetIndex().GetName()))}
   647  
   648  	hds = append(c.xGoogHeaders, hds...)
   649  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   650  	opts = append((*c.CallOptions).UpdateIndex[0:len((*c.CallOptions).UpdateIndex):len((*c.CallOptions).UpdateIndex)], opts...)
   651  	var resp *longrunningpb.Operation
   652  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   653  		var err error
   654  		resp, err = executeRPC(ctx, c.indexClient.UpdateIndex, req, settings.GRPC, c.logger, "UpdateIndex")
   655  		return err
   656  	}, opts...)
   657  	if err != nil {
   658  		return nil, err
   659  	}
   660  	return &UpdateIndexOperation{
   661  		lro: longrunning.InternalNewOperation(*c.LROClient, resp),
   662  	}, nil
   663  }
   664  
   665  func (c *indexGRPCClient) DeleteIndex(ctx context.Context, req *aiplatformpb.DeleteIndexRequest, opts ...gax.CallOption) (*DeleteIndexOperation, error) {
   666  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   667  
   668  	hds = append(c.xGoogHeaders, hds...)
   669  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   670  	opts = append((*c.CallOptions).DeleteIndex[0:len((*c.CallOptions).DeleteIndex):len((*c.CallOptions).DeleteIndex)], opts...)
   671  	var resp *longrunningpb.Operation
   672  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   673  		var err error
   674  		resp, err = executeRPC(ctx, c.indexClient.DeleteIndex, req, settings.GRPC, c.logger, "DeleteIndex")
   675  		return err
   676  	}, opts...)
   677  	if err != nil {
   678  		return nil, err
   679  	}
   680  	return &DeleteIndexOperation{
   681  		lro: longrunning.InternalNewOperation(*c.LROClient, resp),
   682  	}, nil
   683  }
   684  
   685  func (c *indexGRPCClient) UpsertDatapoints(ctx context.Context, req *aiplatformpb.UpsertDatapointsRequest, opts ...gax.CallOption) (*aiplatformpb.UpsertDatapointsResponse, error) {
   686  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "index", url.QueryEscape(req.GetIndex()))}
   687  
   688  	hds = append(c.xGoogHeaders, hds...)
   689  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   690  	opts = append((*c.CallOptions).UpsertDatapoints[0:len((*c.CallOptions).UpsertDatapoints):len((*c.CallOptions).UpsertDatapoints)], opts...)
   691  	var resp *aiplatformpb.UpsertDatapointsResponse
   692  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   693  		var err error
   694  		resp, err = executeRPC(ctx, c.indexClient.UpsertDatapoints, req, settings.GRPC, c.logger, "UpsertDatapoints")
   695  		return err
   696  	}, opts...)
   697  	if err != nil {
   698  		return nil, err
   699  	}
   700  	return resp, nil
   701  }
   702  
   703  func (c *indexGRPCClient) RemoveDatapoints(ctx context.Context, req *aiplatformpb.RemoveDatapointsRequest, opts ...gax.CallOption) (*aiplatformpb.RemoveDatapointsResponse, error) {
   704  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "index", url.QueryEscape(req.GetIndex()))}
   705  
   706  	hds = append(c.xGoogHeaders, hds...)
   707  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   708  	opts = append((*c.CallOptions).RemoveDatapoints[0:len((*c.CallOptions).RemoveDatapoints):len((*c.CallOptions).RemoveDatapoints)], opts...)
   709  	var resp *aiplatformpb.RemoveDatapointsResponse
   710  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   711  		var err error
   712  		resp, err = executeRPC(ctx, c.indexClient.RemoveDatapoints, req, settings.GRPC, c.logger, "RemoveDatapoints")
   713  		return err
   714  	}, opts...)
   715  	if err != nil {
   716  		return nil, err
   717  	}
   718  	return resp, nil
   719  }
   720  
   721  func (c *indexGRPCClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) {
   722  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   723  
   724  	hds = append(c.xGoogHeaders, hds...)
   725  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   726  	opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...)
   727  	var resp *locationpb.Location
   728  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   729  		var err error
   730  		resp, err = executeRPC(ctx, c.locationsClient.GetLocation, req, settings.GRPC, c.logger, "GetLocation")
   731  		return err
   732  	}, opts...)
   733  	if err != nil {
   734  		return nil, err
   735  	}
   736  	return resp, nil
   737  }
   738  
   739  func (c *indexGRPCClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator {
   740  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   741  
   742  	hds = append(c.xGoogHeaders, hds...)
   743  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   744  	opts = append((*c.CallOptions).ListLocations[0:len((*c.CallOptions).ListLocations):len((*c.CallOptions).ListLocations)], opts...)
   745  	it := &LocationIterator{}
   746  	req = proto.Clone(req).(*locationpb.ListLocationsRequest)
   747  	it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) {
   748  		resp := &locationpb.ListLocationsResponse{}
   749  		if pageToken != "" {
   750  			req.PageToken = pageToken
   751  		}
   752  		if pageSize > math.MaxInt32 {
   753  			req.PageSize = math.MaxInt32
   754  		} else if pageSize != 0 {
   755  			req.PageSize = int32(pageSize)
   756  		}
   757  		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   758  			var err error
   759  			resp, err = executeRPC(ctx, c.locationsClient.ListLocations, req, settings.GRPC, c.logger, "ListLocations")
   760  			return err
   761  		}, opts...)
   762  		if err != nil {
   763  			return nil, "", err
   764  		}
   765  
   766  		it.Response = resp
   767  		return resp.GetLocations(), resp.GetNextPageToken(), nil
   768  	}
   769  	fetch := func(pageSize int, pageToken string) (string, error) {
   770  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
   771  		if err != nil {
   772  			return "", err
   773  		}
   774  		it.items = append(it.items, items...)
   775  		return nextPageToken, nil
   776  	}
   777  
   778  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
   779  	it.pageInfo.MaxSize = int(req.GetPageSize())
   780  	it.pageInfo.Token = req.GetPageToken()
   781  
   782  	return it
   783  }
   784  
   785  func (c *indexGRPCClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   786  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
   787  
   788  	hds = append(c.xGoogHeaders, hds...)
   789  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   790  	opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
   791  	var resp *iampb.Policy
   792  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   793  		var err error
   794  		resp, err = executeRPC(ctx, c.iamPolicyClient.GetIamPolicy, req, settings.GRPC, c.logger, "GetIamPolicy")
   795  		return err
   796  	}, opts...)
   797  	if err != nil {
   798  		return nil, err
   799  	}
   800  	return resp, nil
   801  }
   802  
   803  func (c *indexGRPCClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   804  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
   805  
   806  	hds = append(c.xGoogHeaders, hds...)
   807  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   808  	opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
   809  	var resp *iampb.Policy
   810  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   811  		var err error
   812  		resp, err = executeRPC(ctx, c.iamPolicyClient.SetIamPolicy, req, settings.GRPC, c.logger, "SetIamPolicy")
   813  		return err
   814  	}, opts...)
   815  	if err != nil {
   816  		return nil, err
   817  	}
   818  	return resp, nil
   819  }
   820  
   821  func (c *indexGRPCClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
   822  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
   823  
   824  	hds = append(c.xGoogHeaders, hds...)
   825  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   826  	opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...)
   827  	var resp *iampb.TestIamPermissionsResponse
   828  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   829  		var err error
   830  		resp, err = executeRPC(ctx, c.iamPolicyClient.TestIamPermissions, req, settings.GRPC, c.logger, "TestIamPermissions")
   831  		return err
   832  	}, opts...)
   833  	if err != nil {
   834  		return nil, err
   835  	}
   836  	return resp, nil
   837  }
   838  
   839  func (c *indexGRPCClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
   840  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   841  
   842  	hds = append(c.xGoogHeaders, hds...)
   843  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   844  	opts = append((*c.CallOptions).CancelOperation[0:len((*c.CallOptions).CancelOperation):len((*c.CallOptions).CancelOperation)], opts...)
   845  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   846  		var err error
   847  		_, err = executeRPC(ctx, c.operationsClient.CancelOperation, req, settings.GRPC, c.logger, "CancelOperation")
   848  		return err
   849  	}, opts...)
   850  	return err
   851  }
   852  
   853  func (c *indexGRPCClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
   854  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   855  
   856  	hds = append(c.xGoogHeaders, hds...)
   857  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   858  	opts = append((*c.CallOptions).DeleteOperation[0:len((*c.CallOptions).DeleteOperation):len((*c.CallOptions).DeleteOperation)], opts...)
   859  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   860  		var err error
   861  		_, err = executeRPC(ctx, c.operationsClient.DeleteOperation, req, settings.GRPC, c.logger, "DeleteOperation")
   862  		return err
   863  	}, opts...)
   864  	return err
   865  }
   866  
   867  func (c *indexGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
   868  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   869  
   870  	hds = append(c.xGoogHeaders, hds...)
   871  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   872  	opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
   873  	var resp *longrunningpb.Operation
   874  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   875  		var err error
   876  		resp, err = executeRPC(ctx, c.operationsClient.GetOperation, req, settings.GRPC, c.logger, "GetOperation")
   877  		return err
   878  	}, opts...)
   879  	if err != nil {
   880  		return nil, err
   881  	}
   882  	return resp, nil
   883  }
   884  
   885  func (c *indexGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
   886  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   887  
   888  	hds = append(c.xGoogHeaders, hds...)
   889  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   890  	opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...)
   891  	it := &OperationIterator{}
   892  	req = proto.Clone(req).(*longrunningpb.ListOperationsRequest)
   893  	it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) {
   894  		resp := &longrunningpb.ListOperationsResponse{}
   895  		if pageToken != "" {
   896  			req.PageToken = pageToken
   897  		}
   898  		if pageSize > math.MaxInt32 {
   899  			req.PageSize = math.MaxInt32
   900  		} else if pageSize != 0 {
   901  			req.PageSize = int32(pageSize)
   902  		}
   903  		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   904  			var err error
   905  			resp, err = executeRPC(ctx, c.operationsClient.ListOperations, req, settings.GRPC, c.logger, "ListOperations")
   906  			return err
   907  		}, opts...)
   908  		if err != nil {
   909  			return nil, "", err
   910  		}
   911  
   912  		it.Response = resp
   913  		return resp.GetOperations(), resp.GetNextPageToken(), nil
   914  	}
   915  	fetch := func(pageSize int, pageToken string) (string, error) {
   916  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
   917  		if err != nil {
   918  			return "", err
   919  		}
   920  		it.items = append(it.items, items...)
   921  		return nextPageToken, nil
   922  	}
   923  
   924  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
   925  	it.pageInfo.MaxSize = int(req.GetPageSize())
   926  	it.pageInfo.Token = req.GetPageToken()
   927  
   928  	return it
   929  }
   930  
   931  func (c *indexGRPCClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
   932  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   933  
   934  	hds = append(c.xGoogHeaders, hds...)
   935  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   936  	opts = append((*c.CallOptions).WaitOperation[0:len((*c.CallOptions).WaitOperation):len((*c.CallOptions).WaitOperation)], opts...)
   937  	var resp *longrunningpb.Operation
   938  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   939  		var err error
   940  		resp, err = executeRPC(ctx, c.operationsClient.WaitOperation, req, settings.GRPC, c.logger, "WaitOperation")
   941  		return err
   942  	}, opts...)
   943  	if err != nil {
   944  		return nil, err
   945  	}
   946  	return resp, nil
   947  }
   948  
   949  // CreateIndex creates an Index.
   950  func (c *indexRESTClient) CreateIndex(ctx context.Context, req *aiplatformpb.CreateIndexRequest, opts ...gax.CallOption) (*CreateIndexOperation, error) {
   951  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
   952  	body := req.GetIndex()
   953  	jsonReq, err := m.Marshal(body)
   954  	if err != nil {
   955  		return nil, err
   956  	}
   957  
   958  	baseUrl, err := url.Parse(c.endpoint)
   959  	if err != nil {
   960  		return nil, err
   961  	}
   962  	baseUrl.Path += fmt.Sprintf("/v1beta1/%v/indexes", req.GetParent())
   963  
   964  	params := url.Values{}
   965  	params.Add("$alt", "json;enum-encoding=int")
   966  
   967  	baseUrl.RawQuery = params.Encode()
   968  
   969  	// Build HTTP headers from client and context metadata.
   970  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
   971  
   972  	hds = append(c.xGoogHeaders, hds...)
   973  	hds = append(hds, "Content-Type", "application/json")
   974  	headers := gax.BuildHeaders(ctx, hds...)
   975  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
   976  	resp := &longrunningpb.Operation{}
   977  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   978  		if settings.Path != "" {
   979  			baseUrl.Path = settings.Path
   980  		}
   981  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
   982  		if err != nil {
   983  			return err
   984  		}
   985  		httpReq = httpReq.WithContext(ctx)
   986  		httpReq.Header = headers
   987  
   988  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateIndex")
   989  		if err != nil {
   990  			return err
   991  		}
   992  		if err := unm.Unmarshal(buf, resp); err != nil {
   993  			return err
   994  		}
   995  
   996  		return nil
   997  	}, opts...)
   998  	if e != nil {
   999  		return nil, e
  1000  	}
  1001  
  1002  	override := fmt.Sprintf("/ui/%s", resp.GetName())
  1003  	return &CreateIndexOperation{
  1004  		lro:      longrunning.InternalNewOperation(*c.LROClient, resp),
  1005  		pollPath: override,
  1006  	}, nil
  1007  }
  1008  
  1009  // GetIndex gets an Index.
  1010  func (c *indexRESTClient) GetIndex(ctx context.Context, req *aiplatformpb.GetIndexRequest, opts ...gax.CallOption) (*aiplatformpb.Index, error) {
  1011  	baseUrl, err := url.Parse(c.endpoint)
  1012  	if err != nil {
  1013  		return nil, err
  1014  	}
  1015  	baseUrl.Path += fmt.Sprintf("/v1beta1/%v", req.GetName())
  1016  
  1017  	params := url.Values{}
  1018  	params.Add("$alt", "json;enum-encoding=int")
  1019  
  1020  	baseUrl.RawQuery = params.Encode()
  1021  
  1022  	// Build HTTP headers from client and context metadata.
  1023  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  1024  
  1025  	hds = append(c.xGoogHeaders, hds...)
  1026  	hds = append(hds, "Content-Type", "application/json")
  1027  	headers := gax.BuildHeaders(ctx, hds...)
  1028  	opts = append((*c.CallOptions).GetIndex[0:len((*c.CallOptions).GetIndex):len((*c.CallOptions).GetIndex)], opts...)
  1029  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1030  	resp := &aiplatformpb.Index{}
  1031  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1032  		if settings.Path != "" {
  1033  			baseUrl.Path = settings.Path
  1034  		}
  1035  		httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
  1036  		if err != nil {
  1037  			return err
  1038  		}
  1039  		httpReq = httpReq.WithContext(ctx)
  1040  		httpReq.Header = headers
  1041  
  1042  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetIndex")
  1043  		if err != nil {
  1044  			return err
  1045  		}
  1046  
  1047  		if err := unm.Unmarshal(buf, resp); err != nil {
  1048  			return err
  1049  		}
  1050  
  1051  		return nil
  1052  	}, opts...)
  1053  	if e != nil {
  1054  		return nil, e
  1055  	}
  1056  	return resp, nil
  1057  }
  1058  
  1059  // ImportIndex imports an Index from an external source (e.g., BigQuery).
  1060  func (c *indexRESTClient) ImportIndex(ctx context.Context, req *aiplatformpb.ImportIndexRequest, opts ...gax.CallOption) (*ImportIndexOperation, error) {
  1061  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
  1062  	jsonReq, err := m.Marshal(req)
  1063  	if err != nil {
  1064  		return nil, err
  1065  	}
  1066  
  1067  	baseUrl, err := url.Parse(c.endpoint)
  1068  	if err != nil {
  1069  		return nil, err
  1070  	}
  1071  	baseUrl.Path += fmt.Sprintf("/v1beta1/%v:import", req.GetName())
  1072  
  1073  	params := url.Values{}
  1074  	params.Add("$alt", "json;enum-encoding=int")
  1075  
  1076  	baseUrl.RawQuery = params.Encode()
  1077  
  1078  	// Build HTTP headers from client and context metadata.
  1079  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  1080  
  1081  	hds = append(c.xGoogHeaders, hds...)
  1082  	hds = append(hds, "Content-Type", "application/json")
  1083  	headers := gax.BuildHeaders(ctx, hds...)
  1084  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1085  	resp := &longrunningpb.Operation{}
  1086  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1087  		if settings.Path != "" {
  1088  			baseUrl.Path = settings.Path
  1089  		}
  1090  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
  1091  		if err != nil {
  1092  			return err
  1093  		}
  1094  		httpReq = httpReq.WithContext(ctx)
  1095  		httpReq.Header = headers
  1096  
  1097  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "ImportIndex")
  1098  		if err != nil {
  1099  			return err
  1100  		}
  1101  		if err := unm.Unmarshal(buf, resp); err != nil {
  1102  			return err
  1103  		}
  1104  
  1105  		return nil
  1106  	}, opts...)
  1107  	if e != nil {
  1108  		return nil, e
  1109  	}
  1110  
  1111  	override := fmt.Sprintf("/ui/%s", resp.GetName())
  1112  	return &ImportIndexOperation{
  1113  		lro:      longrunning.InternalNewOperation(*c.LROClient, resp),
  1114  		pollPath: override,
  1115  	}, nil
  1116  }
  1117  
  1118  // ListIndexes lists Indexes in a Location.
  1119  func (c *indexRESTClient) ListIndexes(ctx context.Context, req *aiplatformpb.ListIndexesRequest, opts ...gax.CallOption) *IndexIterator {
  1120  	it := &IndexIterator{}
  1121  	req = proto.Clone(req).(*aiplatformpb.ListIndexesRequest)
  1122  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1123  	it.InternalFetch = func(pageSize int, pageToken string) ([]*aiplatformpb.Index, string, error) {
  1124  		resp := &aiplatformpb.ListIndexesResponse{}
  1125  		if pageToken != "" {
  1126  			req.PageToken = pageToken
  1127  		}
  1128  		if pageSize > math.MaxInt32 {
  1129  			req.PageSize = math.MaxInt32
  1130  		} else if pageSize != 0 {
  1131  			req.PageSize = int32(pageSize)
  1132  		}
  1133  		baseUrl, err := url.Parse(c.endpoint)
  1134  		if err != nil {
  1135  			return nil, "", err
  1136  		}
  1137  		baseUrl.Path += fmt.Sprintf("/v1beta1/%v/indexes", req.GetParent())
  1138  
  1139  		params := url.Values{}
  1140  		params.Add("$alt", "json;enum-encoding=int")
  1141  		if req.GetFilter() != "" {
  1142  			params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
  1143  		}
  1144  		if req.GetPageSize() != 0 {
  1145  			params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
  1146  		}
  1147  		if req.GetPageToken() != "" {
  1148  			params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
  1149  		}
  1150  		if req.GetReadMask() != nil {
  1151  			field, err := protojson.Marshal(req.GetReadMask())
  1152  			if err != nil {
  1153  				return nil, "", err
  1154  			}
  1155  			params.Add("readMask", string(field[1:len(field)-1]))
  1156  		}
  1157  
  1158  		baseUrl.RawQuery = params.Encode()
  1159  
  1160  		// Build HTTP headers from client and context metadata.
  1161  		hds := append(c.xGoogHeaders, "Content-Type", "application/json")
  1162  		headers := gax.BuildHeaders(ctx, hds...)
  1163  		e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1164  			if settings.Path != "" {
  1165  				baseUrl.Path = settings.Path
  1166  			}
  1167  			httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
  1168  			if err != nil {
  1169  				return err
  1170  			}
  1171  			httpReq.Header = headers
  1172  
  1173  			buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListIndexes")
  1174  			if err != nil {
  1175  				return err
  1176  			}
  1177  			if err := unm.Unmarshal(buf, resp); err != nil {
  1178  				return err
  1179  			}
  1180  
  1181  			return nil
  1182  		}, opts...)
  1183  		if e != nil {
  1184  			return nil, "", e
  1185  		}
  1186  		it.Response = resp
  1187  		return resp.GetIndexes(), resp.GetNextPageToken(), nil
  1188  	}
  1189  
  1190  	fetch := func(pageSize int, pageToken string) (string, error) {
  1191  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  1192  		if err != nil {
  1193  			return "", err
  1194  		}
  1195  		it.items = append(it.items, items...)
  1196  		return nextPageToken, nil
  1197  	}
  1198  
  1199  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  1200  	it.pageInfo.MaxSize = int(req.GetPageSize())
  1201  	it.pageInfo.Token = req.GetPageToken()
  1202  
  1203  	return it
  1204  }
  1205  
  1206  // UpdateIndex updates an Index.
  1207  func (c *indexRESTClient) UpdateIndex(ctx context.Context, req *aiplatformpb.UpdateIndexRequest, opts ...gax.CallOption) (*UpdateIndexOperation, error) {
  1208  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
  1209  	body := req.GetIndex()
  1210  	jsonReq, err := m.Marshal(body)
  1211  	if err != nil {
  1212  		return nil, err
  1213  	}
  1214  
  1215  	baseUrl, err := url.Parse(c.endpoint)
  1216  	if err != nil {
  1217  		return nil, err
  1218  	}
  1219  	baseUrl.Path += fmt.Sprintf("/v1beta1/%v", req.GetIndex().GetName())
  1220  
  1221  	params := url.Values{}
  1222  	params.Add("$alt", "json;enum-encoding=int")
  1223  	if req.GetUpdateMask() != nil {
  1224  		field, err := protojson.Marshal(req.GetUpdateMask())
  1225  		if err != nil {
  1226  			return nil, err
  1227  		}
  1228  		params.Add("updateMask", string(field[1:len(field)-1]))
  1229  	}
  1230  
  1231  	baseUrl.RawQuery = params.Encode()
  1232  
  1233  	// Build HTTP headers from client and context metadata.
  1234  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "index.name", url.QueryEscape(req.GetIndex().GetName()))}
  1235  
  1236  	hds = append(c.xGoogHeaders, hds...)
  1237  	hds = append(hds, "Content-Type", "application/json")
  1238  	headers := gax.BuildHeaders(ctx, hds...)
  1239  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1240  	resp := &longrunningpb.Operation{}
  1241  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1242  		if settings.Path != "" {
  1243  			baseUrl.Path = settings.Path
  1244  		}
  1245  		httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
  1246  		if err != nil {
  1247  			return err
  1248  		}
  1249  		httpReq = httpReq.WithContext(ctx)
  1250  		httpReq.Header = headers
  1251  
  1252  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateIndex")
  1253  		if err != nil {
  1254  			return err
  1255  		}
  1256  		if err := unm.Unmarshal(buf, resp); err != nil {
  1257  			return err
  1258  		}
  1259  
  1260  		return nil
  1261  	}, opts...)
  1262  	if e != nil {
  1263  		return nil, e
  1264  	}
  1265  
  1266  	override := fmt.Sprintf("/ui/%s", resp.GetName())
  1267  	return &UpdateIndexOperation{
  1268  		lro:      longrunning.InternalNewOperation(*c.LROClient, resp),
  1269  		pollPath: override,
  1270  	}, nil
  1271  }
  1272  
  1273  // DeleteIndex deletes an Index.
  1274  // An Index can only be deleted when all its
  1275  // DeployedIndexes
  1276  // had been undeployed.
  1277  func (c *indexRESTClient) DeleteIndex(ctx context.Context, req *aiplatformpb.DeleteIndexRequest, opts ...gax.CallOption) (*DeleteIndexOperation, error) {
  1278  	baseUrl, err := url.Parse(c.endpoint)
  1279  	if err != nil {
  1280  		return nil, err
  1281  	}
  1282  	baseUrl.Path += fmt.Sprintf("/v1beta1/%v", req.GetName())
  1283  
  1284  	params := url.Values{}
  1285  	params.Add("$alt", "json;enum-encoding=int")
  1286  
  1287  	baseUrl.RawQuery = params.Encode()
  1288  
  1289  	// Build HTTP headers from client and context metadata.
  1290  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  1291  
  1292  	hds = append(c.xGoogHeaders, hds...)
  1293  	hds = append(hds, "Content-Type", "application/json")
  1294  	headers := gax.BuildHeaders(ctx, hds...)
  1295  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1296  	resp := &longrunningpb.Operation{}
  1297  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1298  		if settings.Path != "" {
  1299  			baseUrl.Path = settings.Path
  1300  		}
  1301  		httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
  1302  		if err != nil {
  1303  			return err
  1304  		}
  1305  		httpReq = httpReq.WithContext(ctx)
  1306  		httpReq.Header = headers
  1307  
  1308  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteIndex")
  1309  		if err != nil {
  1310  			return err
  1311  		}
  1312  		if err := unm.Unmarshal(buf, resp); err != nil {
  1313  			return err
  1314  		}
  1315  
  1316  		return nil
  1317  	}, opts...)
  1318  	if e != nil {
  1319  		return nil, e
  1320  	}
  1321  
  1322  	override := fmt.Sprintf("/ui/%s", resp.GetName())
  1323  	return &DeleteIndexOperation{
  1324  		lro:      longrunning.InternalNewOperation(*c.LROClient, resp),
  1325  		pollPath: override,
  1326  	}, nil
  1327  }
  1328  
  1329  // UpsertDatapoints add/update Datapoints into an Index.
  1330  func (c *indexRESTClient) UpsertDatapoints(ctx context.Context, req *aiplatformpb.UpsertDatapointsRequest, opts ...gax.CallOption) (*aiplatformpb.UpsertDatapointsResponse, error) {
  1331  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
  1332  	jsonReq, err := m.Marshal(req)
  1333  	if err != nil {
  1334  		return nil, err
  1335  	}
  1336  
  1337  	baseUrl, err := url.Parse(c.endpoint)
  1338  	if err != nil {
  1339  		return nil, err
  1340  	}
  1341  	baseUrl.Path += fmt.Sprintf("/v1beta1/%v:upsertDatapoints", req.GetIndex())
  1342  
  1343  	params := url.Values{}
  1344  	params.Add("$alt", "json;enum-encoding=int")
  1345  
  1346  	baseUrl.RawQuery = params.Encode()
  1347  
  1348  	// Build HTTP headers from client and context metadata.
  1349  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "index", url.QueryEscape(req.GetIndex()))}
  1350  
  1351  	hds = append(c.xGoogHeaders, hds...)
  1352  	hds = append(hds, "Content-Type", "application/json")
  1353  	headers := gax.BuildHeaders(ctx, hds...)
  1354  	opts = append((*c.CallOptions).UpsertDatapoints[0:len((*c.CallOptions).UpsertDatapoints):len((*c.CallOptions).UpsertDatapoints)], opts...)
  1355  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1356  	resp := &aiplatformpb.UpsertDatapointsResponse{}
  1357  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1358  		if settings.Path != "" {
  1359  			baseUrl.Path = settings.Path
  1360  		}
  1361  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
  1362  		if err != nil {
  1363  			return err
  1364  		}
  1365  		httpReq = httpReq.WithContext(ctx)
  1366  		httpReq.Header = headers
  1367  
  1368  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpsertDatapoints")
  1369  		if err != nil {
  1370  			return err
  1371  		}
  1372  
  1373  		if err := unm.Unmarshal(buf, resp); err != nil {
  1374  			return err
  1375  		}
  1376  
  1377  		return nil
  1378  	}, opts...)
  1379  	if e != nil {
  1380  		return nil, e
  1381  	}
  1382  	return resp, nil
  1383  }
  1384  
  1385  // RemoveDatapoints remove Datapoints from an Index.
  1386  func (c *indexRESTClient) RemoveDatapoints(ctx context.Context, req *aiplatformpb.RemoveDatapointsRequest, opts ...gax.CallOption) (*aiplatformpb.RemoveDatapointsResponse, error) {
  1387  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
  1388  	jsonReq, err := m.Marshal(req)
  1389  	if err != nil {
  1390  		return nil, err
  1391  	}
  1392  
  1393  	baseUrl, err := url.Parse(c.endpoint)
  1394  	if err != nil {
  1395  		return nil, err
  1396  	}
  1397  	baseUrl.Path += fmt.Sprintf("/v1beta1/%v:removeDatapoints", req.GetIndex())
  1398  
  1399  	params := url.Values{}
  1400  	params.Add("$alt", "json;enum-encoding=int")
  1401  
  1402  	baseUrl.RawQuery = params.Encode()
  1403  
  1404  	// Build HTTP headers from client and context metadata.
  1405  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "index", url.QueryEscape(req.GetIndex()))}
  1406  
  1407  	hds = append(c.xGoogHeaders, hds...)
  1408  	hds = append(hds, "Content-Type", "application/json")
  1409  	headers := gax.BuildHeaders(ctx, hds...)
  1410  	opts = append((*c.CallOptions).RemoveDatapoints[0:len((*c.CallOptions).RemoveDatapoints):len((*c.CallOptions).RemoveDatapoints)], opts...)
  1411  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1412  	resp := &aiplatformpb.RemoveDatapointsResponse{}
  1413  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1414  		if settings.Path != "" {
  1415  			baseUrl.Path = settings.Path
  1416  		}
  1417  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
  1418  		if err != nil {
  1419  			return err
  1420  		}
  1421  		httpReq = httpReq.WithContext(ctx)
  1422  		httpReq.Header = headers
  1423  
  1424  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "RemoveDatapoints")
  1425  		if err != nil {
  1426  			return err
  1427  		}
  1428  
  1429  		if err := unm.Unmarshal(buf, resp); err != nil {
  1430  			return err
  1431  		}
  1432  
  1433  		return nil
  1434  	}, opts...)
  1435  	if e != nil {
  1436  		return nil, e
  1437  	}
  1438  	return resp, nil
  1439  }
  1440  
  1441  // GetLocation gets information about a location.
  1442  func (c *indexRESTClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) {
  1443  	baseUrl, err := url.Parse(c.endpoint)
  1444  	if err != nil {
  1445  		return nil, err
  1446  	}
  1447  	baseUrl.Path += fmt.Sprintf("/ui/%v", req.GetName())
  1448  
  1449  	params := url.Values{}
  1450  	params.Add("$alt", "json;enum-encoding=int")
  1451  
  1452  	baseUrl.RawQuery = params.Encode()
  1453  
  1454  	// Build HTTP headers from client and context metadata.
  1455  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  1456  
  1457  	hds = append(c.xGoogHeaders, hds...)
  1458  	hds = append(hds, "Content-Type", "application/json")
  1459  	headers := gax.BuildHeaders(ctx, hds...)
  1460  	opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...)
  1461  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1462  	resp := &locationpb.Location{}
  1463  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1464  		if settings.Path != "" {
  1465  			baseUrl.Path = settings.Path
  1466  		}
  1467  		httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
  1468  		if err != nil {
  1469  			return err
  1470  		}
  1471  		httpReq = httpReq.WithContext(ctx)
  1472  		httpReq.Header = headers
  1473  
  1474  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetLocation")
  1475  		if err != nil {
  1476  			return err
  1477  		}
  1478  
  1479  		if err := unm.Unmarshal(buf, resp); err != nil {
  1480  			return err
  1481  		}
  1482  
  1483  		return nil
  1484  	}, opts...)
  1485  	if e != nil {
  1486  		return nil, e
  1487  	}
  1488  	return resp, nil
  1489  }
  1490  
  1491  // ListLocations lists information about the supported locations for this service.
  1492  func (c *indexRESTClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator {
  1493  	it := &LocationIterator{}
  1494  	req = proto.Clone(req).(*locationpb.ListLocationsRequest)
  1495  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1496  	it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) {
  1497  		resp := &locationpb.ListLocationsResponse{}
  1498  		if pageToken != "" {
  1499  			req.PageToken = pageToken
  1500  		}
  1501  		if pageSize > math.MaxInt32 {
  1502  			req.PageSize = math.MaxInt32
  1503  		} else if pageSize != 0 {
  1504  			req.PageSize = int32(pageSize)
  1505  		}
  1506  		baseUrl, err := url.Parse(c.endpoint)
  1507  		if err != nil {
  1508  			return nil, "", err
  1509  		}
  1510  		baseUrl.Path += fmt.Sprintf("/ui/%v/locations", req.GetName())
  1511  
  1512  		params := url.Values{}
  1513  		params.Add("$alt", "json;enum-encoding=int")
  1514  		if req.GetFilter() != "" {
  1515  			params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
  1516  		}
  1517  		if req.GetPageSize() != 0 {
  1518  			params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
  1519  		}
  1520  		if req.GetPageToken() != "" {
  1521  			params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
  1522  		}
  1523  
  1524  		baseUrl.RawQuery = params.Encode()
  1525  
  1526  		// Build HTTP headers from client and context metadata.
  1527  		hds := append(c.xGoogHeaders, "Content-Type", "application/json")
  1528  		headers := gax.BuildHeaders(ctx, hds...)
  1529  		e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1530  			if settings.Path != "" {
  1531  				baseUrl.Path = settings.Path
  1532  			}
  1533  			httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
  1534  			if err != nil {
  1535  				return err
  1536  			}
  1537  			httpReq.Header = headers
  1538  
  1539  			buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListLocations")
  1540  			if err != nil {
  1541  				return err
  1542  			}
  1543  			if err := unm.Unmarshal(buf, resp); err != nil {
  1544  				return err
  1545  			}
  1546  
  1547  			return nil
  1548  		}, opts...)
  1549  		if e != nil {
  1550  			return nil, "", e
  1551  		}
  1552  		it.Response = resp
  1553  		return resp.GetLocations(), resp.GetNextPageToken(), nil
  1554  	}
  1555  
  1556  	fetch := func(pageSize int, pageToken string) (string, error) {
  1557  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  1558  		if err != nil {
  1559  			return "", err
  1560  		}
  1561  		it.items = append(it.items, items...)
  1562  		return nextPageToken, nil
  1563  	}
  1564  
  1565  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  1566  	it.pageInfo.MaxSize = int(req.GetPageSize())
  1567  	it.pageInfo.Token = req.GetPageToken()
  1568  
  1569  	return it
  1570  }
  1571  
  1572  // GetIamPolicy gets the access control policy for a resource. Returns an empty policy
  1573  // if the resource exists and does not have a policy set.
  1574  func (c *indexRESTClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
  1575  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
  1576  	jsonReq, err := m.Marshal(req)
  1577  	if err != nil {
  1578  		return nil, err
  1579  	}
  1580  
  1581  	baseUrl, err := url.Parse(c.endpoint)
  1582  	if err != nil {
  1583  		return nil, err
  1584  	}
  1585  	baseUrl.Path += fmt.Sprintf("/v1beta1/%v:getIamPolicy", req.GetResource())
  1586  
  1587  	params := url.Values{}
  1588  	params.Add("$alt", "json;enum-encoding=int")
  1589  
  1590  	baseUrl.RawQuery = params.Encode()
  1591  
  1592  	// Build HTTP headers from client and context metadata.
  1593  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
  1594  
  1595  	hds = append(c.xGoogHeaders, hds...)
  1596  	hds = append(hds, "Content-Type", "application/json")
  1597  	headers := gax.BuildHeaders(ctx, hds...)
  1598  	opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
  1599  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1600  	resp := &iampb.Policy{}
  1601  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1602  		if settings.Path != "" {
  1603  			baseUrl.Path = settings.Path
  1604  		}
  1605  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
  1606  		if err != nil {
  1607  			return err
  1608  		}
  1609  		httpReq = httpReq.WithContext(ctx)
  1610  		httpReq.Header = headers
  1611  
  1612  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "GetIamPolicy")
  1613  		if err != nil {
  1614  			return err
  1615  		}
  1616  
  1617  		if err := unm.Unmarshal(buf, resp); err != nil {
  1618  			return err
  1619  		}
  1620  
  1621  		return nil
  1622  	}, opts...)
  1623  	if e != nil {
  1624  		return nil, e
  1625  	}
  1626  	return resp, nil
  1627  }
  1628  
  1629  // SetIamPolicy sets the access control policy on the specified resource. Replaces
  1630  // any existing policy.
  1631  //
  1632  // Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED
  1633  // errors.
  1634  func (c *indexRESTClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
  1635  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
  1636  	jsonReq, err := m.Marshal(req)
  1637  	if err != nil {
  1638  		return nil, err
  1639  	}
  1640  
  1641  	baseUrl, err := url.Parse(c.endpoint)
  1642  	if err != nil {
  1643  		return nil, err
  1644  	}
  1645  	baseUrl.Path += fmt.Sprintf("/v1beta1/%v:setIamPolicy", req.GetResource())
  1646  
  1647  	params := url.Values{}
  1648  	params.Add("$alt", "json;enum-encoding=int")
  1649  
  1650  	baseUrl.RawQuery = params.Encode()
  1651  
  1652  	// Build HTTP headers from client and context metadata.
  1653  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
  1654  
  1655  	hds = append(c.xGoogHeaders, hds...)
  1656  	hds = append(hds, "Content-Type", "application/json")
  1657  	headers := gax.BuildHeaders(ctx, hds...)
  1658  	opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
  1659  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1660  	resp := &iampb.Policy{}
  1661  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1662  		if settings.Path != "" {
  1663  			baseUrl.Path = settings.Path
  1664  		}
  1665  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
  1666  		if err != nil {
  1667  			return err
  1668  		}
  1669  		httpReq = httpReq.WithContext(ctx)
  1670  		httpReq.Header = headers
  1671  
  1672  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "SetIamPolicy")
  1673  		if err != nil {
  1674  			return err
  1675  		}
  1676  
  1677  		if err := unm.Unmarshal(buf, resp); err != nil {
  1678  			return err
  1679  		}
  1680  
  1681  		return nil
  1682  	}, opts...)
  1683  	if e != nil {
  1684  		return nil, e
  1685  	}
  1686  	return resp, nil
  1687  }
  1688  
  1689  // TestIamPermissions returns permissions that a caller has on the specified resource. If the
  1690  // resource does not exist, this will return an empty set of
  1691  // permissions, not a NOT_FOUND error.
  1692  //
  1693  // Note: This operation is designed to be used for building
  1694  // permission-aware UIs and command-line tools, not for authorization
  1695  // checking. This operation may “fail open” without warning.
  1696  func (c *indexRESTClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
  1697  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
  1698  	jsonReq, err := m.Marshal(req)
  1699  	if err != nil {
  1700  		return nil, err
  1701  	}
  1702  
  1703  	baseUrl, err := url.Parse(c.endpoint)
  1704  	if err != nil {
  1705  		return nil, err
  1706  	}
  1707  	baseUrl.Path += fmt.Sprintf("/v1beta1/%v:testIamPermissions", req.GetResource())
  1708  
  1709  	params := url.Values{}
  1710  	params.Add("$alt", "json;enum-encoding=int")
  1711  
  1712  	baseUrl.RawQuery = params.Encode()
  1713  
  1714  	// Build HTTP headers from client and context metadata.
  1715  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
  1716  
  1717  	hds = append(c.xGoogHeaders, hds...)
  1718  	hds = append(hds, "Content-Type", "application/json")
  1719  	headers := gax.BuildHeaders(ctx, hds...)
  1720  	opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...)
  1721  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1722  	resp := &iampb.TestIamPermissionsResponse{}
  1723  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1724  		if settings.Path != "" {
  1725  			baseUrl.Path = settings.Path
  1726  		}
  1727  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
  1728  		if err != nil {
  1729  			return err
  1730  		}
  1731  		httpReq = httpReq.WithContext(ctx)
  1732  		httpReq.Header = headers
  1733  
  1734  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "TestIamPermissions")
  1735  		if err != nil {
  1736  			return err
  1737  		}
  1738  
  1739  		if err := unm.Unmarshal(buf, resp); err != nil {
  1740  			return err
  1741  		}
  1742  
  1743  		return nil
  1744  	}, opts...)
  1745  	if e != nil {
  1746  		return nil, e
  1747  	}
  1748  	return resp, nil
  1749  }
  1750  
  1751  // CancelOperation is a utility method from google.longrunning.Operations.
  1752  func (c *indexRESTClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
  1753  	baseUrl, err := url.Parse(c.endpoint)
  1754  	if err != nil {
  1755  		return err
  1756  	}
  1757  	baseUrl.Path += fmt.Sprintf("/ui/%v:cancel", req.GetName())
  1758  
  1759  	params := url.Values{}
  1760  	params.Add("$alt", "json;enum-encoding=int")
  1761  
  1762  	baseUrl.RawQuery = params.Encode()
  1763  
  1764  	// Build HTTP headers from client and context metadata.
  1765  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  1766  
  1767  	hds = append(c.xGoogHeaders, hds...)
  1768  	hds = append(hds, "Content-Type", "application/json")
  1769  	headers := gax.BuildHeaders(ctx, hds...)
  1770  	return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1771  		if settings.Path != "" {
  1772  			baseUrl.Path = settings.Path
  1773  		}
  1774  		httpReq, err := http.NewRequest("POST", baseUrl.String(), nil)
  1775  		if err != nil {
  1776  			return err
  1777  		}
  1778  		httpReq = httpReq.WithContext(ctx)
  1779  		httpReq.Header = headers
  1780  
  1781  		_, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "CancelOperation")
  1782  		return err
  1783  	}, opts...)
  1784  }
  1785  
  1786  // DeleteOperation is a utility method from google.longrunning.Operations.
  1787  func (c *indexRESTClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
  1788  	baseUrl, err := url.Parse(c.endpoint)
  1789  	if err != nil {
  1790  		return err
  1791  	}
  1792  	baseUrl.Path += fmt.Sprintf("/ui/%v", req.GetName())
  1793  
  1794  	params := url.Values{}
  1795  	params.Add("$alt", "json;enum-encoding=int")
  1796  
  1797  	baseUrl.RawQuery = params.Encode()
  1798  
  1799  	// Build HTTP headers from client and context metadata.
  1800  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  1801  
  1802  	hds = append(c.xGoogHeaders, hds...)
  1803  	hds = append(hds, "Content-Type", "application/json")
  1804  	headers := gax.BuildHeaders(ctx, hds...)
  1805  	return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1806  		if settings.Path != "" {
  1807  			baseUrl.Path = settings.Path
  1808  		}
  1809  		httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
  1810  		if err != nil {
  1811  			return err
  1812  		}
  1813  		httpReq = httpReq.WithContext(ctx)
  1814  		httpReq.Header = headers
  1815  
  1816  		_, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteOperation")
  1817  		return err
  1818  	}, opts...)
  1819  }
  1820  
  1821  // GetOperation is a utility method from google.longrunning.Operations.
  1822  func (c *indexRESTClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
  1823  	baseUrl, err := url.Parse(c.endpoint)
  1824  	if err != nil {
  1825  		return nil, err
  1826  	}
  1827  	baseUrl.Path += fmt.Sprintf("/ui/%v", req.GetName())
  1828  
  1829  	params := url.Values{}
  1830  	params.Add("$alt", "json;enum-encoding=int")
  1831  
  1832  	baseUrl.RawQuery = params.Encode()
  1833  
  1834  	// Build HTTP headers from client and context metadata.
  1835  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  1836  
  1837  	hds = append(c.xGoogHeaders, hds...)
  1838  	hds = append(hds, "Content-Type", "application/json")
  1839  	headers := gax.BuildHeaders(ctx, hds...)
  1840  	opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
  1841  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1842  	resp := &longrunningpb.Operation{}
  1843  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1844  		if settings.Path != "" {
  1845  			baseUrl.Path = settings.Path
  1846  		}
  1847  		httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
  1848  		if err != nil {
  1849  			return err
  1850  		}
  1851  		httpReq = httpReq.WithContext(ctx)
  1852  		httpReq.Header = headers
  1853  
  1854  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetOperation")
  1855  		if err != nil {
  1856  			return err
  1857  		}
  1858  
  1859  		if err := unm.Unmarshal(buf, resp); err != nil {
  1860  			return err
  1861  		}
  1862  
  1863  		return nil
  1864  	}, opts...)
  1865  	if e != nil {
  1866  		return nil, e
  1867  	}
  1868  	return resp, nil
  1869  }
  1870  
  1871  // ListOperations is a utility method from google.longrunning.Operations.
  1872  func (c *indexRESTClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
  1873  	it := &OperationIterator{}
  1874  	req = proto.Clone(req).(*longrunningpb.ListOperationsRequest)
  1875  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1876  	it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) {
  1877  		resp := &longrunningpb.ListOperationsResponse{}
  1878  		if pageToken != "" {
  1879  			req.PageToken = pageToken
  1880  		}
  1881  		if pageSize > math.MaxInt32 {
  1882  			req.PageSize = math.MaxInt32
  1883  		} else if pageSize != 0 {
  1884  			req.PageSize = int32(pageSize)
  1885  		}
  1886  		baseUrl, err := url.Parse(c.endpoint)
  1887  		if err != nil {
  1888  			return nil, "", err
  1889  		}
  1890  		baseUrl.Path += fmt.Sprintf("/ui/%v/operations", req.GetName())
  1891  
  1892  		params := url.Values{}
  1893  		params.Add("$alt", "json;enum-encoding=int")
  1894  		if req.GetFilter() != "" {
  1895  			params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
  1896  		}
  1897  		if req.GetPageSize() != 0 {
  1898  			params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
  1899  		}
  1900  		if req.GetPageToken() != "" {
  1901  			params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
  1902  		}
  1903  
  1904  		baseUrl.RawQuery = params.Encode()
  1905  
  1906  		// Build HTTP headers from client and context metadata.
  1907  		hds := append(c.xGoogHeaders, "Content-Type", "application/json")
  1908  		headers := gax.BuildHeaders(ctx, hds...)
  1909  		e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1910  			if settings.Path != "" {
  1911  				baseUrl.Path = settings.Path
  1912  			}
  1913  			httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
  1914  			if err != nil {
  1915  				return err
  1916  			}
  1917  			httpReq.Header = headers
  1918  
  1919  			buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListOperations")
  1920  			if err != nil {
  1921  				return err
  1922  			}
  1923  			if err := unm.Unmarshal(buf, resp); err != nil {
  1924  				return err
  1925  			}
  1926  
  1927  			return nil
  1928  		}, opts...)
  1929  		if e != nil {
  1930  			return nil, "", e
  1931  		}
  1932  		it.Response = resp
  1933  		return resp.GetOperations(), resp.GetNextPageToken(), nil
  1934  	}
  1935  
  1936  	fetch := func(pageSize int, pageToken string) (string, error) {
  1937  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  1938  		if err != nil {
  1939  			return "", err
  1940  		}
  1941  		it.items = append(it.items, items...)
  1942  		return nextPageToken, nil
  1943  	}
  1944  
  1945  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  1946  	it.pageInfo.MaxSize = int(req.GetPageSize())
  1947  	it.pageInfo.Token = req.GetPageToken()
  1948  
  1949  	return it
  1950  }
  1951  
  1952  // WaitOperation is a utility method from google.longrunning.Operations.
  1953  func (c *indexRESTClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
  1954  	baseUrl, err := url.Parse(c.endpoint)
  1955  	if err != nil {
  1956  		return nil, err
  1957  	}
  1958  	baseUrl.Path += fmt.Sprintf("/ui/%v:wait", req.GetName())
  1959  
  1960  	params := url.Values{}
  1961  	params.Add("$alt", "json;enum-encoding=int")
  1962  	if req.GetTimeout() != nil {
  1963  		field, err := protojson.Marshal(req.GetTimeout())
  1964  		if err != nil {
  1965  			return nil, err
  1966  		}
  1967  		params.Add("timeout", string(field[1:len(field)-1]))
  1968  	}
  1969  
  1970  	baseUrl.RawQuery = params.Encode()
  1971  
  1972  	// Build HTTP headers from client and context metadata.
  1973  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  1974  
  1975  	hds = append(c.xGoogHeaders, hds...)
  1976  	hds = append(hds, "Content-Type", "application/json")
  1977  	headers := gax.BuildHeaders(ctx, hds...)
  1978  	opts = append((*c.CallOptions).WaitOperation[0:len((*c.CallOptions).WaitOperation):len((*c.CallOptions).WaitOperation)], opts...)
  1979  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1980  	resp := &longrunningpb.Operation{}
  1981  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1982  		if settings.Path != "" {
  1983  			baseUrl.Path = settings.Path
  1984  		}
  1985  		httpReq, err := http.NewRequest("POST", baseUrl.String(), nil)
  1986  		if err != nil {
  1987  			return err
  1988  		}
  1989  		httpReq = httpReq.WithContext(ctx)
  1990  		httpReq.Header = headers
  1991  
  1992  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "WaitOperation")
  1993  		if err != nil {
  1994  			return err
  1995  		}
  1996  
  1997  		if err := unm.Unmarshal(buf, resp); err != nil {
  1998  			return err
  1999  		}
  2000  
  2001  		return nil
  2002  	}, opts...)
  2003  	if e != nil {
  2004  		return nil, e
  2005  	}
  2006  	return resp, nil
  2007  }
  2008  
  2009  // CreateIndexOperation returns a new CreateIndexOperation from a given name.
  2010  // The name must be that of a previously created CreateIndexOperation, possibly from a different process.
  2011  func (c *indexGRPCClient) CreateIndexOperation(name string) *CreateIndexOperation {
  2012  	return &CreateIndexOperation{
  2013  		lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
  2014  	}
  2015  }
  2016  
  2017  // CreateIndexOperation returns a new CreateIndexOperation from a given name.
  2018  // The name must be that of a previously created CreateIndexOperation, possibly from a different process.
  2019  func (c *indexRESTClient) CreateIndexOperation(name string) *CreateIndexOperation {
  2020  	override := fmt.Sprintf("/ui/%s", name)
  2021  	return &CreateIndexOperation{
  2022  		lro:      longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
  2023  		pollPath: override,
  2024  	}
  2025  }
  2026  
  2027  // DeleteIndexOperation returns a new DeleteIndexOperation from a given name.
  2028  // The name must be that of a previously created DeleteIndexOperation, possibly from a different process.
  2029  func (c *indexGRPCClient) DeleteIndexOperation(name string) *DeleteIndexOperation {
  2030  	return &DeleteIndexOperation{
  2031  		lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
  2032  	}
  2033  }
  2034  
  2035  // DeleteIndexOperation returns a new DeleteIndexOperation from a given name.
  2036  // The name must be that of a previously created DeleteIndexOperation, possibly from a different process.
  2037  func (c *indexRESTClient) DeleteIndexOperation(name string) *DeleteIndexOperation {
  2038  	override := fmt.Sprintf("/ui/%s", name)
  2039  	return &DeleteIndexOperation{
  2040  		lro:      longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
  2041  		pollPath: override,
  2042  	}
  2043  }
  2044  
  2045  // ImportIndexOperation returns a new ImportIndexOperation from a given name.
  2046  // The name must be that of a previously created ImportIndexOperation, possibly from a different process.
  2047  func (c *indexGRPCClient) ImportIndexOperation(name string) *ImportIndexOperation {
  2048  	return &ImportIndexOperation{
  2049  		lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
  2050  	}
  2051  }
  2052  
  2053  // ImportIndexOperation returns a new ImportIndexOperation from a given name.
  2054  // The name must be that of a previously created ImportIndexOperation, possibly from a different process.
  2055  func (c *indexRESTClient) ImportIndexOperation(name string) *ImportIndexOperation {
  2056  	override := fmt.Sprintf("/ui/%s", name)
  2057  	return &ImportIndexOperation{
  2058  		lro:      longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
  2059  		pollPath: override,
  2060  	}
  2061  }
  2062  
  2063  // UpdateIndexOperation returns a new UpdateIndexOperation from a given name.
  2064  // The name must be that of a previously created UpdateIndexOperation, possibly from a different process.
  2065  func (c *indexGRPCClient) UpdateIndexOperation(name string) *UpdateIndexOperation {
  2066  	return &UpdateIndexOperation{
  2067  		lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
  2068  	}
  2069  }
  2070  
  2071  // UpdateIndexOperation returns a new UpdateIndexOperation from a given name.
  2072  // The name must be that of a previously created UpdateIndexOperation, possibly from a different process.
  2073  func (c *indexRESTClient) UpdateIndexOperation(name string) *UpdateIndexOperation {
  2074  	override := fmt.Sprintf("/ui/%s", name)
  2075  	return &UpdateIndexOperation{
  2076  		lro:      longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
  2077  		pollPath: override,
  2078  	}
  2079  }