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