...

Source file src/cloud.google.com/go/bigquery/connection/apiv1beta1/connection_client.go

Documentation: cloud.google.com/go/bigquery/connection/apiv1beta1

     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 connection
    18  
    19  import (
    20  	"bytes"
    21  	"context"
    22  	"fmt"
    23  	"io"
    24  	"math"
    25  	"net/http"
    26  	"net/url"
    27  	"time"
    28  
    29  	connectionpb "cloud.google.com/go/bigquery/connection/apiv1beta1/connectionpb"
    30  	iampb "cloud.google.com/go/iam/apiv1/iampb"
    31  	gax "github.com/googleapis/gax-go/v2"
    32  	"google.golang.org/api/googleapi"
    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  	"google.golang.org/grpc"
    38  	"google.golang.org/grpc/codes"
    39  	"google.golang.org/protobuf/encoding/protojson"
    40  )
    41  
    42  var newClientHook clientHook
    43  
    44  // CallOptions contains the retry settings for each method of Client.
    45  type CallOptions struct {
    46  	CreateConnection           []gax.CallOption
    47  	GetConnection              []gax.CallOption
    48  	ListConnections            []gax.CallOption
    49  	UpdateConnection           []gax.CallOption
    50  	UpdateConnectionCredential []gax.CallOption
    51  	DeleteConnection           []gax.CallOption
    52  	GetIamPolicy               []gax.CallOption
    53  	SetIamPolicy               []gax.CallOption
    54  	TestIamPermissions         []gax.CallOption
    55  }
    56  
    57  func defaultGRPCClientOptions() []option.ClientOption {
    58  	return []option.ClientOption{
    59  		internaloption.WithDefaultEndpoint("bigqueryconnection.googleapis.com:443"),
    60  		internaloption.WithDefaultEndpointTemplate("bigqueryconnection.UNIVERSE_DOMAIN:443"),
    61  		internaloption.WithDefaultMTLSEndpoint("bigqueryconnection.mtls.googleapis.com:443"),
    62  		internaloption.WithDefaultUniverseDomain("googleapis.com"),
    63  		internaloption.WithDefaultAudience("https://bigqueryconnection.googleapis.com/"),
    64  		internaloption.WithDefaultScopes(DefaultAuthScopes()...),
    65  		internaloption.EnableJwtWithScope(),
    66  		option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
    67  			grpc.MaxCallRecvMsgSize(math.MaxInt32))),
    68  	}
    69  }
    70  
    71  func defaultCallOptions() *CallOptions {
    72  	return &CallOptions{
    73  		CreateConnection: []gax.CallOption{
    74  			gax.WithTimeout(60000 * time.Millisecond),
    75  		},
    76  		GetConnection: []gax.CallOption{
    77  			gax.WithTimeout(60000 * time.Millisecond),
    78  			gax.WithRetry(func() gax.Retryer {
    79  				return gax.OnCodes([]codes.Code{
    80  					codes.DeadlineExceeded,
    81  					codes.Unavailable,
    82  				}, gax.Backoff{
    83  					Initial:    100 * time.Millisecond,
    84  					Max:        60000 * time.Millisecond,
    85  					Multiplier: 1.30,
    86  				})
    87  			}),
    88  		},
    89  		ListConnections: []gax.CallOption{
    90  			gax.WithTimeout(60000 * time.Millisecond),
    91  			gax.WithRetry(func() gax.Retryer {
    92  				return gax.OnCodes([]codes.Code{
    93  					codes.DeadlineExceeded,
    94  					codes.Unavailable,
    95  				}, gax.Backoff{
    96  					Initial:    100 * time.Millisecond,
    97  					Max:        60000 * time.Millisecond,
    98  					Multiplier: 1.30,
    99  				})
   100  			}),
   101  		},
   102  		UpdateConnection: []gax.CallOption{
   103  			gax.WithTimeout(60000 * time.Millisecond),
   104  		},
   105  		UpdateConnectionCredential: []gax.CallOption{
   106  			gax.WithTimeout(60000 * time.Millisecond),
   107  		},
   108  		DeleteConnection: []gax.CallOption{
   109  			gax.WithTimeout(60000 * time.Millisecond),
   110  			gax.WithRetry(func() gax.Retryer {
   111  				return gax.OnCodes([]codes.Code{
   112  					codes.DeadlineExceeded,
   113  					codes.Unavailable,
   114  				}, gax.Backoff{
   115  					Initial:    100 * time.Millisecond,
   116  					Max:        60000 * time.Millisecond,
   117  					Multiplier: 1.30,
   118  				})
   119  			}),
   120  		},
   121  		GetIamPolicy: []gax.CallOption{
   122  			gax.WithTimeout(60000 * time.Millisecond),
   123  		},
   124  		SetIamPolicy: []gax.CallOption{
   125  			gax.WithTimeout(60000 * time.Millisecond),
   126  		},
   127  		TestIamPermissions: []gax.CallOption{
   128  			gax.WithTimeout(60000 * time.Millisecond),
   129  		},
   130  	}
   131  }
   132  
   133  func defaultRESTCallOptions() *CallOptions {
   134  	return &CallOptions{
   135  		CreateConnection: []gax.CallOption{
   136  			gax.WithTimeout(60000 * time.Millisecond),
   137  		},
   138  		GetConnection: []gax.CallOption{
   139  			gax.WithTimeout(60000 * time.Millisecond),
   140  			gax.WithRetry(func() gax.Retryer {
   141  				return gax.OnHTTPCodes(gax.Backoff{
   142  					Initial:    100 * time.Millisecond,
   143  					Max:        60000 * time.Millisecond,
   144  					Multiplier: 1.30,
   145  				},
   146  					http.StatusGatewayTimeout,
   147  					http.StatusServiceUnavailable)
   148  			}),
   149  		},
   150  		ListConnections: []gax.CallOption{
   151  			gax.WithTimeout(60000 * time.Millisecond),
   152  			gax.WithRetry(func() gax.Retryer {
   153  				return gax.OnHTTPCodes(gax.Backoff{
   154  					Initial:    100 * time.Millisecond,
   155  					Max:        60000 * time.Millisecond,
   156  					Multiplier: 1.30,
   157  				},
   158  					http.StatusGatewayTimeout,
   159  					http.StatusServiceUnavailable)
   160  			}),
   161  		},
   162  		UpdateConnection: []gax.CallOption{
   163  			gax.WithTimeout(60000 * time.Millisecond),
   164  		},
   165  		UpdateConnectionCredential: []gax.CallOption{
   166  			gax.WithTimeout(60000 * time.Millisecond),
   167  		},
   168  		DeleteConnection: []gax.CallOption{
   169  			gax.WithTimeout(60000 * time.Millisecond),
   170  			gax.WithRetry(func() gax.Retryer {
   171  				return gax.OnHTTPCodes(gax.Backoff{
   172  					Initial:    100 * time.Millisecond,
   173  					Max:        60000 * time.Millisecond,
   174  					Multiplier: 1.30,
   175  				},
   176  					http.StatusGatewayTimeout,
   177  					http.StatusServiceUnavailable)
   178  			}),
   179  		},
   180  		GetIamPolicy: []gax.CallOption{
   181  			gax.WithTimeout(60000 * time.Millisecond),
   182  		},
   183  		SetIamPolicy: []gax.CallOption{
   184  			gax.WithTimeout(60000 * time.Millisecond),
   185  		},
   186  		TestIamPermissions: []gax.CallOption{
   187  			gax.WithTimeout(60000 * time.Millisecond),
   188  		},
   189  	}
   190  }
   191  
   192  // internalClient is an interface that defines the methods available from BigQuery Connection API.
   193  type internalClient interface {
   194  	Close() error
   195  	setGoogleClientInfo(...string)
   196  	Connection() *grpc.ClientConn
   197  	CreateConnection(context.Context, *connectionpb.CreateConnectionRequest, ...gax.CallOption) (*connectionpb.Connection, error)
   198  	GetConnection(context.Context, *connectionpb.GetConnectionRequest, ...gax.CallOption) (*connectionpb.Connection, error)
   199  	ListConnections(context.Context, *connectionpb.ListConnectionsRequest, ...gax.CallOption) (*connectionpb.ListConnectionsResponse, error)
   200  	UpdateConnection(context.Context, *connectionpb.UpdateConnectionRequest, ...gax.CallOption) (*connectionpb.Connection, error)
   201  	UpdateConnectionCredential(context.Context, *connectionpb.UpdateConnectionCredentialRequest, ...gax.CallOption) error
   202  	DeleteConnection(context.Context, *connectionpb.DeleteConnectionRequest, ...gax.CallOption) error
   203  	GetIamPolicy(context.Context, *iampb.GetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
   204  	SetIamPolicy(context.Context, *iampb.SetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
   205  	TestIamPermissions(context.Context, *iampb.TestIamPermissionsRequest, ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error)
   206  }
   207  
   208  // Client is a client for interacting with BigQuery Connection API.
   209  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   210  //
   211  // Manages external data source connections and credentials.
   212  type Client struct {
   213  	// The internal transport-dependent client.
   214  	internalClient internalClient
   215  
   216  	// The call options for this service.
   217  	CallOptions *CallOptions
   218  }
   219  
   220  // Wrapper methods routed to the internal client.
   221  
   222  // Close closes the connection to the API service. The user should invoke this when
   223  // the client is no longer required.
   224  func (c *Client) Close() error {
   225  	return c.internalClient.Close()
   226  }
   227  
   228  // setGoogleClientInfo sets the name and version of the application in
   229  // the `x-goog-api-client` header passed on each request. Intended for
   230  // use by Google-written clients.
   231  func (c *Client) setGoogleClientInfo(keyval ...string) {
   232  	c.internalClient.setGoogleClientInfo(keyval...)
   233  }
   234  
   235  // Connection returns a connection to the API service.
   236  //
   237  // Deprecated: Connections are now pooled so this method does not always
   238  // return the same resource.
   239  func (c *Client) Connection() *grpc.ClientConn {
   240  	return c.internalClient.Connection()
   241  }
   242  
   243  // CreateConnection creates a new connection.
   244  func (c *Client) CreateConnection(ctx context.Context, req *connectionpb.CreateConnectionRequest, opts ...gax.CallOption) (*connectionpb.Connection, error) {
   245  	return c.internalClient.CreateConnection(ctx, req, opts...)
   246  }
   247  
   248  // GetConnection returns specified connection.
   249  func (c *Client) GetConnection(ctx context.Context, req *connectionpb.GetConnectionRequest, opts ...gax.CallOption) (*connectionpb.Connection, error) {
   250  	return c.internalClient.GetConnection(ctx, req, opts...)
   251  }
   252  
   253  // ListConnections returns a list of connections in the given project.
   254  func (c *Client) ListConnections(ctx context.Context, req *connectionpb.ListConnectionsRequest, opts ...gax.CallOption) (*connectionpb.ListConnectionsResponse, error) {
   255  	return c.internalClient.ListConnections(ctx, req, opts...)
   256  }
   257  
   258  // UpdateConnection updates the specified connection. For security reasons, also resets
   259  // credential if connection properties are in the update field mask.
   260  func (c *Client) UpdateConnection(ctx context.Context, req *connectionpb.UpdateConnectionRequest, opts ...gax.CallOption) (*connectionpb.Connection, error) {
   261  	return c.internalClient.UpdateConnection(ctx, req, opts...)
   262  }
   263  
   264  // UpdateConnectionCredential sets the credential for the specified connection.
   265  func (c *Client) UpdateConnectionCredential(ctx context.Context, req *connectionpb.UpdateConnectionCredentialRequest, opts ...gax.CallOption) error {
   266  	return c.internalClient.UpdateConnectionCredential(ctx, req, opts...)
   267  }
   268  
   269  // DeleteConnection deletes connection and associated credential.
   270  func (c *Client) DeleteConnection(ctx context.Context, req *connectionpb.DeleteConnectionRequest, opts ...gax.CallOption) error {
   271  	return c.internalClient.DeleteConnection(ctx, req, opts...)
   272  }
   273  
   274  // GetIamPolicy gets the access control policy for a resource.
   275  // Returns an empty policy if the resource exists and does not have a policy
   276  // set.
   277  func (c *Client) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   278  	return c.internalClient.GetIamPolicy(ctx, req, opts...)
   279  }
   280  
   281  // SetIamPolicy sets the access control policy on the specified resource. Replaces any
   282  // existing policy.
   283  //
   284  // Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED errors.
   285  func (c *Client) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   286  	return c.internalClient.SetIamPolicy(ctx, req, opts...)
   287  }
   288  
   289  // TestIamPermissions returns permissions that a caller has on the specified resource.
   290  // If the resource does not exist, this will return an empty set of
   291  // permissions, not a NOT_FOUND error.
   292  //
   293  // Note: This operation is designed to be used for building permission-aware
   294  // UIs and command-line tools, not for authorization checking. This operation
   295  // may “fail open” without warning.
   296  func (c *Client) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
   297  	return c.internalClient.TestIamPermissions(ctx, req, opts...)
   298  }
   299  
   300  // gRPCClient is a client for interacting with BigQuery Connection API over gRPC transport.
   301  //
   302  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   303  type gRPCClient struct {
   304  	// Connection pool of gRPC connections to the service.
   305  	connPool gtransport.ConnPool
   306  
   307  	// Points back to the CallOptions field of the containing Client
   308  	CallOptions **CallOptions
   309  
   310  	// The gRPC API client.
   311  	client connectionpb.ConnectionServiceClient
   312  
   313  	// The x-goog-* metadata to be sent with each request.
   314  	xGoogHeaders []string
   315  }
   316  
   317  // NewClient creates a new connection service client based on gRPC.
   318  // The returned client must be Closed when it is done being used to clean up its underlying connections.
   319  //
   320  // Manages external data source connections and credentials.
   321  func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) {
   322  	clientOpts := defaultGRPCClientOptions()
   323  	if newClientHook != nil {
   324  		hookOpts, err := newClientHook(ctx, clientHookParams{})
   325  		if err != nil {
   326  			return nil, err
   327  		}
   328  		clientOpts = append(clientOpts, hookOpts...)
   329  	}
   330  
   331  	connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
   332  	if err != nil {
   333  		return nil, err
   334  	}
   335  	client := Client{CallOptions: defaultCallOptions()}
   336  
   337  	c := &gRPCClient{
   338  		connPool:    connPool,
   339  		client:      connectionpb.NewConnectionServiceClient(connPool),
   340  		CallOptions: &client.CallOptions,
   341  	}
   342  	c.setGoogleClientInfo()
   343  
   344  	client.internalClient = c
   345  
   346  	return &client, nil
   347  }
   348  
   349  // Connection returns a connection to the API service.
   350  //
   351  // Deprecated: Connections are now pooled so this method does not always
   352  // return the same resource.
   353  func (c *gRPCClient) Connection() *grpc.ClientConn {
   354  	return c.connPool.Conn()
   355  }
   356  
   357  // setGoogleClientInfo sets the name and version of the application in
   358  // the `x-goog-api-client` header passed on each request. Intended for
   359  // use by Google-written clients.
   360  func (c *gRPCClient) setGoogleClientInfo(keyval ...string) {
   361  	kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
   362  	kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version)
   363  	c.xGoogHeaders = []string{"x-goog-api-client", gax.XGoogHeader(kv...)}
   364  }
   365  
   366  // Close closes the connection to the API service. The user should invoke this when
   367  // the client is no longer required.
   368  func (c *gRPCClient) Close() error {
   369  	return c.connPool.Close()
   370  }
   371  
   372  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   373  type restClient struct {
   374  	// The http endpoint to connect to.
   375  	endpoint string
   376  
   377  	// The http client.
   378  	httpClient *http.Client
   379  
   380  	// The x-goog-* headers to be sent with each request.
   381  	xGoogHeaders []string
   382  
   383  	// Points back to the CallOptions field of the containing Client
   384  	CallOptions **CallOptions
   385  }
   386  
   387  // NewRESTClient creates a new connection service rest client.
   388  //
   389  // Manages external data source connections and credentials.
   390  func NewRESTClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) {
   391  	clientOpts := append(defaultRESTClientOptions(), opts...)
   392  	httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
   393  	if err != nil {
   394  		return nil, err
   395  	}
   396  
   397  	callOpts := defaultRESTCallOptions()
   398  	c := &restClient{
   399  		endpoint:    endpoint,
   400  		httpClient:  httpClient,
   401  		CallOptions: &callOpts,
   402  	}
   403  	c.setGoogleClientInfo()
   404  
   405  	return &Client{internalClient: c, CallOptions: callOpts}, nil
   406  }
   407  
   408  func defaultRESTClientOptions() []option.ClientOption {
   409  	return []option.ClientOption{
   410  		internaloption.WithDefaultEndpoint("https://bigqueryconnection.googleapis.com"),
   411  		internaloption.WithDefaultEndpointTemplate("https://bigqueryconnection.UNIVERSE_DOMAIN"),
   412  		internaloption.WithDefaultMTLSEndpoint("https://bigqueryconnection.mtls.googleapis.com"),
   413  		internaloption.WithDefaultUniverseDomain("googleapis.com"),
   414  		internaloption.WithDefaultAudience("https://bigqueryconnection.googleapis.com/"),
   415  		internaloption.WithDefaultScopes(DefaultAuthScopes()...),
   416  	}
   417  }
   418  
   419  // setGoogleClientInfo sets the name and version of the application in
   420  // the `x-goog-api-client` header passed on each request. Intended for
   421  // use by Google-written clients.
   422  func (c *restClient) setGoogleClientInfo(keyval ...string) {
   423  	kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
   424  	kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN")
   425  	c.xGoogHeaders = []string{"x-goog-api-client", gax.XGoogHeader(kv...)}
   426  }
   427  
   428  // Close closes the connection to the API service. The user should invoke this when
   429  // the client is no longer required.
   430  func (c *restClient) Close() error {
   431  	// Replace httpClient with nil to force cleanup.
   432  	c.httpClient = nil
   433  	return nil
   434  }
   435  
   436  // Connection returns a connection to the API service.
   437  //
   438  // Deprecated: This method always returns nil.
   439  func (c *restClient) Connection() *grpc.ClientConn {
   440  	return nil
   441  }
   442  func (c *gRPCClient) CreateConnection(ctx context.Context, req *connectionpb.CreateConnectionRequest, opts ...gax.CallOption) (*connectionpb.Connection, error) {
   443  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
   444  
   445  	hds = append(c.xGoogHeaders, hds...)
   446  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   447  	opts = append((*c.CallOptions).CreateConnection[0:len((*c.CallOptions).CreateConnection):len((*c.CallOptions).CreateConnection)], opts...)
   448  	var resp *connectionpb.Connection
   449  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   450  		var err error
   451  		resp, err = c.client.CreateConnection(ctx, req, settings.GRPC...)
   452  		return err
   453  	}, opts...)
   454  	if err != nil {
   455  		return nil, err
   456  	}
   457  	return resp, nil
   458  }
   459  
   460  func (c *gRPCClient) GetConnection(ctx context.Context, req *connectionpb.GetConnectionRequest, opts ...gax.CallOption) (*connectionpb.Connection, error) {
   461  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   462  
   463  	hds = append(c.xGoogHeaders, hds...)
   464  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   465  	opts = append((*c.CallOptions).GetConnection[0:len((*c.CallOptions).GetConnection):len((*c.CallOptions).GetConnection)], opts...)
   466  	var resp *connectionpb.Connection
   467  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   468  		var err error
   469  		resp, err = c.client.GetConnection(ctx, req, settings.GRPC...)
   470  		return err
   471  	}, opts...)
   472  	if err != nil {
   473  		return nil, err
   474  	}
   475  	return resp, nil
   476  }
   477  
   478  func (c *gRPCClient) ListConnections(ctx context.Context, req *connectionpb.ListConnectionsRequest, opts ...gax.CallOption) (*connectionpb.ListConnectionsResponse, error) {
   479  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
   480  
   481  	hds = append(c.xGoogHeaders, hds...)
   482  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   483  	opts = append((*c.CallOptions).ListConnections[0:len((*c.CallOptions).ListConnections):len((*c.CallOptions).ListConnections)], opts...)
   484  	var resp *connectionpb.ListConnectionsResponse
   485  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   486  		var err error
   487  		resp, err = c.client.ListConnections(ctx, req, settings.GRPC...)
   488  		return err
   489  	}, opts...)
   490  	if err != nil {
   491  		return nil, err
   492  	}
   493  	return resp, nil
   494  }
   495  
   496  func (c *gRPCClient) UpdateConnection(ctx context.Context, req *connectionpb.UpdateConnectionRequest, opts ...gax.CallOption) (*connectionpb.Connection, error) {
   497  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   498  
   499  	hds = append(c.xGoogHeaders, hds...)
   500  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   501  	opts = append((*c.CallOptions).UpdateConnection[0:len((*c.CallOptions).UpdateConnection):len((*c.CallOptions).UpdateConnection)], opts...)
   502  	var resp *connectionpb.Connection
   503  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   504  		var err error
   505  		resp, err = c.client.UpdateConnection(ctx, req, settings.GRPC...)
   506  		return err
   507  	}, opts...)
   508  	if err != nil {
   509  		return nil, err
   510  	}
   511  	return resp, nil
   512  }
   513  
   514  func (c *gRPCClient) UpdateConnectionCredential(ctx context.Context, req *connectionpb.UpdateConnectionCredentialRequest, opts ...gax.CallOption) error {
   515  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   516  
   517  	hds = append(c.xGoogHeaders, hds...)
   518  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   519  	opts = append((*c.CallOptions).UpdateConnectionCredential[0:len((*c.CallOptions).UpdateConnectionCredential):len((*c.CallOptions).UpdateConnectionCredential)], opts...)
   520  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   521  		var err error
   522  		_, err = c.client.UpdateConnectionCredential(ctx, req, settings.GRPC...)
   523  		return err
   524  	}, opts...)
   525  	return err
   526  }
   527  
   528  func (c *gRPCClient) DeleteConnection(ctx context.Context, req *connectionpb.DeleteConnectionRequest, opts ...gax.CallOption) error {
   529  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   530  
   531  	hds = append(c.xGoogHeaders, hds...)
   532  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   533  	opts = append((*c.CallOptions).DeleteConnection[0:len((*c.CallOptions).DeleteConnection):len((*c.CallOptions).DeleteConnection)], opts...)
   534  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   535  		var err error
   536  		_, err = c.client.DeleteConnection(ctx, req, settings.GRPC...)
   537  		return err
   538  	}, opts...)
   539  	return err
   540  }
   541  
   542  func (c *gRPCClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   543  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
   544  
   545  	hds = append(c.xGoogHeaders, hds...)
   546  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   547  	opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
   548  	var resp *iampb.Policy
   549  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   550  		var err error
   551  		resp, err = c.client.GetIamPolicy(ctx, req, settings.GRPC...)
   552  		return err
   553  	}, opts...)
   554  	if err != nil {
   555  		return nil, err
   556  	}
   557  	return resp, nil
   558  }
   559  
   560  func (c *gRPCClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   561  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
   562  
   563  	hds = append(c.xGoogHeaders, hds...)
   564  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   565  	opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
   566  	var resp *iampb.Policy
   567  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   568  		var err error
   569  		resp, err = c.client.SetIamPolicy(ctx, req, settings.GRPC...)
   570  		return err
   571  	}, opts...)
   572  	if err != nil {
   573  		return nil, err
   574  	}
   575  	return resp, nil
   576  }
   577  
   578  func (c *gRPCClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
   579  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
   580  
   581  	hds = append(c.xGoogHeaders, hds...)
   582  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   583  	opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...)
   584  	var resp *iampb.TestIamPermissionsResponse
   585  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   586  		var err error
   587  		resp, err = c.client.TestIamPermissions(ctx, req, settings.GRPC...)
   588  		return err
   589  	}, opts...)
   590  	if err != nil {
   591  		return nil, err
   592  	}
   593  	return resp, nil
   594  }
   595  
   596  // CreateConnection creates a new connection.
   597  func (c *restClient) CreateConnection(ctx context.Context, req *connectionpb.CreateConnectionRequest, opts ...gax.CallOption) (*connectionpb.Connection, error) {
   598  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
   599  	body := req.GetConnection()
   600  	jsonReq, err := m.Marshal(body)
   601  	if err != nil {
   602  		return nil, err
   603  	}
   604  
   605  	baseUrl, err := url.Parse(c.endpoint)
   606  	if err != nil {
   607  		return nil, err
   608  	}
   609  	baseUrl.Path += fmt.Sprintf("/v1beta1/%v/connections", req.GetParent())
   610  
   611  	params := url.Values{}
   612  	params.Add("$alt", "json;enum-encoding=int")
   613  	if req.GetConnectionId() != "" {
   614  		params.Add("connectionId", fmt.Sprintf("%v", req.GetConnectionId()))
   615  	}
   616  
   617  	baseUrl.RawQuery = params.Encode()
   618  
   619  	// Build HTTP headers from client and context metadata.
   620  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
   621  
   622  	hds = append(c.xGoogHeaders, hds...)
   623  	hds = append(hds, "Content-Type", "application/json")
   624  	headers := gax.BuildHeaders(ctx, hds...)
   625  	opts = append((*c.CallOptions).CreateConnection[0:len((*c.CallOptions).CreateConnection):len((*c.CallOptions).CreateConnection)], opts...)
   626  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
   627  	resp := &connectionpb.Connection{}
   628  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   629  		if settings.Path != "" {
   630  			baseUrl.Path = settings.Path
   631  		}
   632  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
   633  		if err != nil {
   634  			return err
   635  		}
   636  		httpReq = httpReq.WithContext(ctx)
   637  		httpReq.Header = headers
   638  
   639  		httpRsp, err := c.httpClient.Do(httpReq)
   640  		if err != nil {
   641  			return err
   642  		}
   643  		defer httpRsp.Body.Close()
   644  
   645  		if err = googleapi.CheckResponse(httpRsp); err != nil {
   646  			return err
   647  		}
   648  
   649  		buf, err := io.ReadAll(httpRsp.Body)
   650  		if err != nil {
   651  			return err
   652  		}
   653  
   654  		if err := unm.Unmarshal(buf, resp); err != nil {
   655  			return err
   656  		}
   657  
   658  		return nil
   659  	}, opts...)
   660  	if e != nil {
   661  		return nil, e
   662  	}
   663  	return resp, nil
   664  }
   665  
   666  // GetConnection returns specified connection.
   667  func (c *restClient) GetConnection(ctx context.Context, req *connectionpb.GetConnectionRequest, opts ...gax.CallOption) (*connectionpb.Connection, error) {
   668  	baseUrl, err := url.Parse(c.endpoint)
   669  	if err != nil {
   670  		return nil, err
   671  	}
   672  	baseUrl.Path += fmt.Sprintf("/v1beta1/%v", req.GetName())
   673  
   674  	params := url.Values{}
   675  	params.Add("$alt", "json;enum-encoding=int")
   676  
   677  	baseUrl.RawQuery = params.Encode()
   678  
   679  	// Build HTTP headers from client and context metadata.
   680  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   681  
   682  	hds = append(c.xGoogHeaders, hds...)
   683  	hds = append(hds, "Content-Type", "application/json")
   684  	headers := gax.BuildHeaders(ctx, hds...)
   685  	opts = append((*c.CallOptions).GetConnection[0:len((*c.CallOptions).GetConnection):len((*c.CallOptions).GetConnection)], opts...)
   686  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
   687  	resp := &connectionpb.Connection{}
   688  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   689  		if settings.Path != "" {
   690  			baseUrl.Path = settings.Path
   691  		}
   692  		httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
   693  		if err != nil {
   694  			return err
   695  		}
   696  		httpReq = httpReq.WithContext(ctx)
   697  		httpReq.Header = headers
   698  
   699  		httpRsp, err := c.httpClient.Do(httpReq)
   700  		if err != nil {
   701  			return err
   702  		}
   703  		defer httpRsp.Body.Close()
   704  
   705  		if err = googleapi.CheckResponse(httpRsp); err != nil {
   706  			return err
   707  		}
   708  
   709  		buf, err := io.ReadAll(httpRsp.Body)
   710  		if err != nil {
   711  			return err
   712  		}
   713  
   714  		if err := unm.Unmarshal(buf, resp); err != nil {
   715  			return err
   716  		}
   717  
   718  		return nil
   719  	}, opts...)
   720  	if e != nil {
   721  		return nil, e
   722  	}
   723  	return resp, nil
   724  }
   725  
   726  // ListConnections returns a list of connections in the given project.
   727  func (c *restClient) ListConnections(ctx context.Context, req *connectionpb.ListConnectionsRequest, opts ...gax.CallOption) (*connectionpb.ListConnectionsResponse, error) {
   728  	baseUrl, err := url.Parse(c.endpoint)
   729  	if err != nil {
   730  		return nil, err
   731  	}
   732  	baseUrl.Path += fmt.Sprintf("/v1beta1/%v/connections", req.GetParent())
   733  
   734  	params := url.Values{}
   735  	params.Add("$alt", "json;enum-encoding=int")
   736  	if req.GetMaxResults() != nil {
   737  		maxResults, err := protojson.Marshal(req.GetMaxResults())
   738  		if err != nil {
   739  			return nil, err
   740  		}
   741  		params.Add("maxResults", string(maxResults))
   742  	}
   743  	if req.GetPageToken() != "" {
   744  		params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
   745  	}
   746  
   747  	baseUrl.RawQuery = params.Encode()
   748  
   749  	// Build HTTP headers from client and context metadata.
   750  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
   751  
   752  	hds = append(c.xGoogHeaders, hds...)
   753  	hds = append(hds, "Content-Type", "application/json")
   754  	headers := gax.BuildHeaders(ctx, hds...)
   755  	opts = append((*c.CallOptions).ListConnections[0:len((*c.CallOptions).ListConnections):len((*c.CallOptions).ListConnections)], opts...)
   756  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
   757  	resp := &connectionpb.ListConnectionsResponse{}
   758  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   759  		if settings.Path != "" {
   760  			baseUrl.Path = settings.Path
   761  		}
   762  		httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
   763  		if err != nil {
   764  			return err
   765  		}
   766  		httpReq = httpReq.WithContext(ctx)
   767  		httpReq.Header = headers
   768  
   769  		httpRsp, err := c.httpClient.Do(httpReq)
   770  		if err != nil {
   771  			return err
   772  		}
   773  		defer httpRsp.Body.Close()
   774  
   775  		if err = googleapi.CheckResponse(httpRsp); err != nil {
   776  			return err
   777  		}
   778  
   779  		buf, err := io.ReadAll(httpRsp.Body)
   780  		if err != nil {
   781  			return err
   782  		}
   783  
   784  		if err := unm.Unmarshal(buf, resp); err != nil {
   785  			return err
   786  		}
   787  
   788  		return nil
   789  	}, opts...)
   790  	if e != nil {
   791  		return nil, e
   792  	}
   793  	return resp, nil
   794  }
   795  
   796  // UpdateConnection updates the specified connection. For security reasons, also resets
   797  // credential if connection properties are in the update field mask.
   798  func (c *restClient) UpdateConnection(ctx context.Context, req *connectionpb.UpdateConnectionRequest, opts ...gax.CallOption) (*connectionpb.Connection, error) {
   799  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
   800  	body := req.GetConnection()
   801  	jsonReq, err := m.Marshal(body)
   802  	if err != nil {
   803  		return nil, err
   804  	}
   805  
   806  	baseUrl, err := url.Parse(c.endpoint)
   807  	if err != nil {
   808  		return nil, err
   809  	}
   810  	baseUrl.Path += fmt.Sprintf("/v1beta1/%v", req.GetName())
   811  
   812  	params := url.Values{}
   813  	params.Add("$alt", "json;enum-encoding=int")
   814  	if req.GetUpdateMask() != nil {
   815  		updateMask, err := protojson.Marshal(req.GetUpdateMask())
   816  		if err != nil {
   817  			return nil, err
   818  		}
   819  		params.Add("updateMask", string(updateMask[1:len(updateMask)-1]))
   820  	}
   821  
   822  	baseUrl.RawQuery = params.Encode()
   823  
   824  	// Build HTTP headers from client and context metadata.
   825  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   826  
   827  	hds = append(c.xGoogHeaders, hds...)
   828  	hds = append(hds, "Content-Type", "application/json")
   829  	headers := gax.BuildHeaders(ctx, hds...)
   830  	opts = append((*c.CallOptions).UpdateConnection[0:len((*c.CallOptions).UpdateConnection):len((*c.CallOptions).UpdateConnection)], opts...)
   831  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
   832  	resp := &connectionpb.Connection{}
   833  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   834  		if settings.Path != "" {
   835  			baseUrl.Path = settings.Path
   836  		}
   837  		httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
   838  		if err != nil {
   839  			return err
   840  		}
   841  		httpReq = httpReq.WithContext(ctx)
   842  		httpReq.Header = headers
   843  
   844  		httpRsp, err := c.httpClient.Do(httpReq)
   845  		if err != nil {
   846  			return err
   847  		}
   848  		defer httpRsp.Body.Close()
   849  
   850  		if err = googleapi.CheckResponse(httpRsp); err != nil {
   851  			return err
   852  		}
   853  
   854  		buf, err := io.ReadAll(httpRsp.Body)
   855  		if err != nil {
   856  			return err
   857  		}
   858  
   859  		if err := unm.Unmarshal(buf, resp); err != nil {
   860  			return err
   861  		}
   862  
   863  		return nil
   864  	}, opts...)
   865  	if e != nil {
   866  		return nil, e
   867  	}
   868  	return resp, nil
   869  }
   870  
   871  // UpdateConnectionCredential sets the credential for the specified connection.
   872  func (c *restClient) UpdateConnectionCredential(ctx context.Context, req *connectionpb.UpdateConnectionCredentialRequest, opts ...gax.CallOption) error {
   873  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
   874  	body := req.GetCredential()
   875  	jsonReq, err := m.Marshal(body)
   876  	if err != nil {
   877  		return err
   878  	}
   879  
   880  	baseUrl, err := url.Parse(c.endpoint)
   881  	if err != nil {
   882  		return err
   883  	}
   884  	baseUrl.Path += fmt.Sprintf("/v1beta1/%v", req.GetName())
   885  
   886  	params := url.Values{}
   887  	params.Add("$alt", "json;enum-encoding=int")
   888  
   889  	baseUrl.RawQuery = params.Encode()
   890  
   891  	// Build HTTP headers from client and context metadata.
   892  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   893  
   894  	hds = append(c.xGoogHeaders, hds...)
   895  	hds = append(hds, "Content-Type", "application/json")
   896  	headers := gax.BuildHeaders(ctx, hds...)
   897  	return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   898  		if settings.Path != "" {
   899  			baseUrl.Path = settings.Path
   900  		}
   901  		httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
   902  		if err != nil {
   903  			return err
   904  		}
   905  		httpReq = httpReq.WithContext(ctx)
   906  		httpReq.Header = headers
   907  
   908  		httpRsp, err := c.httpClient.Do(httpReq)
   909  		if err != nil {
   910  			return err
   911  		}
   912  		defer httpRsp.Body.Close()
   913  
   914  		// Returns nil if there is no error, otherwise wraps
   915  		// the response code and body into a non-nil error
   916  		return googleapi.CheckResponse(httpRsp)
   917  	}, opts...)
   918  }
   919  
   920  // DeleteConnection deletes connection and associated credential.
   921  func (c *restClient) DeleteConnection(ctx context.Context, req *connectionpb.DeleteConnectionRequest, opts ...gax.CallOption) error {
   922  	baseUrl, err := url.Parse(c.endpoint)
   923  	if err != nil {
   924  		return err
   925  	}
   926  	baseUrl.Path += fmt.Sprintf("/v1beta1/%v", req.GetName())
   927  
   928  	params := url.Values{}
   929  	params.Add("$alt", "json;enum-encoding=int")
   930  
   931  	baseUrl.RawQuery = params.Encode()
   932  
   933  	// Build HTTP headers from client and context metadata.
   934  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   935  
   936  	hds = append(c.xGoogHeaders, hds...)
   937  	hds = append(hds, "Content-Type", "application/json")
   938  	headers := gax.BuildHeaders(ctx, hds...)
   939  	return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   940  		if settings.Path != "" {
   941  			baseUrl.Path = settings.Path
   942  		}
   943  		httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
   944  		if err != nil {
   945  			return err
   946  		}
   947  		httpReq = httpReq.WithContext(ctx)
   948  		httpReq.Header = headers
   949  
   950  		httpRsp, err := c.httpClient.Do(httpReq)
   951  		if err != nil {
   952  			return err
   953  		}
   954  		defer httpRsp.Body.Close()
   955  
   956  		// Returns nil if there is no error, otherwise wraps
   957  		// the response code and body into a non-nil error
   958  		return googleapi.CheckResponse(httpRsp)
   959  	}, opts...)
   960  }
   961  
   962  // GetIamPolicy gets the access control policy for a resource.
   963  // Returns an empty policy if the resource exists and does not have a policy
   964  // set.
   965  func (c *restClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   966  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
   967  	jsonReq, err := m.Marshal(req)
   968  	if err != nil {
   969  		return nil, err
   970  	}
   971  
   972  	baseUrl, err := url.Parse(c.endpoint)
   973  	if err != nil {
   974  		return nil, err
   975  	}
   976  	baseUrl.Path += fmt.Sprintf("/v1beta1/%v:getIamPolicy", req.GetResource())
   977  
   978  	params := url.Values{}
   979  	params.Add("$alt", "json;enum-encoding=int")
   980  
   981  	baseUrl.RawQuery = params.Encode()
   982  
   983  	// Build HTTP headers from client and context metadata.
   984  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
   985  
   986  	hds = append(c.xGoogHeaders, hds...)
   987  	hds = append(hds, "Content-Type", "application/json")
   988  	headers := gax.BuildHeaders(ctx, hds...)
   989  	opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
   990  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
   991  	resp := &iampb.Policy{}
   992  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   993  		if settings.Path != "" {
   994  			baseUrl.Path = settings.Path
   995  		}
   996  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
   997  		if err != nil {
   998  			return err
   999  		}
  1000  		httpReq = httpReq.WithContext(ctx)
  1001  		httpReq.Header = headers
  1002  
  1003  		httpRsp, err := c.httpClient.Do(httpReq)
  1004  		if err != nil {
  1005  			return err
  1006  		}
  1007  		defer httpRsp.Body.Close()
  1008  
  1009  		if err = googleapi.CheckResponse(httpRsp); err != nil {
  1010  			return err
  1011  		}
  1012  
  1013  		buf, err := io.ReadAll(httpRsp.Body)
  1014  		if err != nil {
  1015  			return err
  1016  		}
  1017  
  1018  		if err := unm.Unmarshal(buf, resp); err != nil {
  1019  			return err
  1020  		}
  1021  
  1022  		return nil
  1023  	}, opts...)
  1024  	if e != nil {
  1025  		return nil, e
  1026  	}
  1027  	return resp, nil
  1028  }
  1029  
  1030  // SetIamPolicy sets the access control policy on the specified resource. Replaces any
  1031  // existing policy.
  1032  //
  1033  // Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED errors.
  1034  func (c *restClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
  1035  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
  1036  	jsonReq, err := m.Marshal(req)
  1037  	if err != nil {
  1038  		return nil, err
  1039  	}
  1040  
  1041  	baseUrl, err := url.Parse(c.endpoint)
  1042  	if err != nil {
  1043  		return nil, err
  1044  	}
  1045  	baseUrl.Path += fmt.Sprintf("/v1beta1/%v:setIamPolicy", req.GetResource())
  1046  
  1047  	params := url.Values{}
  1048  	params.Add("$alt", "json;enum-encoding=int")
  1049  
  1050  	baseUrl.RawQuery = params.Encode()
  1051  
  1052  	// Build HTTP headers from client and context metadata.
  1053  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
  1054  
  1055  	hds = append(c.xGoogHeaders, hds...)
  1056  	hds = append(hds, "Content-Type", "application/json")
  1057  	headers := gax.BuildHeaders(ctx, hds...)
  1058  	opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
  1059  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1060  	resp := &iampb.Policy{}
  1061  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1062  		if settings.Path != "" {
  1063  			baseUrl.Path = settings.Path
  1064  		}
  1065  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
  1066  		if err != nil {
  1067  			return err
  1068  		}
  1069  		httpReq = httpReq.WithContext(ctx)
  1070  		httpReq.Header = headers
  1071  
  1072  		httpRsp, err := c.httpClient.Do(httpReq)
  1073  		if err != nil {
  1074  			return err
  1075  		}
  1076  		defer httpRsp.Body.Close()
  1077  
  1078  		if err = googleapi.CheckResponse(httpRsp); err != nil {
  1079  			return err
  1080  		}
  1081  
  1082  		buf, err := io.ReadAll(httpRsp.Body)
  1083  		if err != nil {
  1084  			return err
  1085  		}
  1086  
  1087  		if err := unm.Unmarshal(buf, resp); err != nil {
  1088  			return err
  1089  		}
  1090  
  1091  		return nil
  1092  	}, opts...)
  1093  	if e != nil {
  1094  		return nil, e
  1095  	}
  1096  	return resp, nil
  1097  }
  1098  
  1099  // TestIamPermissions returns permissions that a caller has on the specified resource.
  1100  // If the resource does not exist, this will return an empty set of
  1101  // permissions, not a NOT_FOUND error.
  1102  //
  1103  // Note: This operation is designed to be used for building permission-aware
  1104  // UIs and command-line tools, not for authorization checking. This operation
  1105  // may “fail open” without warning.
  1106  func (c *restClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
  1107  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
  1108  	jsonReq, err := m.Marshal(req)
  1109  	if err != nil {
  1110  		return nil, err
  1111  	}
  1112  
  1113  	baseUrl, err := url.Parse(c.endpoint)
  1114  	if err != nil {
  1115  		return nil, err
  1116  	}
  1117  	baseUrl.Path += fmt.Sprintf("/v1beta1/%v:testIamPermissions", req.GetResource())
  1118  
  1119  	params := url.Values{}
  1120  	params.Add("$alt", "json;enum-encoding=int")
  1121  
  1122  	baseUrl.RawQuery = params.Encode()
  1123  
  1124  	// Build HTTP headers from client and context metadata.
  1125  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
  1126  
  1127  	hds = append(c.xGoogHeaders, hds...)
  1128  	hds = append(hds, "Content-Type", "application/json")
  1129  	headers := gax.BuildHeaders(ctx, hds...)
  1130  	opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...)
  1131  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1132  	resp := &iampb.TestIamPermissionsResponse{}
  1133  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1134  		if settings.Path != "" {
  1135  			baseUrl.Path = settings.Path
  1136  		}
  1137  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
  1138  		if err != nil {
  1139  			return err
  1140  		}
  1141  		httpReq = httpReq.WithContext(ctx)
  1142  		httpReq.Header = headers
  1143  
  1144  		httpRsp, err := c.httpClient.Do(httpReq)
  1145  		if err != nil {
  1146  			return err
  1147  		}
  1148  		defer httpRsp.Body.Close()
  1149  
  1150  		if err = googleapi.CheckResponse(httpRsp); err != nil {
  1151  			return err
  1152  		}
  1153  
  1154  		buf, err := io.ReadAll(httpRsp.Body)
  1155  		if err != nil {
  1156  			return err
  1157  		}
  1158  
  1159  		if err := unm.Unmarshal(buf, resp); err != nil {
  1160  			return err
  1161  		}
  1162  
  1163  		return nil
  1164  	}, opts...)
  1165  	if e != nil {
  1166  		return nil, e
  1167  	}
  1168  	return resp, nil
  1169  }
  1170  

View as plain text