...

Source file src/cloud.google.com/go/resourcemanager/apiv3/tag_bindings_client.go

Documentation: cloud.google.com/go/resourcemanager/apiv3

     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 resourcemanager
    18  
    19  import (
    20  	"bytes"
    21  	"context"
    22  	"fmt"
    23  	"io"
    24  	"math"
    25  	"net/http"
    26  	"net/url"
    27  	"time"
    28  
    29  	"cloud.google.com/go/longrunning"
    30  	lroauto "cloud.google.com/go/longrunning/autogen"
    31  	longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb"
    32  	resourcemanagerpb "cloud.google.com/go/resourcemanager/apiv3/resourcemanagerpb"
    33  	gax "github.com/googleapis/gax-go/v2"
    34  	"google.golang.org/api/googleapi"
    35  	"google.golang.org/api/iterator"
    36  	"google.golang.org/api/option"
    37  	"google.golang.org/api/option/internaloption"
    38  	gtransport "google.golang.org/api/transport/grpc"
    39  	httptransport "google.golang.org/api/transport/http"
    40  	"google.golang.org/grpc"
    41  	"google.golang.org/grpc/codes"
    42  	"google.golang.org/protobuf/encoding/protojson"
    43  	"google.golang.org/protobuf/proto"
    44  )
    45  
    46  var newTagBindingsClientHook clientHook
    47  
    48  // TagBindingsCallOptions contains the retry settings for each method of TagBindingsClient.
    49  type TagBindingsCallOptions struct {
    50  	ListTagBindings   []gax.CallOption
    51  	CreateTagBinding  []gax.CallOption
    52  	DeleteTagBinding  []gax.CallOption
    53  	ListEffectiveTags []gax.CallOption
    54  	GetOperation      []gax.CallOption
    55  }
    56  
    57  func defaultTagBindingsGRPCClientOptions() []option.ClientOption {
    58  	return []option.ClientOption{
    59  		internaloption.WithDefaultEndpoint("cloudresourcemanager.googleapis.com:443"),
    60  		internaloption.WithDefaultEndpointTemplate("cloudresourcemanager.UNIVERSE_DOMAIN:443"),
    61  		internaloption.WithDefaultMTLSEndpoint("cloudresourcemanager.mtls.googleapis.com:443"),
    62  		internaloption.WithDefaultUniverseDomain("googleapis.com"),
    63  		internaloption.WithDefaultAudience("https://cloudresourcemanager.googleapis.com/"),
    64  		internaloption.WithDefaultScopes(DefaultAuthScopes()...),
    65  		internaloption.EnableJwtWithScope(),
    66  		option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
    67  			grpc.MaxCallRecvMsgSize(math.MaxInt32))),
    68  	}
    69  }
    70  
    71  func defaultTagBindingsCallOptions() *TagBindingsCallOptions {
    72  	return &TagBindingsCallOptions{
    73  		ListTagBindings: []gax.CallOption{
    74  			gax.WithTimeout(60000 * time.Millisecond),
    75  			gax.WithRetry(func() gax.Retryer {
    76  				return gax.OnCodes([]codes.Code{
    77  					codes.Unavailable,
    78  				}, gax.Backoff{
    79  					Initial:    100 * time.Millisecond,
    80  					Max:        60000 * time.Millisecond,
    81  					Multiplier: 1.30,
    82  				})
    83  			}),
    84  		},
    85  		CreateTagBinding: []gax.CallOption{
    86  			gax.WithTimeout(60000 * time.Millisecond),
    87  		},
    88  		DeleteTagBinding: []gax.CallOption{
    89  			gax.WithTimeout(60000 * time.Millisecond),
    90  		},
    91  		ListEffectiveTags: []gax.CallOption{},
    92  		GetOperation:      []gax.CallOption{},
    93  	}
    94  }
    95  
    96  func defaultTagBindingsRESTCallOptions() *TagBindingsCallOptions {
    97  	return &TagBindingsCallOptions{
    98  		ListTagBindings: []gax.CallOption{
    99  			gax.WithTimeout(60000 * time.Millisecond),
   100  			gax.WithRetry(func() gax.Retryer {
   101  				return gax.OnHTTPCodes(gax.Backoff{
   102  					Initial:    100 * time.Millisecond,
   103  					Max:        60000 * time.Millisecond,
   104  					Multiplier: 1.30,
   105  				},
   106  					http.StatusServiceUnavailable)
   107  			}),
   108  		},
   109  		CreateTagBinding: []gax.CallOption{
   110  			gax.WithTimeout(60000 * time.Millisecond),
   111  		},
   112  		DeleteTagBinding: []gax.CallOption{
   113  			gax.WithTimeout(60000 * time.Millisecond),
   114  		},
   115  		ListEffectiveTags: []gax.CallOption{},
   116  		GetOperation:      []gax.CallOption{},
   117  	}
   118  }
   119  
   120  // internalTagBindingsClient is an interface that defines the methods available from Cloud Resource Manager API.
   121  type internalTagBindingsClient interface {
   122  	Close() error
   123  	setGoogleClientInfo(...string)
   124  	Connection() *grpc.ClientConn
   125  	ListTagBindings(context.Context, *resourcemanagerpb.ListTagBindingsRequest, ...gax.CallOption) *TagBindingIterator
   126  	CreateTagBinding(context.Context, *resourcemanagerpb.CreateTagBindingRequest, ...gax.CallOption) (*CreateTagBindingOperation, error)
   127  	CreateTagBindingOperation(name string) *CreateTagBindingOperation
   128  	DeleteTagBinding(context.Context, *resourcemanagerpb.DeleteTagBindingRequest, ...gax.CallOption) (*DeleteTagBindingOperation, error)
   129  	DeleteTagBindingOperation(name string) *DeleteTagBindingOperation
   130  	ListEffectiveTags(context.Context, *resourcemanagerpb.ListEffectiveTagsRequest, ...gax.CallOption) *EffectiveTagIterator
   131  	GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error)
   132  }
   133  
   134  // TagBindingsClient is a client for interacting with Cloud Resource Manager API.
   135  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   136  //
   137  // Allow users to create and manage TagBindings between TagValues and
   138  // different Google Cloud resources throughout the GCP resource hierarchy.
   139  type TagBindingsClient struct {
   140  	// The internal transport-dependent client.
   141  	internalClient internalTagBindingsClient
   142  
   143  	// The call options for this service.
   144  	CallOptions *TagBindingsCallOptions
   145  
   146  	// LROClient is used internally to handle long-running operations.
   147  	// It is exposed so that its CallOptions can be modified if required.
   148  	// Users should not Close this client.
   149  	LROClient *lroauto.OperationsClient
   150  }
   151  
   152  // Wrapper methods routed to the internal client.
   153  
   154  // Close closes the connection to the API service. The user should invoke this when
   155  // the client is no longer required.
   156  func (c *TagBindingsClient) Close() error {
   157  	return c.internalClient.Close()
   158  }
   159  
   160  // setGoogleClientInfo sets the name and version of the application in
   161  // the `x-goog-api-client` header passed on each request. Intended for
   162  // use by Google-written clients.
   163  func (c *TagBindingsClient) setGoogleClientInfo(keyval ...string) {
   164  	c.internalClient.setGoogleClientInfo(keyval...)
   165  }
   166  
   167  // Connection returns a connection to the API service.
   168  //
   169  // Deprecated: Connections are now pooled so this method does not always
   170  // return the same resource.
   171  func (c *TagBindingsClient) Connection() *grpc.ClientConn {
   172  	return c.internalClient.Connection()
   173  }
   174  
   175  // ListTagBindings lists the TagBindings for the given Google Cloud resource, as specified
   176  // with parent.
   177  //
   178  // NOTE: The parent field is expected to be a full resource name:
   179  // https://cloud.google.com/apis/design/resource_names#full_resource_name (at https://cloud.google.com/apis/design/resource_names#full_resource_name)
   180  func (c *TagBindingsClient) ListTagBindings(ctx context.Context, req *resourcemanagerpb.ListTagBindingsRequest, opts ...gax.CallOption) *TagBindingIterator {
   181  	return c.internalClient.ListTagBindings(ctx, req, opts...)
   182  }
   183  
   184  // CreateTagBinding creates a TagBinding between a TagValue and a Google Cloud resource.
   185  func (c *TagBindingsClient) CreateTagBinding(ctx context.Context, req *resourcemanagerpb.CreateTagBindingRequest, opts ...gax.CallOption) (*CreateTagBindingOperation, error) {
   186  	return c.internalClient.CreateTagBinding(ctx, req, opts...)
   187  }
   188  
   189  // CreateTagBindingOperation returns a new CreateTagBindingOperation from a given name.
   190  // The name must be that of a previously created CreateTagBindingOperation, possibly from a different process.
   191  func (c *TagBindingsClient) CreateTagBindingOperation(name string) *CreateTagBindingOperation {
   192  	return c.internalClient.CreateTagBindingOperation(name)
   193  }
   194  
   195  // DeleteTagBinding deletes a TagBinding.
   196  func (c *TagBindingsClient) DeleteTagBinding(ctx context.Context, req *resourcemanagerpb.DeleteTagBindingRequest, opts ...gax.CallOption) (*DeleteTagBindingOperation, error) {
   197  	return c.internalClient.DeleteTagBinding(ctx, req, opts...)
   198  }
   199  
   200  // DeleteTagBindingOperation returns a new DeleteTagBindingOperation from a given name.
   201  // The name must be that of a previously created DeleteTagBindingOperation, possibly from a different process.
   202  func (c *TagBindingsClient) DeleteTagBindingOperation(name string) *DeleteTagBindingOperation {
   203  	return c.internalClient.DeleteTagBindingOperation(name)
   204  }
   205  
   206  // ListEffectiveTags return a list of effective tags for the given Google Cloud resource, as
   207  // specified in parent.
   208  func (c *TagBindingsClient) ListEffectiveTags(ctx context.Context, req *resourcemanagerpb.ListEffectiveTagsRequest, opts ...gax.CallOption) *EffectiveTagIterator {
   209  	return c.internalClient.ListEffectiveTags(ctx, req, opts...)
   210  }
   211  
   212  // GetOperation is a utility method from google.longrunning.Operations.
   213  func (c *TagBindingsClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
   214  	return c.internalClient.GetOperation(ctx, req, opts...)
   215  }
   216  
   217  // tagBindingsGRPCClient is a client for interacting with Cloud Resource Manager API over gRPC transport.
   218  //
   219  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   220  type tagBindingsGRPCClient struct {
   221  	// Connection pool of gRPC connections to the service.
   222  	connPool gtransport.ConnPool
   223  
   224  	// Points back to the CallOptions field of the containing TagBindingsClient
   225  	CallOptions **TagBindingsCallOptions
   226  
   227  	// The gRPC API client.
   228  	tagBindingsClient resourcemanagerpb.TagBindingsClient
   229  
   230  	// LROClient is used internally to handle long-running operations.
   231  	// It is exposed so that its CallOptions can be modified if required.
   232  	// Users should not Close this client.
   233  	LROClient **lroauto.OperationsClient
   234  
   235  	operationsClient longrunningpb.OperationsClient
   236  
   237  	// The x-goog-* metadata to be sent with each request.
   238  	xGoogHeaders []string
   239  }
   240  
   241  // NewTagBindingsClient creates a new tag bindings client based on gRPC.
   242  // The returned client must be Closed when it is done being used to clean up its underlying connections.
   243  //
   244  // Allow users to create and manage TagBindings between TagValues and
   245  // different Google Cloud resources throughout the GCP resource hierarchy.
   246  func NewTagBindingsClient(ctx context.Context, opts ...option.ClientOption) (*TagBindingsClient, error) {
   247  	clientOpts := defaultTagBindingsGRPCClientOptions()
   248  	if newTagBindingsClientHook != nil {
   249  		hookOpts, err := newTagBindingsClientHook(ctx, clientHookParams{})
   250  		if err != nil {
   251  			return nil, err
   252  		}
   253  		clientOpts = append(clientOpts, hookOpts...)
   254  	}
   255  
   256  	connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
   257  	if err != nil {
   258  		return nil, err
   259  	}
   260  	client := TagBindingsClient{CallOptions: defaultTagBindingsCallOptions()}
   261  
   262  	c := &tagBindingsGRPCClient{
   263  		connPool:          connPool,
   264  		tagBindingsClient: resourcemanagerpb.NewTagBindingsClient(connPool),
   265  		CallOptions:       &client.CallOptions,
   266  		operationsClient:  longrunningpb.NewOperationsClient(connPool),
   267  	}
   268  	c.setGoogleClientInfo()
   269  
   270  	client.internalClient = c
   271  
   272  	client.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool))
   273  	if err != nil {
   274  		// This error "should not happen", since we are just reusing old connection pool
   275  		// and never actually need to dial.
   276  		// If this does happen, we could leak connp. However, we cannot close conn:
   277  		// If the user invoked the constructor with option.WithGRPCConn,
   278  		// we would close a connection that's still in use.
   279  		// TODO: investigate error conditions.
   280  		return nil, err
   281  	}
   282  	c.LROClient = &client.LROClient
   283  	return &client, nil
   284  }
   285  
   286  // Connection returns a connection to the API service.
   287  //
   288  // Deprecated: Connections are now pooled so this method does not always
   289  // return the same resource.
   290  func (c *tagBindingsGRPCClient) Connection() *grpc.ClientConn {
   291  	return c.connPool.Conn()
   292  }
   293  
   294  // setGoogleClientInfo sets the name and version of the application in
   295  // the `x-goog-api-client` header passed on each request. Intended for
   296  // use by Google-written clients.
   297  func (c *tagBindingsGRPCClient) setGoogleClientInfo(keyval ...string) {
   298  	kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
   299  	kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version)
   300  	c.xGoogHeaders = []string{"x-goog-api-client", gax.XGoogHeader(kv...)}
   301  }
   302  
   303  // Close closes the connection to the API service. The user should invoke this when
   304  // the client is no longer required.
   305  func (c *tagBindingsGRPCClient) Close() error {
   306  	return c.connPool.Close()
   307  }
   308  
   309  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   310  type tagBindingsRESTClient struct {
   311  	// The http endpoint to connect to.
   312  	endpoint string
   313  
   314  	// The http client.
   315  	httpClient *http.Client
   316  
   317  	// LROClient is used internally to handle long-running operations.
   318  	// It is exposed so that its CallOptions can be modified if required.
   319  	// Users should not Close this client.
   320  	LROClient **lroauto.OperationsClient
   321  
   322  	// The x-goog-* headers to be sent with each request.
   323  	xGoogHeaders []string
   324  
   325  	// Points back to the CallOptions field of the containing TagBindingsClient
   326  	CallOptions **TagBindingsCallOptions
   327  }
   328  
   329  // NewTagBindingsRESTClient creates a new tag bindings rest client.
   330  //
   331  // Allow users to create and manage TagBindings between TagValues and
   332  // different Google Cloud resources throughout the GCP resource hierarchy.
   333  func NewTagBindingsRESTClient(ctx context.Context, opts ...option.ClientOption) (*TagBindingsClient, error) {
   334  	clientOpts := append(defaultTagBindingsRESTClientOptions(), opts...)
   335  	httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
   336  	if err != nil {
   337  		return nil, err
   338  	}
   339  
   340  	callOpts := defaultTagBindingsRESTCallOptions()
   341  	c := &tagBindingsRESTClient{
   342  		endpoint:    endpoint,
   343  		httpClient:  httpClient,
   344  		CallOptions: &callOpts,
   345  	}
   346  	c.setGoogleClientInfo()
   347  
   348  	lroOpts := []option.ClientOption{
   349  		option.WithHTTPClient(httpClient),
   350  		option.WithEndpoint(endpoint),
   351  	}
   352  	opClient, err := lroauto.NewOperationsRESTClient(ctx, lroOpts...)
   353  	if err != nil {
   354  		return nil, err
   355  	}
   356  	c.LROClient = &opClient
   357  
   358  	return &TagBindingsClient{internalClient: c, CallOptions: callOpts}, nil
   359  }
   360  
   361  func defaultTagBindingsRESTClientOptions() []option.ClientOption {
   362  	return []option.ClientOption{
   363  		internaloption.WithDefaultEndpoint("https://cloudresourcemanager.googleapis.com"),
   364  		internaloption.WithDefaultEndpointTemplate("https://cloudresourcemanager.UNIVERSE_DOMAIN"),
   365  		internaloption.WithDefaultMTLSEndpoint("https://cloudresourcemanager.mtls.googleapis.com"),
   366  		internaloption.WithDefaultUniverseDomain("googleapis.com"),
   367  		internaloption.WithDefaultAudience("https://cloudresourcemanager.googleapis.com/"),
   368  		internaloption.WithDefaultScopes(DefaultAuthScopes()...),
   369  	}
   370  }
   371  
   372  // setGoogleClientInfo sets the name and version of the application in
   373  // the `x-goog-api-client` header passed on each request. Intended for
   374  // use by Google-written clients.
   375  func (c *tagBindingsRESTClient) setGoogleClientInfo(keyval ...string) {
   376  	kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
   377  	kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN")
   378  	c.xGoogHeaders = []string{"x-goog-api-client", gax.XGoogHeader(kv...)}
   379  }
   380  
   381  // Close closes the connection to the API service. The user should invoke this when
   382  // the client is no longer required.
   383  func (c *tagBindingsRESTClient) Close() error {
   384  	// Replace httpClient with nil to force cleanup.
   385  	c.httpClient = nil
   386  	return nil
   387  }
   388  
   389  // Connection returns a connection to the API service.
   390  //
   391  // Deprecated: This method always returns nil.
   392  func (c *tagBindingsRESTClient) Connection() *grpc.ClientConn {
   393  	return nil
   394  }
   395  func (c *tagBindingsGRPCClient) ListTagBindings(ctx context.Context, req *resourcemanagerpb.ListTagBindingsRequest, opts ...gax.CallOption) *TagBindingIterator {
   396  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...)
   397  	opts = append((*c.CallOptions).ListTagBindings[0:len((*c.CallOptions).ListTagBindings):len((*c.CallOptions).ListTagBindings)], opts...)
   398  	it := &TagBindingIterator{}
   399  	req = proto.Clone(req).(*resourcemanagerpb.ListTagBindingsRequest)
   400  	it.InternalFetch = func(pageSize int, pageToken string) ([]*resourcemanagerpb.TagBinding, string, error) {
   401  		resp := &resourcemanagerpb.ListTagBindingsResponse{}
   402  		if pageToken != "" {
   403  			req.PageToken = pageToken
   404  		}
   405  		if pageSize > math.MaxInt32 {
   406  			req.PageSize = math.MaxInt32
   407  		} else if pageSize != 0 {
   408  			req.PageSize = int32(pageSize)
   409  		}
   410  		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   411  			var err error
   412  			resp, err = c.tagBindingsClient.ListTagBindings(ctx, req, settings.GRPC...)
   413  			return err
   414  		}, opts...)
   415  		if err != nil {
   416  			return nil, "", err
   417  		}
   418  
   419  		it.Response = resp
   420  		return resp.GetTagBindings(), resp.GetNextPageToken(), nil
   421  	}
   422  	fetch := func(pageSize int, pageToken string) (string, error) {
   423  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
   424  		if err != nil {
   425  			return "", err
   426  		}
   427  		it.items = append(it.items, items...)
   428  		return nextPageToken, nil
   429  	}
   430  
   431  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
   432  	it.pageInfo.MaxSize = int(req.GetPageSize())
   433  	it.pageInfo.Token = req.GetPageToken()
   434  
   435  	return it
   436  }
   437  
   438  func (c *tagBindingsGRPCClient) CreateTagBinding(ctx context.Context, req *resourcemanagerpb.CreateTagBindingRequest, opts ...gax.CallOption) (*CreateTagBindingOperation, error) {
   439  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...)
   440  	opts = append((*c.CallOptions).CreateTagBinding[0:len((*c.CallOptions).CreateTagBinding):len((*c.CallOptions).CreateTagBinding)], opts...)
   441  	var resp *longrunningpb.Operation
   442  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   443  		var err error
   444  		resp, err = c.tagBindingsClient.CreateTagBinding(ctx, req, settings.GRPC...)
   445  		return err
   446  	}, opts...)
   447  	if err != nil {
   448  		return nil, err
   449  	}
   450  	return &CreateTagBindingOperation{
   451  		lro: longrunning.InternalNewOperation(*c.LROClient, resp),
   452  	}, nil
   453  }
   454  
   455  func (c *tagBindingsGRPCClient) DeleteTagBinding(ctx context.Context, req *resourcemanagerpb.DeleteTagBindingRequest, opts ...gax.CallOption) (*DeleteTagBindingOperation, error) {
   456  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   457  
   458  	hds = append(c.xGoogHeaders, hds...)
   459  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   460  	opts = append((*c.CallOptions).DeleteTagBinding[0:len((*c.CallOptions).DeleteTagBinding):len((*c.CallOptions).DeleteTagBinding)], opts...)
   461  	var resp *longrunningpb.Operation
   462  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   463  		var err error
   464  		resp, err = c.tagBindingsClient.DeleteTagBinding(ctx, req, settings.GRPC...)
   465  		return err
   466  	}, opts...)
   467  	if err != nil {
   468  		return nil, err
   469  	}
   470  	return &DeleteTagBindingOperation{
   471  		lro: longrunning.InternalNewOperation(*c.LROClient, resp),
   472  	}, nil
   473  }
   474  
   475  func (c *tagBindingsGRPCClient) ListEffectiveTags(ctx context.Context, req *resourcemanagerpb.ListEffectiveTagsRequest, opts ...gax.CallOption) *EffectiveTagIterator {
   476  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...)
   477  	opts = append((*c.CallOptions).ListEffectiveTags[0:len((*c.CallOptions).ListEffectiveTags):len((*c.CallOptions).ListEffectiveTags)], opts...)
   478  	it := &EffectiveTagIterator{}
   479  	req = proto.Clone(req).(*resourcemanagerpb.ListEffectiveTagsRequest)
   480  	it.InternalFetch = func(pageSize int, pageToken string) ([]*resourcemanagerpb.EffectiveTag, string, error) {
   481  		resp := &resourcemanagerpb.ListEffectiveTagsResponse{}
   482  		if pageToken != "" {
   483  			req.PageToken = pageToken
   484  		}
   485  		if pageSize > math.MaxInt32 {
   486  			req.PageSize = math.MaxInt32
   487  		} else if pageSize != 0 {
   488  			req.PageSize = int32(pageSize)
   489  		}
   490  		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   491  			var err error
   492  			resp, err = c.tagBindingsClient.ListEffectiveTags(ctx, req, settings.GRPC...)
   493  			return err
   494  		}, opts...)
   495  		if err != nil {
   496  			return nil, "", err
   497  		}
   498  
   499  		it.Response = resp
   500  		return resp.GetEffectiveTags(), resp.GetNextPageToken(), nil
   501  	}
   502  	fetch := func(pageSize int, pageToken string) (string, error) {
   503  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
   504  		if err != nil {
   505  			return "", err
   506  		}
   507  		it.items = append(it.items, items...)
   508  		return nextPageToken, nil
   509  	}
   510  
   511  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
   512  	it.pageInfo.MaxSize = int(req.GetPageSize())
   513  	it.pageInfo.Token = req.GetPageToken()
   514  
   515  	return it
   516  }
   517  
   518  func (c *tagBindingsGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
   519  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   520  
   521  	hds = append(c.xGoogHeaders, hds...)
   522  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   523  	opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
   524  	var resp *longrunningpb.Operation
   525  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   526  		var err error
   527  		resp, err = c.operationsClient.GetOperation(ctx, req, settings.GRPC...)
   528  		return err
   529  	}, opts...)
   530  	if err != nil {
   531  		return nil, err
   532  	}
   533  	return resp, nil
   534  }
   535  
   536  // ListTagBindings lists the TagBindings for the given Google Cloud resource, as specified
   537  // with parent.
   538  //
   539  // NOTE: The parent field is expected to be a full resource name:
   540  // https://cloud.google.com/apis/design/resource_names#full_resource_name (at https://cloud.google.com/apis/design/resource_names#full_resource_name)
   541  func (c *tagBindingsRESTClient) ListTagBindings(ctx context.Context, req *resourcemanagerpb.ListTagBindingsRequest, opts ...gax.CallOption) *TagBindingIterator {
   542  	it := &TagBindingIterator{}
   543  	req = proto.Clone(req).(*resourcemanagerpb.ListTagBindingsRequest)
   544  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
   545  	it.InternalFetch = func(pageSize int, pageToken string) ([]*resourcemanagerpb.TagBinding, string, error) {
   546  		resp := &resourcemanagerpb.ListTagBindingsResponse{}
   547  		if pageToken != "" {
   548  			req.PageToken = pageToken
   549  		}
   550  		if pageSize > math.MaxInt32 {
   551  			req.PageSize = math.MaxInt32
   552  		} else if pageSize != 0 {
   553  			req.PageSize = int32(pageSize)
   554  		}
   555  		baseUrl, err := url.Parse(c.endpoint)
   556  		if err != nil {
   557  			return nil, "", err
   558  		}
   559  		baseUrl.Path += fmt.Sprintf("/v3/tagBindings")
   560  
   561  		params := url.Values{}
   562  		params.Add("$alt", "json;enum-encoding=int")
   563  		if req.GetPageSize() != 0 {
   564  			params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
   565  		}
   566  		if req.GetPageToken() != "" {
   567  			params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
   568  		}
   569  		params.Add("parent", fmt.Sprintf("%v", req.GetParent()))
   570  
   571  		baseUrl.RawQuery = params.Encode()
   572  
   573  		// Build HTTP headers from client and context metadata.
   574  		hds := append(c.xGoogHeaders, "Content-Type", "application/json")
   575  		headers := gax.BuildHeaders(ctx, hds...)
   576  		e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   577  			if settings.Path != "" {
   578  				baseUrl.Path = settings.Path
   579  			}
   580  			httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
   581  			if err != nil {
   582  				return err
   583  			}
   584  			httpReq.Header = headers
   585  
   586  			httpRsp, err := c.httpClient.Do(httpReq)
   587  			if err != nil {
   588  				return err
   589  			}
   590  			defer httpRsp.Body.Close()
   591  
   592  			if err = googleapi.CheckResponse(httpRsp); err != nil {
   593  				return err
   594  			}
   595  
   596  			buf, err := io.ReadAll(httpRsp.Body)
   597  			if err != nil {
   598  				return err
   599  			}
   600  
   601  			if err := unm.Unmarshal(buf, resp); err != nil {
   602  				return err
   603  			}
   604  
   605  			return nil
   606  		}, opts...)
   607  		if e != nil {
   608  			return nil, "", e
   609  		}
   610  		it.Response = resp
   611  		return resp.GetTagBindings(), resp.GetNextPageToken(), nil
   612  	}
   613  
   614  	fetch := func(pageSize int, pageToken string) (string, error) {
   615  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
   616  		if err != nil {
   617  			return "", err
   618  		}
   619  		it.items = append(it.items, items...)
   620  		return nextPageToken, nil
   621  	}
   622  
   623  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
   624  	it.pageInfo.MaxSize = int(req.GetPageSize())
   625  	it.pageInfo.Token = req.GetPageToken()
   626  
   627  	return it
   628  }
   629  
   630  // CreateTagBinding creates a TagBinding between a TagValue and a Google Cloud resource.
   631  func (c *tagBindingsRESTClient) CreateTagBinding(ctx context.Context, req *resourcemanagerpb.CreateTagBindingRequest, opts ...gax.CallOption) (*CreateTagBindingOperation, error) {
   632  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
   633  	body := req.GetTagBinding()
   634  	jsonReq, err := m.Marshal(body)
   635  	if err != nil {
   636  		return nil, err
   637  	}
   638  
   639  	baseUrl, err := url.Parse(c.endpoint)
   640  	if err != nil {
   641  		return nil, err
   642  	}
   643  	baseUrl.Path += fmt.Sprintf("/v3/tagBindings")
   644  
   645  	params := url.Values{}
   646  	params.Add("$alt", "json;enum-encoding=int")
   647  	if req.GetValidateOnly() {
   648  		params.Add("validateOnly", fmt.Sprintf("%v", req.GetValidateOnly()))
   649  	}
   650  
   651  	baseUrl.RawQuery = params.Encode()
   652  
   653  	// Build HTTP headers from client and context metadata.
   654  	hds := append(c.xGoogHeaders, "Content-Type", "application/json")
   655  	headers := gax.BuildHeaders(ctx, hds...)
   656  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
   657  	resp := &longrunningpb.Operation{}
   658  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   659  		if settings.Path != "" {
   660  			baseUrl.Path = settings.Path
   661  		}
   662  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
   663  		if err != nil {
   664  			return err
   665  		}
   666  		httpReq = httpReq.WithContext(ctx)
   667  		httpReq.Header = headers
   668  
   669  		httpRsp, err := c.httpClient.Do(httpReq)
   670  		if err != nil {
   671  			return err
   672  		}
   673  		defer httpRsp.Body.Close()
   674  
   675  		if err = googleapi.CheckResponse(httpRsp); err != nil {
   676  			return err
   677  		}
   678  
   679  		buf, err := io.ReadAll(httpRsp.Body)
   680  		if err != nil {
   681  			return err
   682  		}
   683  
   684  		if err := unm.Unmarshal(buf, resp); err != nil {
   685  			return err
   686  		}
   687  
   688  		return nil
   689  	}, opts...)
   690  	if e != nil {
   691  		return nil, e
   692  	}
   693  
   694  	override := fmt.Sprintf("/v3/%s", resp.GetName())
   695  	return &CreateTagBindingOperation{
   696  		lro:      longrunning.InternalNewOperation(*c.LROClient, resp),
   697  		pollPath: override,
   698  	}, nil
   699  }
   700  
   701  // DeleteTagBinding deletes a TagBinding.
   702  func (c *tagBindingsRESTClient) DeleteTagBinding(ctx context.Context, req *resourcemanagerpb.DeleteTagBindingRequest, opts ...gax.CallOption) (*DeleteTagBindingOperation, error) {
   703  	baseUrl, err := url.Parse(c.endpoint)
   704  	if err != nil {
   705  		return nil, err
   706  	}
   707  	baseUrl.Path += fmt.Sprintf("/v3/%v", req.GetName())
   708  
   709  	params := url.Values{}
   710  	params.Add("$alt", "json;enum-encoding=int")
   711  
   712  	baseUrl.RawQuery = params.Encode()
   713  
   714  	// Build HTTP headers from client and context metadata.
   715  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   716  
   717  	hds = append(c.xGoogHeaders, hds...)
   718  	hds = append(hds, "Content-Type", "application/json")
   719  	headers := gax.BuildHeaders(ctx, hds...)
   720  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
   721  	resp := &longrunningpb.Operation{}
   722  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   723  		if settings.Path != "" {
   724  			baseUrl.Path = settings.Path
   725  		}
   726  		httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
   727  		if err != nil {
   728  			return err
   729  		}
   730  		httpReq = httpReq.WithContext(ctx)
   731  		httpReq.Header = headers
   732  
   733  		httpRsp, err := c.httpClient.Do(httpReq)
   734  		if err != nil {
   735  			return err
   736  		}
   737  		defer httpRsp.Body.Close()
   738  
   739  		if err = googleapi.CheckResponse(httpRsp); err != nil {
   740  			return err
   741  		}
   742  
   743  		buf, err := io.ReadAll(httpRsp.Body)
   744  		if err != nil {
   745  			return err
   746  		}
   747  
   748  		if err := unm.Unmarshal(buf, resp); err != nil {
   749  			return err
   750  		}
   751  
   752  		return nil
   753  	}, opts...)
   754  	if e != nil {
   755  		return nil, e
   756  	}
   757  
   758  	override := fmt.Sprintf("/v3/%s", resp.GetName())
   759  	return &DeleteTagBindingOperation{
   760  		lro:      longrunning.InternalNewOperation(*c.LROClient, resp),
   761  		pollPath: override,
   762  	}, nil
   763  }
   764  
   765  // ListEffectiveTags return a list of effective tags for the given Google Cloud resource, as
   766  // specified in parent.
   767  func (c *tagBindingsRESTClient) ListEffectiveTags(ctx context.Context, req *resourcemanagerpb.ListEffectiveTagsRequest, opts ...gax.CallOption) *EffectiveTagIterator {
   768  	it := &EffectiveTagIterator{}
   769  	req = proto.Clone(req).(*resourcemanagerpb.ListEffectiveTagsRequest)
   770  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
   771  	it.InternalFetch = func(pageSize int, pageToken string) ([]*resourcemanagerpb.EffectiveTag, string, error) {
   772  		resp := &resourcemanagerpb.ListEffectiveTagsResponse{}
   773  		if pageToken != "" {
   774  			req.PageToken = pageToken
   775  		}
   776  		if pageSize > math.MaxInt32 {
   777  			req.PageSize = math.MaxInt32
   778  		} else if pageSize != 0 {
   779  			req.PageSize = int32(pageSize)
   780  		}
   781  		baseUrl, err := url.Parse(c.endpoint)
   782  		if err != nil {
   783  			return nil, "", err
   784  		}
   785  		baseUrl.Path += fmt.Sprintf("/v3/effectiveTags")
   786  
   787  		params := url.Values{}
   788  		params.Add("$alt", "json;enum-encoding=int")
   789  		if req.GetPageSize() != 0 {
   790  			params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
   791  		}
   792  		if req.GetPageToken() != "" {
   793  			params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
   794  		}
   795  		params.Add("parent", fmt.Sprintf("%v", req.GetParent()))
   796  
   797  		baseUrl.RawQuery = params.Encode()
   798  
   799  		// Build HTTP headers from client and context metadata.
   800  		hds := append(c.xGoogHeaders, "Content-Type", "application/json")
   801  		headers := gax.BuildHeaders(ctx, hds...)
   802  		e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   803  			if settings.Path != "" {
   804  				baseUrl.Path = settings.Path
   805  			}
   806  			httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
   807  			if err != nil {
   808  				return err
   809  			}
   810  			httpReq.Header = headers
   811  
   812  			httpRsp, err := c.httpClient.Do(httpReq)
   813  			if err != nil {
   814  				return err
   815  			}
   816  			defer httpRsp.Body.Close()
   817  
   818  			if err = googleapi.CheckResponse(httpRsp); err != nil {
   819  				return err
   820  			}
   821  
   822  			buf, err := io.ReadAll(httpRsp.Body)
   823  			if err != nil {
   824  				return err
   825  			}
   826  
   827  			if err := unm.Unmarshal(buf, resp); err != nil {
   828  				return err
   829  			}
   830  
   831  			return nil
   832  		}, opts...)
   833  		if e != nil {
   834  			return nil, "", e
   835  		}
   836  		it.Response = resp
   837  		return resp.GetEffectiveTags(), resp.GetNextPageToken(), nil
   838  	}
   839  
   840  	fetch := func(pageSize int, pageToken string) (string, error) {
   841  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
   842  		if err != nil {
   843  			return "", err
   844  		}
   845  		it.items = append(it.items, items...)
   846  		return nextPageToken, nil
   847  	}
   848  
   849  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
   850  	it.pageInfo.MaxSize = int(req.GetPageSize())
   851  	it.pageInfo.Token = req.GetPageToken()
   852  
   853  	return it
   854  }
   855  
   856  // GetOperation is a utility method from google.longrunning.Operations.
   857  func (c *tagBindingsRESTClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
   858  	baseUrl, err := url.Parse(c.endpoint)
   859  	if err != nil {
   860  		return nil, err
   861  	}
   862  	baseUrl.Path += fmt.Sprintf("/v3/%v", req.GetName())
   863  
   864  	params := url.Values{}
   865  	params.Add("$alt", "json;enum-encoding=int")
   866  
   867  	baseUrl.RawQuery = params.Encode()
   868  
   869  	// Build HTTP headers from client and context metadata.
   870  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   871  
   872  	hds = append(c.xGoogHeaders, hds...)
   873  	hds = append(hds, "Content-Type", "application/json")
   874  	headers := gax.BuildHeaders(ctx, hds...)
   875  	opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
   876  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
   877  	resp := &longrunningpb.Operation{}
   878  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   879  		if settings.Path != "" {
   880  			baseUrl.Path = settings.Path
   881  		}
   882  		httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
   883  		if err != nil {
   884  			return err
   885  		}
   886  		httpReq = httpReq.WithContext(ctx)
   887  		httpReq.Header = headers
   888  
   889  		httpRsp, err := c.httpClient.Do(httpReq)
   890  		if err != nil {
   891  			return err
   892  		}
   893  		defer httpRsp.Body.Close()
   894  
   895  		if err = googleapi.CheckResponse(httpRsp); err != nil {
   896  			return err
   897  		}
   898  
   899  		buf, err := io.ReadAll(httpRsp.Body)
   900  		if err != nil {
   901  			return err
   902  		}
   903  
   904  		if err := unm.Unmarshal(buf, resp); err != nil {
   905  			return err
   906  		}
   907  
   908  		return nil
   909  	}, opts...)
   910  	if e != nil {
   911  		return nil, e
   912  	}
   913  	return resp, nil
   914  }
   915  
   916  // CreateTagBindingOperation returns a new CreateTagBindingOperation from a given name.
   917  // The name must be that of a previously created CreateTagBindingOperation, possibly from a different process.
   918  func (c *tagBindingsGRPCClient) CreateTagBindingOperation(name string) *CreateTagBindingOperation {
   919  	return &CreateTagBindingOperation{
   920  		lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
   921  	}
   922  }
   923  
   924  // CreateTagBindingOperation returns a new CreateTagBindingOperation from a given name.
   925  // The name must be that of a previously created CreateTagBindingOperation, possibly from a different process.
   926  func (c *tagBindingsRESTClient) CreateTagBindingOperation(name string) *CreateTagBindingOperation {
   927  	override := fmt.Sprintf("/v3/%s", name)
   928  	return &CreateTagBindingOperation{
   929  		lro:      longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
   930  		pollPath: override,
   931  	}
   932  }
   933  
   934  // DeleteTagBindingOperation returns a new DeleteTagBindingOperation from a given name.
   935  // The name must be that of a previously created DeleteTagBindingOperation, possibly from a different process.
   936  func (c *tagBindingsGRPCClient) DeleteTagBindingOperation(name string) *DeleteTagBindingOperation {
   937  	return &DeleteTagBindingOperation{
   938  		lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
   939  	}
   940  }
   941  
   942  // DeleteTagBindingOperation returns a new DeleteTagBindingOperation from a given name.
   943  // The name must be that of a previously created DeleteTagBindingOperation, possibly from a different process.
   944  func (c *tagBindingsRESTClient) DeleteTagBindingOperation(name string) *DeleteTagBindingOperation {
   945  	override := fmt.Sprintf("/v3/%s", name)
   946  	return &DeleteTagBindingOperation{
   947  		lro:      longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
   948  		pollPath: override,
   949  	}
   950  }
   951  

View as plain text