1// Copyright 2021 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
17package resourcemanager
18
19import (
20	"context"
21	"fmt"
22	"math"
23	"net/url"
24	"time"
25
26	"cloud.google.com/go/longrunning"
27	lroauto "cloud.google.com/go/longrunning/autogen"
28	gax "github.com/googleapis/gax-go/v2"
29	"google.golang.org/api/iterator"
30	"google.golang.org/api/option"
31	"google.golang.org/api/option/internaloption"
32	gtransport "google.golang.org/api/transport/grpc"
33	resourcemanagerpb "google.golang.org/genproto/googleapis/cloud/resourcemanager/v3"
34	iampb "google.golang.org/genproto/googleapis/iam/v1"
35	longrunningpb "google.golang.org/genproto/googleapis/longrunning"
36	"google.golang.org/grpc"
37	"google.golang.org/grpc/codes"
38	"google.golang.org/grpc/metadata"
39	"google.golang.org/protobuf/proto"
40)
41
42var newTagKeysClientHook clientHook
43
44// TagKeysCallOptions contains the retry settings for each method of TagKeysClient.
45type TagKeysCallOptions struct {
46	ListTagKeys        []gax.CallOption
47	GetTagKey          []gax.CallOption
48	CreateTagKey       []gax.CallOption
49	UpdateTagKey       []gax.CallOption
50	DeleteTagKey       []gax.CallOption
51	GetIamPolicy       []gax.CallOption
52	SetIamPolicy       []gax.CallOption
53	TestIamPermissions []gax.CallOption
54}
55
56func defaultTagKeysGRPCClientOptions() []option.ClientOption {
57	return []option.ClientOption{
58		internaloption.WithDefaultEndpoint("cloudresourcemanager.googleapis.com:443"),
59		internaloption.WithDefaultMTLSEndpoint("cloudresourcemanager.mtls.googleapis.com:443"),
60		internaloption.WithDefaultAudience("https://cloudresourcemanager.googleapis.com/"),
61		internaloption.WithDefaultScopes(DefaultAuthScopes()...),
62		internaloption.EnableJwtWithScope(),
63		option.WithGRPCDialOption(grpc.WithDisableServiceConfig()),
64		option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
65			grpc.MaxCallRecvMsgSize(math.MaxInt32))),
66	}
67}
68
69func defaultTagKeysCallOptions() *TagKeysCallOptions {
70	return &TagKeysCallOptions{
71		ListTagKeys: []gax.CallOption{
72			gax.WithRetry(func() gax.Retryer {
73				return gax.OnCodes([]codes.Code{
74					codes.Unavailable,
75				}, gax.Backoff{
76					Initial:    100 * time.Millisecond,
77					Max:        60000 * time.Millisecond,
78					Multiplier: 1.30,
79				})
80			}),
81		},
82		GetTagKey: []gax.CallOption{
83			gax.WithRetry(func() gax.Retryer {
84				return gax.OnCodes([]codes.Code{
85					codes.Unavailable,
86				}, gax.Backoff{
87					Initial:    100 * time.Millisecond,
88					Max:        60000 * time.Millisecond,
89					Multiplier: 1.30,
90				})
91			}),
92		},
93		CreateTagKey: []gax.CallOption{},
94		UpdateTagKey: []gax.CallOption{},
95		DeleteTagKey: []gax.CallOption{},
96		GetIamPolicy: []gax.CallOption{
97			gax.WithRetry(func() gax.Retryer {
98				return gax.OnCodes([]codes.Code{
99					codes.Unavailable,
100				}, gax.Backoff{
101					Initial:    100 * time.Millisecond,
102					Max:        60000 * time.Millisecond,
103					Multiplier: 1.30,
104				})
105			}),
106		},
107		SetIamPolicy:       []gax.CallOption{},
108		TestIamPermissions: []gax.CallOption{},
109	}
110}
111
112// internalTagKeysClient is an interface that defines the methods availaible from Cloud Resource Manager API.
113type internalTagKeysClient interface {
114	Close() error
115	setGoogleClientInfo(...string)
116	Connection() *grpc.ClientConn
117	ListTagKeys(context.Context, *resourcemanagerpb.ListTagKeysRequest, ...gax.CallOption) *TagKeyIterator
118	GetTagKey(context.Context, *resourcemanagerpb.GetTagKeyRequest, ...gax.CallOption) (*resourcemanagerpb.TagKey, error)
119	CreateTagKey(context.Context, *resourcemanagerpb.CreateTagKeyRequest, ...gax.CallOption) (*CreateTagKeyOperation, error)
120	CreateTagKeyOperation(name string) *CreateTagKeyOperation
121	UpdateTagKey(context.Context, *resourcemanagerpb.UpdateTagKeyRequest, ...gax.CallOption) (*UpdateTagKeyOperation, error)
122	UpdateTagKeyOperation(name string) *UpdateTagKeyOperation
123	DeleteTagKey(context.Context, *resourcemanagerpb.DeleteTagKeyRequest, ...gax.CallOption) (*DeleteTagKeyOperation, error)
124	DeleteTagKeyOperation(name string) *DeleteTagKeyOperation
125	GetIamPolicy(context.Context, *iampb.GetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
126	SetIamPolicy(context.Context, *iampb.SetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
127	TestIamPermissions(context.Context, *iampb.TestIamPermissionsRequest, ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error)
128}
129
130// TagKeysClient is a client for interacting with Cloud Resource Manager API.
131// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
132//
133// Allow users to create and manage tag keys.
134type TagKeysClient struct {
135	// The internal transport-dependent client.
136	internalClient internalTagKeysClient
137
138	// The call options for this service.
139	CallOptions *TagKeysCallOptions
140
141	// LROClient is used internally to handle long-running operations.
142	// It is exposed so that its CallOptions can be modified if required.
143	// Users should not Close this client.
144	LROClient *lroauto.OperationsClient
145}
146
147// Wrapper methods routed to the internal client.
148
149// Close closes the connection to the API service. The user should invoke this when
150// the client is no longer required.
151func (c *TagKeysClient) Close() error {
152	return c.internalClient.Close()
153}
154
155// setGoogleClientInfo sets the name and version of the application in
156// the `x-goog-api-client` header passed on each request. Intended for
157// use by Google-written clients.
158func (c *TagKeysClient) setGoogleClientInfo(keyval ...string) {
159	c.internalClient.setGoogleClientInfo(keyval...)
160}
161
162// Connection returns a connection to the API service.
163//
164// Deprecated.
165func (c *TagKeysClient) Connection() *grpc.ClientConn {
166	return c.internalClient.Connection()
167}
168
169// ListTagKeys lists all TagKeys for a parent resource.
170func (c *TagKeysClient) ListTagKeys(ctx context.Context, req *resourcemanagerpb.ListTagKeysRequest, opts ...gax.CallOption) *TagKeyIterator {
171	return c.internalClient.ListTagKeys(ctx, req, opts...)
172}
173
174// GetTagKey retrieves a TagKey. This method will return PERMISSION_DENIED if the
175// key does not exist or the user does not have permission to view it.
176func (c *TagKeysClient) GetTagKey(ctx context.Context, req *resourcemanagerpb.GetTagKeyRequest, opts ...gax.CallOption) (*resourcemanagerpb.TagKey, error) {
177	return c.internalClient.GetTagKey(ctx, req, opts...)
178}
179
180// CreateTagKey creates a new TagKey. If another request with the same parameters is
181// sent while the original request is in process, the second request
182// will receive an error. A maximum of 300 TagKeys can exist under a parent at
183// any given time.
184func (c *TagKeysClient) CreateTagKey(ctx context.Context, req *resourcemanagerpb.CreateTagKeyRequest, opts ...gax.CallOption) (*CreateTagKeyOperation, error) {
185	return c.internalClient.CreateTagKey(ctx, req, opts...)
186}
187
188// CreateTagKeyOperation returns a new CreateTagKeyOperation from a given name.
189// The name must be that of a previously created CreateTagKeyOperation, possibly from a different process.
190func (c *TagKeysClient) CreateTagKeyOperation(name string) *CreateTagKeyOperation {
191	return c.internalClient.CreateTagKeyOperation(name)
192}
193
194// UpdateTagKey updates the attributes of the TagKey resource.
195func (c *TagKeysClient) UpdateTagKey(ctx context.Context, req *resourcemanagerpb.UpdateTagKeyRequest, opts ...gax.CallOption) (*UpdateTagKeyOperation, error) {
196	return c.internalClient.UpdateTagKey(ctx, req, opts...)
197}
198
199// UpdateTagKeyOperation returns a new UpdateTagKeyOperation from a given name.
200// The name must be that of a previously created UpdateTagKeyOperation, possibly from a different process.
201func (c *TagKeysClient) UpdateTagKeyOperation(name string) *UpdateTagKeyOperation {
202	return c.internalClient.UpdateTagKeyOperation(name)
203}
204
205// DeleteTagKey deletes a TagKey. The TagKey cannot be deleted if it has any child
206// TagValues.
207func (c *TagKeysClient) DeleteTagKey(ctx context.Context, req *resourcemanagerpb.DeleteTagKeyRequest, opts ...gax.CallOption) (*DeleteTagKeyOperation, error) {
208	return c.internalClient.DeleteTagKey(ctx, req, opts...)
209}
210
211// DeleteTagKeyOperation returns a new DeleteTagKeyOperation from a given name.
212// The name must be that of a previously created DeleteTagKeyOperation, possibly from a different process.
213func (c *TagKeysClient) DeleteTagKeyOperation(name string) *DeleteTagKeyOperation {
214	return c.internalClient.DeleteTagKeyOperation(name)
215}
216
217// GetIamPolicy gets the access control policy for a TagKey. The returned policy may be
218// empty if no such policy or resource exists. The resource field should
219// be the TagKey’s resource name. For example, “tagKeys/1234”.
220// The caller must have
221// cloudresourcemanager.googleapis.com/tagKeys.getIamPolicy permission on
222// the specified TagKey.
223func (c *TagKeysClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
224	return c.internalClient.GetIamPolicy(ctx, req, opts...)
225}
226
227// SetIamPolicy sets the access control policy on a TagKey, replacing any existing
228// policy. The resource field should be the TagKey’s resource name.
229// For example, “tagKeys/1234”.
230// The caller must have resourcemanager.tagKeys.setIamPolicy permission
231// on the identified tagValue.
232func (c *TagKeysClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
233	return c.internalClient.SetIamPolicy(ctx, req, opts...)
234}
235
236// TestIamPermissions returns permissions that a caller has on the specified TagKey.
237// The resource field should be the TagKey’s resource name.
238// For example, “tagKeys/1234”.
239//
240// There are no permissions required for making this API call.
241func (c *TagKeysClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
242	return c.internalClient.TestIamPermissions(ctx, req, opts...)
243}
244
245// tagKeysGRPCClient is a client for interacting with Cloud Resource Manager API over gRPC transport.
246//
247// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
248type tagKeysGRPCClient struct {
249	// Connection pool of gRPC connections to the service.
250	connPool gtransport.ConnPool
251
252	// flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE
253	disableDeadlines bool
254
255	// Points back to the CallOptions field of the containing TagKeysClient
256	CallOptions **TagKeysCallOptions
257
258	// The gRPC API client.
259	tagKeysClient resourcemanagerpb.TagKeysClient
260
261	// LROClient is used internally to handle long-running operations.
262	// It is exposed so that its CallOptions can be modified if required.
263	// Users should not Close this client.
264	LROClient **lroauto.OperationsClient
265
266	// The x-goog-* metadata to be sent with each request.
267	xGoogMetadata metadata.MD
268}
269
270// NewTagKeysClient creates a new tag keys client based on gRPC.
271// The returned client must be Closed when it is done being used to clean up its underlying connections.
272//
273// Allow users to create and manage tag keys.
274func NewTagKeysClient(ctx context.Context, opts ...option.ClientOption) (*TagKeysClient, error) {
275	clientOpts := defaultTagKeysGRPCClientOptions()
276	if newTagKeysClientHook != nil {
277		hookOpts, err := newTagKeysClientHook(ctx, clientHookParams{})
278		if err != nil {
279			return nil, err
280		}
281		clientOpts = append(clientOpts, hookOpts...)
282	}
283
284	disableDeadlines, err := checkDisableDeadlines()
285	if err != nil {
286		return nil, err
287	}
288
289	connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
290	if err != nil {
291		return nil, err
292	}
293	client := TagKeysClient{CallOptions: defaultTagKeysCallOptions()}
294
295	c := &tagKeysGRPCClient{
296		connPool:         connPool,
297		disableDeadlines: disableDeadlines,
298		tagKeysClient:    resourcemanagerpb.NewTagKeysClient(connPool),
299		CallOptions:      &client.CallOptions,
300	}
301	c.setGoogleClientInfo()
302
303	client.internalClient = c
304
305	client.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool))
306	if err != nil {
307		// This error "should not happen", since we are just reusing old connection pool
308		// and never actually need to dial.
309		// If this does happen, we could leak connp. However, we cannot close conn:
310		// If the user invoked the constructor with option.WithGRPCConn,
311		// we would close a connection that's still in use.
312		// TODO: investigate error conditions.
313		return nil, err
314	}
315	c.LROClient = &client.LROClient
316	return &client, nil
317}
318
319// Connection returns a connection to the API service.
320//
321// Deprecated.
322func (c *tagKeysGRPCClient) Connection() *grpc.ClientConn {
323	return c.connPool.Conn()
324}
325
326// setGoogleClientInfo sets the name and version of the application in
327// the `x-goog-api-client` header passed on each request. Intended for
328// use by Google-written clients.
329func (c *tagKeysGRPCClient) setGoogleClientInfo(keyval ...string) {
330	kv := append([]string{"gl-go", versionGo()}, keyval...)
331	kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version)
332	c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
333}
334
335// Close closes the connection to the API service. The user should invoke this when
336// the client is no longer required.
337func (c *tagKeysGRPCClient) Close() error {
338	return c.connPool.Close()
339}
340
341func (c *tagKeysGRPCClient) ListTagKeys(ctx context.Context, req *resourcemanagerpb.ListTagKeysRequest, opts ...gax.CallOption) *TagKeyIterator {
342	ctx = insertMetadata(ctx, c.xGoogMetadata)
343	opts = append((*c.CallOptions).ListTagKeys[0:len((*c.CallOptions).ListTagKeys):len((*c.CallOptions).ListTagKeys)], opts...)
344	it := &TagKeyIterator{}
345	req = proto.Clone(req).(*resourcemanagerpb.ListTagKeysRequest)
346	it.InternalFetch = func(pageSize int, pageToken string) ([]*resourcemanagerpb.TagKey, string, error) {
347		resp := &resourcemanagerpb.ListTagKeysResponse{}
348		if pageToken != "" {
349			req.PageToken = pageToken
350		}
351		if pageSize > math.MaxInt32 {
352			req.PageSize = math.MaxInt32
353		} else if pageSize != 0 {
354			req.PageSize = int32(pageSize)
355		}
356		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
357			var err error
358			resp, err = c.tagKeysClient.ListTagKeys(ctx, req, settings.GRPC...)
359			return err
360		}, opts...)
361		if err != nil {
362			return nil, "", err
363		}
364
365		it.Response = resp
366		return resp.GetTagKeys(), resp.GetNextPageToken(), nil
367	}
368	fetch := func(pageSize int, pageToken string) (string, error) {
369		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
370		if err != nil {
371			return "", err
372		}
373		it.items = append(it.items, items...)
374		return nextPageToken, nil
375	}
376
377	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
378	it.pageInfo.MaxSize = int(req.GetPageSize())
379	it.pageInfo.Token = req.GetPageToken()
380
381	return it
382}
383
384func (c *tagKeysGRPCClient) GetTagKey(ctx context.Context, req *resourcemanagerpb.GetTagKeyRequest, opts ...gax.CallOption) (*resourcemanagerpb.TagKey, error) {
385	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
386		cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond)
387		defer cancel()
388		ctx = cctx
389	}
390	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName())))
391	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
392	opts = append((*c.CallOptions).GetTagKey[0:len((*c.CallOptions).GetTagKey):len((*c.CallOptions).GetTagKey)], opts...)
393	var resp *resourcemanagerpb.TagKey
394	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
395		var err error
396		resp, err = c.tagKeysClient.GetTagKey(ctx, req, settings.GRPC...)
397		return err
398	}, opts...)
399	if err != nil {
400		return nil, err
401	}
402	return resp, nil
403}
404
405func (c *tagKeysGRPCClient) CreateTagKey(ctx context.Context, req *resourcemanagerpb.CreateTagKeyRequest, opts ...gax.CallOption) (*CreateTagKeyOperation, error) {
406	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
407		cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond)
408		defer cancel()
409		ctx = cctx
410	}
411	ctx = insertMetadata(ctx, c.xGoogMetadata)
412	opts = append((*c.CallOptions).CreateTagKey[0:len((*c.CallOptions).CreateTagKey):len((*c.CallOptions).CreateTagKey)], opts...)
413	var resp *longrunningpb.Operation
414	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
415		var err error
416		resp, err = c.tagKeysClient.CreateTagKey(ctx, req, settings.GRPC...)
417		return err
418	}, opts...)
419	if err != nil {
420		return nil, err
421	}
422	return &CreateTagKeyOperation{
423		lro: longrunning.InternalNewOperation(*c.LROClient, resp),
424	}, nil
425}
426
427func (c *tagKeysGRPCClient) UpdateTagKey(ctx context.Context, req *resourcemanagerpb.UpdateTagKeyRequest, opts ...gax.CallOption) (*UpdateTagKeyOperation, error) {
428	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
429		cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond)
430		defer cancel()
431		ctx = cctx
432	}
433	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "tag_key.name", url.QueryEscape(req.GetTagKey().GetName())))
434	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
435	opts = append((*c.CallOptions).UpdateTagKey[0:len((*c.CallOptions).UpdateTagKey):len((*c.CallOptions).UpdateTagKey)], opts...)
436	var resp *longrunningpb.Operation
437	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
438		var err error
439		resp, err = c.tagKeysClient.UpdateTagKey(ctx, req, settings.GRPC...)
440		return err
441	}, opts...)
442	if err != nil {
443		return nil, err
444	}
445	return &UpdateTagKeyOperation{
446		lro: longrunning.InternalNewOperation(*c.LROClient, resp),
447	}, nil
448}
449
450func (c *tagKeysGRPCClient) DeleteTagKey(ctx context.Context, req *resourcemanagerpb.DeleteTagKeyRequest, opts ...gax.CallOption) (*DeleteTagKeyOperation, error) {
451	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
452		cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond)
453		defer cancel()
454		ctx = cctx
455	}
456	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName())))
457	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
458	opts = append((*c.CallOptions).DeleteTagKey[0:len((*c.CallOptions).DeleteTagKey):len((*c.CallOptions).DeleteTagKey)], opts...)
459	var resp *longrunningpb.Operation
460	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
461		var err error
462		resp, err = c.tagKeysClient.DeleteTagKey(ctx, req, settings.GRPC...)
463		return err
464	}, opts...)
465	if err != nil {
466		return nil, err
467	}
468	return &DeleteTagKeyOperation{
469		lro: longrunning.InternalNewOperation(*c.LROClient, resp),
470	}, nil
471}
472
473func (c *tagKeysGRPCClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
474	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
475		cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond)
476		defer cancel()
477		ctx = cctx
478	}
479	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource())))
480	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
481	opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
482	var resp *iampb.Policy
483	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
484		var err error
485		resp, err = c.tagKeysClient.GetIamPolicy(ctx, req, settings.GRPC...)
486		return err
487	}, opts...)
488	if err != nil {
489		return nil, err
490	}
491	return resp, nil
492}
493
494func (c *tagKeysGRPCClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
495	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
496		cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond)
497		defer cancel()
498		ctx = cctx
499	}
500	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource())))
501	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
502	opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
503	var resp *iampb.Policy
504	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
505		var err error
506		resp, err = c.tagKeysClient.SetIamPolicy(ctx, req, settings.GRPC...)
507		return err
508	}, opts...)
509	if err != nil {
510		return nil, err
511	}
512	return resp, nil
513}
514
515func (c *tagKeysGRPCClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
516	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource())))
517	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
518	opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...)
519	var resp *iampb.TestIamPermissionsResponse
520	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
521		var err error
522		resp, err = c.tagKeysClient.TestIamPermissions(ctx, req, settings.GRPC...)
523		return err
524	}, opts...)
525	if err != nil {
526		return nil, err
527	}
528	return resp, nil
529}
530
531// CreateTagKeyOperation manages a long-running operation from CreateTagKey.
532type CreateTagKeyOperation struct {
533	lro *longrunning.Operation
534}
535
536// CreateTagKeyOperation returns a new CreateTagKeyOperation from a given name.
537// The name must be that of a previously created CreateTagKeyOperation, possibly from a different process.
538func (c *tagKeysGRPCClient) CreateTagKeyOperation(name string) *CreateTagKeyOperation {
539	return &CreateTagKeyOperation{
540		lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
541	}
542}
543
544// Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
545//
546// See documentation of Poll for error-handling information.
547func (op *CreateTagKeyOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*resourcemanagerpb.TagKey, error) {
548	var resp resourcemanagerpb.TagKey
549	if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil {
550		return nil, err
551	}
552	return &resp, nil
553}
554
555// Poll fetches the latest state of the long-running operation.
556//
557// Poll also fetches the latest metadata, which can be retrieved by Metadata.
558//
559// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
560// the operation has completed with failure, the error is returned and op.Done will return true.
561// If Poll succeeds and the operation has completed successfully,
562// op.Done will return true, and the response of the operation is returned.
563// If Poll succeeds and the operation has not completed, the returned response and error are both nil.
564func (op *CreateTagKeyOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*resourcemanagerpb.TagKey, error) {
565	var resp resourcemanagerpb.TagKey
566	if err := op.lro.Poll(ctx, &resp, opts...); err != nil {
567		return nil, err
568	}
569	if !op.Done() {
570		return nil, nil
571	}
572	return &resp, nil
573}
574
575// Metadata returns metadata associated with the long-running operation.
576// Metadata itself does not contact the server, but Poll does.
577// To get the latest metadata, call this method after a successful call to Poll.
578// If the metadata is not available, the returned metadata and error are both nil.
579func (op *CreateTagKeyOperation) Metadata() (*resourcemanagerpb.CreateTagKeyMetadata, error) {
580	var meta resourcemanagerpb.CreateTagKeyMetadata
581	if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
582		return nil, nil
583	} else if err != nil {
584		return nil, err
585	}
586	return &meta, nil
587}
588
589// Done reports whether the long-running operation has completed.
590func (op *CreateTagKeyOperation) Done() bool {
591	return op.lro.Done()
592}
593
594// Name returns the name of the long-running operation.
595// The name is assigned by the server and is unique within the service from which the operation is created.
596func (op *CreateTagKeyOperation) Name() string {
597	return op.lro.Name()
598}
599
600// DeleteTagKeyOperation manages a long-running operation from DeleteTagKey.
601type DeleteTagKeyOperation struct {
602	lro *longrunning.Operation
603}
604
605// DeleteTagKeyOperation returns a new DeleteTagKeyOperation from a given name.
606// The name must be that of a previously created DeleteTagKeyOperation, possibly from a different process.
607func (c *tagKeysGRPCClient) DeleteTagKeyOperation(name string) *DeleteTagKeyOperation {
608	return &DeleteTagKeyOperation{
609		lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
610	}
611}
612
613// Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
614//
615// See documentation of Poll for error-handling information.
616func (op *DeleteTagKeyOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*resourcemanagerpb.TagKey, error) {
617	var resp resourcemanagerpb.TagKey
618	if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil {
619		return nil, err
620	}
621	return &resp, nil
622}
623
624// Poll fetches the latest state of the long-running operation.
625//
626// Poll also fetches the latest metadata, which can be retrieved by Metadata.
627//
628// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
629// the operation has completed with failure, the error is returned and op.Done will return true.
630// If Poll succeeds and the operation has completed successfully,
631// op.Done will return true, and the response of the operation is returned.
632// If Poll succeeds and the operation has not completed, the returned response and error are both nil.
633func (op *DeleteTagKeyOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*resourcemanagerpb.TagKey, error) {
634	var resp resourcemanagerpb.TagKey
635	if err := op.lro.Poll(ctx, &resp, opts...); err != nil {
636		return nil, err
637	}
638	if !op.Done() {
639		return nil, nil
640	}
641	return &resp, nil
642}
643
644// Metadata returns metadata associated with the long-running operation.
645// Metadata itself does not contact the server, but Poll does.
646// To get the latest metadata, call this method after a successful call to Poll.
647// If the metadata is not available, the returned metadata and error are both nil.
648func (op *DeleteTagKeyOperation) Metadata() (*resourcemanagerpb.DeleteTagKeyMetadata, error) {
649	var meta resourcemanagerpb.DeleteTagKeyMetadata
650	if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
651		return nil, nil
652	} else if err != nil {
653		return nil, err
654	}
655	return &meta, nil
656}
657
658// Done reports whether the long-running operation has completed.
659func (op *DeleteTagKeyOperation) Done() bool {
660	return op.lro.Done()
661}
662
663// Name returns the name of the long-running operation.
664// The name is assigned by the server and is unique within the service from which the operation is created.
665func (op *DeleteTagKeyOperation) Name() string {
666	return op.lro.Name()
667}
668
669// UpdateTagKeyOperation manages a long-running operation from UpdateTagKey.
670type UpdateTagKeyOperation struct {
671	lro *longrunning.Operation
672}
673
674// UpdateTagKeyOperation returns a new UpdateTagKeyOperation from a given name.
675// The name must be that of a previously created UpdateTagKeyOperation, possibly from a different process.
676func (c *tagKeysGRPCClient) UpdateTagKeyOperation(name string) *UpdateTagKeyOperation {
677	return &UpdateTagKeyOperation{
678		lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
679	}
680}
681
682// Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
683//
684// See documentation of Poll for error-handling information.
685func (op *UpdateTagKeyOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*resourcemanagerpb.TagKey, error) {
686	var resp resourcemanagerpb.TagKey
687	if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil {
688		return nil, err
689	}
690	return &resp, nil
691}
692
693// Poll fetches the latest state of the long-running operation.
694//
695// Poll also fetches the latest metadata, which can be retrieved by Metadata.
696//
697// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
698// the operation has completed with failure, the error is returned and op.Done will return true.
699// If Poll succeeds and the operation has completed successfully,
700// op.Done will return true, and the response of the operation is returned.
701// If Poll succeeds and the operation has not completed, the returned response and error are both nil.
702func (op *UpdateTagKeyOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*resourcemanagerpb.TagKey, error) {
703	var resp resourcemanagerpb.TagKey
704	if err := op.lro.Poll(ctx, &resp, opts...); err != nil {
705		return nil, err
706	}
707	if !op.Done() {
708		return nil, nil
709	}
710	return &resp, nil
711}
712
713// Metadata returns metadata associated with the long-running operation.
714// Metadata itself does not contact the server, but Poll does.
715// To get the latest metadata, call this method after a successful call to Poll.
716// If the metadata is not available, the returned metadata and error are both nil.
717func (op *UpdateTagKeyOperation) Metadata() (*resourcemanagerpb.UpdateTagKeyMetadata, error) {
718	var meta resourcemanagerpb.UpdateTagKeyMetadata
719	if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
720		return nil, nil
721	} else if err != nil {
722		return nil, err
723	}
724	return &meta, nil
725}
726
727// Done reports whether the long-running operation has completed.
728func (op *UpdateTagKeyOperation) Done() bool {
729	return op.lro.Done()
730}
731
732// Name returns the name of the long-running operation.
733// The name is assigned by the server and is unique within the service from which the operation is created.
734func (op *UpdateTagKeyOperation) Name() string {
735	return op.lro.Name()
736}
737
738// TagKeyIterator manages a stream of *resourcemanagerpb.TagKey.
739type TagKeyIterator struct {
740	items    []*resourcemanagerpb.TagKey
741	pageInfo *iterator.PageInfo
742	nextFunc func() error
743
744	// Response is the raw response for the current page.
745	// It must be cast to the RPC response type.
746	// Calling Next() or InternalFetch() updates this value.
747	Response interface{}
748
749	// InternalFetch is for use by the Google Cloud Libraries only.
750	// It is not part of the stable interface of this package.
751	//
752	// InternalFetch returns results from a single call to the underlying RPC.
753	// The number of results is no greater than pageSize.
754	// If there are no more results, nextPageToken is empty and err is nil.
755	InternalFetch func(pageSize int, pageToken string) (results []*resourcemanagerpb.TagKey, nextPageToken string, err error)
756}
757
758// PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
759func (it *TagKeyIterator) PageInfo() *iterator.PageInfo {
760	return it.pageInfo
761}
762
763// Next returns the next result. Its second return value is iterator.Done if there are no more
764// results. Once Next returns Done, all subsequent calls will return Done.
765func (it *TagKeyIterator) Next() (*resourcemanagerpb.TagKey, error) {
766	var item *resourcemanagerpb.TagKey
767	if err := it.nextFunc(); err != nil {
768		return item, err
769	}
770	item = it.items[0]
771	it.items = it.items[1:]
772	return item, nil
773}
774
775func (it *TagKeyIterator) bufLen() int {
776	return len(it.items)
777}
778
779func (it *TagKeyIterator) takeBuf() interface{} {
780	b := it.items
781	it.items = nil
782	return b
783}
784