1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package pubsub
18
19 import (
20 "bytes"
21 "context"
22 "errors"
23 "fmt"
24 "io"
25 "math"
26 "net/http"
27 "net/url"
28 "time"
29
30 iampb "cloud.google.com/go/iam/apiv1/iampb"
31 pubsubpb "cloud.google.com/go/pubsub/apiv1/pubsubpb"
32 gax "github.com/googleapis/gax-go/v2"
33 "google.golang.org/api/googleapi"
34 "google.golang.org/api/iterator"
35 "google.golang.org/api/option"
36 "google.golang.org/api/option/internaloption"
37 gtransport "google.golang.org/api/transport/grpc"
38 httptransport "google.golang.org/api/transport/http"
39 "google.golang.org/grpc"
40 "google.golang.org/grpc/codes"
41 "google.golang.org/protobuf/encoding/protojson"
42 "google.golang.org/protobuf/proto"
43 )
44
45 var newSubscriberClientHook clientHook
46
47
48 type SubscriberCallOptions struct {
49 CreateSubscription []gax.CallOption
50 GetSubscription []gax.CallOption
51 UpdateSubscription []gax.CallOption
52 ListSubscriptions []gax.CallOption
53 DeleteSubscription []gax.CallOption
54 ModifyAckDeadline []gax.CallOption
55 Acknowledge []gax.CallOption
56 Pull []gax.CallOption
57 StreamingPull []gax.CallOption
58 ModifyPushConfig []gax.CallOption
59 GetSnapshot []gax.CallOption
60 ListSnapshots []gax.CallOption
61 CreateSnapshot []gax.CallOption
62 UpdateSnapshot []gax.CallOption
63 DeleteSnapshot []gax.CallOption
64 Seek []gax.CallOption
65 GetIamPolicy []gax.CallOption
66 SetIamPolicy []gax.CallOption
67 TestIamPermissions []gax.CallOption
68 }
69
70 func defaultSubscriberGRPCClientOptions() []option.ClientOption {
71 return []option.ClientOption{
72 internaloption.WithDefaultEndpoint("pubsub.googleapis.com:443"),
73 internaloption.WithDefaultEndpointTemplate("pubsub.UNIVERSE_DOMAIN:443"),
74 internaloption.WithDefaultMTLSEndpoint("pubsub.mtls.googleapis.com:443"),
75 internaloption.WithDefaultUniverseDomain("googleapis.com"),
76 internaloption.WithDefaultAudience("https://pubsub.googleapis.com/"),
77 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
78 internaloption.EnableJwtWithScope(),
79 option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
80 grpc.MaxCallRecvMsgSize(math.MaxInt32))),
81 }
82 }
83
84 func defaultSubscriberCallOptions() *SubscriberCallOptions {
85 return &SubscriberCallOptions{
86 CreateSubscription: []gax.CallOption{
87 gax.WithTimeout(60000 * time.Millisecond),
88 gax.WithRetry(func() gax.Retryer {
89 return gax.OnCodes([]codes.Code{
90 codes.Unknown,
91 codes.Aborted,
92 codes.Unavailable,
93 }, gax.Backoff{
94 Initial: 100 * time.Millisecond,
95 Max: 60000 * time.Millisecond,
96 Multiplier: 1.30,
97 })
98 }),
99 },
100 GetSubscription: []gax.CallOption{
101 gax.WithTimeout(60000 * time.Millisecond),
102 gax.WithRetry(func() gax.Retryer {
103 return gax.OnCodes([]codes.Code{
104 codes.Unknown,
105 codes.Aborted,
106 codes.Unavailable,
107 }, gax.Backoff{
108 Initial: 100 * time.Millisecond,
109 Max: 60000 * time.Millisecond,
110 Multiplier: 1.30,
111 })
112 }),
113 },
114 UpdateSubscription: []gax.CallOption{
115 gax.WithTimeout(60000 * time.Millisecond),
116 gax.WithRetry(func() gax.Retryer {
117 return gax.OnCodes([]codes.Code{
118 codes.Unavailable,
119 }, gax.Backoff{
120 Initial: 100 * time.Millisecond,
121 Max: 60000 * time.Millisecond,
122 Multiplier: 1.30,
123 })
124 }),
125 },
126 ListSubscriptions: []gax.CallOption{
127 gax.WithTimeout(60000 * time.Millisecond),
128 gax.WithRetry(func() gax.Retryer {
129 return gax.OnCodes([]codes.Code{
130 codes.Unknown,
131 codes.Aborted,
132 codes.Unavailable,
133 }, gax.Backoff{
134 Initial: 100 * time.Millisecond,
135 Max: 60000 * time.Millisecond,
136 Multiplier: 1.30,
137 })
138 }),
139 },
140 DeleteSubscription: []gax.CallOption{
141 gax.WithTimeout(60000 * time.Millisecond),
142 gax.WithRetry(func() gax.Retryer {
143 return gax.OnCodes([]codes.Code{
144 codes.Unavailable,
145 }, gax.Backoff{
146 Initial: 100 * time.Millisecond,
147 Max: 60000 * time.Millisecond,
148 Multiplier: 1.30,
149 })
150 }),
151 },
152 ModifyAckDeadline: []gax.CallOption{
153 gax.WithTimeout(60000 * time.Millisecond),
154 gax.WithRetry(func() gax.Retryer {
155 return gax.OnCodes([]codes.Code{
156 codes.Unavailable,
157 }, gax.Backoff{
158 Initial: 100 * time.Millisecond,
159 Max: 60000 * time.Millisecond,
160 Multiplier: 1.30,
161 })
162 }),
163 },
164 Acknowledge: []gax.CallOption{
165 gax.WithTimeout(60000 * time.Millisecond),
166 gax.WithRetry(func() gax.Retryer {
167 return gax.OnCodes([]codes.Code{
168 codes.Unavailable,
169 }, gax.Backoff{
170 Initial: 100 * time.Millisecond,
171 Max: 60000 * time.Millisecond,
172 Multiplier: 1.30,
173 })
174 }),
175 },
176 Pull: []gax.CallOption{
177 gax.WithTimeout(60000 * time.Millisecond),
178 gax.WithRetry(func() gax.Retryer {
179 return gax.OnCodes([]codes.Code{
180 codes.Unknown,
181 codes.Aborted,
182 codes.Unavailable,
183 codes.Internal,
184 }, gax.Backoff{
185 Initial: 100 * time.Millisecond,
186 Max: 60000 * time.Millisecond,
187 Multiplier: 1.30,
188 })
189 }),
190 },
191 StreamingPull: []gax.CallOption{
192 gax.WithRetry(func() gax.Retryer {
193 return gax.OnCodes([]codes.Code{
194 codes.DeadlineExceeded,
195 codes.ResourceExhausted,
196 codes.Aborted,
197 codes.Internal,
198 codes.Unavailable,
199 }, gax.Backoff{
200 Initial: 100 * time.Millisecond,
201 Max: 60000 * time.Millisecond,
202 Multiplier: 4.00,
203 })
204 }),
205 },
206 ModifyPushConfig: []gax.CallOption{
207 gax.WithTimeout(60000 * time.Millisecond),
208 gax.WithRetry(func() gax.Retryer {
209 return gax.OnCodes([]codes.Code{
210 codes.Unavailable,
211 }, gax.Backoff{
212 Initial: 100 * time.Millisecond,
213 Max: 60000 * time.Millisecond,
214 Multiplier: 1.30,
215 })
216 }),
217 },
218 GetSnapshot: []gax.CallOption{
219 gax.WithTimeout(60000 * time.Millisecond),
220 gax.WithRetry(func() gax.Retryer {
221 return gax.OnCodes([]codes.Code{
222 codes.Unknown,
223 codes.Aborted,
224 codes.Unavailable,
225 }, gax.Backoff{
226 Initial: 100 * time.Millisecond,
227 Max: 60000 * time.Millisecond,
228 Multiplier: 1.30,
229 })
230 }),
231 },
232 ListSnapshots: []gax.CallOption{
233 gax.WithTimeout(60000 * time.Millisecond),
234 gax.WithRetry(func() gax.Retryer {
235 return gax.OnCodes([]codes.Code{
236 codes.Unknown,
237 codes.Aborted,
238 codes.Unavailable,
239 }, gax.Backoff{
240 Initial: 100 * time.Millisecond,
241 Max: 60000 * time.Millisecond,
242 Multiplier: 1.30,
243 })
244 }),
245 },
246 CreateSnapshot: []gax.CallOption{
247 gax.WithTimeout(60000 * time.Millisecond),
248 gax.WithRetry(func() gax.Retryer {
249 return gax.OnCodes([]codes.Code{
250 codes.Unavailable,
251 }, gax.Backoff{
252 Initial: 100 * time.Millisecond,
253 Max: 60000 * time.Millisecond,
254 Multiplier: 1.30,
255 })
256 }),
257 },
258 UpdateSnapshot: []gax.CallOption{
259 gax.WithTimeout(60000 * time.Millisecond),
260 gax.WithRetry(func() gax.Retryer {
261 return gax.OnCodes([]codes.Code{
262 codes.Unavailable,
263 }, gax.Backoff{
264 Initial: 100 * time.Millisecond,
265 Max: 60000 * time.Millisecond,
266 Multiplier: 1.30,
267 })
268 }),
269 },
270 DeleteSnapshot: []gax.CallOption{
271 gax.WithTimeout(60000 * time.Millisecond),
272 gax.WithRetry(func() gax.Retryer {
273 return gax.OnCodes([]codes.Code{
274 codes.Unavailable,
275 }, gax.Backoff{
276 Initial: 100 * time.Millisecond,
277 Max: 60000 * time.Millisecond,
278 Multiplier: 1.30,
279 })
280 }),
281 },
282 Seek: []gax.CallOption{
283 gax.WithTimeout(60000 * time.Millisecond),
284 gax.WithRetry(func() gax.Retryer {
285 return gax.OnCodes([]codes.Code{
286 codes.Unknown,
287 codes.Aborted,
288 codes.Unavailable,
289 }, gax.Backoff{
290 Initial: 100 * time.Millisecond,
291 Max: 60000 * time.Millisecond,
292 Multiplier: 1.30,
293 })
294 }),
295 },
296 GetIamPolicy: []gax.CallOption{},
297 SetIamPolicy: []gax.CallOption{},
298 TestIamPermissions: []gax.CallOption{},
299 }
300 }
301
302 func defaultSubscriberRESTCallOptions() *SubscriberCallOptions {
303 return &SubscriberCallOptions{
304 CreateSubscription: []gax.CallOption{
305 gax.WithTimeout(60000 * time.Millisecond),
306 gax.WithRetry(func() gax.Retryer {
307 return gax.OnHTTPCodes(gax.Backoff{
308 Initial: 100 * time.Millisecond,
309 Max: 60000 * time.Millisecond,
310 Multiplier: 1.30,
311 },
312 http.StatusInternalServerError,
313 http.StatusConflict,
314 http.StatusServiceUnavailable)
315 }),
316 },
317 GetSubscription: []gax.CallOption{
318 gax.WithTimeout(60000 * time.Millisecond),
319 gax.WithRetry(func() gax.Retryer {
320 return gax.OnHTTPCodes(gax.Backoff{
321 Initial: 100 * time.Millisecond,
322 Max: 60000 * time.Millisecond,
323 Multiplier: 1.30,
324 },
325 http.StatusInternalServerError,
326 http.StatusConflict,
327 http.StatusServiceUnavailable)
328 }),
329 },
330 UpdateSubscription: []gax.CallOption{
331 gax.WithTimeout(60000 * time.Millisecond),
332 gax.WithRetry(func() gax.Retryer {
333 return gax.OnHTTPCodes(gax.Backoff{
334 Initial: 100 * time.Millisecond,
335 Max: 60000 * time.Millisecond,
336 Multiplier: 1.30,
337 },
338 http.StatusServiceUnavailable)
339 }),
340 },
341 ListSubscriptions: []gax.CallOption{
342 gax.WithTimeout(60000 * time.Millisecond),
343 gax.WithRetry(func() gax.Retryer {
344 return gax.OnHTTPCodes(gax.Backoff{
345 Initial: 100 * time.Millisecond,
346 Max: 60000 * time.Millisecond,
347 Multiplier: 1.30,
348 },
349 http.StatusInternalServerError,
350 http.StatusConflict,
351 http.StatusServiceUnavailable)
352 }),
353 },
354 DeleteSubscription: []gax.CallOption{
355 gax.WithTimeout(60000 * time.Millisecond),
356 gax.WithRetry(func() gax.Retryer {
357 return gax.OnHTTPCodes(gax.Backoff{
358 Initial: 100 * time.Millisecond,
359 Max: 60000 * time.Millisecond,
360 Multiplier: 1.30,
361 },
362 http.StatusServiceUnavailable)
363 }),
364 },
365 ModifyAckDeadline: []gax.CallOption{
366 gax.WithTimeout(60000 * time.Millisecond),
367 gax.WithRetry(func() gax.Retryer {
368 return gax.OnHTTPCodes(gax.Backoff{
369 Initial: 100 * time.Millisecond,
370 Max: 60000 * time.Millisecond,
371 Multiplier: 1.30,
372 },
373 http.StatusServiceUnavailable)
374 }),
375 },
376 Acknowledge: []gax.CallOption{
377 gax.WithTimeout(60000 * time.Millisecond),
378 gax.WithRetry(func() gax.Retryer {
379 return gax.OnHTTPCodes(gax.Backoff{
380 Initial: 100 * time.Millisecond,
381 Max: 60000 * time.Millisecond,
382 Multiplier: 1.30,
383 },
384 http.StatusServiceUnavailable)
385 }),
386 },
387 Pull: []gax.CallOption{
388 gax.WithTimeout(60000 * time.Millisecond),
389 gax.WithRetry(func() gax.Retryer {
390 return gax.OnHTTPCodes(gax.Backoff{
391 Initial: 100 * time.Millisecond,
392 Max: 60000 * time.Millisecond,
393 Multiplier: 1.30,
394 },
395 http.StatusInternalServerError,
396 http.StatusConflict,
397 http.StatusServiceUnavailable,
398 http.StatusInternalServerError)
399 }),
400 },
401 StreamingPull: []gax.CallOption{
402 gax.WithTimeout(900000 * time.Millisecond),
403 gax.WithRetry(func() gax.Retryer {
404 return gax.OnHTTPCodes(gax.Backoff{
405 Initial: 100 * time.Millisecond,
406 Max: 60000 * time.Millisecond,
407 Multiplier: 4.00,
408 },
409 http.StatusGatewayTimeout,
410 http.StatusTooManyRequests,
411 http.StatusConflict,
412 http.StatusInternalServerError,
413 http.StatusServiceUnavailable)
414 }),
415 },
416 ModifyPushConfig: []gax.CallOption{
417 gax.WithTimeout(60000 * time.Millisecond),
418 gax.WithRetry(func() gax.Retryer {
419 return gax.OnHTTPCodes(gax.Backoff{
420 Initial: 100 * time.Millisecond,
421 Max: 60000 * time.Millisecond,
422 Multiplier: 1.30,
423 },
424 http.StatusServiceUnavailable)
425 }),
426 },
427 GetSnapshot: []gax.CallOption{
428 gax.WithTimeout(60000 * time.Millisecond),
429 gax.WithRetry(func() gax.Retryer {
430 return gax.OnHTTPCodes(gax.Backoff{
431 Initial: 100 * time.Millisecond,
432 Max: 60000 * time.Millisecond,
433 Multiplier: 1.30,
434 },
435 http.StatusInternalServerError,
436 http.StatusConflict,
437 http.StatusServiceUnavailable)
438 }),
439 },
440 ListSnapshots: []gax.CallOption{
441 gax.WithTimeout(60000 * time.Millisecond),
442 gax.WithRetry(func() gax.Retryer {
443 return gax.OnHTTPCodes(gax.Backoff{
444 Initial: 100 * time.Millisecond,
445 Max: 60000 * time.Millisecond,
446 Multiplier: 1.30,
447 },
448 http.StatusInternalServerError,
449 http.StatusConflict,
450 http.StatusServiceUnavailable)
451 }),
452 },
453 CreateSnapshot: []gax.CallOption{
454 gax.WithTimeout(60000 * time.Millisecond),
455 gax.WithRetry(func() gax.Retryer {
456 return gax.OnHTTPCodes(gax.Backoff{
457 Initial: 100 * time.Millisecond,
458 Max: 60000 * time.Millisecond,
459 Multiplier: 1.30,
460 },
461 http.StatusServiceUnavailable)
462 }),
463 },
464 UpdateSnapshot: []gax.CallOption{
465 gax.WithTimeout(60000 * time.Millisecond),
466 gax.WithRetry(func() gax.Retryer {
467 return gax.OnHTTPCodes(gax.Backoff{
468 Initial: 100 * time.Millisecond,
469 Max: 60000 * time.Millisecond,
470 Multiplier: 1.30,
471 },
472 http.StatusServiceUnavailable)
473 }),
474 },
475 DeleteSnapshot: []gax.CallOption{
476 gax.WithTimeout(60000 * time.Millisecond),
477 gax.WithRetry(func() gax.Retryer {
478 return gax.OnHTTPCodes(gax.Backoff{
479 Initial: 100 * time.Millisecond,
480 Max: 60000 * time.Millisecond,
481 Multiplier: 1.30,
482 },
483 http.StatusServiceUnavailable)
484 }),
485 },
486 Seek: []gax.CallOption{
487 gax.WithTimeout(60000 * time.Millisecond),
488 gax.WithRetry(func() gax.Retryer {
489 return gax.OnHTTPCodes(gax.Backoff{
490 Initial: 100 * time.Millisecond,
491 Max: 60000 * time.Millisecond,
492 Multiplier: 1.30,
493 },
494 http.StatusInternalServerError,
495 http.StatusConflict,
496 http.StatusServiceUnavailable)
497 }),
498 },
499 GetIamPolicy: []gax.CallOption{},
500 SetIamPolicy: []gax.CallOption{},
501 TestIamPermissions: []gax.CallOption{},
502 }
503 }
504
505
506 type internalSubscriberClient interface {
507 Close() error
508 setGoogleClientInfo(...string)
509 Connection() *grpc.ClientConn
510 CreateSubscription(context.Context, *pubsubpb.Subscription, ...gax.CallOption) (*pubsubpb.Subscription, error)
511 GetSubscription(context.Context, *pubsubpb.GetSubscriptionRequest, ...gax.CallOption) (*pubsubpb.Subscription, error)
512 UpdateSubscription(context.Context, *pubsubpb.UpdateSubscriptionRequest, ...gax.CallOption) (*pubsubpb.Subscription, error)
513 ListSubscriptions(context.Context, *pubsubpb.ListSubscriptionsRequest, ...gax.CallOption) *SubscriptionIterator
514 DeleteSubscription(context.Context, *pubsubpb.DeleteSubscriptionRequest, ...gax.CallOption) error
515 ModifyAckDeadline(context.Context, *pubsubpb.ModifyAckDeadlineRequest, ...gax.CallOption) error
516 Acknowledge(context.Context, *pubsubpb.AcknowledgeRequest, ...gax.CallOption) error
517 Pull(context.Context, *pubsubpb.PullRequest, ...gax.CallOption) (*pubsubpb.PullResponse, error)
518 StreamingPull(context.Context, ...gax.CallOption) (pubsubpb.Subscriber_StreamingPullClient, error)
519 ModifyPushConfig(context.Context, *pubsubpb.ModifyPushConfigRequest, ...gax.CallOption) error
520 GetSnapshot(context.Context, *pubsubpb.GetSnapshotRequest, ...gax.CallOption) (*pubsubpb.Snapshot, error)
521 ListSnapshots(context.Context, *pubsubpb.ListSnapshotsRequest, ...gax.CallOption) *SnapshotIterator
522 CreateSnapshot(context.Context, *pubsubpb.CreateSnapshotRequest, ...gax.CallOption) (*pubsubpb.Snapshot, error)
523 UpdateSnapshot(context.Context, *pubsubpb.UpdateSnapshotRequest, ...gax.CallOption) (*pubsubpb.Snapshot, error)
524 DeleteSnapshot(context.Context, *pubsubpb.DeleteSnapshotRequest, ...gax.CallOption) error
525 Seek(context.Context, *pubsubpb.SeekRequest, ...gax.CallOption) (*pubsubpb.SeekResponse, error)
526 GetIamPolicy(context.Context, *iampb.GetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
527 SetIamPolicy(context.Context, *iampb.SetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
528 TestIamPermissions(context.Context, *iampb.TestIamPermissionsRequest, ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error)
529 }
530
531
532
533
534
535
536
537 type SubscriberClient struct {
538
539 internalClient internalSubscriberClient
540
541
542 CallOptions *SubscriberCallOptions
543 }
544
545
546
547
548
549 func (c *SubscriberClient) Close() error {
550 return c.internalClient.Close()
551 }
552
553
554
555
556 func (c *SubscriberClient) setGoogleClientInfo(keyval ...string) {
557 c.internalClient.setGoogleClientInfo(keyval...)
558 }
559
560
561
562
563
564 func (c *SubscriberClient) Connection() *grpc.ClientConn {
565 return c.internalClient.Connection()
566 }
567
568
569
570
571
572
573
574
575
576
577
578
579 func (c *SubscriberClient) CreateSubscription(ctx context.Context, req *pubsubpb.Subscription, opts ...gax.CallOption) (*pubsubpb.Subscription, error) {
580 return c.internalClient.CreateSubscription(ctx, req, opts...)
581 }
582
583
584 func (c *SubscriberClient) GetSubscription(ctx context.Context, req *pubsubpb.GetSubscriptionRequest, opts ...gax.CallOption) (*pubsubpb.Subscription, error) {
585 return c.internalClient.GetSubscription(ctx, req, opts...)
586 }
587
588
589
590
591 func (c *SubscriberClient) UpdateSubscription(ctx context.Context, req *pubsubpb.UpdateSubscriptionRequest, opts ...gax.CallOption) (*pubsubpb.Subscription, error) {
592 return c.internalClient.UpdateSubscription(ctx, req, opts...)
593 }
594
595
596 func (c *SubscriberClient) ListSubscriptions(ctx context.Context, req *pubsubpb.ListSubscriptionsRequest, opts ...gax.CallOption) *SubscriptionIterator {
597 return c.internalClient.ListSubscriptions(ctx, req, opts...)
598 }
599
600
601
602
603
604
605 func (c *SubscriberClient) DeleteSubscription(ctx context.Context, req *pubsubpb.DeleteSubscriptionRequest, opts ...gax.CallOption) error {
606 return c.internalClient.DeleteSubscription(ctx, req, opts...)
607 }
608
609
610
611
612
613
614 func (c *SubscriberClient) ModifyAckDeadline(ctx context.Context, req *pubsubpb.ModifyAckDeadlineRequest, opts ...gax.CallOption) error {
615 return c.internalClient.ModifyAckDeadline(ctx, req, opts...)
616 }
617
618
619
620
621
622
623
624
625 func (c *SubscriberClient) Acknowledge(ctx context.Context, req *pubsubpb.AcknowledgeRequest, opts ...gax.CallOption) error {
626 return c.internalClient.Acknowledge(ctx, req, opts...)
627 }
628
629
630 func (c *SubscriberClient) Pull(ctx context.Context, req *pubsubpb.PullRequest, opts ...gax.CallOption) (*pubsubpb.PullResponse, error) {
631 return c.internalClient.Pull(ctx, req, opts...)
632 }
633
634
635
636
637
638
639
640
641
642
643 func (c *SubscriberClient) StreamingPull(ctx context.Context, opts ...gax.CallOption) (pubsubpb.Subscriber_StreamingPullClient, error) {
644 return c.internalClient.StreamingPull(ctx, opts...)
645 }
646
647
648
649
650
651
652
653 func (c *SubscriberClient) ModifyPushConfig(ctx context.Context, req *pubsubpb.ModifyPushConfigRequest, opts ...gax.CallOption) error {
654 return c.internalClient.ModifyPushConfig(ctx, req, opts...)
655 }
656
657
658
659
660
661
662 func (c *SubscriberClient) GetSnapshot(ctx context.Context, req *pubsubpb.GetSnapshotRequest, opts ...gax.CallOption) (*pubsubpb.Snapshot, error) {
663 return c.internalClient.GetSnapshot(ctx, req, opts...)
664 }
665
666
667
668
669
670 func (c *SubscriberClient) ListSnapshots(ctx context.Context, req *pubsubpb.ListSnapshotsRequest, opts ...gax.CallOption) *SnapshotIterator {
671 return c.internalClient.ListSnapshots(ctx, req, opts...)
672 }
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690 func (c *SubscriberClient) CreateSnapshot(ctx context.Context, req *pubsubpb.CreateSnapshotRequest, opts ...gax.CallOption) (*pubsubpb.Snapshot, error) {
691 return c.internalClient.CreateSnapshot(ctx, req, opts...)
692 }
693
694
695
696
697
698
699
700 func (c *SubscriberClient) UpdateSnapshot(ctx context.Context, req *pubsubpb.UpdateSnapshotRequest, opts ...gax.CallOption) (*pubsubpb.Snapshot, error) {
701 return c.internalClient.UpdateSnapshot(ctx, req, opts...)
702 }
703
704
705
706
707
708
709
710
711
712
713 func (c *SubscriberClient) DeleteSnapshot(ctx context.Context, req *pubsubpb.DeleteSnapshotRequest, opts ...gax.CallOption) error {
714 return c.internalClient.DeleteSnapshot(ctx, req, opts...)
715 }
716
717
718
719
720
721
722
723
724 func (c *SubscriberClient) Seek(ctx context.Context, req *pubsubpb.SeekRequest, opts ...gax.CallOption) (*pubsubpb.SeekResponse, error) {
725 return c.internalClient.Seek(ctx, req, opts...)
726 }
727
728
729
730 func (c *SubscriberClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
731 return c.internalClient.GetIamPolicy(ctx, req, opts...)
732 }
733
734
735
736
737
738
739 func (c *SubscriberClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
740 return c.internalClient.SetIamPolicy(ctx, req, opts...)
741 }
742
743
744
745
746
747
748
749
750 func (c *SubscriberClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
751 return c.internalClient.TestIamPermissions(ctx, req, opts...)
752 }
753
754
755
756
757 type subscriberGRPCClient struct {
758
759 connPool gtransport.ConnPool
760
761
762 CallOptions **SubscriberCallOptions
763
764
765 subscriberClient pubsubpb.SubscriberClient
766
767 iamPolicyClient iampb.IAMPolicyClient
768
769
770 xGoogHeaders []string
771 }
772
773
774
775
776
777
778
779 func NewSubscriberClient(ctx context.Context, opts ...option.ClientOption) (*SubscriberClient, error) {
780 clientOpts := defaultSubscriberGRPCClientOptions()
781 if newSubscriberClientHook != nil {
782 hookOpts, err := newSubscriberClientHook(ctx, clientHookParams{})
783 if err != nil {
784 return nil, err
785 }
786 clientOpts = append(clientOpts, hookOpts...)
787 }
788
789 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
790 if err != nil {
791 return nil, err
792 }
793 client := SubscriberClient{CallOptions: defaultSubscriberCallOptions()}
794
795 c := &subscriberGRPCClient{
796 connPool: connPool,
797 subscriberClient: pubsubpb.NewSubscriberClient(connPool),
798 CallOptions: &client.CallOptions,
799 iamPolicyClient: iampb.NewIAMPolicyClient(connPool),
800 }
801 c.setGoogleClientInfo()
802
803 client.internalClient = c
804
805 return &client, nil
806 }
807
808
809
810
811
812 func (c *subscriberGRPCClient) Connection() *grpc.ClientConn {
813 return c.connPool.Conn()
814 }
815
816
817
818
819 func (c *subscriberGRPCClient) setGoogleClientInfo(keyval ...string) {
820 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
821 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version)
822 c.xGoogHeaders = []string{"x-goog-api-client", gax.XGoogHeader(kv...)}
823 }
824
825
826
827 func (c *subscriberGRPCClient) Close() error {
828 return c.connPool.Close()
829 }
830
831
832 type subscriberRESTClient struct {
833
834 endpoint string
835
836
837 httpClient *http.Client
838
839
840 xGoogHeaders []string
841
842
843 CallOptions **SubscriberCallOptions
844 }
845
846
847
848
849
850
851 func NewSubscriberRESTClient(ctx context.Context, opts ...option.ClientOption) (*SubscriberClient, error) {
852 clientOpts := append(defaultSubscriberRESTClientOptions(), opts...)
853 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
854 if err != nil {
855 return nil, err
856 }
857
858 callOpts := defaultSubscriberRESTCallOptions()
859 c := &subscriberRESTClient{
860 endpoint: endpoint,
861 httpClient: httpClient,
862 CallOptions: &callOpts,
863 }
864 c.setGoogleClientInfo()
865
866 return &SubscriberClient{internalClient: c, CallOptions: callOpts}, nil
867 }
868
869 func defaultSubscriberRESTClientOptions() []option.ClientOption {
870 return []option.ClientOption{
871 internaloption.WithDefaultEndpoint("https://pubsub.googleapis.com"),
872 internaloption.WithDefaultEndpointTemplate("https://pubsub.UNIVERSE_DOMAIN"),
873 internaloption.WithDefaultMTLSEndpoint("https://pubsub.mtls.googleapis.com"),
874 internaloption.WithDefaultUniverseDomain("googleapis.com"),
875 internaloption.WithDefaultAudience("https://pubsub.googleapis.com/"),
876 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
877 }
878 }
879
880
881
882
883 func (c *subscriberRESTClient) setGoogleClientInfo(keyval ...string) {
884 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
885 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN")
886 c.xGoogHeaders = []string{"x-goog-api-client", gax.XGoogHeader(kv...)}
887 }
888
889
890
891 func (c *subscriberRESTClient) Close() error {
892
893 c.httpClient = nil
894 return nil
895 }
896
897
898
899
900 func (c *subscriberRESTClient) Connection() *grpc.ClientConn {
901 return nil
902 }
903 func (c *subscriberGRPCClient) CreateSubscription(ctx context.Context, req *pubsubpb.Subscription, opts ...gax.CallOption) (*pubsubpb.Subscription, error) {
904 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
905
906 hds = append(c.xGoogHeaders, hds...)
907 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
908 opts = append((*c.CallOptions).CreateSubscription[0:len((*c.CallOptions).CreateSubscription):len((*c.CallOptions).CreateSubscription)], opts...)
909 var resp *pubsubpb.Subscription
910 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
911 var err error
912 resp, err = c.subscriberClient.CreateSubscription(ctx, req, settings.GRPC...)
913 return err
914 }, opts...)
915 if err != nil {
916 return nil, err
917 }
918 return resp, nil
919 }
920
921 func (c *subscriberGRPCClient) GetSubscription(ctx context.Context, req *pubsubpb.GetSubscriptionRequest, opts ...gax.CallOption) (*pubsubpb.Subscription, error) {
922 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "subscription", url.QueryEscape(req.GetSubscription()))}
923
924 hds = append(c.xGoogHeaders, hds...)
925 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
926 opts = append((*c.CallOptions).GetSubscription[0:len((*c.CallOptions).GetSubscription):len((*c.CallOptions).GetSubscription)], opts...)
927 var resp *pubsubpb.Subscription
928 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
929 var err error
930 resp, err = c.subscriberClient.GetSubscription(ctx, req, settings.GRPC...)
931 return err
932 }, opts...)
933 if err != nil {
934 return nil, err
935 }
936 return resp, nil
937 }
938
939 func (c *subscriberGRPCClient) UpdateSubscription(ctx context.Context, req *pubsubpb.UpdateSubscriptionRequest, opts ...gax.CallOption) (*pubsubpb.Subscription, error) {
940 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "subscription.name", url.QueryEscape(req.GetSubscription().GetName()))}
941
942 hds = append(c.xGoogHeaders, hds...)
943 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
944 opts = append((*c.CallOptions).UpdateSubscription[0:len((*c.CallOptions).UpdateSubscription):len((*c.CallOptions).UpdateSubscription)], opts...)
945 var resp *pubsubpb.Subscription
946 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
947 var err error
948 resp, err = c.subscriberClient.UpdateSubscription(ctx, req, settings.GRPC...)
949 return err
950 }, opts...)
951 if err != nil {
952 return nil, err
953 }
954 return resp, nil
955 }
956
957 func (c *subscriberGRPCClient) ListSubscriptions(ctx context.Context, req *pubsubpb.ListSubscriptionsRequest, opts ...gax.CallOption) *SubscriptionIterator {
958 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "project", url.QueryEscape(req.GetProject()))}
959
960 hds = append(c.xGoogHeaders, hds...)
961 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
962 opts = append((*c.CallOptions).ListSubscriptions[0:len((*c.CallOptions).ListSubscriptions):len((*c.CallOptions).ListSubscriptions)], opts...)
963 it := &SubscriptionIterator{}
964 req = proto.Clone(req).(*pubsubpb.ListSubscriptionsRequest)
965 it.InternalFetch = func(pageSize int, pageToken string) ([]*pubsubpb.Subscription, string, error) {
966 resp := &pubsubpb.ListSubscriptionsResponse{}
967 if pageToken != "" {
968 req.PageToken = pageToken
969 }
970 if pageSize > math.MaxInt32 {
971 req.PageSize = math.MaxInt32
972 } else if pageSize != 0 {
973 req.PageSize = int32(pageSize)
974 }
975 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
976 var err error
977 resp, err = c.subscriberClient.ListSubscriptions(ctx, req, settings.GRPC...)
978 return err
979 }, opts...)
980 if err != nil {
981 return nil, "", err
982 }
983
984 it.Response = resp
985 return resp.GetSubscriptions(), resp.GetNextPageToken(), nil
986 }
987 fetch := func(pageSize int, pageToken string) (string, error) {
988 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
989 if err != nil {
990 return "", err
991 }
992 it.items = append(it.items, items...)
993 return nextPageToken, nil
994 }
995
996 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
997 it.pageInfo.MaxSize = int(req.GetPageSize())
998 it.pageInfo.Token = req.GetPageToken()
999
1000 return it
1001 }
1002
1003 func (c *subscriberGRPCClient) DeleteSubscription(ctx context.Context, req *pubsubpb.DeleteSubscriptionRequest, opts ...gax.CallOption) error {
1004 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "subscription", url.QueryEscape(req.GetSubscription()))}
1005
1006 hds = append(c.xGoogHeaders, hds...)
1007 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1008 opts = append((*c.CallOptions).DeleteSubscription[0:len((*c.CallOptions).DeleteSubscription):len((*c.CallOptions).DeleteSubscription)], opts...)
1009 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1010 var err error
1011 _, err = c.subscriberClient.DeleteSubscription(ctx, req, settings.GRPC...)
1012 return err
1013 }, opts...)
1014 return err
1015 }
1016
1017 func (c *subscriberGRPCClient) ModifyAckDeadline(ctx context.Context, req *pubsubpb.ModifyAckDeadlineRequest, opts ...gax.CallOption) error {
1018 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "subscription", url.QueryEscape(req.GetSubscription()))}
1019
1020 hds = append(c.xGoogHeaders, hds...)
1021 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1022 opts = append((*c.CallOptions).ModifyAckDeadline[0:len((*c.CallOptions).ModifyAckDeadline):len((*c.CallOptions).ModifyAckDeadline)], opts...)
1023 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1024 var err error
1025 _, err = c.subscriberClient.ModifyAckDeadline(ctx, req, settings.GRPC...)
1026 return err
1027 }, opts...)
1028 return err
1029 }
1030
1031 func (c *subscriberGRPCClient) Acknowledge(ctx context.Context, req *pubsubpb.AcknowledgeRequest, opts ...gax.CallOption) error {
1032 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "subscription", url.QueryEscape(req.GetSubscription()))}
1033
1034 hds = append(c.xGoogHeaders, hds...)
1035 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1036 opts = append((*c.CallOptions).Acknowledge[0:len((*c.CallOptions).Acknowledge):len((*c.CallOptions).Acknowledge)], opts...)
1037 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1038 var err error
1039 _, err = c.subscriberClient.Acknowledge(ctx, req, settings.GRPC...)
1040 return err
1041 }, opts...)
1042 return err
1043 }
1044
1045 func (c *subscriberGRPCClient) Pull(ctx context.Context, req *pubsubpb.PullRequest, opts ...gax.CallOption) (*pubsubpb.PullResponse, error) {
1046 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "subscription", url.QueryEscape(req.GetSubscription()))}
1047
1048 hds = append(c.xGoogHeaders, hds...)
1049 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1050 opts = append((*c.CallOptions).Pull[0:len((*c.CallOptions).Pull):len((*c.CallOptions).Pull)], opts...)
1051 var resp *pubsubpb.PullResponse
1052 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1053 var err error
1054 resp, err = c.subscriberClient.Pull(ctx, req, settings.GRPC...)
1055 return err
1056 }, opts...)
1057 if err != nil {
1058 return nil, err
1059 }
1060 return resp, nil
1061 }
1062
1063 func (c *subscriberGRPCClient) StreamingPull(ctx context.Context, opts ...gax.CallOption) (pubsubpb.Subscriber_StreamingPullClient, error) {
1064 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...)
1065 var resp pubsubpb.Subscriber_StreamingPullClient
1066 opts = append((*c.CallOptions).StreamingPull[0:len((*c.CallOptions).StreamingPull):len((*c.CallOptions).StreamingPull)], opts...)
1067 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1068 var err error
1069 resp, err = c.subscriberClient.StreamingPull(ctx, settings.GRPC...)
1070 return err
1071 }, opts...)
1072 if err != nil {
1073 return nil, err
1074 }
1075 return resp, nil
1076 }
1077
1078 func (c *subscriberGRPCClient) ModifyPushConfig(ctx context.Context, req *pubsubpb.ModifyPushConfigRequest, opts ...gax.CallOption) error {
1079 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "subscription", url.QueryEscape(req.GetSubscription()))}
1080
1081 hds = append(c.xGoogHeaders, hds...)
1082 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1083 opts = append((*c.CallOptions).ModifyPushConfig[0:len((*c.CallOptions).ModifyPushConfig):len((*c.CallOptions).ModifyPushConfig)], opts...)
1084 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1085 var err error
1086 _, err = c.subscriberClient.ModifyPushConfig(ctx, req, settings.GRPC...)
1087 return err
1088 }, opts...)
1089 return err
1090 }
1091
1092 func (c *subscriberGRPCClient) GetSnapshot(ctx context.Context, req *pubsubpb.GetSnapshotRequest, opts ...gax.CallOption) (*pubsubpb.Snapshot, error) {
1093 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "snapshot", url.QueryEscape(req.GetSnapshot()))}
1094
1095 hds = append(c.xGoogHeaders, hds...)
1096 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1097 opts = append((*c.CallOptions).GetSnapshot[0:len((*c.CallOptions).GetSnapshot):len((*c.CallOptions).GetSnapshot)], opts...)
1098 var resp *pubsubpb.Snapshot
1099 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1100 var err error
1101 resp, err = c.subscriberClient.GetSnapshot(ctx, req, settings.GRPC...)
1102 return err
1103 }, opts...)
1104 if err != nil {
1105 return nil, err
1106 }
1107 return resp, nil
1108 }
1109
1110 func (c *subscriberGRPCClient) ListSnapshots(ctx context.Context, req *pubsubpb.ListSnapshotsRequest, opts ...gax.CallOption) *SnapshotIterator {
1111 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "project", url.QueryEscape(req.GetProject()))}
1112
1113 hds = append(c.xGoogHeaders, hds...)
1114 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1115 opts = append((*c.CallOptions).ListSnapshots[0:len((*c.CallOptions).ListSnapshots):len((*c.CallOptions).ListSnapshots)], opts...)
1116 it := &SnapshotIterator{}
1117 req = proto.Clone(req).(*pubsubpb.ListSnapshotsRequest)
1118 it.InternalFetch = func(pageSize int, pageToken string) ([]*pubsubpb.Snapshot, string, error) {
1119 resp := &pubsubpb.ListSnapshotsResponse{}
1120 if pageToken != "" {
1121 req.PageToken = pageToken
1122 }
1123 if pageSize > math.MaxInt32 {
1124 req.PageSize = math.MaxInt32
1125 } else if pageSize != 0 {
1126 req.PageSize = int32(pageSize)
1127 }
1128 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1129 var err error
1130 resp, err = c.subscriberClient.ListSnapshots(ctx, req, settings.GRPC...)
1131 return err
1132 }, opts...)
1133 if err != nil {
1134 return nil, "", err
1135 }
1136
1137 it.Response = resp
1138 return resp.GetSnapshots(), resp.GetNextPageToken(), nil
1139 }
1140 fetch := func(pageSize int, pageToken string) (string, error) {
1141 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1142 if err != nil {
1143 return "", err
1144 }
1145 it.items = append(it.items, items...)
1146 return nextPageToken, nil
1147 }
1148
1149 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1150 it.pageInfo.MaxSize = int(req.GetPageSize())
1151 it.pageInfo.Token = req.GetPageToken()
1152
1153 return it
1154 }
1155
1156 func (c *subscriberGRPCClient) CreateSnapshot(ctx context.Context, req *pubsubpb.CreateSnapshotRequest, opts ...gax.CallOption) (*pubsubpb.Snapshot, error) {
1157 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1158
1159 hds = append(c.xGoogHeaders, hds...)
1160 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1161 opts = append((*c.CallOptions).CreateSnapshot[0:len((*c.CallOptions).CreateSnapshot):len((*c.CallOptions).CreateSnapshot)], opts...)
1162 var resp *pubsubpb.Snapshot
1163 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1164 var err error
1165 resp, err = c.subscriberClient.CreateSnapshot(ctx, req, settings.GRPC...)
1166 return err
1167 }, opts...)
1168 if err != nil {
1169 return nil, err
1170 }
1171 return resp, nil
1172 }
1173
1174 func (c *subscriberGRPCClient) UpdateSnapshot(ctx context.Context, req *pubsubpb.UpdateSnapshotRequest, opts ...gax.CallOption) (*pubsubpb.Snapshot, error) {
1175 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "snapshot.name", url.QueryEscape(req.GetSnapshot().GetName()))}
1176
1177 hds = append(c.xGoogHeaders, hds...)
1178 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1179 opts = append((*c.CallOptions).UpdateSnapshot[0:len((*c.CallOptions).UpdateSnapshot):len((*c.CallOptions).UpdateSnapshot)], opts...)
1180 var resp *pubsubpb.Snapshot
1181 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1182 var err error
1183 resp, err = c.subscriberClient.UpdateSnapshot(ctx, req, settings.GRPC...)
1184 return err
1185 }, opts...)
1186 if err != nil {
1187 return nil, err
1188 }
1189 return resp, nil
1190 }
1191
1192 func (c *subscriberGRPCClient) DeleteSnapshot(ctx context.Context, req *pubsubpb.DeleteSnapshotRequest, opts ...gax.CallOption) error {
1193 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "snapshot", url.QueryEscape(req.GetSnapshot()))}
1194
1195 hds = append(c.xGoogHeaders, hds...)
1196 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1197 opts = append((*c.CallOptions).DeleteSnapshot[0:len((*c.CallOptions).DeleteSnapshot):len((*c.CallOptions).DeleteSnapshot)], opts...)
1198 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1199 var err error
1200 _, err = c.subscriberClient.DeleteSnapshot(ctx, req, settings.GRPC...)
1201 return err
1202 }, opts...)
1203 return err
1204 }
1205
1206 func (c *subscriberGRPCClient) Seek(ctx context.Context, req *pubsubpb.SeekRequest, opts ...gax.CallOption) (*pubsubpb.SeekResponse, error) {
1207 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "subscription", url.QueryEscape(req.GetSubscription()))}
1208
1209 hds = append(c.xGoogHeaders, hds...)
1210 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1211 opts = append((*c.CallOptions).Seek[0:len((*c.CallOptions).Seek):len((*c.CallOptions).Seek)], opts...)
1212 var resp *pubsubpb.SeekResponse
1213 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1214 var err error
1215 resp, err = c.subscriberClient.Seek(ctx, req, settings.GRPC...)
1216 return err
1217 }, opts...)
1218 if err != nil {
1219 return nil, err
1220 }
1221 return resp, nil
1222 }
1223
1224 func (c *subscriberGRPCClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
1225 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
1226
1227 hds = append(c.xGoogHeaders, hds...)
1228 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1229 opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
1230 var resp *iampb.Policy
1231 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1232 var err error
1233 resp, err = c.iamPolicyClient.GetIamPolicy(ctx, req, settings.GRPC...)
1234 return err
1235 }, opts...)
1236 if err != nil {
1237 return nil, err
1238 }
1239 return resp, nil
1240 }
1241
1242 func (c *subscriberGRPCClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
1243 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
1244
1245 hds = append(c.xGoogHeaders, hds...)
1246 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1247 opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
1248 var resp *iampb.Policy
1249 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1250 var err error
1251 resp, err = c.iamPolicyClient.SetIamPolicy(ctx, req, settings.GRPC...)
1252 return err
1253 }, opts...)
1254 if err != nil {
1255 return nil, err
1256 }
1257 return resp, nil
1258 }
1259
1260 func (c *subscriberGRPCClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
1261 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
1262
1263 hds = append(c.xGoogHeaders, hds...)
1264 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1265 opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...)
1266 var resp *iampb.TestIamPermissionsResponse
1267 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1268 var err error
1269 resp, err = c.iamPolicyClient.TestIamPermissions(ctx, req, settings.GRPC...)
1270 return err
1271 }, opts...)
1272 if err != nil {
1273 return nil, err
1274 }
1275 return resp, nil
1276 }
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289 func (c *subscriberRESTClient) CreateSubscription(ctx context.Context, req *pubsubpb.Subscription, opts ...gax.CallOption) (*pubsubpb.Subscription, error) {
1290 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1291 jsonReq, err := m.Marshal(req)
1292 if err != nil {
1293 return nil, err
1294 }
1295
1296 baseUrl, err := url.Parse(c.endpoint)
1297 if err != nil {
1298 return nil, err
1299 }
1300 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
1301
1302 params := url.Values{}
1303 params.Add("$alt", "json;enum-encoding=int")
1304
1305 baseUrl.RawQuery = params.Encode()
1306
1307
1308 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1309
1310 hds = append(c.xGoogHeaders, hds...)
1311 hds = append(hds, "Content-Type", "application/json")
1312 headers := gax.BuildHeaders(ctx, hds...)
1313 opts = append((*c.CallOptions).CreateSubscription[0:len((*c.CallOptions).CreateSubscription):len((*c.CallOptions).CreateSubscription)], opts...)
1314 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1315 resp := &pubsubpb.Subscription{}
1316 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1317 if settings.Path != "" {
1318 baseUrl.Path = settings.Path
1319 }
1320 httpReq, err := http.NewRequest("PUT", baseUrl.String(), bytes.NewReader(jsonReq))
1321 if err != nil {
1322 return err
1323 }
1324 httpReq = httpReq.WithContext(ctx)
1325 httpReq.Header = headers
1326
1327 httpRsp, err := c.httpClient.Do(httpReq)
1328 if err != nil {
1329 return err
1330 }
1331 defer httpRsp.Body.Close()
1332
1333 if err = googleapi.CheckResponse(httpRsp); err != nil {
1334 return err
1335 }
1336
1337 buf, err := io.ReadAll(httpRsp.Body)
1338 if err != nil {
1339 return err
1340 }
1341
1342 if err := unm.Unmarshal(buf, resp); err != nil {
1343 return err
1344 }
1345
1346 return nil
1347 }, opts...)
1348 if e != nil {
1349 return nil, e
1350 }
1351 return resp, nil
1352 }
1353
1354
1355 func (c *subscriberRESTClient) GetSubscription(ctx context.Context, req *pubsubpb.GetSubscriptionRequest, opts ...gax.CallOption) (*pubsubpb.Subscription, error) {
1356 baseUrl, err := url.Parse(c.endpoint)
1357 if err != nil {
1358 return nil, err
1359 }
1360 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetSubscription())
1361
1362 params := url.Values{}
1363 params.Add("$alt", "json;enum-encoding=int")
1364
1365 baseUrl.RawQuery = params.Encode()
1366
1367
1368 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "subscription", url.QueryEscape(req.GetSubscription()))}
1369
1370 hds = append(c.xGoogHeaders, hds...)
1371 hds = append(hds, "Content-Type", "application/json")
1372 headers := gax.BuildHeaders(ctx, hds...)
1373 opts = append((*c.CallOptions).GetSubscription[0:len((*c.CallOptions).GetSubscription):len((*c.CallOptions).GetSubscription)], opts...)
1374 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1375 resp := &pubsubpb.Subscription{}
1376 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1377 if settings.Path != "" {
1378 baseUrl.Path = settings.Path
1379 }
1380 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1381 if err != nil {
1382 return err
1383 }
1384 httpReq = httpReq.WithContext(ctx)
1385 httpReq.Header = headers
1386
1387 httpRsp, err := c.httpClient.Do(httpReq)
1388 if err != nil {
1389 return err
1390 }
1391 defer httpRsp.Body.Close()
1392
1393 if err = googleapi.CheckResponse(httpRsp); err != nil {
1394 return err
1395 }
1396
1397 buf, err := io.ReadAll(httpRsp.Body)
1398 if err != nil {
1399 return err
1400 }
1401
1402 if err := unm.Unmarshal(buf, resp); err != nil {
1403 return err
1404 }
1405
1406 return nil
1407 }, opts...)
1408 if e != nil {
1409 return nil, e
1410 }
1411 return resp, nil
1412 }
1413
1414
1415
1416
1417 func (c *subscriberRESTClient) UpdateSubscription(ctx context.Context, req *pubsubpb.UpdateSubscriptionRequest, opts ...gax.CallOption) (*pubsubpb.Subscription, error) {
1418 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1419 jsonReq, err := m.Marshal(req)
1420 if err != nil {
1421 return nil, err
1422 }
1423
1424 baseUrl, err := url.Parse(c.endpoint)
1425 if err != nil {
1426 return nil, err
1427 }
1428 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetSubscription().GetName())
1429
1430 params := url.Values{}
1431 params.Add("$alt", "json;enum-encoding=int")
1432
1433 baseUrl.RawQuery = params.Encode()
1434
1435
1436 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "subscription.name", url.QueryEscape(req.GetSubscription().GetName()))}
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).UpdateSubscription[0:len((*c.CallOptions).UpdateSubscription):len((*c.CallOptions).UpdateSubscription)], opts...)
1442 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1443 resp := &pubsubpb.Subscription{}
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("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
1449 if err != nil {
1450 return err
1451 }
1452 httpReq = httpReq.WithContext(ctx)
1453 httpReq.Header = headers
1454
1455 httpRsp, err := c.httpClient.Do(httpReq)
1456 if err != nil {
1457 return err
1458 }
1459 defer httpRsp.Body.Close()
1460
1461 if err = googleapi.CheckResponse(httpRsp); err != nil {
1462 return err
1463 }
1464
1465 buf, err := io.ReadAll(httpRsp.Body)
1466 if err != nil {
1467 return err
1468 }
1469
1470 if err := unm.Unmarshal(buf, resp); err != nil {
1471 return err
1472 }
1473
1474 return nil
1475 }, opts...)
1476 if e != nil {
1477 return nil, e
1478 }
1479 return resp, nil
1480 }
1481
1482
1483 func (c *subscriberRESTClient) ListSubscriptions(ctx context.Context, req *pubsubpb.ListSubscriptionsRequest, opts ...gax.CallOption) *SubscriptionIterator {
1484 it := &SubscriptionIterator{}
1485 req = proto.Clone(req).(*pubsubpb.ListSubscriptionsRequest)
1486 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1487 it.InternalFetch = func(pageSize int, pageToken string) ([]*pubsubpb.Subscription, string, error) {
1488 resp := &pubsubpb.ListSubscriptionsResponse{}
1489 if pageToken != "" {
1490 req.PageToken = pageToken
1491 }
1492 if pageSize > math.MaxInt32 {
1493 req.PageSize = math.MaxInt32
1494 } else if pageSize != 0 {
1495 req.PageSize = int32(pageSize)
1496 }
1497 baseUrl, err := url.Parse(c.endpoint)
1498 if err != nil {
1499 return nil, "", err
1500 }
1501 baseUrl.Path += fmt.Sprintf("/v1/%v/subscriptions", req.GetProject())
1502
1503 params := url.Values{}
1504 params.Add("$alt", "json;enum-encoding=int")
1505 if req.GetPageSize() != 0 {
1506 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
1507 }
1508 if req.GetPageToken() != "" {
1509 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
1510 }
1511
1512 baseUrl.RawQuery = params.Encode()
1513
1514
1515 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
1516 headers := gax.BuildHeaders(ctx, hds...)
1517 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1518 if settings.Path != "" {
1519 baseUrl.Path = settings.Path
1520 }
1521 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1522 if err != nil {
1523 return err
1524 }
1525 httpReq.Header = headers
1526
1527 httpRsp, err := c.httpClient.Do(httpReq)
1528 if err != nil {
1529 return err
1530 }
1531 defer httpRsp.Body.Close()
1532
1533 if err = googleapi.CheckResponse(httpRsp); err != nil {
1534 return err
1535 }
1536
1537 buf, err := io.ReadAll(httpRsp.Body)
1538 if err != nil {
1539 return err
1540 }
1541
1542 if err := unm.Unmarshal(buf, resp); err != nil {
1543 return err
1544 }
1545
1546 return nil
1547 }, opts...)
1548 if e != nil {
1549 return nil, "", e
1550 }
1551 it.Response = resp
1552 return resp.GetSubscriptions(), resp.GetNextPageToken(), nil
1553 }
1554
1555 fetch := func(pageSize int, pageToken string) (string, error) {
1556 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1557 if err != nil {
1558 return "", err
1559 }
1560 it.items = append(it.items, items...)
1561 return nextPageToken, nil
1562 }
1563
1564 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1565 it.pageInfo.MaxSize = int(req.GetPageSize())
1566 it.pageInfo.Token = req.GetPageToken()
1567
1568 return it
1569 }
1570
1571
1572
1573
1574
1575
1576 func (c *subscriberRESTClient) DeleteSubscription(ctx context.Context, req *pubsubpb.DeleteSubscriptionRequest, opts ...gax.CallOption) error {
1577 baseUrl, err := url.Parse(c.endpoint)
1578 if err != nil {
1579 return err
1580 }
1581 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetSubscription())
1582
1583 params := url.Values{}
1584 params.Add("$alt", "json;enum-encoding=int")
1585
1586 baseUrl.RawQuery = params.Encode()
1587
1588
1589 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "subscription", url.QueryEscape(req.GetSubscription()))}
1590
1591 hds = append(c.xGoogHeaders, hds...)
1592 hds = append(hds, "Content-Type", "application/json")
1593 headers := gax.BuildHeaders(ctx, hds...)
1594 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1595 if settings.Path != "" {
1596 baseUrl.Path = settings.Path
1597 }
1598 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
1599 if err != nil {
1600 return err
1601 }
1602 httpReq = httpReq.WithContext(ctx)
1603 httpReq.Header = headers
1604
1605 httpRsp, err := c.httpClient.Do(httpReq)
1606 if err != nil {
1607 return err
1608 }
1609 defer httpRsp.Body.Close()
1610
1611
1612
1613 return googleapi.CheckResponse(httpRsp)
1614 }, opts...)
1615 }
1616
1617
1618
1619
1620
1621
1622 func (c *subscriberRESTClient) ModifyAckDeadline(ctx context.Context, req *pubsubpb.ModifyAckDeadlineRequest, opts ...gax.CallOption) error {
1623 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1624 jsonReq, err := m.Marshal(req)
1625 if err != nil {
1626 return err
1627 }
1628
1629 baseUrl, err := url.Parse(c.endpoint)
1630 if err != nil {
1631 return err
1632 }
1633 baseUrl.Path += fmt.Sprintf("/v1/%v:modifyAckDeadline", req.GetSubscription())
1634
1635 params := url.Values{}
1636 params.Add("$alt", "json;enum-encoding=int")
1637
1638 baseUrl.RawQuery = params.Encode()
1639
1640
1641 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "subscription", url.QueryEscape(req.GetSubscription()))}
1642
1643 hds = append(c.xGoogHeaders, hds...)
1644 hds = append(hds, "Content-Type", "application/json")
1645 headers := gax.BuildHeaders(ctx, hds...)
1646 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1647 if settings.Path != "" {
1648 baseUrl.Path = settings.Path
1649 }
1650 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1651 if err != nil {
1652 return err
1653 }
1654 httpReq = httpReq.WithContext(ctx)
1655 httpReq.Header = headers
1656
1657 httpRsp, err := c.httpClient.Do(httpReq)
1658 if err != nil {
1659 return err
1660 }
1661 defer httpRsp.Body.Close()
1662
1663
1664
1665 return googleapi.CheckResponse(httpRsp)
1666 }, opts...)
1667 }
1668
1669
1670
1671
1672
1673
1674
1675
1676 func (c *subscriberRESTClient) Acknowledge(ctx context.Context, req *pubsubpb.AcknowledgeRequest, opts ...gax.CallOption) error {
1677 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1678 jsonReq, err := m.Marshal(req)
1679 if err != nil {
1680 return err
1681 }
1682
1683 baseUrl, err := url.Parse(c.endpoint)
1684 if err != nil {
1685 return err
1686 }
1687 baseUrl.Path += fmt.Sprintf("/v1/%v:acknowledge", req.GetSubscription())
1688
1689 params := url.Values{}
1690 params.Add("$alt", "json;enum-encoding=int")
1691
1692 baseUrl.RawQuery = params.Encode()
1693
1694
1695 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "subscription", url.QueryEscape(req.GetSubscription()))}
1696
1697 hds = append(c.xGoogHeaders, hds...)
1698 hds = append(hds, "Content-Type", "application/json")
1699 headers := gax.BuildHeaders(ctx, hds...)
1700 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1701 if settings.Path != "" {
1702 baseUrl.Path = settings.Path
1703 }
1704 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1705 if err != nil {
1706 return err
1707 }
1708 httpReq = httpReq.WithContext(ctx)
1709 httpReq.Header = headers
1710
1711 httpRsp, err := c.httpClient.Do(httpReq)
1712 if err != nil {
1713 return err
1714 }
1715 defer httpRsp.Body.Close()
1716
1717
1718
1719 return googleapi.CheckResponse(httpRsp)
1720 }, opts...)
1721 }
1722
1723
1724 func (c *subscriberRESTClient) Pull(ctx context.Context, req *pubsubpb.PullRequest, opts ...gax.CallOption) (*pubsubpb.PullResponse, error) {
1725 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1726 jsonReq, err := m.Marshal(req)
1727 if err != nil {
1728 return nil, err
1729 }
1730
1731 baseUrl, err := url.Parse(c.endpoint)
1732 if err != nil {
1733 return nil, err
1734 }
1735 baseUrl.Path += fmt.Sprintf("/v1/%v:pull", req.GetSubscription())
1736
1737 params := url.Values{}
1738 params.Add("$alt", "json;enum-encoding=int")
1739
1740 baseUrl.RawQuery = params.Encode()
1741
1742
1743 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "subscription", url.QueryEscape(req.GetSubscription()))}
1744
1745 hds = append(c.xGoogHeaders, hds...)
1746 hds = append(hds, "Content-Type", "application/json")
1747 headers := gax.BuildHeaders(ctx, hds...)
1748 opts = append((*c.CallOptions).Pull[0:len((*c.CallOptions).Pull):len((*c.CallOptions).Pull)], opts...)
1749 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1750 resp := &pubsubpb.PullResponse{}
1751 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1752 if settings.Path != "" {
1753 baseUrl.Path = settings.Path
1754 }
1755 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1756 if err != nil {
1757 return err
1758 }
1759 httpReq = httpReq.WithContext(ctx)
1760 httpReq.Header = headers
1761
1762 httpRsp, err := c.httpClient.Do(httpReq)
1763 if err != nil {
1764 return err
1765 }
1766 defer httpRsp.Body.Close()
1767
1768 if err = googleapi.CheckResponse(httpRsp); err != nil {
1769 return err
1770 }
1771
1772 buf, err := io.ReadAll(httpRsp.Body)
1773 if err != nil {
1774 return err
1775 }
1776
1777 if err := unm.Unmarshal(buf, resp); err != nil {
1778 return err
1779 }
1780
1781 return nil
1782 }, opts...)
1783 if e != nil {
1784 return nil, e
1785 }
1786 return resp, nil
1787 }
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798 func (c *subscriberRESTClient) StreamingPull(ctx context.Context, opts ...gax.CallOption) (pubsubpb.Subscriber_StreamingPullClient, error) {
1799 return nil, errors.New("StreamingPull not yet supported for REST clients")
1800 }
1801
1802
1803
1804
1805
1806
1807
1808 func (c *subscriberRESTClient) ModifyPushConfig(ctx context.Context, req *pubsubpb.ModifyPushConfigRequest, opts ...gax.CallOption) error {
1809 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1810 jsonReq, err := m.Marshal(req)
1811 if err != nil {
1812 return err
1813 }
1814
1815 baseUrl, err := url.Parse(c.endpoint)
1816 if err != nil {
1817 return err
1818 }
1819 baseUrl.Path += fmt.Sprintf("/v1/%v:modifyPushConfig", req.GetSubscription())
1820
1821 params := url.Values{}
1822 params.Add("$alt", "json;enum-encoding=int")
1823
1824 baseUrl.RawQuery = params.Encode()
1825
1826
1827 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "subscription", url.QueryEscape(req.GetSubscription()))}
1828
1829 hds = append(c.xGoogHeaders, hds...)
1830 hds = append(hds, "Content-Type", "application/json")
1831 headers := gax.BuildHeaders(ctx, hds...)
1832 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1833 if settings.Path != "" {
1834 baseUrl.Path = settings.Path
1835 }
1836 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1837 if err != nil {
1838 return err
1839 }
1840 httpReq = httpReq.WithContext(ctx)
1841 httpReq.Header = headers
1842
1843 httpRsp, err := c.httpClient.Do(httpReq)
1844 if err != nil {
1845 return err
1846 }
1847 defer httpRsp.Body.Close()
1848
1849
1850
1851 return googleapi.CheckResponse(httpRsp)
1852 }, opts...)
1853 }
1854
1855
1856
1857
1858
1859
1860 func (c *subscriberRESTClient) GetSnapshot(ctx context.Context, req *pubsubpb.GetSnapshotRequest, opts ...gax.CallOption) (*pubsubpb.Snapshot, error) {
1861 baseUrl, err := url.Parse(c.endpoint)
1862 if err != nil {
1863 return nil, err
1864 }
1865 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetSnapshot())
1866
1867 params := url.Values{}
1868 params.Add("$alt", "json;enum-encoding=int")
1869
1870 baseUrl.RawQuery = params.Encode()
1871
1872
1873 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "snapshot", url.QueryEscape(req.GetSnapshot()))}
1874
1875 hds = append(c.xGoogHeaders, hds...)
1876 hds = append(hds, "Content-Type", "application/json")
1877 headers := gax.BuildHeaders(ctx, hds...)
1878 opts = append((*c.CallOptions).GetSnapshot[0:len((*c.CallOptions).GetSnapshot):len((*c.CallOptions).GetSnapshot)], opts...)
1879 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1880 resp := &pubsubpb.Snapshot{}
1881 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1882 if settings.Path != "" {
1883 baseUrl.Path = settings.Path
1884 }
1885 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1886 if err != nil {
1887 return err
1888 }
1889 httpReq = httpReq.WithContext(ctx)
1890 httpReq.Header = headers
1891
1892 httpRsp, err := c.httpClient.Do(httpReq)
1893 if err != nil {
1894 return err
1895 }
1896 defer httpRsp.Body.Close()
1897
1898 if err = googleapi.CheckResponse(httpRsp); err != nil {
1899 return err
1900 }
1901
1902 buf, err := io.ReadAll(httpRsp.Body)
1903 if err != nil {
1904 return err
1905 }
1906
1907 if err := unm.Unmarshal(buf, resp); err != nil {
1908 return err
1909 }
1910
1911 return nil
1912 }, opts...)
1913 if e != nil {
1914 return nil, e
1915 }
1916 return resp, nil
1917 }
1918
1919
1920
1921
1922
1923 func (c *subscriberRESTClient) ListSnapshots(ctx context.Context, req *pubsubpb.ListSnapshotsRequest, opts ...gax.CallOption) *SnapshotIterator {
1924 it := &SnapshotIterator{}
1925 req = proto.Clone(req).(*pubsubpb.ListSnapshotsRequest)
1926 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1927 it.InternalFetch = func(pageSize int, pageToken string) ([]*pubsubpb.Snapshot, string, error) {
1928 resp := &pubsubpb.ListSnapshotsResponse{}
1929 if pageToken != "" {
1930 req.PageToken = pageToken
1931 }
1932 if pageSize > math.MaxInt32 {
1933 req.PageSize = math.MaxInt32
1934 } else if pageSize != 0 {
1935 req.PageSize = int32(pageSize)
1936 }
1937 baseUrl, err := url.Parse(c.endpoint)
1938 if err != nil {
1939 return nil, "", err
1940 }
1941 baseUrl.Path += fmt.Sprintf("/v1/%v/snapshots", req.GetProject())
1942
1943 params := url.Values{}
1944 params.Add("$alt", "json;enum-encoding=int")
1945 if req.GetPageSize() != 0 {
1946 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
1947 }
1948 if req.GetPageToken() != "" {
1949 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
1950 }
1951
1952 baseUrl.RawQuery = params.Encode()
1953
1954
1955 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
1956 headers := gax.BuildHeaders(ctx, hds...)
1957 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1958 if settings.Path != "" {
1959 baseUrl.Path = settings.Path
1960 }
1961 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1962 if err != nil {
1963 return err
1964 }
1965 httpReq.Header = headers
1966
1967 httpRsp, err := c.httpClient.Do(httpReq)
1968 if err != nil {
1969 return err
1970 }
1971 defer httpRsp.Body.Close()
1972
1973 if err = googleapi.CheckResponse(httpRsp); err != nil {
1974 return err
1975 }
1976
1977 buf, err := io.ReadAll(httpRsp.Body)
1978 if err != nil {
1979 return err
1980 }
1981
1982 if err := unm.Unmarshal(buf, resp); err != nil {
1983 return err
1984 }
1985
1986 return nil
1987 }, opts...)
1988 if e != nil {
1989 return nil, "", e
1990 }
1991 it.Response = resp
1992 return resp.GetSnapshots(), resp.GetNextPageToken(), nil
1993 }
1994
1995 fetch := func(pageSize int, pageToken string) (string, error) {
1996 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1997 if err != nil {
1998 return "", err
1999 }
2000 it.items = append(it.items, items...)
2001 return nextPageToken, nil
2002 }
2003
2004 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
2005 it.pageInfo.MaxSize = int(req.GetPageSize())
2006 it.pageInfo.Token = req.GetPageToken()
2007
2008 return it
2009 }
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027 func (c *subscriberRESTClient) CreateSnapshot(ctx context.Context, req *pubsubpb.CreateSnapshotRequest, opts ...gax.CallOption) (*pubsubpb.Snapshot, error) {
2028 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
2029 jsonReq, err := m.Marshal(req)
2030 if err != nil {
2031 return nil, err
2032 }
2033
2034 baseUrl, err := url.Parse(c.endpoint)
2035 if err != nil {
2036 return nil, err
2037 }
2038 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
2039
2040 params := url.Values{}
2041 params.Add("$alt", "json;enum-encoding=int")
2042
2043 baseUrl.RawQuery = params.Encode()
2044
2045
2046 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
2047
2048 hds = append(c.xGoogHeaders, hds...)
2049 hds = append(hds, "Content-Type", "application/json")
2050 headers := gax.BuildHeaders(ctx, hds...)
2051 opts = append((*c.CallOptions).CreateSnapshot[0:len((*c.CallOptions).CreateSnapshot):len((*c.CallOptions).CreateSnapshot)], opts...)
2052 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2053 resp := &pubsubpb.Snapshot{}
2054 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2055 if settings.Path != "" {
2056 baseUrl.Path = settings.Path
2057 }
2058 httpReq, err := http.NewRequest("PUT", baseUrl.String(), bytes.NewReader(jsonReq))
2059 if err != nil {
2060 return err
2061 }
2062 httpReq = httpReq.WithContext(ctx)
2063 httpReq.Header = headers
2064
2065 httpRsp, err := c.httpClient.Do(httpReq)
2066 if err != nil {
2067 return err
2068 }
2069 defer httpRsp.Body.Close()
2070
2071 if err = googleapi.CheckResponse(httpRsp); err != nil {
2072 return err
2073 }
2074
2075 buf, err := io.ReadAll(httpRsp.Body)
2076 if err != nil {
2077 return err
2078 }
2079
2080 if err := unm.Unmarshal(buf, resp); err != nil {
2081 return err
2082 }
2083
2084 return nil
2085 }, opts...)
2086 if e != nil {
2087 return nil, e
2088 }
2089 return resp, nil
2090 }
2091
2092
2093
2094
2095
2096
2097
2098 func (c *subscriberRESTClient) UpdateSnapshot(ctx context.Context, req *pubsubpb.UpdateSnapshotRequest, opts ...gax.CallOption) (*pubsubpb.Snapshot, error) {
2099 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
2100 jsonReq, err := m.Marshal(req)
2101 if err != nil {
2102 return nil, err
2103 }
2104
2105 baseUrl, err := url.Parse(c.endpoint)
2106 if err != nil {
2107 return nil, err
2108 }
2109 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetSnapshot().GetName())
2110
2111 params := url.Values{}
2112 params.Add("$alt", "json;enum-encoding=int")
2113
2114 baseUrl.RawQuery = params.Encode()
2115
2116
2117 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "snapshot.name", url.QueryEscape(req.GetSnapshot().GetName()))}
2118
2119 hds = append(c.xGoogHeaders, hds...)
2120 hds = append(hds, "Content-Type", "application/json")
2121 headers := gax.BuildHeaders(ctx, hds...)
2122 opts = append((*c.CallOptions).UpdateSnapshot[0:len((*c.CallOptions).UpdateSnapshot):len((*c.CallOptions).UpdateSnapshot)], opts...)
2123 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2124 resp := &pubsubpb.Snapshot{}
2125 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2126 if settings.Path != "" {
2127 baseUrl.Path = settings.Path
2128 }
2129 httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
2130 if err != nil {
2131 return err
2132 }
2133 httpReq = httpReq.WithContext(ctx)
2134 httpReq.Header = headers
2135
2136 httpRsp, err := c.httpClient.Do(httpReq)
2137 if err != nil {
2138 return err
2139 }
2140 defer httpRsp.Body.Close()
2141
2142 if err = googleapi.CheckResponse(httpRsp); err != nil {
2143 return err
2144 }
2145
2146 buf, err := io.ReadAll(httpRsp.Body)
2147 if err != nil {
2148 return err
2149 }
2150
2151 if err := unm.Unmarshal(buf, resp); err != nil {
2152 return err
2153 }
2154
2155 return nil
2156 }, opts...)
2157 if e != nil {
2158 return nil, e
2159 }
2160 return resp, nil
2161 }
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172 func (c *subscriberRESTClient) DeleteSnapshot(ctx context.Context, req *pubsubpb.DeleteSnapshotRequest, opts ...gax.CallOption) error {
2173 baseUrl, err := url.Parse(c.endpoint)
2174 if err != nil {
2175 return err
2176 }
2177 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetSnapshot())
2178
2179 params := url.Values{}
2180 params.Add("$alt", "json;enum-encoding=int")
2181
2182 baseUrl.RawQuery = params.Encode()
2183
2184
2185 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "snapshot", url.QueryEscape(req.GetSnapshot()))}
2186
2187 hds = append(c.xGoogHeaders, hds...)
2188 hds = append(hds, "Content-Type", "application/json")
2189 headers := gax.BuildHeaders(ctx, hds...)
2190 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2191 if settings.Path != "" {
2192 baseUrl.Path = settings.Path
2193 }
2194 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
2195 if err != nil {
2196 return err
2197 }
2198 httpReq = httpReq.WithContext(ctx)
2199 httpReq.Header = headers
2200
2201 httpRsp, err := c.httpClient.Do(httpReq)
2202 if err != nil {
2203 return err
2204 }
2205 defer httpRsp.Body.Close()
2206
2207
2208
2209 return googleapi.CheckResponse(httpRsp)
2210 }, opts...)
2211 }
2212
2213
2214
2215
2216
2217
2218
2219
2220 func (c *subscriberRESTClient) Seek(ctx context.Context, req *pubsubpb.SeekRequest, opts ...gax.CallOption) (*pubsubpb.SeekResponse, error) {
2221 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
2222 jsonReq, err := m.Marshal(req)
2223 if err != nil {
2224 return nil, err
2225 }
2226
2227 baseUrl, err := url.Parse(c.endpoint)
2228 if err != nil {
2229 return nil, err
2230 }
2231 baseUrl.Path += fmt.Sprintf("/v1/%v:seek", req.GetSubscription())
2232
2233 params := url.Values{}
2234 params.Add("$alt", "json;enum-encoding=int")
2235
2236 baseUrl.RawQuery = params.Encode()
2237
2238
2239 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "subscription", url.QueryEscape(req.GetSubscription()))}
2240
2241 hds = append(c.xGoogHeaders, hds...)
2242 hds = append(hds, "Content-Type", "application/json")
2243 headers := gax.BuildHeaders(ctx, hds...)
2244 opts = append((*c.CallOptions).Seek[0:len((*c.CallOptions).Seek):len((*c.CallOptions).Seek)], opts...)
2245 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2246 resp := &pubsubpb.SeekResponse{}
2247 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2248 if settings.Path != "" {
2249 baseUrl.Path = settings.Path
2250 }
2251 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
2252 if err != nil {
2253 return err
2254 }
2255 httpReq = httpReq.WithContext(ctx)
2256 httpReq.Header = headers
2257
2258 httpRsp, err := c.httpClient.Do(httpReq)
2259 if err != nil {
2260 return err
2261 }
2262 defer httpRsp.Body.Close()
2263
2264 if err = googleapi.CheckResponse(httpRsp); err != nil {
2265 return err
2266 }
2267
2268 buf, err := io.ReadAll(httpRsp.Body)
2269 if err != nil {
2270 return err
2271 }
2272
2273 if err := unm.Unmarshal(buf, resp); err != nil {
2274 return err
2275 }
2276
2277 return nil
2278 }, opts...)
2279 if e != nil {
2280 return nil, e
2281 }
2282 return resp, nil
2283 }
2284
2285
2286
2287 func (c *subscriberRESTClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
2288 baseUrl, err := url.Parse(c.endpoint)
2289 if err != nil {
2290 return nil, err
2291 }
2292 baseUrl.Path += fmt.Sprintf("/v1/%v:getIamPolicy", req.GetResource())
2293
2294 params := url.Values{}
2295 params.Add("$alt", "json;enum-encoding=int")
2296 if req.GetOptions().GetRequestedPolicyVersion() != 0 {
2297 params.Add("options.requestedPolicyVersion", fmt.Sprintf("%v", req.GetOptions().GetRequestedPolicyVersion()))
2298 }
2299
2300 baseUrl.RawQuery = params.Encode()
2301
2302
2303 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
2304
2305 hds = append(c.xGoogHeaders, hds...)
2306 hds = append(hds, "Content-Type", "application/json")
2307 headers := gax.BuildHeaders(ctx, hds...)
2308 opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
2309 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2310 resp := &iampb.Policy{}
2311 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2312 if settings.Path != "" {
2313 baseUrl.Path = settings.Path
2314 }
2315 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
2316 if err != nil {
2317 return err
2318 }
2319 httpReq = httpReq.WithContext(ctx)
2320 httpReq.Header = headers
2321
2322 httpRsp, err := c.httpClient.Do(httpReq)
2323 if err != nil {
2324 return err
2325 }
2326 defer httpRsp.Body.Close()
2327
2328 if err = googleapi.CheckResponse(httpRsp); err != nil {
2329 return err
2330 }
2331
2332 buf, err := io.ReadAll(httpRsp.Body)
2333 if err != nil {
2334 return err
2335 }
2336
2337 if err := unm.Unmarshal(buf, resp); err != nil {
2338 return err
2339 }
2340
2341 return nil
2342 }, opts...)
2343 if e != nil {
2344 return nil, e
2345 }
2346 return resp, nil
2347 }
2348
2349
2350
2351
2352
2353
2354 func (c *subscriberRESTClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
2355 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
2356 jsonReq, err := m.Marshal(req)
2357 if err != nil {
2358 return nil, err
2359 }
2360
2361 baseUrl, err := url.Parse(c.endpoint)
2362 if err != nil {
2363 return nil, err
2364 }
2365 baseUrl.Path += fmt.Sprintf("/v1/%v:setIamPolicy", req.GetResource())
2366
2367 params := url.Values{}
2368 params.Add("$alt", "json;enum-encoding=int")
2369
2370 baseUrl.RawQuery = params.Encode()
2371
2372
2373 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
2374
2375 hds = append(c.xGoogHeaders, hds...)
2376 hds = append(hds, "Content-Type", "application/json")
2377 headers := gax.BuildHeaders(ctx, hds...)
2378 opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
2379 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2380 resp := &iampb.Policy{}
2381 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2382 if settings.Path != "" {
2383 baseUrl.Path = settings.Path
2384 }
2385 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
2386 if err != nil {
2387 return err
2388 }
2389 httpReq = httpReq.WithContext(ctx)
2390 httpReq.Header = headers
2391
2392 httpRsp, err := c.httpClient.Do(httpReq)
2393 if err != nil {
2394 return err
2395 }
2396 defer httpRsp.Body.Close()
2397
2398 if err = googleapi.CheckResponse(httpRsp); err != nil {
2399 return err
2400 }
2401
2402 buf, err := io.ReadAll(httpRsp.Body)
2403 if err != nil {
2404 return err
2405 }
2406
2407 if err := unm.Unmarshal(buf, resp); err != nil {
2408 return err
2409 }
2410
2411 return nil
2412 }, opts...)
2413 if e != nil {
2414 return nil, e
2415 }
2416 return resp, nil
2417 }
2418
2419
2420
2421
2422
2423
2424
2425
2426 func (c *subscriberRESTClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
2427 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
2428 jsonReq, err := m.Marshal(req)
2429 if err != nil {
2430 return nil, err
2431 }
2432
2433 baseUrl, err := url.Parse(c.endpoint)
2434 if err != nil {
2435 return nil, err
2436 }
2437 baseUrl.Path += fmt.Sprintf("/v1/%v:testIamPermissions", req.GetResource())
2438
2439 params := url.Values{}
2440 params.Add("$alt", "json;enum-encoding=int")
2441
2442 baseUrl.RawQuery = params.Encode()
2443
2444
2445 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
2446
2447 hds = append(c.xGoogHeaders, hds...)
2448 hds = append(hds, "Content-Type", "application/json")
2449 headers := gax.BuildHeaders(ctx, hds...)
2450 opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...)
2451 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2452 resp := &iampb.TestIamPermissionsResponse{}
2453 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2454 if settings.Path != "" {
2455 baseUrl.Path = settings.Path
2456 }
2457 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
2458 if err != nil {
2459 return err
2460 }
2461 httpReq = httpReq.WithContext(ctx)
2462 httpReq.Header = headers
2463
2464 httpRsp, err := c.httpClient.Do(httpReq)
2465 if err != nil {
2466 return err
2467 }
2468 defer httpRsp.Body.Close()
2469
2470 if err = googleapi.CheckResponse(httpRsp); err != nil {
2471 return err
2472 }
2473
2474 buf, err := io.ReadAll(httpRsp.Body)
2475 if err != nil {
2476 return err
2477 }
2478
2479 if err := unm.Unmarshal(buf, resp); err != nil {
2480 return err
2481 }
2482
2483 return nil
2484 }, opts...)
2485 if e != nil {
2486 return nil, e
2487 }
2488 return resp, nil
2489 }
2490
View as plain text