Debian Codegraph @

gkehub/apiv1beta1/gke_hub_membership_client.go

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