...

Source file src/cloud.google.com/go/secretmanager/apiv1/secret_manager_client.go

Documentation: cloud.google.com/go/secretmanager/apiv1

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

View as plain text