Debian Codegraph @

pubsub/v2/apiv1/topic_admin_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 pubsub
18
19 import (
20 "bytes"
21 "context"
22 "fmt"
23 "log/slog"
24 "math"
25 "net/http"
26 "net/url"
27 "time"
28
29 iampb "cloud.google.com/go/iam/apiv1/iampb"
30 pubsubpb "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
31 gax "github.com/googleapis/gax-go/v2"
32 "google.golang.org/api/iterator"
33 "google.golang.org/api/option"
34 "google.golang.org/api/option/internaloption"
35 gtransport "google.golang.org/api/transport/grpc"
36 httptransport "google.golang.org/api/transport/http"
37 "google.golang.org/grpc"
38 "google.golang.org/grpc/codes"
39 "google.golang.org/protobuf/encoding/protojson"
40 "google.golang.org/protobuf/proto"
41 )
42
43 var newTopicAdminClientHook clientHook
44
45 // TopicAdminCallOptions contains the retry settings for each method of TopicAdminClient.
46 type TopicAdminCallOptions struct {
47 CreateTopic []gax.CallOption
48 UpdateTopic []gax.CallOption
49 Publish []gax.CallOption
50 GetTopic []gax.CallOption
51 ListTopics []gax.CallOption
52 ListTopicSubscriptions []gax.CallOption
53 ListTopicSnapshots []gax.CallOption
54 DeleteTopic []gax.CallOption
55 DetachSubscription []gax.CallOption
56 GetIamPolicy []gax.CallOption
57 SetIamPolicy []gax.CallOption
58 TestIamPermissions []gax.CallOption
59 }
60
61 func defaultTopicAdminGRPCClientOptions() []option.ClientOption {
62 return []option.ClientOption{
63 internaloption.WithDefaultEndpoint("pubsub.googleapis.com:443"),
64 internaloption.WithDefaultEndpointTemplate("pubsub.UNIVERSE_DOMAIN:443"),
65 internaloption.WithDefaultMTLSEndpoint("pubsub.mtls.googleapis.com:443"),
66 internaloption.WithDefaultUniverseDomain("googleapis.com"),
67 internaloption.WithDefaultAudience("https://pubsub.googleapis.com/"),
68 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
69 internaloption.EnableJwtWithScope(),
70 internaloption.EnableNewAuthLibrary(),
71 option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
72 grpc.MaxCallRecvMsgSize(math.MaxInt32))),
73 }
74 }
75
76 func defaultTopicAdminCallOptions() *TopicAdminCallOptions {
77 return &TopicAdminCallOptions{
78 CreateTopic: []gax.CallOption{
79 gax.WithTimeout(60000 * time.Millisecond),
80 gax.WithRetry(func() gax.Retryer {
81 return gax.OnCodes([]codes.Code{
82 codes.Unavailable,
83 }, gax.Backoff{
84 Initial: 100 * time.Millisecond,
85 Max: 60000 * time.Millisecond,
86 Multiplier: 1.30,
87 })
88 }),
89 },
90 UpdateTopic: []gax.CallOption{
91 gax.WithTimeout(60000 * time.Millisecond),
92 gax.WithRetry(func() gax.Retryer {
93 return gax.OnCodes([]codes.Code{
94 codes.Unavailable,
95 }, gax.Backoff{
96 Initial: 100 * time.Millisecond,
97 Max: 60000 * time.Millisecond,
98 Multiplier: 1.30,
99 })
100 }),
101 },
102 Publish: []gax.CallOption{
103 gax.WithTimeout(60000 * time.Millisecond),
104 gax.WithRetry(func() gax.Retryer {
105 return gax.OnCodes([]codes.Code{
106 codes.Aborted,
107 codes.Canceled,
108 codes.Internal,
109 codes.ResourceExhausted,
110 codes.Unknown,
111 codes.Unavailable,
112 codes.DeadlineExceeded,
113 }, gax.Backoff{
114 Initial: 100 * time.Millisecond,
115 Max: 60000 * time.Millisecond,
116 Multiplier: 4.00,
117 })
118 }),
119 },
120 GetTopic: []gax.CallOption{
121 gax.WithTimeout(60000 * time.Millisecond),
122 gax.WithRetry(func() gax.Retryer {
123 return gax.OnCodes([]codes.Code{
124 codes.Unknown,
125 codes.Aborted,
126 codes.Unavailable,
127 }, gax.Backoff{
128 Initial: 100 * time.Millisecond,
129 Max: 60000 * time.Millisecond,
130 Multiplier: 1.30,
131 })
132 }),
133 },
134 ListTopics: []gax.CallOption{
135 gax.WithTimeout(60000 * time.Millisecond),
136 gax.WithRetry(func() gax.Retryer {
137 return gax.OnCodes([]codes.Code{
138 codes.Unknown,
139 codes.Aborted,
140 codes.Unavailable,
141 }, gax.Backoff{
142 Initial: 100 * time.Millisecond,
143 Max: 60000 * time.Millisecond,
144 Multiplier: 1.30,
145 })
146 }),
147 },
148 ListTopicSubscriptions: []gax.CallOption{
149 gax.WithTimeout(60000 * time.Millisecond),
150 gax.WithRetry(func() gax.Retryer {
151 return gax.OnCodes([]codes.Code{
152 codes.Unknown,
153 codes.Aborted,
154 codes.Unavailable,
155 }, gax.Backoff{
156 Initial: 100 * time.Millisecond,
157 Max: 60000 * time.Millisecond,
158 Multiplier: 1.30,
159 })
160 }),
161 },
162 ListTopicSnapshots: []gax.CallOption{
163 gax.WithTimeout(60000 * time.Millisecond),
164 gax.WithRetry(func() gax.Retryer {
165 return gax.OnCodes([]codes.Code{
166 codes.Unknown,
167 codes.Aborted,
168 codes.Unavailable,
169 }, gax.Backoff{
170 Initial: 100 * time.Millisecond,
171 Max: 60000 * time.Millisecond,
172 Multiplier: 1.30,
173 })
174 }),
175 },
176 DeleteTopic: []gax.CallOption{
177 gax.WithTimeout(60000 * time.Millisecond),
178 gax.WithRetry(func() gax.Retryer {
179 return gax.OnCodes([]codes.Code{
180 codes.Unavailable,
181 }, gax.Backoff{
182 Initial: 100 * time.Millisecond,
183 Max: 60000 * time.Millisecond,
184 Multiplier: 1.30,
185 })
186 }),
187 },
188 DetachSubscription: []gax.CallOption{
189 gax.WithTimeout(60000 * time.Millisecond),
190 gax.WithRetry(func() gax.Retryer {
191 return gax.OnCodes([]codes.Code{
192 codes.Unavailable,
193 }, gax.Backoff{
194 Initial: 100 * time.Millisecond,
195 Max: 60000 * time.Millisecond,
196 Multiplier: 1.30,
197 })
198 }),
199 },
200 GetIamPolicy: []gax.CallOption{},
201 SetIamPolicy: []gax.CallOption{},
202 TestIamPermissions: []gax.CallOption{},
203 }
204 }
205
206 func defaultTopicAdminRESTCallOptions() *TopicAdminCallOptions {
207 return &TopicAdminCallOptions{
208 CreateTopic: []gax.CallOption{
209 gax.WithTimeout(60000 * time.Millisecond),
210 gax.WithRetry(func() gax.Retryer {
211 return gax.OnHTTPCodes(gax.Backoff{
212 Initial: 100 * time.Millisecond,
213 Max: 60000 * time.Millisecond,
214 Multiplier: 1.30,
215 },
216 http.StatusServiceUnavailable)
217 }),
218 },
219 UpdateTopic: []gax.CallOption{
220 gax.WithTimeout(60000 * time.Millisecond),
221 gax.WithRetry(func() gax.Retryer {
222 return gax.OnHTTPCodes(gax.Backoff{
223 Initial: 100 * time.Millisecond,
224 Max: 60000 * time.Millisecond,
225 Multiplier: 1.30,
226 },
227 http.StatusServiceUnavailable)
228 }),
229 },
230 Publish: []gax.CallOption{
231 gax.WithTimeout(60000 * time.Millisecond),
232 gax.WithRetry(func() gax.Retryer {
233 return gax.OnHTTPCodes(gax.Backoff{
234 Initial: 100 * time.Millisecond,
235 Max: 60000 * time.Millisecond,
236 Multiplier: 4.00,
237 },
238 http.StatusConflict,
239 499,
240 http.StatusInternalServerError,
241 http.StatusTooManyRequests,
242 http.StatusInternalServerError,
243 http.StatusServiceUnavailable,
244 http.StatusGatewayTimeout)
245 }),
246 },
247 GetTopic: []gax.CallOption{
248 gax.WithTimeout(60000 * time.Millisecond),
249 gax.WithRetry(func() gax.Retryer {
250 return gax.OnHTTPCodes(gax.Backoff{
251 Initial: 100 * time.Millisecond,
252 Max: 60000 * time.Millisecond,
253 Multiplier: 1.30,
254 },
255 http.StatusInternalServerError,
256 http.StatusConflict,
257 http.StatusServiceUnavailable)
258 }),
259 },
260 ListTopics: []gax.CallOption{
261 gax.WithTimeout(60000 * time.Millisecond),
262 gax.WithRetry(func() gax.Retryer {
263 return gax.OnHTTPCodes(gax.Backoff{
264 Initial: 100 * time.Millisecond,
265 Max: 60000 * time.Millisecond,
266 Multiplier: 1.30,
267 },
268 http.StatusInternalServerError,
269 http.StatusConflict,
270 http.StatusServiceUnavailable)
271 }),
272 },
273 ListTopicSubscriptions: []gax.CallOption{
274 gax.WithTimeout(60000 * time.Millisecond),
275 gax.WithRetry(func() gax.Retryer {
276 return gax.OnHTTPCodes(gax.Backoff{
277 Initial: 100 * time.Millisecond,
278 Max: 60000 * time.Millisecond,
279 Multiplier: 1.30,
280 },
281 http.StatusInternalServerError,
282 http.StatusConflict,
283 http.StatusServiceUnavailable)
284 }),
285 },
286 ListTopicSnapshots: []gax.CallOption{
287 gax.WithTimeout(60000 * time.Millisecond),
288 gax.WithRetry(func() gax.Retryer {
289 return gax.OnHTTPCodes(gax.Backoff{
290 Initial: 100 * time.Millisecond,
291 Max: 60000 * time.Millisecond,
292 Multiplier: 1.30,
293 },
294 http.StatusInternalServerError,
295 http.StatusConflict,
296 http.StatusServiceUnavailable)
297 }),
298 },
299 DeleteTopic: []gax.CallOption{
300 gax.WithTimeout(60000 * time.Millisecond),
301 gax.WithRetry(func() gax.Retryer {
302 return gax.OnHTTPCodes(gax.Backoff{
303 Initial: 100 * time.Millisecond,
304 Max: 60000 * time.Millisecond,
305 Multiplier: 1.30,
306 },
307 http.StatusServiceUnavailable)
308 }),
309 },
310 DetachSubscription: []gax.CallOption{
311 gax.WithTimeout(60000 * time.Millisecond),
312 gax.WithRetry(func() gax.Retryer {
313 return gax.OnHTTPCodes(gax.Backoff{
314 Initial: 100 * time.Millisecond,
315 Max: 60000 * time.Millisecond,
316 Multiplier: 1.30,
317 },
318 http.StatusServiceUnavailable)
319 }),
320 },
321 GetIamPolicy: []gax.CallOption{},
322 SetIamPolicy: []gax.CallOption{},
323 TestIamPermissions: []gax.CallOption{},
324 }
325 }
326
327 // internalTopicAdminClient is an interface that defines the methods available from Cloud Pub/Sub API.
328 type internalTopicAdminClient interface {
329 Close() error
330 setGoogleClientInfo(...string)
331 Connection() *grpc.ClientConn
332 CreateTopic(context.Context, *pubsubpb.Topic, ...gax.CallOption) (*pubsubpb.Topic, error)
333 UpdateTopic(context.Context, *pubsubpb.UpdateTopicRequest, ...gax.CallOption) (*pubsubpb.Topic, error)
334 Publish(context.Context, *pubsubpb.PublishRequest, ...gax.CallOption) (*pubsubpb.PublishResponse, error)
335 GetTopic(context.Context, *pubsubpb.GetTopicRequest, ...gax.CallOption) (*pubsubpb.Topic, error)
336 ListTopics(context.Context, *pubsubpb.ListTopicsRequest, ...gax.CallOption) *TopicIterator
337 ListTopicSubscriptions(context.Context, *pubsubpb.ListTopicSubscriptionsRequest, ...gax.CallOption) *StringIterator
338 ListTopicSnapshots(context.Context, *pubsubpb.ListTopicSnapshotsRequest, ...gax.CallOption) *StringIterator
339 DeleteTopic(context.Context, *pubsubpb.DeleteTopicRequest, ...gax.CallOption) error
340 DetachSubscription(context.Context, *pubsubpb.DetachSubscriptionRequest, ...gax.CallOption) (*pubsubpb.DetachSubscriptionResponse, error)
341 GetIamPolicy(context.Context, *iampb.GetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
342 SetIamPolicy(context.Context, *iampb.SetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
343 TestIamPermissions(context.Context, *iampb.TestIamPermissionsRequest, ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error)
344 }
345
346 // TopicAdminClient is a client for interacting with Cloud Pub/Sub API.
347 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
348 //
349 // The service that an application uses to manipulate topics, and to send
350 // messages to a topic.
351 type TopicAdminClient struct {
352 // The internal transport-dependent client.
353 internalClient internalTopicAdminClient
354
355 // The call options for this service.
356 CallOptions *TopicAdminCallOptions
357 }
358
359 // Wrapper methods routed to the internal client.
360
361 // Close closes the connection to the API service. The user should invoke this when
362 // the client is no longer required.
363 func (c *TopicAdminClient) Close() error {
364 return c.internalClient.Close()
365 }
366
367 // setGoogleClientInfo sets the name and version of the application in
368 // the `x-goog-api-client` header passed on each request. Intended for
369 // use by Google-written clients.
370 func (c *TopicAdminClient) setGoogleClientInfo(keyval ...string) {
371 c.internalClient.setGoogleClientInfo(keyval...)
372 }
373
374 // Connection returns a connection to the API service.
375 //
376 // Deprecated: Connections are now pooled so this method does not always
377 // return the same resource.
378 func (c *TopicAdminClient) Connection() *grpc.ClientConn {
379 return c.internalClient.Connection()
380 }
381
382 // CreateTopic creates the given topic with the given name. See the [resource name rules]
383 // (https://cloud.google.com/pubsub/docs/pubsub-basics#resource_names (at https://cloud.google.com/pubsub/docs/pubsub-basics#resource_names)).
384 func (c *TopicAdminClient) CreateTopic(ctx context.Context, req *pubsubpb.Topic, opts ...gax.CallOption) (*pubsubpb.Topic, error) {
385 return c.internalClient.CreateTopic(ctx, req, opts...)
386 }
387
388 // UpdateTopic updates an existing topic by updating the fields specified in the update
389 // mask. Note that certain properties of a topic are not modifiable.
390 func (c *TopicAdminClient) UpdateTopic(ctx context.Context, req *pubsubpb.UpdateTopicRequest, opts ...gax.CallOption) (*pubsubpb.Topic, error) {
391 return c.internalClient.UpdateTopic(ctx, req, opts...)
392 }
393
394 // Publish adds one or more messages to the topic. Returns NOT_FOUND if the topic
395 // does not exist.
396 func (c *TopicAdminClient) Publish(ctx context.Context, req *pubsubpb.PublishRequest, opts ...gax.CallOption) (*pubsubpb.PublishResponse, error) {
397 return c.internalClient.Publish(ctx, req, opts...)
398 }
399
400 // GetTopic gets the configuration of a topic.
401 func (c *TopicAdminClient) GetTopic(ctx context.Context, req *pubsubpb.GetTopicRequest, opts ...gax.CallOption) (*pubsubpb.Topic, error) {
402 return c.internalClient.GetTopic(ctx, req, opts...)
403 }
404
405 // ListTopics lists matching topics.
406 func (c *TopicAdminClient) ListTopics(ctx context.Context, req *pubsubpb.ListTopicsRequest, opts ...gax.CallOption) *TopicIterator {
407 return c.internalClient.ListTopics(ctx, req, opts...)
408 }
409
410 // ListTopicSubscriptions lists the names of the attached subscriptions on this topic.
411 func (c *TopicAdminClient) ListTopicSubscriptions(ctx context.Context, req *pubsubpb.ListTopicSubscriptionsRequest, opts ...gax.CallOption) *StringIterator {
412 return c.internalClient.ListTopicSubscriptions(ctx, req, opts...)
413 }
414
415 // ListTopicSnapshots lists the names of the snapshots on this topic. Snapshots are used in
416 // Seek (at https://cloud.google.com/pubsub/docs/replay-overview) operations,
417 // which allow you to manage message acknowledgments in bulk. That is, you can
418 // set the acknowledgment state of messages in an existing subscription to the
419 // state captured by a snapshot.
420 func (c *TopicAdminClient) ListTopicSnapshots(ctx context.Context, req *pubsubpb.ListTopicSnapshotsRequest, opts ...gax.CallOption) *StringIterator {
421 return c.internalClient.ListTopicSnapshots(ctx, req, opts...)
422 }
423
424 // DeleteTopic deletes the topic with the given name. Returns NOT_FOUND if the topic
425 // does not exist. After a topic is deleted, a new topic may be created with
426 // the same name; this is an entirely new topic with none of the old
427 // configuration or subscriptions. Existing subscriptions to this topic are
428 // not deleted, but their topic field is set to _deleted-topic_.
429 func (c *TopicAdminClient) DeleteTopic(ctx context.Context, req *pubsubpb.DeleteTopicRequest, opts ...gax.CallOption) error {
430 return c.internalClient.DeleteTopic(ctx, req, opts...)
431 }
432
433 // DetachSubscription detaches a subscription from this topic. All messages retained in the
434 // subscription are dropped. Subsequent Pull and StreamingPull requests
435 // will return FAILED_PRECONDITION. If the subscription is a push
436 // subscription, pushes to the endpoint will stop.
437 func (c *TopicAdminClient) DetachSubscription(ctx context.Context, req *pubsubpb.DetachSubscriptionRequest, opts ...gax.CallOption) (*pubsubpb.DetachSubscriptionResponse, error) {
438 return c.internalClient.DetachSubscription(ctx, req, opts...)
439 }
440
441 // GetIamPolicy gets the access control policy for a resource. Returns an empty policy
442 // if the resource exists and does not have a policy set.
443 func (c *TopicAdminClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
444 return c.internalClient.GetIamPolicy(ctx, req, opts...)
445 }
446
447 // SetIamPolicy sets the access control policy on the specified resource. Replaces
448 // any existing policy.
449 //
450 // Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED
451 // errors.
452 func (c *TopicAdminClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
453 return c.internalClient.SetIamPolicy(ctx, req, opts...)
454 }
455
456 // TestIamPermissions returns permissions that a caller has on the specified resource. If the
457 // resource does not exist, this will return an empty set of
458 // permissions, not a NOT_FOUND error.
459 //
460 // Note: This operation is designed to be used for building
461 // permission-aware UIs and command-line tools, not for authorization
462 // checking. This operation may “fail open” without warning.
463 func (c *TopicAdminClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
464 return c.internalClient.TestIamPermissions(ctx, req, opts...)
465 }
466
467 // topicAdminGRPCClient is a client for interacting with Cloud Pub/Sub API over gRPC transport.
468 //
469 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
470 type topicAdminGRPCClient struct {
471 // Connection pool of gRPC connections to the service.
472 connPool gtransport.ConnPool
473
474 // Points back to the CallOptions field of the containing TopicAdminClient
475 CallOptions **TopicAdminCallOptions
476
477 // The gRPC API client.
478 topicAdminClient pubsubpb.PublisherClient
479
480 iamPolicyClient iampb.IAMPolicyClient
481
482 // The x-goog-* metadata to be sent with each request.
483 xGoogHeaders []string
484
485 logger *slog.Logger
486 }
487
488 // NewTopicAdminClient creates a new topic admin client based on gRPC.
489 // The returned client must be Closed when it is done being used to clean up its underlying connections.
490 //
491 // The service that an application uses to manipulate topics, and to send
492 // messages to a topic.
493 func NewTopicAdminClient(ctx context.Context, opts ...option.ClientOption) (*TopicAdminClient, error) {
494 clientOpts := defaultTopicAdminGRPCClientOptions()
495 if newTopicAdminClientHook != nil {
496 hookOpts, err := newTopicAdminClientHook(ctx, clientHookParams{})
497 if err != nil {
498 return nil, err
499 }
500 clientOpts = append(clientOpts, hookOpts...)
501 }
502
503 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
504 if err != nil {
505 return nil, err
506 }
507 client := TopicAdminClient{CallOptions: defaultTopicAdminCallOptions()}
508
509 c := &topicAdminGRPCClient{
510 connPool: connPool,
511 topicAdminClient: pubsubpb.NewPublisherClient(connPool),
512 CallOptions: &client.CallOptions,
513 logger: internaloption.GetLogger(opts),
514 iamPolicyClient: iampb.NewIAMPolicyClient(connPool),
515 }
516 c.setGoogleClientInfo()
517
518 client.internalClient = c
519
520 return &client, nil
521 }
522
523 // Connection returns a connection to the API service.
524 //
525 // Deprecated: Connections are now pooled so this method does not always
526 // return the same resource.
527 func (c *topicAdminGRPCClient) Connection() *grpc.ClientConn {
528 return c.connPool.Conn()
529 }
530
531 // setGoogleClientInfo sets the name and version of the application in
532 // the `x-goog-api-client` header passed on each request. Intended for
533 // use by Google-written clients.
534 func (c *topicAdminGRPCClient) setGoogleClientInfo(keyval ...string) {
535 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
536 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
537 c.xGoogHeaders = []string{
538 "x-goog-api-client", gax.XGoogHeader(kv...),
539 }
540 }
541
542 // Close closes the connection to the API service. The user should invoke this when
543 // the client is no longer required.
544 func (c *topicAdminGRPCClient) Close() error {
545 return c.connPool.Close()
546 }
547
548 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
549 type topicAdminRESTClient struct {
550 // The http endpoint to connect to.
551 endpoint string
552
553 // The http client.
554 httpClient *http.Client
555
556 // The x-goog-* headers to be sent with each request.
557 xGoogHeaders []string
558
559 // Points back to the CallOptions field of the containing TopicAdminClient
560 CallOptions **TopicAdminCallOptions
561
562 logger *slog.Logger
563 }
564
565 // NewTopicAdminRESTClient creates a new topic admin rest client.
566 //
567 // The service that an application uses to manipulate topics, and to send
568 // messages to a topic.
569 func NewTopicAdminRESTClient(ctx context.Context, opts ...option.ClientOption) (*TopicAdminClient, error) {
570 clientOpts := append(defaultTopicAdminRESTClientOptions(), opts...)
571 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
572 if err != nil {
573 return nil, err
574 }
575
576 callOpts := defaultTopicAdminRESTCallOptions()
577 c := &topicAdminRESTClient{
578 endpoint: endpoint,
579 httpClient: httpClient,
580 CallOptions: &callOpts,
581 logger: internaloption.GetLogger(opts),
582 }
583 c.setGoogleClientInfo()
584
585 return &TopicAdminClient{internalClient: c, CallOptions: callOpts}, nil
586 }
587
588 func defaultTopicAdminRESTClientOptions() []option.ClientOption {
589 return []option.ClientOption{
590 internaloption.WithDefaultEndpoint("https://pubsub.googleapis.com"),
591 internaloption.WithDefaultEndpointTemplate("https://pubsub.UNIVERSE_DOMAIN"),
592 internaloption.WithDefaultMTLSEndpoint("https://pubsub.mtls.googleapis.com"),
593 internaloption.WithDefaultUniverseDomain("googleapis.com"),
594 internaloption.WithDefaultAudience("https://pubsub.googleapis.com/"),
595 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
596 internaloption.EnableNewAuthLibrary(),
597 }
598 }
599
600 // setGoogleClientInfo sets the name and version of the application in
601 // the `x-goog-api-client` header passed on each request. Intended for
602 // use by Google-written clients.
603 func (c *topicAdminRESTClient) setGoogleClientInfo(keyval ...string) {
604 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
605 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
606 c.xGoogHeaders = []string{
607 "x-goog-api-client", gax.XGoogHeader(kv...),
608 }
609 }
610
611 // Close closes the connection to the API service. The user should invoke this when
612 // the client is no longer required.
613 func (c *topicAdminRESTClient) Close() error {
614 // Replace httpClient with nil to force cleanup.
615 c.httpClient = nil
616 return nil
617 }
618
619 // Connection returns a connection to the API service.
620 //
621 // Deprecated: This method always returns nil.
622 func (c *topicAdminRESTClient) Connection() *grpc.ClientConn {
623 return nil
624 }
625 func (c *topicAdminGRPCClient) CreateTopic(ctx context.Context, req *pubsubpb.Topic, opts ...gax.CallOption) (*pubsubpb.Topic, error) {
626 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
627
628 hds = append(c.xGoogHeaders, hds...)
629 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
630 opts = append((*c.CallOptions).CreateTopic[0:len((*c.CallOptions).CreateTopic):len((*c.CallOptions).CreateTopic)], opts...)
631 var resp *pubsubpb.Topic
632 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
633 var err error
634 resp, err = executeRPC(ctx, c.topicAdminClient.CreateTopic, req, settings.GRPC, c.logger, "CreateTopic")
635 return err
636 }, opts...)
637 if err != nil {
638 return nil, err
639 }
640 return resp, nil
641 }
642
643 func (c *topicAdminGRPCClient) UpdateTopic(ctx context.Context, req *pubsubpb.UpdateTopicRequest, opts ...gax.CallOption) (*pubsubpb.Topic, error) {
644 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "topic.name", url.QueryEscape(req.GetTopic().GetName()))}
645
646 hds = append(c.xGoogHeaders, hds...)
647 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
648 opts = append((*c.CallOptions).UpdateTopic[0:len((*c.CallOptions).UpdateTopic):len((*c.CallOptions).UpdateTopic)], opts...)
649 var resp *pubsubpb.Topic
650 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
651 var err error
652 resp, err = executeRPC(ctx, c.topicAdminClient.UpdateTopic, req, settings.GRPC, c.logger, "UpdateTopic")
653 return err
654 }, opts...)
655 if err != nil {
656 return nil, err
657 }
658 return resp, nil
659 }
660
661 func (c *topicAdminGRPCClient) Publish(ctx context.Context, req *pubsubpb.PublishRequest, opts ...gax.CallOption) (*pubsubpb.PublishResponse, error) {
662 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "topic", url.QueryEscape(req.GetTopic()))}
663
664 hds = append(c.xGoogHeaders, hds...)
665 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
666 opts = append((*c.CallOptions).Publish[0:len((*c.CallOptions).Publish):len((*c.CallOptions).Publish)], opts...)
667 var resp *pubsubpb.PublishResponse
668 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
669 var err error
670 resp, err = executeRPC(ctx, c.topicAdminClient.Publish, req, settings.GRPC, c.logger, "Publish")
671 return err
672 }, opts...)
673 if err != nil {
674 return nil, err
675 }
676 return resp, nil
677 }
678
679 func (c *topicAdminGRPCClient) GetTopic(ctx context.Context, req *pubsubpb.GetTopicRequest, opts ...gax.CallOption) (*pubsubpb.Topic, error) {
680 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "topic", url.QueryEscape(req.GetTopic()))}
681
682 hds = append(c.xGoogHeaders, hds...)
683 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
684 opts = append((*c.CallOptions).GetTopic[0:len((*c.CallOptions).GetTopic):len((*c.CallOptions).GetTopic)], opts...)
685 var resp *pubsubpb.Topic
686 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
687 var err error
688 resp, err = executeRPC(ctx, c.topicAdminClient.GetTopic, req, settings.GRPC, c.logger, "GetTopic")
689 return err
690 }, opts...)
691 if err != nil {
692 return nil, err
693 }
694 return resp, nil
695 }
696
697 func (c *topicAdminGRPCClient) ListTopics(ctx context.Context, req *pubsubpb.ListTopicsRequest, opts ...gax.CallOption) *TopicIterator {
698 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "project", url.QueryEscape(req.GetProject()))}
699
700 hds = append(c.xGoogHeaders, hds...)
701 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
702 opts = append((*c.CallOptions).ListTopics[0:len((*c.CallOptions).ListTopics):len((*c.CallOptions).ListTopics)], opts...)
703 it := &TopicIterator{}
704 req = proto.Clone(req).(*pubsubpb.ListTopicsRequest)
705 it.InternalFetch = func(pageSize int, pageToken string) ([]*pubsubpb.Topic, string, error) {
706 resp := &pubsubpb.ListTopicsResponse{}
707 if pageToken != "" {
708 req.PageToken = pageToken
709 }
710 if pageSize > math.MaxInt32 {
711 req.PageSize = math.MaxInt32
712 } else if pageSize != 0 {
713 req.PageSize = int32(pageSize)
714 }
715 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
716 var err error
717 resp, err = executeRPC(ctx, c.topicAdminClient.ListTopics, req, settings.GRPC, c.logger, "ListTopics")
718 return err
719 }, opts...)
720 if err != nil {
721 return nil, "", err
722 }
723
724 it.Response = resp
725 return resp.GetTopics(), resp.GetNextPageToken(), nil
726 }
727 fetch := func(pageSize int, pageToken string) (string, error) {
728 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
729 if err != nil {
730 return "", err
731 }
732 it.items = append(it.items, items...)
733 return nextPageToken, nil
734 }
735
736 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
737 it.pageInfo.MaxSize = int(req.GetPageSize())
738 it.pageInfo.Token = req.GetPageToken()
739
740 return it
741 }
742
743 func (c *topicAdminGRPCClient) ListTopicSubscriptions(ctx context.Context, req *pubsubpb.ListTopicSubscriptionsRequest, opts ...gax.CallOption) *StringIterator {
744 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "topic", url.QueryEscape(req.GetTopic()))}
745
746 hds = append(c.xGoogHeaders, hds...)
747 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
748 opts = append((*c.CallOptions).ListTopicSubscriptions[0:len((*c.CallOptions).ListTopicSubscriptions):len((*c.CallOptions).ListTopicSubscriptions)], opts...)
749 it := &StringIterator{}
750 req = proto.Clone(req).(*pubsubpb.ListTopicSubscriptionsRequest)
751 it.InternalFetch = func(pageSize int, pageToken string) ([]string, string, error) {
752 resp := &pubsubpb.ListTopicSubscriptionsResponse{}
753 if pageToken != "" {
754 req.PageToken = pageToken
755 }
756 if pageSize > math.MaxInt32 {
757 req.PageSize = math.MaxInt32
758 } else if pageSize != 0 {
759 req.PageSize = int32(pageSize)
760 }
761 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
762 var err error
763 resp, err = executeRPC(ctx, c.topicAdminClient.ListTopicSubscriptions, req, settings.GRPC, c.logger, "ListTopicSubscriptions")
764 return err
765 }, opts...)
766 if err != nil {
767 return nil, "", err
768 }
769
770 it.Response = resp
771 return resp.GetSubscriptions(), resp.GetNextPageToken(), nil
772 }
773 fetch := func(pageSize int, pageToken string) (string, error) {
774 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
775 if err != nil {
776 return "", err
777 }
778 it.items = append(it.items, items...)
779 return nextPageToken, nil
780 }
781
782 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
783 it.pageInfo.MaxSize = int(req.GetPageSize())
784 it.pageInfo.Token = req.GetPageToken()
785
786 return it
787 }
788
789 func (c *topicAdminGRPCClient) ListTopicSnapshots(ctx context.Context, req *pubsubpb.ListTopicSnapshotsRequest, opts ...gax.CallOption) *StringIterator {
790 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "topic", url.QueryEscape(req.GetTopic()))}
791
792 hds = append(c.xGoogHeaders, hds...)
793 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
794 opts = append((*c.CallOptions).ListTopicSnapshots[0:len((*c.CallOptions).ListTopicSnapshots):len((*c.CallOptions).ListTopicSnapshots)], opts...)
795 it := &StringIterator{}
796 req = proto.Clone(req).(*pubsubpb.ListTopicSnapshotsRequest)
797 it.InternalFetch = func(pageSize int, pageToken string) ([]string, string, error) {
798 resp := &pubsubpb.ListTopicSnapshotsResponse{}
799 if pageToken != "" {
800 req.PageToken = pageToken
801 }
802 if pageSize > math.MaxInt32 {
803 req.PageSize = math.MaxInt32
804 } else if pageSize != 0 {
805 req.PageSize = int32(pageSize)
806 }
807 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
808 var err error
809 resp, err = executeRPC(ctx, c.topicAdminClient.ListTopicSnapshots, req, settings.GRPC, c.logger, "ListTopicSnapshots")
810 return err
811 }, opts...)
812 if err != nil {
813 return nil, "", err
814 }
815
816 it.Response = resp
817 return resp.GetSnapshots(), resp.GetNextPageToken(), nil
818 }
819 fetch := func(pageSize int, pageToken string) (string, error) {
820 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
821 if err != nil {
822 return "", err
823 }
824 it.items = append(it.items, items...)
825 return nextPageToken, nil
826 }
827
828 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
829 it.pageInfo.MaxSize = int(req.GetPageSize())
830 it.pageInfo.Token = req.GetPageToken()
831
832 return it
833 }
834
835 func (c *topicAdminGRPCClient) DeleteTopic(ctx context.Context, req *pubsubpb.DeleteTopicRequest, opts ...gax.CallOption) error {
836 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "topic", url.QueryEscape(req.GetTopic()))}
837
838 hds = append(c.xGoogHeaders, hds...)
839 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
840 opts = append((*c.CallOptions).DeleteTopic[0:len((*c.CallOptions).DeleteTopic):len((*c.CallOptions).DeleteTopic)], opts...)
841 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
842 var err error
843 _, err = executeRPC(ctx, c.topicAdminClient.DeleteTopic, req, settings.GRPC, c.logger, "DeleteTopic")
844 return err
845 }, opts...)
846 return err
847 }
848
849 func (c *topicAdminGRPCClient) DetachSubscription(ctx context.Context, req *pubsubpb.DetachSubscriptionRequest, opts ...gax.CallOption) (*pubsubpb.DetachSubscriptionResponse, error) {
850 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "subscription", url.QueryEscape(req.GetSubscription()))}
851
852 hds = append(c.xGoogHeaders, hds...)
853 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
854 opts = append((*c.CallOptions).DetachSubscription[0:len((*c.CallOptions).DetachSubscription):len((*c.CallOptions).DetachSubscription)], opts...)
855 var resp *pubsubpb.DetachSubscriptionResponse
856 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
857 var err error
858 resp, err = executeRPC(ctx, c.topicAdminClient.DetachSubscription, req, settings.GRPC, c.logger, "DetachSubscription")
859 return err
860 }, opts...)
861 if err != nil {
862 return nil, err
863 }
864 return resp, nil
865 }
866
867 func (c *topicAdminGRPCClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
868 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
869
870 hds = append(c.xGoogHeaders, hds...)
871 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
872 opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
873 var resp *iampb.Policy
874 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
875 var err error
876 resp, err = executeRPC(ctx, c.iamPolicyClient.GetIamPolicy, req, settings.GRPC, c.logger, "GetIamPolicy")
877 return err
878 }, opts...)
879 if err != nil {
880 return nil, err
881 }
882 return resp, nil
883 }
884
885 func (c *topicAdminGRPCClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
886 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
887
888 hds = append(c.xGoogHeaders, hds...)
889 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
890 opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
891 var resp *iampb.Policy
892 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
893 var err error
894 resp, err = executeRPC(ctx, c.iamPolicyClient.SetIamPolicy, req, settings.GRPC, c.logger, "SetIamPolicy")
895 return err
896 }, opts...)
897 if err != nil {
898 return nil, err
899 }
900 return resp, nil
901 }
902
903 func (c *topicAdminGRPCClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
904 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
905
906 hds = append(c.xGoogHeaders, hds...)
907 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
908 opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...)
909 var resp *iampb.TestIamPermissionsResponse
910 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
911 var err error
912 resp, err = executeRPC(ctx, c.iamPolicyClient.TestIamPermissions, req, settings.GRPC, c.logger, "TestIamPermissions")
913 return err
914 }, opts...)
915 if err != nil {
916 return nil, err
917 }
918 return resp, nil
919 }
920
921 // CreateTopic creates the given topic with the given name. See the [resource name rules]
922 // (https://cloud.google.com/pubsub/docs/pubsub-basics#resource_names (at https://cloud.google.com/pubsub/docs/pubsub-basics#resource_names)).
923 func (c *topicAdminRESTClient) CreateTopic(ctx context.Context, req *pubsubpb.Topic, opts ...gax.CallOption) (*pubsubpb.Topic, error) {
924 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
925 jsonReq, err := m.Marshal(req)
926 if err != nil {
927 return nil, err
928 }
929
930 baseUrl, err := url.Parse(c.endpoint)
931 if err != nil {
932 return nil, err
933 }
934 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
935
936 params := url.Values{}
937 params.Add("$alt", "json;enum-encoding=int")
938
939 baseUrl.RawQuery = params.Encode()
940
941 // Build HTTP headers from client and context metadata.
942 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
943
944 hds = append(c.xGoogHeaders, hds...)
945 hds = append(hds, "Content-Type", "application/json")
946 headers := gax.BuildHeaders(ctx, hds...)
947 opts = append((*c.CallOptions).CreateTopic[0:len((*c.CallOptions).CreateTopic):len((*c.CallOptions).CreateTopic)], opts...)
948 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
949 resp := &pubsubpb.Topic{}
950 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
951 if settings.Path != "" {
952 baseUrl.Path = settings.Path
953 }
954 httpReq, err := http.NewRequest("PUT", baseUrl.String(), bytes.NewReader(jsonReq))
955 if err != nil {
956 return err
957 }
958 httpReq = httpReq.WithContext(ctx)
959 httpReq.Header = headers
960
961 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateTopic")
962 if err != nil {
963 return err
964 }
965
966 if err := unm.Unmarshal(buf, resp); err != nil {
967 return err
968 }
969
970 return nil
971 }, opts...)
972 if e != nil {
973 return nil, e
974 }
975 return resp, nil
976 }
977
978 // UpdateTopic updates an existing topic by updating the fields specified in the update
979 // mask. Note that certain properties of a topic are not modifiable.
980 func (c *topicAdminRESTClient) UpdateTopic(ctx context.Context, req *pubsubpb.UpdateTopicRequest, opts ...gax.CallOption) (*pubsubpb.Topic, error) {
981 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
982 jsonReq, err := m.Marshal(req)
983 if err != nil {
984 return nil, err
985 }
986
987 baseUrl, err := url.Parse(c.endpoint)
988 if err != nil {
989 return nil, err
990 }
991 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetTopic().GetName())
992
993 params := url.Values{}
994 params.Add("$alt", "json;enum-encoding=int")
995
996 baseUrl.RawQuery = params.Encode()
997
998 // Build HTTP headers from client and context metadata.
999 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "topic.name", url.QueryEscape(req.GetTopic().GetName()))}
1000
1001 hds = append(c.xGoogHeaders, hds...)
1002 hds = append(hds, "Content-Type", "application/json")
1003 headers := gax.BuildHeaders(ctx, hds...)
1004 opts = append((*c.CallOptions).UpdateTopic[0:len((*c.CallOptions).UpdateTopic):len((*c.CallOptions).UpdateTopic)], opts...)
1005 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1006 resp := &pubsubpb.Topic{}
1007 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1008 if settings.Path != "" {
1009 baseUrl.Path = settings.Path
1010 }
1011 httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
1012 if err != nil {
1013 return err
1014 }
1015 httpReq = httpReq.WithContext(ctx)
1016 httpReq.Header = headers
1017
1018 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateTopic")
1019 if err != nil {
1020 return err
1021 }
1022
1023 if err := unm.Unmarshal(buf, resp); err != nil {
1024 return err
1025 }
1026
1027 return nil
1028 }, opts...)
1029 if e != nil {
1030 return nil, e
1031 }
1032 return resp, nil
1033 }
1034
1035 // Publish adds one or more messages to the topic. Returns NOT_FOUND if the topic
1036 // does not exist.
1037 func (c *topicAdminRESTClient) Publish(ctx context.Context, req *pubsubpb.PublishRequest, opts ...gax.CallOption) (*pubsubpb.PublishResponse, error) {
1038 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1039 jsonReq, err := m.Marshal(req)
1040 if err != nil {
1041 return nil, err
1042 }
1043
1044 baseUrl, err := url.Parse(c.endpoint)
1045 if err != nil {
1046 return nil, err
1047 }
1048 baseUrl.Path += fmt.Sprintf("/v1/%v:publish", req.GetTopic())
1049
1050 params := url.Values{}
1051 params.Add("$alt", "json;enum-encoding=int")
1052
1053 baseUrl.RawQuery = params.Encode()
1054
1055 // Build HTTP headers from client and context metadata.
1056 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "topic", url.QueryEscape(req.GetTopic()))}
1057
1058 hds = append(c.xGoogHeaders, hds...)
1059 hds = append(hds, "Content-Type", "application/json")
1060 headers := gax.BuildHeaders(ctx, hds...)
1061 opts = append((*c.CallOptions).Publish[0:len((*c.CallOptions).Publish):len((*c.CallOptions).Publish)], opts...)
1062 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1063 resp := &pubsubpb.PublishResponse{}
1064 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1065 if settings.Path != "" {
1066 baseUrl.Path = settings.Path
1067 }
1068 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1069 if err != nil {
1070 return err
1071 }
1072 httpReq = httpReq.WithContext(ctx)
1073 httpReq.Header = headers
1074
1075 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "Publish")
1076 if err != nil {
1077 return err
1078 }
1079
1080 if err := unm.Unmarshal(buf, resp); err != nil {
1081 return err
1082 }
1083
1084 return nil
1085 }, opts...)
1086 if e != nil {
1087 return nil, e
1088 }
1089 return resp, nil
1090 }
1091
1092 // GetTopic gets the configuration of a topic.
1093 func (c *topicAdminRESTClient) GetTopic(ctx context.Context, req *pubsubpb.GetTopicRequest, opts ...gax.CallOption) (*pubsubpb.Topic, error) {
1094 baseUrl, err := url.Parse(c.endpoint)
1095 if err != nil {
1096 return nil, err
1097 }
1098 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetTopic())
1099
1100 params := url.Values{}
1101 params.Add("$alt", "json;enum-encoding=int")
1102
1103 baseUrl.RawQuery = params.Encode()
1104
1105 // Build HTTP headers from client and context metadata.
1106 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "topic", url.QueryEscape(req.GetTopic()))}
1107
1108 hds = append(c.xGoogHeaders, hds...)
1109 hds = append(hds, "Content-Type", "application/json")
1110 headers := gax.BuildHeaders(ctx, hds...)
1111 opts = append((*c.CallOptions).GetTopic[0:len((*c.CallOptions).GetTopic):len((*c.CallOptions).GetTopic)], opts...)
1112 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1113 resp := &pubsubpb.Topic{}
1114 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1115 if settings.Path != "" {
1116 baseUrl.Path = settings.Path
1117 }
1118 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1119 if err != nil {
1120 return err
1121 }
1122 httpReq = httpReq.WithContext(ctx)
1123 httpReq.Header = headers
1124
1125 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetTopic")
1126 if err != nil {
1127 return err
1128 }
1129
1130 if err := unm.Unmarshal(buf, resp); err != nil {
1131 return err
1132 }
1133
1134 return nil
1135 }, opts...)
1136 if e != nil {
1137 return nil, e
1138 }
1139 return resp, nil
1140 }
1141
1142 // ListTopics lists matching topics.
1143 func (c *topicAdminRESTClient) ListTopics(ctx context.Context, req *pubsubpb.ListTopicsRequest, opts ...gax.CallOption) *TopicIterator {
1144 it := &TopicIterator{}
1145 req = proto.Clone(req).(*pubsubpb.ListTopicsRequest)
1146 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1147 it.InternalFetch = func(pageSize int, pageToken string) ([]*pubsubpb.Topic, string, error) {
1148 resp := &pubsubpb.ListTopicsResponse{}
1149 if pageToken != "" {
1150 req.PageToken = pageToken
1151 }
1152 if pageSize > math.MaxInt32 {
1153 req.PageSize = math.MaxInt32
1154 } else if pageSize != 0 {
1155 req.PageSize = int32(pageSize)
1156 }
1157 baseUrl, err := url.Parse(c.endpoint)
1158 if err != nil {
1159 return nil, "", err
1160 }
1161 baseUrl.Path += fmt.Sprintf("/v1/%v/topics", req.GetProject())
1162
1163 params := url.Values{}
1164 params.Add("$alt", "json;enum-encoding=int")
1165 if req.GetPageSize() != 0 {
1166 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
1167 }
1168 if req.GetPageToken() != "" {
1169 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
1170 }
1171
1172 baseUrl.RawQuery = params.Encode()
1173
1174 // Build HTTP headers from client and context metadata.
1175 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
1176 headers := gax.BuildHeaders(ctx, hds...)
1177 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1178 if settings.Path != "" {
1179 baseUrl.Path = settings.Path
1180 }
1181 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1182 if err != nil {
1183 return err
1184 }
1185 httpReq.Header = headers
1186
1187 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListTopics")
1188 if err != nil {
1189 return err
1190 }
1191 if err := unm.Unmarshal(buf, resp); err != nil {
1192 return err
1193 }
1194
1195 return nil
1196 }, opts...)
1197 if e != nil {
1198 return nil, "", e
1199 }
1200 it.Response = resp
1201 return resp.GetTopics(), resp.GetNextPageToken(), nil
1202 }
1203
1204 fetch := func(pageSize int, pageToken string) (string, error) {
1205 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1206 if err != nil {
1207 return "", err
1208 }
1209 it.items = append(it.items, items...)
1210 return nextPageToken, nil
1211 }
1212
1213 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1214 it.pageInfo.MaxSize = int(req.GetPageSize())
1215 it.pageInfo.Token = req.GetPageToken()
1216
1217 return it
1218 }
1219
1220 // ListTopicSubscriptions lists the names of the attached subscriptions on this topic.
1221 func (c *topicAdminRESTClient) ListTopicSubscriptions(ctx context.Context, req *pubsubpb.ListTopicSubscriptionsRequest, opts ...gax.CallOption) *StringIterator {
1222 it := &StringIterator{}
1223 req = proto.Clone(req).(*pubsubpb.ListTopicSubscriptionsRequest)
1224 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1225 it.InternalFetch = func(pageSize int, pageToken string) ([]string, string, error) {
1226 resp := &pubsubpb.ListTopicSubscriptionsResponse{}
1227 if pageToken != "" {
1228 req.PageToken = pageToken
1229 }
1230 if pageSize > math.MaxInt32 {
1231 req.PageSize = math.MaxInt32
1232 } else if pageSize != 0 {
1233 req.PageSize = int32(pageSize)
1234 }
1235 baseUrl, err := url.Parse(c.endpoint)
1236 if err != nil {
1237 return nil, "", err
1238 }
1239 baseUrl.Path += fmt.Sprintf("/v1/%v/subscriptions", req.GetTopic())
1240
1241 params := url.Values{}
1242 params.Add("$alt", "json;enum-encoding=int")
1243 if req.GetPageSize() != 0 {
1244 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
1245 }
1246 if req.GetPageToken() != "" {
1247 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
1248 }
1249
1250 baseUrl.RawQuery = params.Encode()
1251
1252 // Build HTTP headers from client and context metadata.
1253 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
1254 headers := gax.BuildHeaders(ctx, hds...)
1255 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1256 if settings.Path != "" {
1257 baseUrl.Path = settings.Path
1258 }
1259 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1260 if err != nil {
1261 return err
1262 }
1263 httpReq.Header = headers
1264
1265 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListTopicSubscriptions")
1266 if err != nil {
1267 return err
1268 }
1269 if err := unm.Unmarshal(buf, resp); err != nil {
1270 return err
1271 }
1272
1273 return nil
1274 }, opts...)
1275 if e != nil {
1276 return nil, "", e
1277 }
1278 it.Response = resp
1279 return resp.GetSubscriptions(), resp.GetNextPageToken(), nil
1280 }
1281
1282 fetch := func(pageSize int, pageToken string) (string, error) {
1283 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1284 if err != nil {
1285 return "", err
1286 }
1287 it.items = append(it.items, items...)
1288 return nextPageToken, nil
1289 }
1290
1291 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1292 it.pageInfo.MaxSize = int(req.GetPageSize())
1293 it.pageInfo.Token = req.GetPageToken()
1294
1295 return it
1296 }
1297
1298 // ListTopicSnapshots lists the names of the snapshots on this topic. Snapshots are used in
1299 // Seek (at https://cloud.google.com/pubsub/docs/replay-overview) operations,
1300 // which allow you to manage message acknowledgments in bulk. That is, you can
1301 // set the acknowledgment state of messages in an existing subscription to the
1302 // state captured by a snapshot.
1303 func (c *topicAdminRESTClient) ListTopicSnapshots(ctx context.Context, req *pubsubpb.ListTopicSnapshotsRequest, opts ...gax.CallOption) *StringIterator {
1304 it := &StringIterator{}
1305 req = proto.Clone(req).(*pubsubpb.ListTopicSnapshotsRequest)
1306 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1307 it.InternalFetch = func(pageSize int, pageToken string) ([]string, string, error) {
1308 resp := &pubsubpb.ListTopicSnapshotsResponse{}
1309 if pageToken != "" {
1310 req.PageToken = pageToken
1311 }
1312 if pageSize > math.MaxInt32 {
1313 req.PageSize = math.MaxInt32
1314 } else if pageSize != 0 {
1315 req.PageSize = int32(pageSize)
1316 }
1317 baseUrl, err := url.Parse(c.endpoint)
1318 if err != nil {
1319 return nil, "", err
1320 }
1321 baseUrl.Path += fmt.Sprintf("/v1/%v/snapshots", req.GetTopic())
1322
1323 params := url.Values{}
1324 params.Add("$alt", "json;enum-encoding=int")
1325 if req.GetPageSize() != 0 {
1326 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
1327 }
1328 if req.GetPageToken() != "" {
1329 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
1330 }
1331
1332 baseUrl.RawQuery = params.Encode()
1333
1334 // Build HTTP headers from client and context metadata.
1335 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
1336 headers := gax.BuildHeaders(ctx, hds...)
1337 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1338 if settings.Path != "" {
1339 baseUrl.Path = settings.Path
1340 }
1341 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1342 if err != nil {
1343 return err
1344 }
1345 httpReq.Header = headers
1346
1347 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListTopicSnapshots")
1348 if err != nil {
1349 return err
1350 }
1351 if err := unm.Unmarshal(buf, resp); err != nil {
1352 return err
1353 }
1354
1355 return nil
1356 }, opts...)
1357 if e != nil {
1358 return nil, "", e
1359 }
1360 it.Response = resp
1361 return resp.GetSnapshots(), resp.GetNextPageToken(), nil
1362 }
1363
1364 fetch := func(pageSize int, pageToken string) (string, error) {
1365 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1366 if err != nil {
1367 return "", err
1368 }
1369 it.items = append(it.items, items...)
1370 return nextPageToken, nil
1371 }
1372
1373 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1374 it.pageInfo.MaxSize = int(req.GetPageSize())
1375 it.pageInfo.Token = req.GetPageToken()
1376
1377 return it
1378 }
1379
1380 // DeleteTopic deletes the topic with the given name. Returns NOT_FOUND if the topic
1381 // does not exist. After a topic is deleted, a new topic may be created with
1382 // the same name; this is an entirely new topic with none of the old
1383 // configuration or subscriptions. Existing subscriptions to this topic are
1384 // not deleted, but their topic field is set to _deleted-topic_.
1385 func (c *topicAdminRESTClient) DeleteTopic(ctx context.Context, req *pubsubpb.DeleteTopicRequest, opts ...gax.CallOption) error {
1386 baseUrl, err := url.Parse(c.endpoint)
1387 if err != nil {
1388 return err
1389 }
1390 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetTopic())
1391
1392 params := url.Values{}
1393 params.Add("$alt", "json;enum-encoding=int")
1394
1395 baseUrl.RawQuery = params.Encode()
1396
1397 // Build HTTP headers from client and context metadata.
1398 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "topic", url.QueryEscape(req.GetTopic()))}
1399
1400 hds = append(c.xGoogHeaders, hds...)
1401 hds = append(hds, "Content-Type", "application/json")
1402 headers := gax.BuildHeaders(ctx, hds...)
1403 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1404 if settings.Path != "" {
1405 baseUrl.Path = settings.Path
1406 }
1407 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
1408 if err != nil {
1409 return err
1410 }
1411 httpReq = httpReq.WithContext(ctx)
1412 httpReq.Header = headers
1413
1414 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteTopic")
1415 return err
1416 }, opts...)
1417 }
1418
1419 // DetachSubscription detaches a subscription from this topic. All messages retained in the
1420 // subscription are dropped. Subsequent Pull and StreamingPull requests
1421 // will return FAILED_PRECONDITION. If the subscription is a push
1422 // subscription, pushes to the endpoint will stop.
1423 func (c *topicAdminRESTClient) DetachSubscription(ctx context.Context, req *pubsubpb.DetachSubscriptionRequest, opts ...gax.CallOption) (*pubsubpb.DetachSubscriptionResponse, error) {
1424 baseUrl, err := url.Parse(c.endpoint)
1425 if err != nil {
1426 return nil, err
1427 }
1428 baseUrl.Path += fmt.Sprintf("/v1/%v:detach", req.GetSubscription())
1429
1430 params := url.Values{}
1431 params.Add("$alt", "json;enum-encoding=int")
1432
1433 baseUrl.RawQuery = params.Encode()
1434
1435 // Build HTTP headers from client and context metadata.
1436 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "subscription", url.QueryEscape(req.GetSubscription()))}
1437
1438 hds = append(c.xGoogHeaders, hds...)
1439 hds = append(hds, "Content-Type", "application/json")
1440 headers := gax.BuildHeaders(ctx, hds...)
1441 opts = append((*c.CallOptions).DetachSubscription[0:len((*c.CallOptions).DetachSubscription):len((*c.CallOptions).DetachSubscription)], opts...)
1442 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1443 resp := &pubsubpb.DetachSubscriptionResponse{}
1444 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1445 if settings.Path != "" {
1446 baseUrl.Path = settings.Path
1447 }
1448 httpReq, err := http.NewRequest("POST", baseUrl.String(), nil)
1449 if err != nil {
1450 return err
1451 }
1452 httpReq = httpReq.WithContext(ctx)
1453 httpReq.Header = headers
1454
1455 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DetachSubscription")
1456 if err != nil {
1457 return err
1458 }
1459
1460 if err := unm.Unmarshal(buf, resp); err != nil {
1461 return err
1462 }
1463
1464 return nil
1465 }, opts...)
1466 if e != nil {
1467 return nil, e
1468 }
1469 return resp, nil
1470 }
1471
1472 // GetIamPolicy gets the access control policy for a resource. Returns an empty policy
1473 // if the resource exists and does not have a policy set.
1474 func (c *topicAdminRESTClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
1475 baseUrl, err := url.Parse(c.endpoint)
1476 if err != nil {
1477 return nil, err
1478 }
1479 baseUrl.Path += fmt.Sprintf("/v1/%v:getIamPolicy", req.GetResource())
1480
1481 params := url.Values{}
1482 params.Add("$alt", "json;enum-encoding=int")
1483 if req.GetOptions().GetRequestedPolicyVersion() != 0 {
1484 params.Add("options.requestedPolicyVersion", fmt.Sprintf("%v", req.GetOptions().GetRequestedPolicyVersion()))
1485 }
1486
1487 baseUrl.RawQuery = params.Encode()
1488
1489 // Build HTTP headers from client and context metadata.
1490 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
1491
1492 hds = append(c.xGoogHeaders, hds...)
1493 hds = append(hds, "Content-Type", "application/json")
1494 headers := gax.BuildHeaders(ctx, hds...)
1495 opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
1496 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1497 resp := &iampb.Policy{}
1498 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1499 if settings.Path != "" {
1500 baseUrl.Path = settings.Path
1501 }
1502 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1503 if err != nil {
1504 return err
1505 }
1506 httpReq = httpReq.WithContext(ctx)
1507 httpReq.Header = headers
1508
1509 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetIamPolicy")
1510 if err != nil {
1511 return err
1512 }
1513
1514 if err := unm.Unmarshal(buf, resp); err != nil {
1515 return err
1516 }
1517
1518 return nil
1519 }, opts...)
1520 if e != nil {
1521 return nil, e
1522 }
1523 return resp, nil
1524 }
1525
1526 // SetIamPolicy sets the access control policy on the specified resource. Replaces
1527 // any existing policy.
1528 //
1529 // Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED
1530 // errors.
1531 func (c *topicAdminRESTClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
1532 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1533 jsonReq, err := m.Marshal(req)
1534 if err != nil {
1535 return nil, err
1536 }
1537
1538 baseUrl, err := url.Parse(c.endpoint)
1539 if err != nil {
1540 return nil, err
1541 }
1542 baseUrl.Path += fmt.Sprintf("/v1/%v:setIamPolicy", req.GetResource())
1543
1544 params := url.Values{}
1545 params.Add("$alt", "json;enum-encoding=int")
1546
1547 baseUrl.RawQuery = params.Encode()
1548
1549 // Build HTTP headers from client and context metadata.
1550 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
1551
1552 hds = append(c.xGoogHeaders, hds...)
1553 hds = append(hds, "Content-Type", "application/json")
1554 headers := gax.BuildHeaders(ctx, hds...)
1555 opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
1556 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1557 resp := &iampb.Policy{}
1558 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1559 if settings.Path != "" {
1560 baseUrl.Path = settings.Path
1561 }
1562 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1563 if err != nil {
1564 return err
1565 }
1566 httpReq = httpReq.WithContext(ctx)
1567 httpReq.Header = headers
1568
1569 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "SetIamPolicy")
1570 if err != nil {
1571 return err
1572 }
1573
1574 if err := unm.Unmarshal(buf, resp); err != nil {
1575 return err
1576 }
1577
1578 return nil
1579 }, opts...)
1580 if e != nil {
1581 return nil, e
1582 }
1583 return resp, nil
1584 }
1585
1586 // TestIamPermissions returns permissions that a caller has on the specified resource. If the
1587 // resource does not exist, this will return an empty set of
1588 // permissions, not a NOT_FOUND error.
1589 //
1590 // Note: This operation is designed to be used for building
1591 // permission-aware UIs and command-line tools, not for authorization
1592 // checking. This operation may “fail open” without warning.
1593 func (c *topicAdminRESTClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
1594 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1595 jsonReq, err := m.Marshal(req)
1596 if err != nil {
1597 return nil, err
1598 }
1599
1600 baseUrl, err := url.Parse(c.endpoint)
1601 if err != nil {
1602 return nil, err
1603 }
1604 baseUrl.Path += fmt.Sprintf("/v1/%v:testIamPermissions", req.GetResource())
1605
1606 params := url.Values{}
1607 params.Add("$alt", "json;enum-encoding=int")
1608
1609 baseUrl.RawQuery = params.Encode()
1610
1611 // Build HTTP headers from client and context metadata.
1612 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
1613
1614 hds = append(c.xGoogHeaders, hds...)
1615 hds = append(hds, "Content-Type", "application/json")
1616 headers := gax.BuildHeaders(ctx, hds...)
1617 opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...)
1618 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1619 resp := &iampb.TestIamPermissionsResponse{}
1620 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1621 if settings.Path != "" {
1622 baseUrl.Path = settings.Path
1623 }
1624 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1625 if err != nil {
1626 return err
1627 }
1628 httpReq = httpReq.WithContext(ctx)
1629 httpReq.Header = headers
1630
1631 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "TestIamPermissions")
1632 if err != nil {
1633 return err
1634 }
1635
1636 if err := unm.Unmarshal(buf, resp); err != nil {
1637 return err
1638 }
1639
1640 return nil
1641 }, opts...)
1642 if e != nil {
1643 return nil, e
1644 }
1645 return resp, nil
1646 }