cloud.google.com/go/aiplatform@v1.106.0/apiv1beta1/extension_execution_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  	longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb"
    31  	gax "github.com/googleapis/gax-go/v2"
    32  	"google.golang.org/api/iterator"
    33  	"google.golang.org/api/option"
    34  	"google.golang.org/api/option/internaloption"
    35  	gtransport "google.golang.org/api/transport/grpc"
    36  	httptransport "google.golang.org/api/transport/http"
    37  	locationpb "google.golang.org/genproto/googleapis/cloud/location"
    38  	"google.golang.org/grpc"
    39  	"google.golang.org/protobuf/encoding/protojson"
    40  	"google.golang.org/protobuf/proto"
    41  )
    42  
    43  var newExtensionExecutionClientHook clientHook
    44  
    45  // ExtensionExecutionCallOptions contains the retry settings for each method of ExtensionExecutionClient.
    46  type ExtensionExecutionCallOptions struct {
    47  	ExecuteExtension   []gax.CallOption
    48  	QueryExtension     []gax.CallOption
    49  	GetLocation        []gax.CallOption
    50  	ListLocations      []gax.CallOption
    51  	GetIamPolicy       []gax.CallOption
    52  	SetIamPolicy       []gax.CallOption
    53  	TestIamPermissions []gax.CallOption
    54  	CancelOperation    []gax.CallOption
    55  	DeleteOperation    []gax.CallOption
    56  	GetOperation       []gax.CallOption
    57  	ListOperations     []gax.CallOption
    58  	WaitOperation      []gax.CallOption
    59  }
    60  
    61  func defaultExtensionExecutionGRPCClientOptions() []option.ClientOption {
    62  	return []option.ClientOption{
    63  		internaloption.WithDefaultEndpoint("aiplatform.googleapis.com:443"),
    64  		internaloption.WithDefaultEndpointTemplate("aiplatform.UNIVERSE_DOMAIN:443"),
    65  		internaloption.WithDefaultMTLSEndpoint("aiplatform.mtls.googleapis.com:443"),
    66  		internaloption.WithDefaultUniverseDomain("googleapis.com"),
    67  		internaloption.WithDefaultAudience("https://aiplatform.googleapis.com/"),
    68  		internaloption.WithDefaultScopes(DefaultAuthScopes()...),
    69  		internaloption.EnableJwtWithScope(),
    70  		internaloption.EnableNewAuthLibrary(),
    71  		option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
    72  			grpc.MaxCallRecvMsgSize(math.MaxInt32))),
    73  	}
    74  }
    75  
    76  func defaultExtensionExecutionCallOptions() *ExtensionExecutionCallOptions {
    77  	return &ExtensionExecutionCallOptions{
    78  		ExecuteExtension:   []gax.CallOption{},
    79  		QueryExtension:     []gax.CallOption{},
    80  		GetLocation:        []gax.CallOption{},
    81  		ListLocations:      []gax.CallOption{},
    82  		GetIamPolicy:       []gax.CallOption{},
    83  		SetIamPolicy:       []gax.CallOption{},
    84  		TestIamPermissions: []gax.CallOption{},
    85  		CancelOperation:    []gax.CallOption{},
    86  		DeleteOperation:    []gax.CallOption{},
    87  		GetOperation:       []gax.CallOption{},
    88  		ListOperations:     []gax.CallOption{},
    89  		WaitOperation:      []gax.CallOption{},
    90  	}
    91  }
    92  
    93  func defaultExtensionExecutionRESTCallOptions() *ExtensionExecutionCallOptions {
    94  	return &ExtensionExecutionCallOptions{
    95  		ExecuteExtension:   []gax.CallOption{},
    96  		QueryExtension:     []gax.CallOption{},
    97  		GetLocation:        []gax.CallOption{},
    98  		ListLocations:      []gax.CallOption{},
    99  		GetIamPolicy:       []gax.CallOption{},
   100  		SetIamPolicy:       []gax.CallOption{},
   101  		TestIamPermissions: []gax.CallOption{},
   102  		CancelOperation:    []gax.CallOption{},
   103  		DeleteOperation:    []gax.CallOption{},
   104  		GetOperation:       []gax.CallOption{},
   105  		ListOperations:     []gax.CallOption{},
   106  		WaitOperation:      []gax.CallOption{},
   107  	}
   108  }
   109  
   110  // internalExtensionExecutionClient is an interface that defines the methods available from Vertex AI API.
   111  type internalExtensionExecutionClient interface {
   112  	Close() error
   113  	setGoogleClientInfo(...string)
   114  	Connection() *grpc.ClientConn
   115  	ExecuteExtension(context.Context, *aiplatformpb.ExecuteExtensionRequest, ...gax.CallOption) (*aiplatformpb.ExecuteExtensionResponse, error)
   116  	QueryExtension(context.Context, *aiplatformpb.QueryExtensionRequest, ...gax.CallOption) (*aiplatformpb.QueryExtensionResponse, error)
   117  	GetLocation(context.Context, *locationpb.GetLocationRequest, ...gax.CallOption) (*locationpb.Location, error)
   118  	ListLocations(context.Context, *locationpb.ListLocationsRequest, ...gax.CallOption) *LocationIterator
   119  	GetIamPolicy(context.Context, *iampb.GetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
   120  	SetIamPolicy(context.Context, *iampb.SetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
   121  	TestIamPermissions(context.Context, *iampb.TestIamPermissionsRequest, ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error)
   122  	CancelOperation(context.Context, *longrunningpb.CancelOperationRequest, ...gax.CallOption) error
   123  	DeleteOperation(context.Context, *longrunningpb.DeleteOperationRequest, ...gax.CallOption) error
   124  	GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error)
   125  	ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator
   126  	WaitOperation(context.Context, *longrunningpb.WaitOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error)
   127  }
   128  
   129  // ExtensionExecutionClient is a client for interacting with Vertex AI API.
   130  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   131  //
   132  // A service for Extension execution.
   133  type ExtensionExecutionClient struct {
   134  	// The internal transport-dependent client.
   135  	internalClient internalExtensionExecutionClient
   136  
   137  	// The call options for this service.
   138  	CallOptions *ExtensionExecutionCallOptions
   139  }
   140  
   141  // Wrapper methods routed to the internal client.
   142  
   143  // Close closes the connection to the API service. The user should invoke this when
   144  // the client is no longer required.
   145  func (c *ExtensionExecutionClient) Close() error {
   146  	return c.internalClient.Close()
   147  }
   148  
   149  // setGoogleClientInfo sets the name and version of the application in
   150  // the `x-goog-api-client` header passed on each request. Intended for
   151  // use by Google-written clients.
   152  func (c *ExtensionExecutionClient) setGoogleClientInfo(keyval ...string) {
   153  	c.internalClient.setGoogleClientInfo(keyval...)
   154  }
   155  
   156  // Connection returns a connection to the API service.
   157  //
   158  // Deprecated: Connections are now pooled so this method does not always
   159  // return the same resource.
   160  func (c *ExtensionExecutionClient) Connection() *grpc.ClientConn {
   161  	return c.internalClient.Connection()
   162  }
   163  
   164  // ExecuteExtension executes the request against a given extension.
   165  func (c *ExtensionExecutionClient) ExecuteExtension(ctx context.Context, req *aiplatformpb.ExecuteExtensionRequest, opts ...gax.CallOption) (*aiplatformpb.ExecuteExtensionResponse, error) {
   166  	return c.internalClient.ExecuteExtension(ctx, req, opts...)
   167  }
   168  
   169  // QueryExtension queries an extension with a default controller.
   170  func (c *ExtensionExecutionClient) QueryExtension(ctx context.Context, req *aiplatformpb.QueryExtensionRequest, opts ...gax.CallOption) (*aiplatformpb.QueryExtensionResponse, error) {
   171  	return c.internalClient.QueryExtension(ctx, req, opts...)
   172  }
   173  
   174  // GetLocation gets information about a location.
   175  func (c *ExtensionExecutionClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) {
   176  	return c.internalClient.GetLocation(ctx, req, opts...)
   177  }
   178  
   179  // ListLocations lists information about the supported locations for this service.
   180  func (c *ExtensionExecutionClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator {
   181  	return c.internalClient.ListLocations(ctx, req, opts...)
   182  }
   183  
   184  // GetIamPolicy gets the access control policy for a resource. Returns an empty policy
   185  // if the resource exists and does not have a policy set.
   186  func (c *ExtensionExecutionClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   187  	return c.internalClient.GetIamPolicy(ctx, req, opts...)
   188  }
   189  
   190  // SetIamPolicy sets the access control policy on the specified resource. Replaces
   191  // any existing policy.
   192  //
   193  // Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED
   194  // errors.
   195  func (c *ExtensionExecutionClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   196  	return c.internalClient.SetIamPolicy(ctx, req, opts...)
   197  }
   198  
   199  // TestIamPermissions returns permissions that a caller has on the specified resource. If the
   200  // resource does not exist, this will return an empty set of
   201  // permissions, not a NOT_FOUND error.
   202  //
   203  // Note: This operation is designed to be used for building
   204  // permission-aware UIs and command-line tools, not for authorization
   205  // checking. This operation may “fail open” without warning.
   206  func (c *ExtensionExecutionClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
   207  	return c.internalClient.TestIamPermissions(ctx, req, opts...)
   208  }
   209  
   210  // CancelOperation is a utility method from google.longrunning.Operations.
   211  func (c *ExtensionExecutionClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
   212  	return c.internalClient.CancelOperation(ctx, req, opts...)
   213  }
   214  
   215  // DeleteOperation is a utility method from google.longrunning.Operations.
   216  func (c *ExtensionExecutionClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
   217  	return c.internalClient.DeleteOperation(ctx, req, opts...)
   218  }
   219  
   220  // GetOperation is a utility method from google.longrunning.Operations.
   221  func (c *ExtensionExecutionClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
   222  	return c.internalClient.GetOperation(ctx, req, opts...)
   223  }
   224  
   225  // ListOperations is a utility method from google.longrunning.Operations.
   226  func (c *ExtensionExecutionClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
   227  	return c.internalClient.ListOperations(ctx, req, opts...)
   228  }
   229  
   230  // WaitOperation is a utility method from google.longrunning.Operations.
   231  func (c *ExtensionExecutionClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
   232  	return c.internalClient.WaitOperation(ctx, req, opts...)
   233  }
   234  
   235  // extensionExecutionGRPCClient is a client for interacting with Vertex AI API over gRPC transport.
   236  //
   237  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   238  type extensionExecutionGRPCClient struct {
   239  	// Connection pool of gRPC connections to the service.
   240  	connPool gtransport.ConnPool
   241  
   242  	// Points back to the CallOptions field of the containing ExtensionExecutionClient
   243  	CallOptions **ExtensionExecutionCallOptions
   244  
   245  	// The gRPC API client.
   246  	extensionExecutionClient aiplatformpb.ExtensionExecutionServiceClient
   247  
   248  	operationsClient longrunningpb.OperationsClient
   249  
   250  	iamPolicyClient iampb.IAMPolicyClient
   251  
   252  	locationsClient locationpb.LocationsClient
   253  
   254  	// The x-goog-* metadata to be sent with each request.
   255  	xGoogHeaders []string
   256  
   257  	logger *slog.Logger
   258  }
   259  
   260  // NewExtensionExecutionClient creates a new extension execution service client based on gRPC.
   261  // The returned client must be Closed when it is done being used to clean up its underlying connections.
   262  //
   263  // A service for Extension execution.
   264  func NewExtensionExecutionClient(ctx context.Context, opts ...option.ClientOption) (*ExtensionExecutionClient, error) {
   265  	clientOpts := defaultExtensionExecutionGRPCClientOptions()
   266  	if newExtensionExecutionClientHook != nil {
   267  		hookOpts, err := newExtensionExecutionClientHook(ctx, clientHookParams{})
   268  		if err != nil {
   269  			return nil, err
   270  		}
   271  		clientOpts = append(clientOpts, hookOpts...)
   272  	}
   273  
   274  	connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
   275  	if err != nil {
   276  		return nil, err
   277  	}
   278  	client := ExtensionExecutionClient{CallOptions: defaultExtensionExecutionCallOptions()}
   279  
   280  	c := &extensionExecutionGRPCClient{
   281  		connPool:                 connPool,
   282  		extensionExecutionClient: aiplatformpb.NewExtensionExecutionServiceClient(connPool),
   283  		CallOptions:              &client.CallOptions,
   284  		logger:                   internaloption.GetLogger(opts),
   285  		operationsClient:         longrunningpb.NewOperationsClient(connPool),
   286  		iamPolicyClient:          iampb.NewIAMPolicyClient(connPool),
   287  		locationsClient:          locationpb.NewLocationsClient(connPool),
   288  	}
   289  	c.setGoogleClientInfo()
   290  
   291  	client.internalClient = c
   292  
   293  	return &client, nil
   294  }
   295  
   296  // Connection returns a connection to the API service.
   297  //
   298  // Deprecated: Connections are now pooled so this method does not always
   299  // return the same resource.
   300  func (c *extensionExecutionGRPCClient) Connection() *grpc.ClientConn {
   301  	return c.connPool.Conn()
   302  }
   303  
   304  // setGoogleClientInfo sets the name and version of the application in
   305  // the `x-goog-api-client` header passed on each request. Intended for
   306  // use by Google-written clients.
   307  func (c *extensionExecutionGRPCClient) setGoogleClientInfo(keyval ...string) {
   308  	kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
   309  	kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
   310  	c.xGoogHeaders = []string{
   311  		"x-goog-api-client", gax.XGoogHeader(kv...),
   312  	}
   313  }
   314  
   315  // Close closes the connection to the API service. The user should invoke this when
   316  // the client is no longer required.
   317  func (c *extensionExecutionGRPCClient) Close() error {
   318  	return c.connPool.Close()
   319  }
   320  
   321  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   322  type extensionExecutionRESTClient struct {
   323  	// The http endpoint to connect to.
   324  	endpoint string
   325  
   326  	// The http client.
   327  	httpClient *http.Client
   328  
   329  	// The x-goog-* headers to be sent with each request.
   330  	xGoogHeaders []string
   331  
   332  	// Points back to the CallOptions field of the containing ExtensionExecutionClient
   333  	CallOptions **ExtensionExecutionCallOptions
   334  
   335  	logger *slog.Logger
   336  }
   337  
   338  // NewExtensionExecutionRESTClient creates a new extension execution service rest client.
   339  //
   340  // A service for Extension execution.
   341  func NewExtensionExecutionRESTClient(ctx context.Context, opts ...option.ClientOption) (*ExtensionExecutionClient, error) {
   342  	clientOpts := append(defaultExtensionExecutionRESTClientOptions(), opts...)
   343  	httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
   344  	if err != nil {
   345  		return nil, err
   346  	}
   347  
   348  	callOpts := defaultExtensionExecutionRESTCallOptions()
   349  	c := &extensionExecutionRESTClient{
   350  		endpoint:    endpoint,
   351  		httpClient:  httpClient,
   352  		CallOptions: &callOpts,
   353  		logger:      internaloption.GetLogger(opts),
   354  	}
   355  	c.setGoogleClientInfo()
   356  
   357  	return &ExtensionExecutionClient{internalClient: c, CallOptions: callOpts}, nil
   358  }
   359  
   360  func defaultExtensionExecutionRESTClientOptions() []option.ClientOption {
   361  	return []option.ClientOption{
   362  		internaloption.WithDefaultEndpoint("https://aiplatform.googleapis.com"),
   363  		internaloption.WithDefaultEndpointTemplate("https://aiplatform.UNIVERSE_DOMAIN"),
   364  		internaloption.WithDefaultMTLSEndpoint("https://aiplatform.mtls.googleapis.com"),
   365  		internaloption.WithDefaultUniverseDomain("googleapis.com"),
   366  		internaloption.WithDefaultAudience("https://aiplatform.googleapis.com/"),
   367  		internaloption.WithDefaultScopes(DefaultAuthScopes()...),
   368  		internaloption.EnableNewAuthLibrary(),
   369  	}
   370  }
   371  
   372  // setGoogleClientInfo sets the name and version of the application in
   373  // the `x-goog-api-client` header passed on each request. Intended for
   374  // use by Google-written clients.
   375  func (c *extensionExecutionRESTClient) setGoogleClientInfo(keyval ...string) {
   376  	kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
   377  	kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
   378  	c.xGoogHeaders = []string{
   379  		"x-goog-api-client", gax.XGoogHeader(kv...),
   380  	}
   381  }
   382  
   383  // Close closes the connection to the API service. The user should invoke this when
   384  // the client is no longer required.
   385  func (c *extensionExecutionRESTClient) Close() error {
   386  	// Replace httpClient with nil to force cleanup.
   387  	c.httpClient = nil
   388  	return nil
   389  }
   390  
   391  // Connection returns a connection to the API service.
   392  //
   393  // Deprecated: This method always returns nil.
   394  func (c *extensionExecutionRESTClient) Connection() *grpc.ClientConn {
   395  	return nil
   396  }
   397  func (c *extensionExecutionGRPCClient) ExecuteExtension(ctx context.Context, req *aiplatformpb.ExecuteExtensionRequest, opts ...gax.CallOption) (*aiplatformpb.ExecuteExtensionResponse, error) {
   398  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   399  
   400  	hds = append(c.xGoogHeaders, hds...)
   401  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   402  	opts = append((*c.CallOptions).ExecuteExtension[0:len((*c.CallOptions).ExecuteExtension):len((*c.CallOptions).ExecuteExtension)], opts...)
   403  	var resp *aiplatformpb.ExecuteExtensionResponse
   404  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   405  		var err error
   406  		resp, err = executeRPC(ctx, c.extensionExecutionClient.ExecuteExtension, req, settings.GRPC, c.logger, "ExecuteExtension")
   407  		return err
   408  	}, opts...)
   409  	if err != nil {
   410  		return nil, err
   411  	}
   412  	return resp, nil
   413  }
   414  
   415  func (c *extensionExecutionGRPCClient) QueryExtension(ctx context.Context, req *aiplatformpb.QueryExtensionRequest, opts ...gax.CallOption) (*aiplatformpb.QueryExtensionResponse, error) {
   416  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   417  
   418  	hds = append(c.xGoogHeaders, hds...)
   419  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   420  	opts = append((*c.CallOptions).QueryExtension[0:len((*c.CallOptions).QueryExtension):len((*c.CallOptions).QueryExtension)], opts...)
   421  	var resp *aiplatformpb.QueryExtensionResponse
   422  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   423  		var err error
   424  		resp, err = executeRPC(ctx, c.extensionExecutionClient.QueryExtension, req, settings.GRPC, c.logger, "QueryExtension")
   425  		return err
   426  	}, opts...)
   427  	if err != nil {
   428  		return nil, err
   429  	}
   430  	return resp, nil
   431  }
   432  
   433  func (c *extensionExecutionGRPCClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) {
   434  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   435  
   436  	hds = append(c.xGoogHeaders, hds...)
   437  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   438  	opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...)
   439  	var resp *locationpb.Location
   440  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   441  		var err error
   442  		resp, err = executeRPC(ctx, c.locationsClient.GetLocation, req, settings.GRPC, c.logger, "GetLocation")
   443  		return err
   444  	}, opts...)
   445  	if err != nil {
   446  		return nil, err
   447  	}
   448  	return resp, nil
   449  }
   450  
   451  func (c *extensionExecutionGRPCClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator {
   452  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   453  
   454  	hds = append(c.xGoogHeaders, hds...)
   455  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   456  	opts = append((*c.CallOptions).ListLocations[0:len((*c.CallOptions).ListLocations):len((*c.CallOptions).ListLocations)], opts...)
   457  	it := &LocationIterator{}
   458  	req = proto.Clone(req).(*locationpb.ListLocationsRequest)
   459  	it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) {
   460  		resp := &locationpb.ListLocationsResponse{}
   461  		if pageToken != "" {
   462  			req.PageToken = pageToken
   463  		}
   464  		if pageSize > math.MaxInt32 {
   465  			req.PageSize = math.MaxInt32
   466  		} else if pageSize != 0 {
   467  			req.PageSize = int32(pageSize)
   468  		}
   469  		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   470  			var err error
   471  			resp, err = executeRPC(ctx, c.locationsClient.ListLocations, req, settings.GRPC, c.logger, "ListLocations")
   472  			return err
   473  		}, opts...)
   474  		if err != nil {
   475  			return nil, "", err
   476  		}
   477  
   478  		it.Response = resp
   479  		return resp.GetLocations(), resp.GetNextPageToken(), nil
   480  	}
   481  	fetch := func(pageSize int, pageToken string) (string, error) {
   482  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
   483  		if err != nil {
   484  			return "", err
   485  		}
   486  		it.items = append(it.items, items...)
   487  		return nextPageToken, nil
   488  	}
   489  
   490  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
   491  	it.pageInfo.MaxSize = int(req.GetPageSize())
   492  	it.pageInfo.Token = req.GetPageToken()
   493  
   494  	return it
   495  }
   496  
   497  func (c *extensionExecutionGRPCClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   498  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
   499  
   500  	hds = append(c.xGoogHeaders, hds...)
   501  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   502  	opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
   503  	var resp *iampb.Policy
   504  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   505  		var err error
   506  		resp, err = executeRPC(ctx, c.iamPolicyClient.GetIamPolicy, req, settings.GRPC, c.logger, "GetIamPolicy")
   507  		return err
   508  	}, opts...)
   509  	if err != nil {
   510  		return nil, err
   511  	}
   512  	return resp, nil
   513  }
   514  
   515  func (c *extensionExecutionGRPCClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   516  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
   517  
   518  	hds = append(c.xGoogHeaders, hds...)
   519  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   520  	opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
   521  	var resp *iampb.Policy
   522  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   523  		var err error
   524  		resp, err = executeRPC(ctx, c.iamPolicyClient.SetIamPolicy, req, settings.GRPC, c.logger, "SetIamPolicy")
   525  		return err
   526  	}, opts...)
   527  	if err != nil {
   528  		return nil, err
   529  	}
   530  	return resp, nil
   531  }
   532  
   533  func (c *extensionExecutionGRPCClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
   534  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
   535  
   536  	hds = append(c.xGoogHeaders, hds...)
   537  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   538  	opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...)
   539  	var resp *iampb.TestIamPermissionsResponse
   540  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   541  		var err error
   542  		resp, err = executeRPC(ctx, c.iamPolicyClient.TestIamPermissions, req, settings.GRPC, c.logger, "TestIamPermissions")
   543  		return err
   544  	}, opts...)
   545  	if err != nil {
   546  		return nil, err
   547  	}
   548  	return resp, nil
   549  }
   550  
   551  func (c *extensionExecutionGRPCClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
   552  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   553  
   554  	hds = append(c.xGoogHeaders, hds...)
   555  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   556  	opts = append((*c.CallOptions).CancelOperation[0:len((*c.CallOptions).CancelOperation):len((*c.CallOptions).CancelOperation)], opts...)
   557  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   558  		var err error
   559  		_, err = executeRPC(ctx, c.operationsClient.CancelOperation, req, settings.GRPC, c.logger, "CancelOperation")
   560  		return err
   561  	}, opts...)
   562  	return err
   563  }
   564  
   565  func (c *extensionExecutionGRPCClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
   566  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   567  
   568  	hds = append(c.xGoogHeaders, hds...)
   569  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   570  	opts = append((*c.CallOptions).DeleteOperation[0:len((*c.CallOptions).DeleteOperation):len((*c.CallOptions).DeleteOperation)], opts...)
   571  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   572  		var err error
   573  		_, err = executeRPC(ctx, c.operationsClient.DeleteOperation, req, settings.GRPC, c.logger, "DeleteOperation")
   574  		return err
   575  	}, opts...)
   576  	return err
   577  }
   578  
   579  func (c *extensionExecutionGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, 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).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], 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.operationsClient.GetOperation, req, settings.GRPC, c.logger, "GetOperation")
   589  		return err
   590  	}, opts...)
   591  	if err != nil {
   592  		return nil, err
   593  	}
   594  	return resp, nil
   595  }
   596  
   597  func (c *extensionExecutionGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
   598  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   599  
   600  	hds = append(c.xGoogHeaders, hds...)
   601  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   602  	opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...)
   603  	it := &OperationIterator{}
   604  	req = proto.Clone(req).(*longrunningpb.ListOperationsRequest)
   605  	it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) {
   606  		resp := &longrunningpb.ListOperationsResponse{}
   607  		if pageToken != "" {
   608  			req.PageToken = pageToken
   609  		}
   610  		if pageSize > math.MaxInt32 {
   611  			req.PageSize = math.MaxInt32
   612  		} else if pageSize != 0 {
   613  			req.PageSize = int32(pageSize)
   614  		}
   615  		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   616  			var err error
   617  			resp, err = executeRPC(ctx, c.operationsClient.ListOperations, req, settings.GRPC, c.logger, "ListOperations")
   618  			return err
   619  		}, opts...)
   620  		if err != nil {
   621  			return nil, "", err
   622  		}
   623  
   624  		it.Response = resp
   625  		return resp.GetOperations(), resp.GetNextPageToken(), nil
   626  	}
   627  	fetch := func(pageSize int, pageToken string) (string, error) {
   628  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
   629  		if err != nil {
   630  			return "", err
   631  		}
   632  		it.items = append(it.items, items...)
   633  		return nextPageToken, nil
   634  	}
   635  
   636  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
   637  	it.pageInfo.MaxSize = int(req.GetPageSize())
   638  	it.pageInfo.Token = req.GetPageToken()
   639  
   640  	return it
   641  }
   642  
   643  func (c *extensionExecutionGRPCClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, 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).WaitOperation[0:len((*c.CallOptions).WaitOperation):len((*c.CallOptions).WaitOperation)], opts...)
   649  	var resp *longrunningpb.Operation
   650  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   651  		var err error
   652  		resp, err = executeRPC(ctx, c.operationsClient.WaitOperation, req, settings.GRPC, c.logger, "WaitOperation")
   653  		return err
   654  	}, opts...)
   655  	if err != nil {
   656  		return nil, err
   657  	}
   658  	return resp, nil
   659  }
   660  
   661  // ExecuteExtension executes the request against a given extension.
   662  func (c *extensionExecutionRESTClient) ExecuteExtension(ctx context.Context, req *aiplatformpb.ExecuteExtensionRequest, opts ...gax.CallOption) (*aiplatformpb.ExecuteExtensionResponse, error) {
   663  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
   664  	jsonReq, err := m.Marshal(req)
   665  	if err != nil {
   666  		return nil, err
   667  	}
   668  
   669  	baseUrl, err := url.Parse(c.endpoint)
   670  	if err != nil {
   671  		return nil, err
   672  	}
   673  	baseUrl.Path += fmt.Sprintf("/v1beta1/%v:execute", req.GetName())
   674  
   675  	params := url.Values{}
   676  	params.Add("$alt", "json;enum-encoding=int")
   677  
   678  	baseUrl.RawQuery = params.Encode()
   679  
   680  	// Build HTTP headers from client and context metadata.
   681  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   682  
   683  	hds = append(c.xGoogHeaders, hds...)
   684  	hds = append(hds, "Content-Type", "application/json")
   685  	headers := gax.BuildHeaders(ctx, hds...)
   686  	opts = append((*c.CallOptions).ExecuteExtension[0:len((*c.CallOptions).ExecuteExtension):len((*c.CallOptions).ExecuteExtension)], opts...)
   687  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
   688  	resp := &aiplatformpb.ExecuteExtensionResponse{}
   689  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   690  		if settings.Path != "" {
   691  			baseUrl.Path = settings.Path
   692  		}
   693  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
   694  		if err != nil {
   695  			return err
   696  		}
   697  		httpReq = httpReq.WithContext(ctx)
   698  		httpReq.Header = headers
   699  
   700  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "ExecuteExtension")
   701  		if err != nil {
   702  			return err
   703  		}
   704  
   705  		if err := unm.Unmarshal(buf, resp); err != nil {
   706  			return err
   707  		}
   708  
   709  		return nil
   710  	}, opts...)
   711  	if e != nil {
   712  		return nil, e
   713  	}
   714  	return resp, nil
   715  }
   716  
   717  // QueryExtension queries an extension with a default controller.
   718  func (c *extensionExecutionRESTClient) QueryExtension(ctx context.Context, req *aiplatformpb.QueryExtensionRequest, opts ...gax.CallOption) (*aiplatformpb.QueryExtensionResponse, error) {
   719  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
   720  	jsonReq, err := m.Marshal(req)
   721  	if err != nil {
   722  		return nil, err
   723  	}
   724  
   725  	baseUrl, err := url.Parse(c.endpoint)
   726  	if err != nil {
   727  		return nil, err
   728  	}
   729  	baseUrl.Path += fmt.Sprintf("/v1beta1/%v:query", req.GetName())
   730  
   731  	params := url.Values{}
   732  	params.Add("$alt", "json;enum-encoding=int")
   733  
   734  	baseUrl.RawQuery = params.Encode()
   735  
   736  	// Build HTTP headers from client and context metadata.
   737  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   738  
   739  	hds = append(c.xGoogHeaders, hds...)
   740  	hds = append(hds, "Content-Type", "application/json")
   741  	headers := gax.BuildHeaders(ctx, hds...)
   742  	opts = append((*c.CallOptions).QueryExtension[0:len((*c.CallOptions).QueryExtension):len((*c.CallOptions).QueryExtension)], opts...)
   743  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
   744  	resp := &aiplatformpb.QueryExtensionResponse{}
   745  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   746  		if settings.Path != "" {
   747  			baseUrl.Path = settings.Path
   748  		}
   749  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
   750  		if err != nil {
   751  			return err
   752  		}
   753  		httpReq = httpReq.WithContext(ctx)
   754  		httpReq.Header = headers
   755  
   756  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "QueryExtension")
   757  		if err != nil {
   758  			return err
   759  		}
   760  
   761  		if err := unm.Unmarshal(buf, resp); err != nil {
   762  			return err
   763  		}
   764  
   765  		return nil
   766  	}, opts...)
   767  	if e != nil {
   768  		return nil, e
   769  	}
   770  	return resp, nil
   771  }
   772  
   773  // GetLocation gets information about a location.
   774  func (c *extensionExecutionRESTClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) {
   775  	baseUrl, err := url.Parse(c.endpoint)
   776  	if err != nil {
   777  		return nil, err
   778  	}
   779  	baseUrl.Path += fmt.Sprintf("/ui/%v", req.GetName())
   780  
   781  	params := url.Values{}
   782  	params.Add("$alt", "json;enum-encoding=int")
   783  
   784  	baseUrl.RawQuery = params.Encode()
   785  
   786  	// Build HTTP headers from client and context metadata.
   787  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   788  
   789  	hds = append(c.xGoogHeaders, hds...)
   790  	hds = append(hds, "Content-Type", "application/json")
   791  	headers := gax.BuildHeaders(ctx, hds...)
   792  	opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...)
   793  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
   794  	resp := &locationpb.Location{}
   795  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   796  		if settings.Path != "" {
   797  			baseUrl.Path = settings.Path
   798  		}
   799  		httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
   800  		if err != nil {
   801  			return err
   802  		}
   803  		httpReq = httpReq.WithContext(ctx)
   804  		httpReq.Header = headers
   805  
   806  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetLocation")
   807  		if err != nil {
   808  			return err
   809  		}
   810  
   811  		if err := unm.Unmarshal(buf, resp); err != nil {
   812  			return err
   813  		}
   814  
   815  		return nil
   816  	}, opts...)
   817  	if e != nil {
   818  		return nil, e
   819  	}
   820  	return resp, nil
   821  }
   822  
   823  // ListLocations lists information about the supported locations for this service.
   824  func (c *extensionExecutionRESTClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator {
   825  	it := &LocationIterator{}
   826  	req = proto.Clone(req).(*locationpb.ListLocationsRequest)
   827  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
   828  	it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) {
   829  		resp := &locationpb.ListLocationsResponse{}
   830  		if pageToken != "" {
   831  			req.PageToken = pageToken
   832  		}
   833  		if pageSize > math.MaxInt32 {
   834  			req.PageSize = math.MaxInt32
   835  		} else if pageSize != 0 {
   836  			req.PageSize = int32(pageSize)
   837  		}
   838  		baseUrl, err := url.Parse(c.endpoint)
   839  		if err != nil {
   840  			return nil, "", err
   841  		}
   842  		baseUrl.Path += fmt.Sprintf("/ui/%v/locations", req.GetName())
   843  
   844  		params := url.Values{}
   845  		params.Add("$alt", "json;enum-encoding=int")
   846  		if req.GetFilter() != "" {
   847  			params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
   848  		}
   849  		if req.GetPageSize() != 0 {
   850  			params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
   851  		}
   852  		if req.GetPageToken() != "" {
   853  			params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
   854  		}
   855  
   856  		baseUrl.RawQuery = params.Encode()
   857  
   858  		// Build HTTP headers from client and context metadata.
   859  		hds := append(c.xGoogHeaders, "Content-Type", "application/json")
   860  		headers := gax.BuildHeaders(ctx, hds...)
   861  		e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   862  			if settings.Path != "" {
   863  				baseUrl.Path = settings.Path
   864  			}
   865  			httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
   866  			if err != nil {
   867  				return err
   868  			}
   869  			httpReq.Header = headers
   870  
   871  			buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListLocations")
   872  			if err != nil {
   873  				return err
   874  			}
   875  			if err := unm.Unmarshal(buf, resp); err != nil {
   876  				return err
   877  			}
   878  
   879  			return nil
   880  		}, opts...)
   881  		if e != nil {
   882  			return nil, "", e
   883  		}
   884  		it.Response = resp
   885  		return resp.GetLocations(), resp.GetNextPageToken(), nil
   886  	}
   887  
   888  	fetch := func(pageSize int, pageToken string) (string, error) {
   889  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
   890  		if err != nil {
   891  			return "", err
   892  		}
   893  		it.items = append(it.items, items...)
   894  		return nextPageToken, nil
   895  	}
   896  
   897  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
   898  	it.pageInfo.MaxSize = int(req.GetPageSize())
   899  	it.pageInfo.Token = req.GetPageToken()
   900  
   901  	return it
   902  }
   903  
   904  // GetIamPolicy gets the access control policy for a resource. Returns an empty policy
   905  // if the resource exists and does not have a policy set.
   906  func (c *extensionExecutionRESTClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   907  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
   908  	jsonReq, err := m.Marshal(req)
   909  	if err != nil {
   910  		return nil, err
   911  	}
   912  
   913  	baseUrl, err := url.Parse(c.endpoint)
   914  	if err != nil {
   915  		return nil, err
   916  	}
   917  	baseUrl.Path += fmt.Sprintf("/v1beta1/%v:getIamPolicy", req.GetResource())
   918  
   919  	params := url.Values{}
   920  	params.Add("$alt", "json;enum-encoding=int")
   921  
   922  	baseUrl.RawQuery = params.Encode()
   923  
   924  	// Build HTTP headers from client and context metadata.
   925  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
   926  
   927  	hds = append(c.xGoogHeaders, hds...)
   928  	hds = append(hds, "Content-Type", "application/json")
   929  	headers := gax.BuildHeaders(ctx, hds...)
   930  	opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
   931  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
   932  	resp := &iampb.Policy{}
   933  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   934  		if settings.Path != "" {
   935  			baseUrl.Path = settings.Path
   936  		}
   937  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
   938  		if err != nil {
   939  			return err
   940  		}
   941  		httpReq = httpReq.WithContext(ctx)
   942  		httpReq.Header = headers
   943  
   944  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "GetIamPolicy")
   945  		if err != nil {
   946  			return err
   947  		}
   948  
   949  		if err := unm.Unmarshal(buf, resp); err != nil {
   950  			return err
   951  		}
   952  
   953  		return nil
   954  	}, opts...)
   955  	if e != nil {
   956  		return nil, e
   957  	}
   958  	return resp, nil
   959  }
   960  
   961  // SetIamPolicy sets the access control policy on the specified resource. Replaces
   962  // any existing policy.
   963  //
   964  // Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED
   965  // errors.
   966  func (c *extensionExecutionRESTClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   967  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
   968  	jsonReq, err := m.Marshal(req)
   969  	if err != nil {
   970  		return nil, err
   971  	}
   972  
   973  	baseUrl, err := url.Parse(c.endpoint)
   974  	if err != nil {
   975  		return nil, err
   976  	}
   977  	baseUrl.Path += fmt.Sprintf("/v1beta1/%v:setIamPolicy", req.GetResource())
   978  
   979  	params := url.Values{}
   980  	params.Add("$alt", "json;enum-encoding=int")
   981  
   982  	baseUrl.RawQuery = params.Encode()
   983  
   984  	// Build HTTP headers from client and context metadata.
   985  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
   986  
   987  	hds = append(c.xGoogHeaders, hds...)
   988  	hds = append(hds, "Content-Type", "application/json")
   989  	headers := gax.BuildHeaders(ctx, hds...)
   990  	opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
   991  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
   992  	resp := &iampb.Policy{}
   993  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   994  		if settings.Path != "" {
   995  			baseUrl.Path = settings.Path
   996  		}
   997  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
   998  		if err != nil {
   999  			return err
  1000  		}
  1001  		httpReq = httpReq.WithContext(ctx)
  1002  		httpReq.Header = headers
  1003  
  1004  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "SetIamPolicy")
  1005  		if err != nil {
  1006  			return err
  1007  		}
  1008  
  1009  		if err := unm.Unmarshal(buf, resp); err != nil {
  1010  			return err
  1011  		}
  1012  
  1013  		return nil
  1014  	}, opts...)
  1015  	if e != nil {
  1016  		return nil, e
  1017  	}
  1018  	return resp, nil
  1019  }
  1020  
  1021  // TestIamPermissions returns permissions that a caller has on the specified resource. If the
  1022  // resource does not exist, this will return an empty set of
  1023  // permissions, not a NOT_FOUND error.
  1024  //
  1025  // Note: This operation is designed to be used for building
  1026  // permission-aware UIs and command-line tools, not for authorization
  1027  // checking. This operation may “fail open” without warning.
  1028  func (c *extensionExecutionRESTClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
  1029  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
  1030  	jsonReq, err := m.Marshal(req)
  1031  	if err != nil {
  1032  		return nil, err
  1033  	}
  1034  
  1035  	baseUrl, err := url.Parse(c.endpoint)
  1036  	if err != nil {
  1037  		return nil, err
  1038  	}
  1039  	baseUrl.Path += fmt.Sprintf("/v1beta1/%v:testIamPermissions", req.GetResource())
  1040  
  1041  	params := url.Values{}
  1042  	params.Add("$alt", "json;enum-encoding=int")
  1043  
  1044  	baseUrl.RawQuery = params.Encode()
  1045  
  1046  	// Build HTTP headers from client and context metadata.
  1047  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
  1048  
  1049  	hds = append(c.xGoogHeaders, hds...)
  1050  	hds = append(hds, "Content-Type", "application/json")
  1051  	headers := gax.BuildHeaders(ctx, hds...)
  1052  	opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...)
  1053  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1054  	resp := &iampb.TestIamPermissionsResponse{}
  1055  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1056  		if settings.Path != "" {
  1057  			baseUrl.Path = settings.Path
  1058  		}
  1059  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
  1060  		if err != nil {
  1061  			return err
  1062  		}
  1063  		httpReq = httpReq.WithContext(ctx)
  1064  		httpReq.Header = headers
  1065  
  1066  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "TestIamPermissions")
  1067  		if err != nil {
  1068  			return err
  1069  		}
  1070  
  1071  		if err := unm.Unmarshal(buf, resp); err != nil {
  1072  			return err
  1073  		}
  1074  
  1075  		return nil
  1076  	}, opts...)
  1077  	if e != nil {
  1078  		return nil, e
  1079  	}
  1080  	return resp, nil
  1081  }
  1082  
  1083  // CancelOperation is a utility method from google.longrunning.Operations.
  1084  func (c *extensionExecutionRESTClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
  1085  	baseUrl, err := url.Parse(c.endpoint)
  1086  	if err != nil {
  1087  		return err
  1088  	}
  1089  	baseUrl.Path += fmt.Sprintf("/ui/%v:cancel", req.GetName())
  1090  
  1091  	params := url.Values{}
  1092  	params.Add("$alt", "json;enum-encoding=int")
  1093  
  1094  	baseUrl.RawQuery = params.Encode()
  1095  
  1096  	// Build HTTP headers from client and context metadata.
  1097  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  1098  
  1099  	hds = append(c.xGoogHeaders, hds...)
  1100  	hds = append(hds, "Content-Type", "application/json")
  1101  	headers := gax.BuildHeaders(ctx, hds...)
  1102  	return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1103  		if settings.Path != "" {
  1104  			baseUrl.Path = settings.Path
  1105  		}
  1106  		httpReq, err := http.NewRequest("POST", baseUrl.String(), nil)
  1107  		if err != nil {
  1108  			return err
  1109  		}
  1110  		httpReq = httpReq.WithContext(ctx)
  1111  		httpReq.Header = headers
  1112  
  1113  		_, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "CancelOperation")
  1114  		return err
  1115  	}, opts...)
  1116  }
  1117  
  1118  // DeleteOperation is a utility method from google.longrunning.Operations.
  1119  func (c *extensionExecutionRESTClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
  1120  	baseUrl, err := url.Parse(c.endpoint)
  1121  	if err != nil {
  1122  		return err
  1123  	}
  1124  	baseUrl.Path += fmt.Sprintf("/ui/%v", req.GetName())
  1125  
  1126  	params := url.Values{}
  1127  	params.Add("$alt", "json;enum-encoding=int")
  1128  
  1129  	baseUrl.RawQuery = params.Encode()
  1130  
  1131  	// Build HTTP headers from client and context metadata.
  1132  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  1133  
  1134  	hds = append(c.xGoogHeaders, hds...)
  1135  	hds = append(hds, "Content-Type", "application/json")
  1136  	headers := gax.BuildHeaders(ctx, hds...)
  1137  	return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1138  		if settings.Path != "" {
  1139  			baseUrl.Path = settings.Path
  1140  		}
  1141  		httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
  1142  		if err != nil {
  1143  			return err
  1144  		}
  1145  		httpReq = httpReq.WithContext(ctx)
  1146  		httpReq.Header = headers
  1147  
  1148  		_, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteOperation")
  1149  		return err
  1150  	}, opts...)
  1151  }
  1152  
  1153  // GetOperation is a utility method from google.longrunning.Operations.
  1154  func (c *extensionExecutionRESTClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
  1155  	baseUrl, err := url.Parse(c.endpoint)
  1156  	if err != nil {
  1157  		return nil, err
  1158  	}
  1159  	baseUrl.Path += fmt.Sprintf("/ui/%v", req.GetName())
  1160  
  1161  	params := url.Values{}
  1162  	params.Add("$alt", "json;enum-encoding=int")
  1163  
  1164  	baseUrl.RawQuery = params.Encode()
  1165  
  1166  	// Build HTTP headers from client and context metadata.
  1167  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  1168  
  1169  	hds = append(c.xGoogHeaders, hds...)
  1170  	hds = append(hds, "Content-Type", "application/json")
  1171  	headers := gax.BuildHeaders(ctx, hds...)
  1172  	opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
  1173  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1174  	resp := &longrunningpb.Operation{}
  1175  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1176  		if settings.Path != "" {
  1177  			baseUrl.Path = settings.Path
  1178  		}
  1179  		httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
  1180  		if err != nil {
  1181  			return err
  1182  		}
  1183  		httpReq = httpReq.WithContext(ctx)
  1184  		httpReq.Header = headers
  1185  
  1186  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetOperation")
  1187  		if err != nil {
  1188  			return err
  1189  		}
  1190  
  1191  		if err := unm.Unmarshal(buf, resp); err != nil {
  1192  			return err
  1193  		}
  1194  
  1195  		return nil
  1196  	}, opts...)
  1197  	if e != nil {
  1198  		return nil, e
  1199  	}
  1200  	return resp, nil
  1201  }
  1202  
  1203  // ListOperations is a utility method from google.longrunning.Operations.
  1204  func (c *extensionExecutionRESTClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
  1205  	it := &OperationIterator{}
  1206  	req = proto.Clone(req).(*longrunningpb.ListOperationsRequest)
  1207  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1208  	it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) {
  1209  		resp := &longrunningpb.ListOperationsResponse{}
  1210  		if pageToken != "" {
  1211  			req.PageToken = pageToken
  1212  		}
  1213  		if pageSize > math.MaxInt32 {
  1214  			req.PageSize = math.MaxInt32
  1215  		} else if pageSize != 0 {
  1216  			req.PageSize = int32(pageSize)
  1217  		}
  1218  		baseUrl, err := url.Parse(c.endpoint)
  1219  		if err != nil {
  1220  			return nil, "", err
  1221  		}
  1222  		baseUrl.Path += fmt.Sprintf("/ui/%v/operations", req.GetName())
  1223  
  1224  		params := url.Values{}
  1225  		params.Add("$alt", "json;enum-encoding=int")
  1226  		if req.GetFilter() != "" {
  1227  			params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
  1228  		}
  1229  		if req.GetPageSize() != 0 {
  1230  			params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
  1231  		}
  1232  		if req.GetPageToken() != "" {
  1233  			params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
  1234  		}
  1235  
  1236  		baseUrl.RawQuery = params.Encode()
  1237  
  1238  		// Build HTTP headers from client and context metadata.
  1239  		hds := append(c.xGoogHeaders, "Content-Type", "application/json")
  1240  		headers := gax.BuildHeaders(ctx, hds...)
  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("GET", baseUrl.String(), nil)
  1246  			if err != nil {
  1247  				return err
  1248  			}
  1249  			httpReq.Header = headers
  1250  
  1251  			buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListOperations")
  1252  			if err != nil {
  1253  				return err
  1254  			}
  1255  			if err := unm.Unmarshal(buf, resp); err != nil {
  1256  				return err
  1257  			}
  1258  
  1259  			return nil
  1260  		}, opts...)
  1261  		if e != nil {
  1262  			return nil, "", e
  1263  		}
  1264  		it.Response = resp
  1265  		return resp.GetOperations(), resp.GetNextPageToken(), nil
  1266  	}
  1267  
  1268  	fetch := func(pageSize int, pageToken string) (string, error) {
  1269  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  1270  		if err != nil {
  1271  			return "", err
  1272  		}
  1273  		it.items = append(it.items, items...)
  1274  		return nextPageToken, nil
  1275  	}
  1276  
  1277  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  1278  	it.pageInfo.MaxSize = int(req.GetPageSize())
  1279  	it.pageInfo.Token = req.GetPageToken()
  1280  
  1281  	return it
  1282  }
  1283  
  1284  // WaitOperation is a utility method from google.longrunning.Operations.
  1285  func (c *extensionExecutionRESTClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
  1286  	baseUrl, err := url.Parse(c.endpoint)
  1287  	if err != nil {
  1288  		return nil, err
  1289  	}
  1290  	baseUrl.Path += fmt.Sprintf("/ui/%v:wait", req.GetName())
  1291  
  1292  	params := url.Values{}
  1293  	params.Add("$alt", "json;enum-encoding=int")
  1294  	if req.GetTimeout() != nil {
  1295  		field, err := protojson.Marshal(req.GetTimeout())
  1296  		if err != nil {
  1297  			return nil, err
  1298  		}
  1299  		params.Add("timeout", string(field[1:len(field)-1]))
  1300  	}
  1301  
  1302  	baseUrl.RawQuery = params.Encode()
  1303  
  1304  	// Build HTTP headers from client and context metadata.
  1305  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  1306  
  1307  	hds = append(c.xGoogHeaders, hds...)
  1308  	hds = append(hds, "Content-Type", "application/json")
  1309  	headers := gax.BuildHeaders(ctx, hds...)
  1310  	opts = append((*c.CallOptions).WaitOperation[0:len((*c.CallOptions).WaitOperation):len((*c.CallOptions).WaitOperation)], opts...)
  1311  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1312  	resp := &longrunningpb.Operation{}
  1313  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1314  		if settings.Path != "" {
  1315  			baseUrl.Path = settings.Path
  1316  		}
  1317  		httpReq, err := http.NewRequest("POST", baseUrl.String(), nil)
  1318  		if err != nil {
  1319  			return err
  1320  		}
  1321  		httpReq = httpReq.WithContext(ctx)
  1322  		httpReq.Header = headers
  1323  
  1324  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "WaitOperation")
  1325  		if err != nil {
  1326  			return err
  1327  		}
  1328  
  1329  		if err := unm.Unmarshal(buf, resp); err != nil {
  1330  			return err
  1331  		}
  1332  
  1333  		return nil
  1334  	}, opts...)
  1335  	if e != nil {
  1336  		return nil, e
  1337  	}
  1338  	return resp, nil
  1339  }