Debian Codegraph @

pubsub/v2/apiv1/subscription_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 "errors"
23 "fmt"
24 "log/slog"
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/v2/apiv1/pubsubpb"
32 gax "github.com/googleapis/gax-go/v2"
33 "google.golang.org/api/iterator"
34 "google.golang.org/api/option"
35 "google.golang.org/api/option/internaloption"
36 gtransport "google.golang.org/api/transport/grpc"
37 httptransport "google.golang.org/api/transport/http"
38 "google.golang.org/grpc"
39 "google.golang.org/grpc/codes"
40 "google.golang.org/protobuf/encoding/protojson"
41 "google.golang.org/protobuf/proto"
42 )
43
44 var newSubscriptionAdminClientHook clientHook
45
46 // SubscriptionAdminCallOptions contains the retry settings for each method of SubscriptionAdminClient.
47 type SubscriptionAdminCallOptions struct {
48 CreateSubscription []gax.CallOption
49 GetSubscription []gax.CallOption
50 UpdateSubscription []gax.CallOption
51 ListSubscriptions []gax.CallOption
52 DeleteSubscription []gax.CallOption
53 ModifyAckDeadline []gax.CallOption
54 Acknowledge []gax.CallOption
55 Pull []gax.CallOption
56 StreamingPull []gax.CallOption
57 ModifyPushConfig []gax.CallOption
58 GetSnapshot []gax.CallOption
59 ListSnapshots []gax.CallOption
60 CreateSnapshot []gax.CallOption
61 UpdateSnapshot []gax.CallOption
62 DeleteSnapshot []gax.CallOption
63 Seek []gax.CallOption
64 GetIamPolicy []gax.CallOption
65 SetIamPolicy []gax.CallOption
66 TestIamPermissions []gax.CallOption
67 }
68
69 func defaultSubscriptionAdminGRPCClientOptions() []option.ClientOption {
70 return []option.ClientOption{
71 internaloption.WithDefaultEndpoint("pubsub.googleapis.com:443"),
72 internaloption.WithDefaultEndpointTemplate("pubsub.UNIVERSE_DOMAIN:443"),
73 internaloption.WithDefaultMTLSEndpoint("pubsub.mtls.googleapis.com:443"),
74 internaloption.WithDefaultUniverseDomain("googleapis.com"),
75 internaloption.WithDefaultAudience("https://pubsub.googleapis.com/"),
76 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
77 internaloption.EnableJwtWithScope(),
78 internaloption.EnableNewAuthLibrary(),
79 option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
80 grpc.MaxCallRecvMsgSize(math.MaxInt32))),
81 }
82 }
83
84 func defaultSubscriptionAdminCallOptions() *SubscriptionAdminCallOptions {
85 return &SubscriptionAdminCallOptions{
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 defaultSubscriptionAdminRESTCallOptions() *SubscriptionAdminCallOptions {
303 return &SubscriptionAdminCallOptions{
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 // internalSubscriptionAdminClient is an interface that defines the methods available from Cloud Pub/Sub API.
506 type internalSubscriptionAdminClient 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 // SubscriptionAdminClient is a client for interacting with Cloud Pub/Sub API.
532 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
533 //
534 // The service that an application uses to manipulate subscriptions and to
535 // consume messages from a subscription via the Pull method or by
536 // establishing a bi-directional stream using the StreamingPull method.
537 type SubscriptionAdminClient struct {
538 // The internal transport-dependent client.
539 internalClient internalSubscriptionAdminClient
540
541 // The call options for this service.
542 CallOptions *SubscriptionAdminCallOptions
543 }
544
545 // Wrapper methods routed to the internal client.
546
547 // Close closes the connection to the API service. The user should invoke this when
548 // the client is no longer required.
549 func (c *SubscriptionAdminClient) Close() error {
550 return c.internalClient.Close()
551 }
552
553 // setGoogleClientInfo sets the name and version of the application in
554 // the `x-goog-api-client` header passed on each request. Intended for
555 // use by Google-written clients.
556 func (c *SubscriptionAdminClient) setGoogleClientInfo(keyval ...string) {
557 c.internalClient.setGoogleClientInfo(keyval...)
558 }
559
560 // Connection returns a connection to the API service.
561 //
562 // Deprecated: Connections are now pooled so this method does not always
563 // return the same resource.
564 func (c *SubscriptionAdminClient) Connection() *grpc.ClientConn {
565 return c.internalClient.Connection()
566 }
567
568 // CreateSubscription creates a subscription to a given topic. See the [resource name rules]
569 // (https://cloud.google.com/pubsub/docs/pubsub-basics#resource_names (at https://cloud.google.com/pubsub/docs/pubsub-basics#resource_names)).
570 // If the subscription already exists, returns ALREADY_EXISTS.
571 // If the corresponding topic doesn’t exist, returns NOT_FOUND.
572 //
573 // If the name is not provided in the request, the server will assign a random
574 // name for this subscription on the same project as the topic, conforming
575 // to the [resource name format]
576 // (https://cloud.google.com/pubsub/docs/pubsub-basics#resource_names (at https://cloud.google.com/pubsub/docs/pubsub-basics#resource_names)). The
577 // generated name is populated in the returned Subscription object. Note that
578 // for REST API requests, you must specify a name in the request.
579 func (c *SubscriptionAdminClient) CreateSubscription(ctx context.Context, req *pubsubpb.Subscription, opts ...gax.CallOption) (*pubsubpb.Subscription, error) {
580 return c.internalClient.CreateSubscription(ctx, req, opts...)
581 }
582
583 // GetSubscription gets the configuration details of a subscription.
584 func (c *SubscriptionAdminClient) GetSubscription(ctx context.Context, req *pubsubpb.GetSubscriptionRequest, opts ...gax.CallOption) (*pubsubpb.Subscription, error) {
585 return c.internalClient.GetSubscription(ctx, req, opts...)
586 }
587
588 // UpdateSubscription updates an existing subscription by updating the fields specified in the
589 // update mask. Note that certain properties of a subscription, such as its
590 // topic, are not modifiable.
591 func (c *SubscriptionAdminClient) UpdateSubscription(ctx context.Context, req *pubsubpb.UpdateSubscriptionRequest, opts ...gax.CallOption) (*pubsubpb.Subscription, error) {
592 return c.internalClient.UpdateSubscription(ctx, req, opts...)
593 }
594
595 // ListSubscriptions lists matching subscriptions.
596 func (c *SubscriptionAdminClient) ListSubscriptions(ctx context.Context, req *pubsubpb.ListSubscriptionsRequest, opts ...gax.CallOption) *SubscriptionIterator {
597 return c.internalClient.ListSubscriptions(ctx, req, opts...)
598 }
599
600 // DeleteSubscription deletes an existing subscription. All messages retained in the subscription
601 // are immediately dropped. Calls to Pull after deletion will return
602 // NOT_FOUND. After a subscription is deleted, a new one may be created with
603 // the same name, but the new one has no association with the old
604 // subscription or its topic unless the same topic is specified.
605 func (c *SubscriptionAdminClient) DeleteSubscription(ctx context.Context, req *pubsubpb.DeleteSubscriptionRequest, opts ...gax.CallOption) error {
606 return c.internalClient.DeleteSubscription(ctx, req, opts...)
607 }
608
609 // ModifyAckDeadline modifies the ack deadline for a specific message. This method is useful
610 // to indicate that more time is needed to process a message by the
611 // subscriber, or to make the message available for redelivery if the
612 // processing was interrupted. Note that this does not modify the
613 // subscription-level ackDeadlineSeconds used for subsequent messages.
614 func (c *SubscriptionAdminClient) ModifyAckDeadline(ctx context.Context, req *pubsubpb.ModifyAckDeadlineRequest, opts ...gax.CallOption) error {
615 return c.internalClient.ModifyAckDeadline(ctx, req, opts...)
616 }
617
618 // Acknowledge acknowledges the messages associated with the ack_ids in the
619 // AcknowledgeRequest. The Pub/Sub system can remove the relevant messages
620 // from the subscription.
621 //
622 // Acknowledging a message whose ack deadline has expired may succeed,
623 // but such a message may be redelivered later. Acknowledging a message more
624 // than once will not result in an error.
625 func (c *SubscriptionAdminClient) Acknowledge(ctx context.Context, req *pubsubpb.AcknowledgeRequest, opts ...gax.CallOption) error {
626 return c.internalClient.Acknowledge(ctx, req, opts...)
627 }
628
629 // Pull pulls messages from the server.
630 func (c *SubscriptionAdminClient) Pull(ctx context.Context, req *pubsubpb.PullRequest, opts ...gax.CallOption) (*pubsubpb.PullResponse, error) {
631 return c.internalClient.Pull(ctx, req, opts...)
632 }
633
634 // StreamingPull establishes a stream with the server, which sends messages down to the
635 // client. The client streams acknowledgments and ack deadline modifications
636 // back to the server. The server will close the stream and return the status
637 // on any error. The server may close the stream with status UNAVAILABLE to
638 // reassign server-side resources, in which case, the client should
639 // re-establish the stream. Flow control can be achieved by configuring the
640 // underlying RPC channel.
641 //
642 // This method is not supported for the REST transport.
643 func (c *SubscriptionAdminClient) StreamingPull(ctx context.Context, opts ...gax.CallOption) (pubsubpb.Subscriber_StreamingPullClient, error) {
644 return c.internalClient.StreamingPull(ctx, opts...)
645 }
646
647 // ModifyPushConfig modifies the PushConfig for a specified subscription.
648 //
649 // This may be used to change a push subscription to a pull one (signified by
650 // an empty PushConfig) or vice versa, or change the endpoint URL and other
651 // attributes of a push subscription. Messages will accumulate for delivery
652 // continuously through the call regardless of changes to the PushConfig.
653 func (c *SubscriptionAdminClient) ModifyPushConfig(ctx context.Context, req *pubsubpb.ModifyPushConfigRequest, opts ...gax.CallOption) error {
654 return c.internalClient.ModifyPushConfig(ctx, req, opts...)
655 }
656
657 // GetSnapshot gets the configuration details of a snapshot. Snapshots are used in
658 // Seek (at https://cloud.google.com/pubsub/docs/replay-overview) operations,
659 // which allow you to manage message acknowledgments in bulk. That is, you can
660 // set the acknowledgment state of messages in an existing subscription to the
661 // state captured by a snapshot.
662 func (c *SubscriptionAdminClient) GetSnapshot(ctx context.Context, req *pubsubpb.GetSnapshotRequest, opts ...gax.CallOption) (*pubsubpb.Snapshot, error) {
663 return c.internalClient.GetSnapshot(ctx, req, opts...)
664 }
665
666 // ListSnapshots lists the existing snapshots. Snapshots are used in Seek (at https://cloud.google.com/pubsub/docs/replay-overview) operations, which
667 // allow you to manage message acknowledgments in bulk. That is, you can set
668 // the acknowledgment state of messages in an existing subscription to the
669 // state captured by a snapshot.
670 func (c *SubscriptionAdminClient) ListSnapshots(ctx context.Context, req *pubsubpb.ListSnapshotsRequest, opts ...gax.CallOption) *SnapshotIterator {
671 return c.internalClient.ListSnapshots(ctx, req, opts...)
672 }
673
674 // CreateSnapshot creates a snapshot from the requested subscription. Snapshots are used in
675 // Seek (at https://cloud.google.com/pubsub/docs/replay-overview) operations,
676 // which allow you to manage message acknowledgments in bulk. That is, you can
677 // set the acknowledgment state of messages in an existing subscription to the
678 // state captured by a snapshot.
679 // If the snapshot already exists, returns ALREADY_EXISTS.
680 // If the requested subscription doesn’t exist, returns NOT_FOUND.
681 // If the backlog in the subscription is too old – and the resulting snapshot
682 // would expire in less than 1 hour – then FAILED_PRECONDITION is returned.
683 // See also the Snapshot.expire_time field. If the name is not provided in
684 // the request, the server will assign a random
685 // name for this snapshot on the same project as the subscription, conforming
686 // to the [resource name format]
687 // (https://cloud.google.com/pubsub/docs/pubsub-basics#resource_names (at https://cloud.google.com/pubsub/docs/pubsub-basics#resource_names)). The
688 // generated name is populated in the returned Snapshot object. Note that for
689 // REST API requests, you must specify a name in the request.
690 func (c *SubscriptionAdminClient) CreateSnapshot(ctx context.Context, req *pubsubpb.CreateSnapshotRequest, opts ...gax.CallOption) (*pubsubpb.Snapshot, error) {
691 return c.internalClient.CreateSnapshot(ctx, req, opts...)
692 }
693
694 // UpdateSnapshot updates an existing snapshot by updating the fields specified in the update
695 // mask. Snapshots are used in
696 // Seek (at https://cloud.google.com/pubsub/docs/replay-overview) operations,
697 // which allow you to manage message acknowledgments in bulk. That is, you can
698 // set the acknowledgment state of messages in an existing subscription to the
699 // state captured by a snapshot.
700 func (c *SubscriptionAdminClient) UpdateSnapshot(ctx context.Context, req *pubsubpb.UpdateSnapshotRequest, opts ...gax.CallOption) (*pubsubpb.Snapshot, error) {
701 return c.internalClient.UpdateSnapshot(ctx, req, opts...)
702 }
703
704 // DeleteSnapshot removes an existing snapshot. Snapshots are used in [Seek]
705 // (https://cloud.google.com/pubsub/docs/replay-overview (at https://cloud.google.com/pubsub/docs/replay-overview)) operations, which
706 // allow you to manage message acknowledgments in bulk. That is, you can set
707 // the acknowledgment state of messages in an existing subscription to the
708 // state captured by a snapshot.
709 // When the snapshot is deleted, all messages retained in the snapshot
710 // are immediately dropped. After a snapshot is deleted, a new one may be
711 // created with the same name, but the new one has no association with the old
712 // snapshot or its subscription, unless the same subscription is specified.
713 func (c *SubscriptionAdminClient) DeleteSnapshot(ctx context.Context, req *pubsubpb.DeleteSnapshotRequest, opts ...gax.CallOption) error {
714 return c.internalClient.DeleteSnapshot(ctx, req, opts...)
715 }
716
717 // Seek seeks an existing subscription to a point in time or to a given snapshot,
718 // whichever is provided in the request. Snapshots are used in [Seek]
719 // (https://cloud.google.com/pubsub/docs/replay-overview (at https://cloud.google.com/pubsub/docs/replay-overview)) operations, which
720 // allow you to manage message acknowledgments in bulk. That is, you can set
721 // the acknowledgment state of messages in an existing subscription to the
722 // state captured by a snapshot. Note that both the subscription and the
723 // snapshot must be on the same topic.
724 func (c *SubscriptionAdminClient) Seek(ctx context.Context, req *pubsubpb.SeekRequest, opts ...gax.CallOption) (*pubsubpb.SeekResponse, error) {
725 return c.internalClient.Seek(ctx, req, opts...)
726 }
727
728 // GetIamPolicy gets the access control policy for a resource. Returns an empty policy
729 // if the resource exists and does not have a policy set.
730 func (c *SubscriptionAdminClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
731 return c.internalClient.GetIamPolicy(ctx, req, opts...)
732 }
733
734 // SetIamPolicy sets the access control policy on the specified resource. Replaces
735 // any existing policy.
736 //
737 // Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED
738 // errors.
739 func (c *SubscriptionAdminClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
740 return c.internalClient.SetIamPolicy(ctx, req, opts...)
741 }
742
743 // TestIamPermissions returns permissions that a caller has on the specified resource. If the
744 // resource does not exist, this will return an empty set of
745 // permissions, not a NOT_FOUND error.
746 //
747 // Note: This operation is designed to be used for building
748 // permission-aware UIs and command-line tools, not for authorization
749 // checking. This operation may “fail open” without warning.
750 func (c *SubscriptionAdminClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
751 return c.internalClient.TestIamPermissions(ctx, req, opts...)
752 }
753
754 // subscriptionAdminGRPCClient is a client for interacting with Cloud Pub/Sub API over gRPC transport.
755 //
756 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
757 type subscriptionAdminGRPCClient struct {
758 // Connection pool of gRPC connections to the service.
759 connPool gtransport.ConnPool
760
761 // Points back to the CallOptions field of the containing SubscriptionAdminClient
762 CallOptions **SubscriptionAdminCallOptions
763
764 // The gRPC API client.
765 subscriptionAdminClient pubsubpb.SubscriberClient
766
767 iamPolicyClient iampb.IAMPolicyClient
768
769 // The x-goog-* metadata to be sent with each request.
770 xGoogHeaders []string
771
772 logger *slog.Logger
773 }
774
775 // NewSubscriptionAdminClient creates a new subscription admin client based on gRPC.
776 // The returned client must be Closed when it is done being used to clean up its underlying connections.
777 //
778 // The service that an application uses to manipulate subscriptions and to
779 // consume messages from a subscription via the Pull method or by
780 // establishing a bi-directional stream using the StreamingPull method.
781 func NewSubscriptionAdminClient(ctx context.Context, opts ...option.ClientOption) (*SubscriptionAdminClient, error) {
782 clientOpts := defaultSubscriptionAdminGRPCClientOptions()
783 if newSubscriptionAdminClientHook != nil {
784 hookOpts, err := newSubscriptionAdminClientHook(ctx, clientHookParams{})
785 if err != nil {
786 return nil, err
787 }
788 clientOpts = append(clientOpts, hookOpts...)
789 }
790
791 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
792 if err != nil {
793 return nil, err
794 }
795 client := SubscriptionAdminClient{CallOptions: defaultSubscriptionAdminCallOptions()}
796
797 c := &subscriptionAdminGRPCClient{
798 connPool: connPool,
799 subscriptionAdminClient: pubsubpb.NewSubscriberClient(connPool),
800 CallOptions: &client.CallOptions,
801 logger: internaloption.GetLogger(opts),
802 iamPolicyClient: iampb.NewIAMPolicyClient(connPool),
803 }
804 c.setGoogleClientInfo()
805
806 client.internalClient = c
807
808 return &client, nil
809 }
810
811 // Connection returns a connection to the API service.
812 //
813 // Deprecated: Connections are now pooled so this method does not always
814 // return the same resource.
815 func (c *subscriptionAdminGRPCClient) Connection() *grpc.ClientConn {
816 return c.connPool.Conn()
817 }
818
819 // setGoogleClientInfo sets the name and version of the application in
820 // the `x-goog-api-client` header passed on each request. Intended for
821 // use by Google-written clients.
822 func (c *subscriptionAdminGRPCClient) setGoogleClientInfo(keyval ...string) {
823 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
824 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
825 c.xGoogHeaders = []string{
826 "x-goog-api-client", gax.XGoogHeader(kv...),
827 }
828 }
829
830 // Close closes the connection to the API service. The user should invoke this when
831 // the client is no longer required.
832 func (c *subscriptionAdminGRPCClient) Close() error {
833 return c.connPool.Close()
834 }
835
836 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
837 type subscriptionAdminRESTClient struct {
838 // The http endpoint to connect to.
839 endpoint string
840
841 // The http client.
842 httpClient *http.Client
843
844 // The x-goog-* headers to be sent with each request.
845 xGoogHeaders []string
846
847 // Points back to the CallOptions field of the containing SubscriptionAdminClient
848 CallOptions **SubscriptionAdminCallOptions
849
850 logger *slog.Logger
851 }
852
853 // NewSubscriptionAdminRESTClient creates a new subscription admin rest client.
854 //
855 // The service that an application uses to manipulate subscriptions and to
856 // consume messages from a subscription via the Pull method or by
857 // establishing a bi-directional stream using the StreamingPull method.
858 func NewSubscriptionAdminRESTClient(ctx context.Context, opts ...option.ClientOption) (*SubscriptionAdminClient, error) {
859 clientOpts := append(defaultSubscriptionAdminRESTClientOptions(), opts...)
860 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
861 if err != nil {
862 return nil, err
863 }
864
865 callOpts := defaultSubscriptionAdminRESTCallOptions()
866 c := &subscriptionAdminRESTClient{
867 endpoint: endpoint,
868 httpClient: httpClient,
869 CallOptions: &callOpts,
870 logger: internaloption.GetLogger(opts),
871 }
872 c.setGoogleClientInfo()
873
874 return &SubscriptionAdminClient{internalClient: c, CallOptions: callOpts}, nil
875 }
876
877 func defaultSubscriptionAdminRESTClientOptions() []option.ClientOption {
878 return []option.ClientOption{
879 internaloption.WithDefaultEndpoint("https://pubsub.googleapis.com"),
880 internaloption.WithDefaultEndpointTemplate("https://pubsub.UNIVERSE_DOMAIN"),
881 internaloption.WithDefaultMTLSEndpoint("https://pubsub.mtls.googleapis.com"),
882 internaloption.WithDefaultUniverseDomain("googleapis.com"),
883 internaloption.WithDefaultAudience("https://pubsub.googleapis.com/"),
884 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
885 internaloption.EnableNewAuthLibrary(),
886 }
887 }
888
889 // setGoogleClientInfo sets the name and version of the application in
890 // the `x-goog-api-client` header passed on each request. Intended for
891 // use by Google-written clients.
892 func (c *subscriptionAdminRESTClient) setGoogleClientInfo(keyval ...string) {
893 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
894 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
895 c.xGoogHeaders = []string{
896 "x-goog-api-client", gax.XGoogHeader(kv...),
897 }
898 }
899
900 // Close closes the connection to the API service. The user should invoke this when
901 // the client is no longer required.
902 func (c *subscriptionAdminRESTClient) Close() error {
903 // Replace httpClient with nil to force cleanup.
904 c.httpClient = nil
905 return nil
906 }
907
908 // Connection returns a connection to the API service.
909 //
910 // Deprecated: This method always returns nil.
911 func (c *subscriptionAdminRESTClient) Connection() *grpc.ClientConn {
912 return nil
913 }
914 func (c *subscriptionAdminGRPCClient) CreateSubscription(ctx context.Context, req *pubsubpb.Subscription, opts ...gax.CallOption) (*pubsubpb.Subscription, error) {
915 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
916
917 hds = append(c.xGoogHeaders, hds...)
918 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
919 opts = append((*c.CallOptions).CreateSubscription[0:len((*c.CallOptions).CreateSubscription):len((*c.CallOptions).CreateSubscription)], opts...)
920 var resp *pubsubpb.Subscription
921 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
922 var err error
923 resp, err = executeRPC(ctx, c.subscriptionAdminClient.CreateSubscription, req, settings.GRPC, c.logger, "CreateSubscription")
924 return err
925 }, opts...)
926 if err != nil {
927 return nil, err
928 }
929 return resp, nil
930 }
931
932 func (c *subscriptionAdminGRPCClient) GetSubscription(ctx context.Context, req *pubsubpb.GetSubscriptionRequest, opts ...gax.CallOption) (*pubsubpb.Subscription, error) {
933 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "subscription", url.QueryEscape(req.GetSubscription()))}
934
935 hds = append(c.xGoogHeaders, hds...)
936 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
937 opts = append((*c.CallOptions).GetSubscription[0:len((*c.CallOptions).GetSubscription):len((*c.CallOptions).GetSubscription)], opts...)
938 var resp *pubsubpb.Subscription
939 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
940 var err error
941 resp, err = executeRPC(ctx, c.subscriptionAdminClient.GetSubscription, req, settings.GRPC, c.logger, "GetSubscription")
942 return err
943 }, opts...)
944 if err != nil {
945 return nil, err
946 }
947 return resp, nil
948 }
949
950 func (c *subscriptionAdminGRPCClient) UpdateSubscription(ctx context.Context, req *pubsubpb.UpdateSubscriptionRequest, opts ...gax.CallOption) (*pubsubpb.Subscription, error) {
951 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "subscription.name", url.QueryEscape(req.GetSubscription().GetName()))}
952
953 hds = append(c.xGoogHeaders, hds...)
954 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
955 opts = append((*c.CallOptions).UpdateSubscription[0:len((*c.CallOptions).UpdateSubscription):len((*c.CallOptions).UpdateSubscription)], opts...)
956 var resp *pubsubpb.Subscription
957 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
958 var err error
959 resp, err = executeRPC(ctx, c.subscriptionAdminClient.UpdateSubscription, req, settings.GRPC, c.logger, "UpdateSubscription")
960 return err
961 }, opts...)
962 if err != nil {
963 return nil, err
964 }
965 return resp, nil
966 }
967
968 func (c *subscriptionAdminGRPCClient) ListSubscriptions(ctx context.Context, req *pubsubpb.ListSubscriptionsRequest, opts ...gax.CallOption) *SubscriptionIterator {
969 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "project", url.QueryEscape(req.GetProject()))}
970
971 hds = append(c.xGoogHeaders, hds...)
972 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
973 opts = append((*c.CallOptions).ListSubscriptions[0:len((*c.CallOptions).ListSubscriptions):len((*c.CallOptions).ListSubscriptions)], opts...)
974 it := &SubscriptionIterator{}
975 req = proto.Clone(req).(*pubsubpb.ListSubscriptionsRequest)
976 it.InternalFetch = func(pageSize int, pageToken string) ([]*pubsubpb.Subscription, string, error) {
977 resp := &pubsubpb.ListSubscriptionsResponse{}
978 if pageToken != "" {
979 req.PageToken = pageToken
980 }
981 if pageSize > math.MaxInt32 {
982 req.PageSize = math.MaxInt32
983 } else if pageSize != 0 {
984 req.PageSize = int32(pageSize)
985 }
986 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
987 var err error
988 resp, err = executeRPC(ctx, c.subscriptionAdminClient.ListSubscriptions, req, settings.GRPC, c.logger, "ListSubscriptions")
989 return err
990 }, opts...)
991 if err != nil {
992 return nil, "", err
993 }
994
995 it.Response = resp
996 return resp.GetSubscriptions(), resp.GetNextPageToken(), nil
997 }
998 fetch := func(pageSize int, pageToken string) (string, error) {
999 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1000 if err != nil {
1001 return "", err
1002 }
1003 it.items = append(it.items, items...)
1004 return nextPageToken, nil
1005 }
1006
1007 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1008 it.pageInfo.MaxSize = int(req.GetPageSize())
1009 it.pageInfo.Token = req.GetPageToken()
1010
1011 return it
1012 }
1013
1014 func (c *subscriptionAdminGRPCClient) DeleteSubscription(ctx context.Context, req *pubsubpb.DeleteSubscriptionRequest, opts ...gax.CallOption) error {
1015 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "subscription", url.QueryEscape(req.GetSubscription()))}
1016
1017 hds = append(c.xGoogHeaders, hds...)
1018 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1019 opts = append((*c.CallOptions).DeleteSubscription[0:len((*c.CallOptions).DeleteSubscription):len((*c.CallOptions).DeleteSubscription)], opts...)
1020 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1021 var err error
1022 _, err = executeRPC(ctx, c.subscriptionAdminClient.DeleteSubscription, req, settings.GRPC, c.logger, "DeleteSubscription")
1023 return err
1024 }, opts...)
1025 return err
1026 }
1027
1028 func (c *subscriptionAdminGRPCClient) ModifyAckDeadline(ctx context.Context, req *pubsubpb.ModifyAckDeadlineRequest, opts ...gax.CallOption) error {
1029 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "subscription", url.QueryEscape(req.GetSubscription()))}
1030
1031 hds = append(c.xGoogHeaders, hds...)
1032 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1033 opts = append((*c.CallOptions).ModifyAckDeadline[0:len((*c.CallOptions).ModifyAckDeadline):len((*c.CallOptions).ModifyAckDeadline)], opts...)
1034 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1035 var err error
1036 _, err = executeRPC(ctx, c.subscriptionAdminClient.ModifyAckDeadline, req, settings.GRPC, c.logger, "ModifyAckDeadline")
1037 return err
1038 }, opts...)
1039 return err
1040 }
1041
1042 func (c *subscriptionAdminGRPCClient) Acknowledge(ctx context.Context, req *pubsubpb.AcknowledgeRequest, opts ...gax.CallOption) error {
1043 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "subscription", url.QueryEscape(req.GetSubscription()))}
1044
1045 hds = append(c.xGoogHeaders, hds...)
1046 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1047 opts = append((*c.CallOptions).Acknowledge[0:len((*c.CallOptions).Acknowledge):len((*c.CallOptions).Acknowledge)], opts...)
1048 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1049 var err error
1050 _, err = executeRPC(ctx, c.subscriptionAdminClient.Acknowledge, req, settings.GRPC, c.logger, "Acknowledge")
1051 return err
1052 }, opts...)
1053 return err
1054 }
1055
1056 func (c *subscriptionAdminGRPCClient) Pull(ctx context.Context, req *pubsubpb.PullRequest, opts ...gax.CallOption) (*pubsubpb.PullResponse, error) {
1057 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "subscription", url.QueryEscape(req.GetSubscription()))}
1058
1059 hds = append(c.xGoogHeaders, hds...)
1060 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1061 opts = append((*c.CallOptions).Pull[0:len((*c.CallOptions).Pull):len((*c.CallOptions).Pull)], opts...)
1062 var resp *pubsubpb.PullResponse
1063 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1064 var err error
1065 resp, err = executeRPC(ctx, c.subscriptionAdminClient.Pull, req, settings.GRPC, c.logger, "Pull")
1066 return err
1067 }, opts...)
1068 if err != nil {
1069 return nil, err
1070 }
1071 return resp, nil
1072 }
1073
1074 func (c *subscriptionAdminGRPCClient) StreamingPull(ctx context.Context, opts ...gax.CallOption) (pubsubpb.Subscriber_StreamingPullClient, error) {
1075 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...)
1076 var resp pubsubpb.Subscriber_StreamingPullClient
1077 opts = append((*c.CallOptions).StreamingPull[0:len((*c.CallOptions).StreamingPull):len((*c.CallOptions).StreamingPull)], opts...)
1078 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1079 var err error
1080 c.logger.DebugContext(ctx, "api streaming client request", "serviceName", serviceName, "rpcName", "StreamingPull")
1081 resp, err = c.subscriptionAdminClient.StreamingPull(ctx, settings.GRPC...)
1082 c.logger.DebugContext(ctx, "api streaming client response", "serviceName", serviceName, "rpcName", "StreamingPull")
1083 return err
1084 }, opts...)
1085 if err != nil {
1086 return nil, err
1087 }
1088 return resp, nil
1089 }
1090
1091 func (c *subscriptionAdminGRPCClient) ModifyPushConfig(ctx context.Context, req *pubsubpb.ModifyPushConfigRequest, opts ...gax.CallOption) error {
1092 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "subscription", url.QueryEscape(req.GetSubscription()))}
1093
1094 hds = append(c.xGoogHeaders, hds...)
1095 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1096 opts = append((*c.CallOptions).ModifyPushConfig[0:len((*c.CallOptions).ModifyPushConfig):len((*c.CallOptions).ModifyPushConfig)], opts...)
1097 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1098 var err error
1099 _, err = executeRPC(ctx, c.subscriptionAdminClient.ModifyPushConfig, req, settings.GRPC, c.logger, "ModifyPushConfig")
1100 return err
1101 }, opts...)
1102 return err
1103 }
1104
1105 func (c *subscriptionAdminGRPCClient) GetSnapshot(ctx context.Context, req *pubsubpb.GetSnapshotRequest, opts ...gax.CallOption) (*pubsubpb.Snapshot, error) {
1106 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "snapshot", url.QueryEscape(req.GetSnapshot()))}
1107
1108 hds = append(c.xGoogHeaders, hds...)
1109 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1110 opts = append((*c.CallOptions).GetSnapshot[0:len((*c.CallOptions).GetSnapshot):len((*c.CallOptions).GetSnapshot)], opts...)
1111 var resp *pubsubpb.Snapshot
1112 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1113 var err error
1114 resp, err = executeRPC(ctx, c.subscriptionAdminClient.GetSnapshot, req, settings.GRPC, c.logger, "GetSnapshot")
1115 return err
1116 }, opts...)
1117 if err != nil {
1118 return nil, err
1119 }
1120 return resp, nil
1121 }
1122
1123 func (c *subscriptionAdminGRPCClient) ListSnapshots(ctx context.Context, req *pubsubpb.ListSnapshotsRequest, opts ...gax.CallOption) *SnapshotIterator {
1124 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "project", url.QueryEscape(req.GetProject()))}
1125
1126 hds = append(c.xGoogHeaders, hds...)
1127 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1128 opts = append((*c.CallOptions).ListSnapshots[0:len((*c.CallOptions).ListSnapshots):len((*c.CallOptions).ListSnapshots)], opts...)
1129 it := &SnapshotIterator{}
1130 req = proto.Clone(req).(*pubsubpb.ListSnapshotsRequest)
1131 it.InternalFetch = func(pageSize int, pageToken string) ([]*pubsubpb.Snapshot, string, error) {
1132 resp := &pubsubpb.ListSnapshotsResponse{}
1133 if pageToken != "" {
1134 req.PageToken = pageToken
1135 }
1136 if pageSize > math.MaxInt32 {
1137 req.PageSize = math.MaxInt32
1138 } else if pageSize != 0 {
1139 req.PageSize = int32(pageSize)
1140 }
1141 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1142 var err error
1143 resp, err = executeRPC(ctx, c.subscriptionAdminClient.ListSnapshots, req, settings.GRPC, c.logger, "ListSnapshots")
1144 return err
1145 }, opts...)
1146 if err != nil {
1147 return nil, "", err
1148 }
1149
1150 it.Response = resp
1151 return resp.GetSnapshots(), resp.GetNextPageToken(), nil
1152 }
1153 fetch := func(pageSize int, pageToken string) (string, error) {
1154 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1155 if err != nil {
1156 return "", err
1157 }
1158 it.items = append(it.items, items...)
1159 return nextPageToken, nil
1160 }
1161
1162 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1163 it.pageInfo.MaxSize = int(req.GetPageSize())
1164 it.pageInfo.Token = req.GetPageToken()
1165
1166 return it
1167 }
1168
1169 func (c *subscriptionAdminGRPCClient) CreateSnapshot(ctx context.Context, req *pubsubpb.CreateSnapshotRequest, opts ...gax.CallOption) (*pubsubpb.Snapshot, error) {
1170 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1171
1172 hds = append(c.xGoogHeaders, hds...)
1173 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1174 opts = append((*c.CallOptions).CreateSnapshot[0:len((*c.CallOptions).CreateSnapshot):len((*c.CallOptions).CreateSnapshot)], opts...)
1175 var resp *pubsubpb.Snapshot
1176 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1177 var err error
1178 resp, err = executeRPC(ctx, c.subscriptionAdminClient.CreateSnapshot, req, settings.GRPC, c.logger, "CreateSnapshot")
1179 return err
1180 }, opts...)
1181 if err != nil {
1182 return nil, err
1183 }
1184 return resp, nil
1185 }
1186
1187 func (c *subscriptionAdminGRPCClient) UpdateSnapshot(ctx context.Context, req *pubsubpb.UpdateSnapshotRequest, opts ...gax.CallOption) (*pubsubpb.Snapshot, error) {
1188 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "snapshot.name", url.QueryEscape(req.GetSnapshot().GetName()))}
1189
1190 hds = append(c.xGoogHeaders, hds...)
1191 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1192 opts = append((*c.CallOptions).UpdateSnapshot[0:len((*c.CallOptions).UpdateSnapshot):len((*c.CallOptions).UpdateSnapshot)], opts...)
1193 var resp *pubsubpb.Snapshot
1194 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1195 var err error
1196 resp, err = executeRPC(ctx, c.subscriptionAdminClient.UpdateSnapshot, req, settings.GRPC, c.logger, "UpdateSnapshot")
1197 return err
1198 }, opts...)
1199 if err != nil {
1200 return nil, err
1201 }
1202 return resp, nil
1203 }
1204
1205 func (c *subscriptionAdminGRPCClient) DeleteSnapshot(ctx context.Context, req *pubsubpb.DeleteSnapshotRequest, opts ...gax.CallOption) error {
1206 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "snapshot", url.QueryEscape(req.GetSnapshot()))}
1207
1208 hds = append(c.xGoogHeaders, hds...)
1209 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1210 opts = append((*c.CallOptions).DeleteSnapshot[0:len((*c.CallOptions).DeleteSnapshot):len((*c.CallOptions).DeleteSnapshot)], opts...)
1211 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1212 var err error
1213 _, err = executeRPC(ctx, c.subscriptionAdminClient.DeleteSnapshot, req, settings.GRPC, c.logger, "DeleteSnapshot")
1214 return err
1215 }, opts...)
1216 return err
1217 }
1218
1219 func (c *subscriptionAdminGRPCClient) Seek(ctx context.Context, req *pubsubpb.SeekRequest, opts ...gax.CallOption) (*pubsubpb.SeekResponse, error) {
1220 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "subscription", url.QueryEscape(req.GetSubscription()))}
1221
1222 hds = append(c.xGoogHeaders, hds...)
1223 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1224 opts = append((*c.CallOptions).Seek[0:len((*c.CallOptions).Seek):len((*c.CallOptions).Seek)], opts...)
1225 var resp *pubsubpb.SeekResponse
1226 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1227 var err error
1228 resp, err = executeRPC(ctx, c.subscriptionAdminClient.Seek, req, settings.GRPC, c.logger, "Seek")
1229 return err
1230 }, opts...)
1231 if err != nil {
1232 return nil, err
1233 }
1234 return resp, nil
1235 }
1236
1237 func (c *subscriptionAdminGRPCClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
1238 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
1239
1240 hds = append(c.xGoogHeaders, hds...)
1241 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1242 opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
1243 var resp *iampb.Policy
1244 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1245 var err error
1246 resp, err = executeRPC(ctx, c.iamPolicyClient.GetIamPolicy, req, settings.GRPC, c.logger, "GetIamPolicy")
1247 return err
1248 }, opts...)
1249 if err != nil {
1250 return nil, err
1251 }
1252 return resp, nil
1253 }
1254
1255 func (c *subscriptionAdminGRPCClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
1256 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
1257
1258 hds = append(c.xGoogHeaders, hds...)
1259 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1260 opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
1261 var resp *iampb.Policy
1262 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1263 var err error
1264 resp, err = executeRPC(ctx, c.iamPolicyClient.SetIamPolicy, req, settings.GRPC, c.logger, "SetIamPolicy")
1265 return err
1266 }, opts...)
1267 if err != nil {
1268 return nil, err
1269 }
1270 return resp, nil
1271 }
1272
1273 func (c *subscriptionAdminGRPCClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
1274 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
1275
1276 hds = append(c.xGoogHeaders, hds...)
1277 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1278 opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...)
1279 var resp *iampb.TestIamPermissionsResponse
1280 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1281 var err error
1282 resp, err = executeRPC(ctx, c.iamPolicyClient.TestIamPermissions, req, settings.GRPC, c.logger, "TestIamPermissions")
1283 return err
1284 }, opts...)
1285 if err != nil {
1286 return nil, err
1287 }
1288 return resp, nil
1289 }
1290
1291 // CreateSubscription creates a subscription to a given topic. See the [resource name rules]
1292 // (https://cloud.google.com/pubsub/docs/pubsub-basics#resource_names (at https://cloud.google.com/pubsub/docs/pubsub-basics#resource_names)).
1293 // If the subscription already exists, returns ALREADY_EXISTS.
1294 // If the corresponding topic doesn’t exist, returns NOT_FOUND.
1295 //
1296 // If the name is not provided in the request, the server will assign a random
1297 // name for this subscription on the same project as the topic, conforming
1298 // to the [resource name format]
1299 // (https://cloud.google.com/pubsub/docs/pubsub-basics#resource_names (at https://cloud.google.com/pubsub/docs/pubsub-basics#resource_names)). The
1300 // generated name is populated in the returned Subscription object. Note that
1301 // for REST API requests, you must specify a name in the request.
1302 func (c *subscriptionAdminRESTClient) CreateSubscription(ctx context.Context, req *pubsubpb.Subscription, opts ...gax.CallOption) (*pubsubpb.Subscription, error) {
1303 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1304 jsonReq, err := m.Marshal(req)
1305 if err != nil {
1306 return nil, err
1307 }
1308
1309 baseUrl, err := url.Parse(c.endpoint)
1310 if err != nil {
1311 return nil, err
1312 }
1313 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
1314
1315 params := url.Values{}
1316 params.Add("$alt", "json;enum-encoding=int")
1317
1318 baseUrl.RawQuery = params.Encode()
1319
1320 // Build HTTP headers from client and context metadata.
1321 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1322
1323 hds = append(c.xGoogHeaders, hds...)
1324 hds = append(hds, "Content-Type", "application/json")
1325 headers := gax.BuildHeaders(ctx, hds...)
1326 opts = append((*c.CallOptions).CreateSubscription[0:len((*c.CallOptions).CreateSubscription):len((*c.CallOptions).CreateSubscription)], opts...)
1327 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1328 resp := &pubsubpb.Subscription{}
1329 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1330 if settings.Path != "" {
1331 baseUrl.Path = settings.Path
1332 }
1333 httpReq, err := http.NewRequest("PUT", baseUrl.String(), bytes.NewReader(jsonReq))
1334 if err != nil {
1335 return err
1336 }
1337 httpReq = httpReq.WithContext(ctx)
1338 httpReq.Header = headers
1339
1340 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateSubscription")
1341 if err != nil {
1342 return err
1343 }
1344
1345 if err := unm.Unmarshal(buf, resp); err != nil {
1346 return err
1347 }
1348
1349 return nil
1350 }, opts...)
1351 if e != nil {
1352 return nil, e
1353 }
1354 return resp, nil
1355 }
1356
1357 // GetSubscription gets the configuration details of a subscription.
1358 func (c *subscriptionAdminRESTClient) GetSubscription(ctx context.Context, req *pubsubpb.GetSubscriptionRequest, opts ...gax.CallOption) (*pubsubpb.Subscription, error) {
1359 baseUrl, err := url.Parse(c.endpoint)
1360 if err != nil {
1361 return nil, err
1362 }
1363 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetSubscription())
1364
1365 params := url.Values{}
1366 params.Add("$alt", "json;enum-encoding=int")
1367
1368 baseUrl.RawQuery = params.Encode()
1369
1370 // Build HTTP headers from client and context metadata.
1371 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "subscription", url.QueryEscape(req.GetSubscription()))}
1372
1373 hds = append(c.xGoogHeaders, hds...)
1374 hds = append(hds, "Content-Type", "application/json")
1375 headers := gax.BuildHeaders(ctx, hds...)
1376 opts = append((*c.CallOptions).GetSubscription[0:len((*c.CallOptions).GetSubscription):len((*c.CallOptions).GetSubscription)], opts...)
1377 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1378 resp := &pubsubpb.Subscription{}
1379 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1380 if settings.Path != "" {
1381 baseUrl.Path = settings.Path
1382 }
1383 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1384 if err != nil {
1385 return err
1386 }
1387 httpReq = httpReq.WithContext(ctx)
1388 httpReq.Header = headers
1389
1390 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetSubscription")
1391 if err != nil {
1392 return err
1393 }
1394
1395 if err := unm.Unmarshal(buf, resp); err != nil {
1396 return err
1397 }
1398
1399 return nil
1400 }, opts...)
1401 if e != nil {
1402 return nil, e
1403 }
1404 return resp, nil
1405 }
1406
1407 // UpdateSubscription updates an existing subscription by updating the fields specified in the
1408 // update mask. Note that certain properties of a subscription, such as its
1409 // topic, are not modifiable.
1410 func (c *subscriptionAdminRESTClient) UpdateSubscription(ctx context.Context, req *pubsubpb.UpdateSubscriptionRequest, opts ...gax.CallOption) (*pubsubpb.Subscription, error) {
1411 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1412 jsonReq, err := m.Marshal(req)
1413 if err != nil {
1414 return nil, err
1415 }
1416
1417 baseUrl, err := url.Parse(c.endpoint)
1418 if err != nil {
1419 return nil, err
1420 }
1421 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetSubscription().GetName())
1422
1423 params := url.Values{}
1424 params.Add("$alt", "json;enum-encoding=int")
1425
1426 baseUrl.RawQuery = params.Encode()
1427
1428 // Build HTTP headers from client and context metadata.
1429 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "subscription.name", url.QueryEscape(req.GetSubscription().GetName()))}
1430
1431 hds = append(c.xGoogHeaders, hds...)
1432 hds = append(hds, "Content-Type", "application/json")
1433 headers := gax.BuildHeaders(ctx, hds...)
1434 opts = append((*c.CallOptions).UpdateSubscription[0:len((*c.CallOptions).UpdateSubscription):len((*c.CallOptions).UpdateSubscription)], opts...)
1435 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1436 resp := &pubsubpb.Subscription{}
1437 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1438 if settings.Path != "" {
1439 baseUrl.Path = settings.Path
1440 }
1441 httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
1442 if err != nil {
1443 return err
1444 }
1445 httpReq = httpReq.WithContext(ctx)
1446 httpReq.Header = headers
1447
1448 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateSubscription")
1449 if err != nil {
1450 return err
1451 }
1452
1453 if err := unm.Unmarshal(buf, resp); err != nil {
1454 return err
1455 }
1456
1457 return nil
1458 }, opts...)
1459 if e != nil {
1460 return nil, e
1461 }
1462 return resp, nil
1463 }
1464
1465 // ListSubscriptions lists matching subscriptions.
1466 func (c *subscriptionAdminRESTClient) ListSubscriptions(ctx context.Context, req *pubsubpb.ListSubscriptionsRequest, opts ...gax.CallOption) *SubscriptionIterator {
1467 it := &SubscriptionIterator{}
1468 req = proto.Clone(req).(*pubsubpb.ListSubscriptionsRequest)
1469 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1470 it.InternalFetch = func(pageSize int, pageToken string) ([]*pubsubpb.Subscription, string, error) {
1471 resp := &pubsubpb.ListSubscriptionsResponse{}
1472 if pageToken != "" {
1473 req.PageToken = pageToken
1474 }
1475 if pageSize > math.MaxInt32 {
1476 req.PageSize = math.MaxInt32
1477 } else if pageSize != 0 {
1478 req.PageSize = int32(pageSize)
1479 }
1480 baseUrl, err := url.Parse(c.endpoint)
1481 if err != nil {
1482 return nil, "", err
1483 }
1484 baseUrl.Path += fmt.Sprintf("/v1/%v/subscriptions", req.GetProject())
1485
1486 params := url.Values{}
1487 params.Add("$alt", "json;enum-encoding=int")
1488 if req.GetPageSize() != 0 {
1489 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
1490 }
1491 if req.GetPageToken() != "" {
1492 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
1493 }
1494
1495 baseUrl.RawQuery = params.Encode()
1496
1497 // Build HTTP headers from client and context metadata.
1498 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
1499 headers := gax.BuildHeaders(ctx, hds...)
1500 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1501 if settings.Path != "" {
1502 baseUrl.Path = settings.Path
1503 }
1504 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1505 if err != nil {
1506 return err
1507 }
1508 httpReq.Header = headers
1509
1510 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListSubscriptions")
1511 if err != nil {
1512 return err
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 it.Response = resp
1524 return resp.GetSubscriptions(), resp.GetNextPageToken(), nil
1525 }
1526
1527 fetch := func(pageSize int, pageToken string) (string, error) {
1528 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1529 if err != nil {
1530 return "", err
1531 }
1532 it.items = append(it.items, items...)
1533 return nextPageToken, nil
1534 }
1535
1536 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1537 it.pageInfo.MaxSize = int(req.GetPageSize())
1538 it.pageInfo.Token = req.GetPageToken()
1539
1540 return it
1541 }
1542
1543 // DeleteSubscription deletes an existing subscription. All messages retained in the subscription
1544 // are immediately dropped. Calls to Pull after deletion will return
1545 // NOT_FOUND. After a subscription is deleted, a new one may be created with
1546 // the same name, but the new one has no association with the old
1547 // subscription or its topic unless the same topic is specified.
1548 func (c *subscriptionAdminRESTClient) DeleteSubscription(ctx context.Context, req *pubsubpb.DeleteSubscriptionRequest, opts ...gax.CallOption) error {
1549 baseUrl, err := url.Parse(c.endpoint)
1550 if err != nil {
1551 return err
1552 }
1553 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetSubscription())
1554
1555 params := url.Values{}
1556 params.Add("$alt", "json;enum-encoding=int")
1557
1558 baseUrl.RawQuery = params.Encode()
1559
1560 // Build HTTP headers from client and context metadata.
1561 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "subscription", url.QueryEscape(req.GetSubscription()))}
1562
1563 hds = append(c.xGoogHeaders, hds...)
1564 hds = append(hds, "Content-Type", "application/json")
1565 headers := gax.BuildHeaders(ctx, hds...)
1566 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1567 if settings.Path != "" {
1568 baseUrl.Path = settings.Path
1569 }
1570 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
1571 if err != nil {
1572 return err
1573 }
1574 httpReq = httpReq.WithContext(ctx)
1575 httpReq.Header = headers
1576
1577 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteSubscription")
1578 return err
1579 }, opts...)
1580 }
1581
1582 // ModifyAckDeadline modifies the ack deadline for a specific message. This method is useful
1583 // to indicate that more time is needed to process a message by the
1584 // subscriber, or to make the message available for redelivery if the
1585 // processing was interrupted. Note that this does not modify the
1586 // subscription-level ackDeadlineSeconds used for subsequent messages.
1587 func (c *subscriptionAdminRESTClient) ModifyAckDeadline(ctx context.Context, req *pubsubpb.ModifyAckDeadlineRequest, opts ...gax.CallOption) error {
1588 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1589 jsonReq, err := m.Marshal(req)
1590 if err != nil {
1591 return err
1592 }
1593
1594 baseUrl, err := url.Parse(c.endpoint)
1595 if err != nil {
1596 return err
1597 }
1598 baseUrl.Path += fmt.Sprintf("/v1/%v:modifyAckDeadline", req.GetSubscription())
1599
1600 params := url.Values{}
1601 params.Add("$alt", "json;enum-encoding=int")
1602
1603 baseUrl.RawQuery = params.Encode()
1604
1605 // Build HTTP headers from client and context metadata.
1606 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "subscription", url.QueryEscape(req.GetSubscription()))}
1607
1608 hds = append(c.xGoogHeaders, hds...)
1609 hds = append(hds, "Content-Type", "application/json")
1610 headers := gax.BuildHeaders(ctx, hds...)
1611 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1612 if settings.Path != "" {
1613 baseUrl.Path = settings.Path
1614 }
1615 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1616 if err != nil {
1617 return err
1618 }
1619 httpReq = httpReq.WithContext(ctx)
1620 httpReq.Header = headers
1621
1622 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "ModifyAckDeadline")
1623 return err
1624 }, opts...)
1625 }
1626
1627 // Acknowledge acknowledges the messages associated with the ack_ids in the
1628 // AcknowledgeRequest. The Pub/Sub system can remove the relevant messages
1629 // from the subscription.
1630 //
1631 // Acknowledging a message whose ack deadline has expired may succeed,
1632 // but such a message may be redelivered later. Acknowledging a message more
1633 // than once will not result in an error.
1634 func (c *subscriptionAdminRESTClient) Acknowledge(ctx context.Context, req *pubsubpb.AcknowledgeRequest, opts ...gax.CallOption) error {
1635 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1636 jsonReq, err := m.Marshal(req)
1637 if err != nil {
1638 return err
1639 }
1640
1641 baseUrl, err := url.Parse(c.endpoint)
1642 if err != nil {
1643 return err
1644 }
1645 baseUrl.Path += fmt.Sprintf("/v1/%v:acknowledge", req.GetSubscription())
1646
1647 params := url.Values{}
1648 params.Add("$alt", "json;enum-encoding=int")
1649
1650 baseUrl.RawQuery = params.Encode()
1651
1652 // Build HTTP headers from client and context metadata.
1653 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "subscription", url.QueryEscape(req.GetSubscription()))}
1654
1655 hds = append(c.xGoogHeaders, hds...)
1656 hds = append(hds, "Content-Type", "application/json")
1657 headers := gax.BuildHeaders(ctx, hds...)
1658 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1659 if settings.Path != "" {
1660 baseUrl.Path = settings.Path
1661 }
1662 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1663 if err != nil {
1664 return err
1665 }
1666 httpReq = httpReq.WithContext(ctx)
1667 httpReq.Header = headers
1668
1669 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "Acknowledge")
1670 return err
1671 }, opts...)
1672 }
1673
1674 // Pull pulls messages from the server.
1675 func (c *subscriptionAdminRESTClient) Pull(ctx context.Context, req *pubsubpb.PullRequest, opts ...gax.CallOption) (*pubsubpb.PullResponse, error) {
1676 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1677 jsonReq, err := m.Marshal(req)
1678 if err != nil {
1679 return nil, err
1680 }
1681
1682 baseUrl, err := url.Parse(c.endpoint)
1683 if err != nil {
1684 return nil, err
1685 }
1686 baseUrl.Path += fmt.Sprintf("/v1/%v:pull", req.GetSubscription())
1687
1688 params := url.Values{}
1689 params.Add("$alt", "json;enum-encoding=int")
1690
1691 baseUrl.RawQuery = params.Encode()
1692
1693 // Build HTTP headers from client and context metadata.
1694 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "subscription", url.QueryEscape(req.GetSubscription()))}
1695
1696 hds = append(c.xGoogHeaders, hds...)
1697 hds = append(hds, "Content-Type", "application/json")
1698 headers := gax.BuildHeaders(ctx, hds...)
1699 opts = append((*c.CallOptions).Pull[0:len((*c.CallOptions).Pull):len((*c.CallOptions).Pull)], opts...)
1700 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1701 resp := &pubsubpb.PullResponse{}
1702 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1703 if settings.Path != "" {
1704 baseUrl.Path = settings.Path
1705 }
1706 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1707 if err != nil {
1708 return err
1709 }
1710 httpReq = httpReq.WithContext(ctx)
1711 httpReq.Header = headers
1712
1713 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "Pull")
1714 if err != nil {
1715 return err
1716 }
1717
1718 if err := unm.Unmarshal(buf, resp); err != nil {
1719 return err
1720 }
1721
1722 return nil
1723 }, opts...)
1724 if e != nil {
1725 return nil, e
1726 }
1727 return resp, nil
1728 }
1729
1730 // StreamingPull establishes a stream with the server, which sends messages down to the
1731 // client. The client streams acknowledgments and ack deadline modifications
1732 // back to the server. The server will close the stream and return the status
1733 // on any error. The server may close the stream with status UNAVAILABLE to
1734 // reassign server-side resources, in which case, the client should
1735 // re-establish the stream. Flow control can be achieved by configuring the
1736 // underlying RPC channel.
1737 //
1738 // This method is not supported for the REST transport.
1739 func (c *subscriptionAdminRESTClient) StreamingPull(ctx context.Context, opts ...gax.CallOption) (pubsubpb.Subscriber_StreamingPullClient, error) {
1740 return nil, errors.New("StreamingPull not yet supported for REST clients")
1741 }
1742
1743 // ModifyPushConfig modifies the PushConfig for a specified subscription.
1744 //
1745 // This may be used to change a push subscription to a pull one (signified by
1746 // an empty PushConfig) or vice versa, or change the endpoint URL and other
1747 // attributes of a push subscription. Messages will accumulate for delivery
1748 // continuously through the call regardless of changes to the PushConfig.
1749 func (c *subscriptionAdminRESTClient) ModifyPushConfig(ctx context.Context, req *pubsubpb.ModifyPushConfigRequest, opts ...gax.CallOption) error {
1750 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1751 jsonReq, err := m.Marshal(req)
1752 if err != nil {
1753 return err
1754 }
1755
1756 baseUrl, err := url.Parse(c.endpoint)
1757 if err != nil {
1758 return err
1759 }
1760 baseUrl.Path += fmt.Sprintf("/v1/%v:modifyPushConfig", req.GetSubscription())
1761
1762 params := url.Values{}
1763 params.Add("$alt", "json;enum-encoding=int")
1764
1765 baseUrl.RawQuery = params.Encode()
1766
1767 // Build HTTP headers from client and context metadata.
1768 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "subscription", url.QueryEscape(req.GetSubscription()))}
1769
1770 hds = append(c.xGoogHeaders, hds...)
1771 hds = append(hds, "Content-Type", "application/json")
1772 headers := gax.BuildHeaders(ctx, hds...)
1773 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1774 if settings.Path != "" {
1775 baseUrl.Path = settings.Path
1776 }
1777 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1778 if err != nil {
1779 return err
1780 }
1781 httpReq = httpReq.WithContext(ctx)
1782 httpReq.Header = headers
1783
1784 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "ModifyPushConfig")
1785 return err
1786 }, opts...)
1787 }
1788
1789 // GetSnapshot gets the configuration details of a snapshot. Snapshots are used in
1790 // Seek (at https://cloud.google.com/pubsub/docs/replay-overview) operations,
1791 // which allow you to manage message acknowledgments in bulk. That is, you can
1792 // set the acknowledgment state of messages in an existing subscription to the
1793 // state captured by a snapshot.
1794 func (c *subscriptionAdminRESTClient) GetSnapshot(ctx context.Context, req *pubsubpb.GetSnapshotRequest, opts ...gax.CallOption) (*pubsubpb.Snapshot, error) {
1795 baseUrl, err := url.Parse(c.endpoint)
1796 if err != nil {
1797 return nil, err
1798 }
1799 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetSnapshot())
1800
1801 params := url.Values{}
1802 params.Add("$alt", "json;enum-encoding=int")
1803
1804 baseUrl.RawQuery = params.Encode()
1805
1806 // Build HTTP headers from client and context metadata.
1807 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "snapshot", url.QueryEscape(req.GetSnapshot()))}
1808
1809 hds = append(c.xGoogHeaders, hds...)
1810 hds = append(hds, "Content-Type", "application/json")
1811 headers := gax.BuildHeaders(ctx, hds...)
1812 opts = append((*c.CallOptions).GetSnapshot[0:len((*c.CallOptions).GetSnapshot):len((*c.CallOptions).GetSnapshot)], opts...)
1813 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1814 resp := &pubsubpb.Snapshot{}
1815 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1816 if settings.Path != "" {
1817 baseUrl.Path = settings.Path
1818 }
1819 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1820 if err != nil {
1821 return err
1822 }
1823 httpReq = httpReq.WithContext(ctx)
1824 httpReq.Header = headers
1825
1826 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetSnapshot")
1827 if err != nil {
1828 return err
1829 }
1830
1831 if err := unm.Unmarshal(buf, resp); err != nil {
1832 return err
1833 }
1834
1835 return nil
1836 }, opts...)
1837 if e != nil {
1838 return nil, e
1839 }
1840 return resp, nil
1841 }
1842
1843 // ListSnapshots lists the existing snapshots. Snapshots are used in Seek (at https://cloud.google.com/pubsub/docs/replay-overview) operations, which
1844 // allow you to manage message acknowledgments in bulk. That is, you can set
1845 // the acknowledgment state of messages in an existing subscription to the
1846 // state captured by a snapshot.
1847 func (c *subscriptionAdminRESTClient) ListSnapshots(ctx context.Context, req *pubsubpb.ListSnapshotsRequest, opts ...gax.CallOption) *SnapshotIterator {
1848 it := &SnapshotIterator{}
1849 req = proto.Clone(req).(*pubsubpb.ListSnapshotsRequest)
1850 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1851 it.InternalFetch = func(pageSize int, pageToken string) ([]*pubsubpb.Snapshot, string, error) {
1852 resp := &pubsubpb.ListSnapshotsResponse{}
1853 if pageToken != "" {
1854 req.PageToken = pageToken
1855 }
1856 if pageSize > math.MaxInt32 {
1857 req.PageSize = math.MaxInt32
1858 } else if pageSize != 0 {
1859 req.PageSize = int32(pageSize)
1860 }
1861 baseUrl, err := url.Parse(c.endpoint)
1862 if err != nil {
1863 return nil, "", err
1864 }
1865 baseUrl.Path += fmt.Sprintf("/v1/%v/snapshots", req.GetProject())
1866
1867 params := url.Values{}
1868 params.Add("$alt", "json;enum-encoding=int")
1869 if req.GetPageSize() != 0 {
1870 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
1871 }
1872 if req.GetPageToken() != "" {
1873 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
1874 }
1875
1876 baseUrl.RawQuery = params.Encode()
1877
1878 // Build HTTP headers from client and context metadata.
1879 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
1880 headers := gax.BuildHeaders(ctx, hds...)
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.Header = headers
1890
1891 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListSnapshots")
1892 if err != nil {
1893 return err
1894 }
1895 if err := unm.Unmarshal(buf, resp); err != nil {
1896 return err
1897 }
1898
1899 return nil
1900 }, opts...)
1901 if e != nil {
1902 return nil, "", e
1903 }
1904 it.Response = resp
1905 return resp.GetSnapshots(), resp.GetNextPageToken(), nil
1906 }
1907
1908 fetch := func(pageSize int, pageToken string) (string, error) {
1909 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1910 if err != nil {
1911 return "", err
1912 }
1913 it.items = append(it.items, items...)
1914 return nextPageToken, nil
1915 }
1916
1917 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1918 it.pageInfo.MaxSize = int(req.GetPageSize())
1919 it.pageInfo.Token = req.GetPageToken()
1920
1921 return it
1922 }
1923
1924 // CreateSnapshot creates a snapshot from the requested subscription. Snapshots are used in
1925 // Seek (at https://cloud.google.com/pubsub/docs/replay-overview) operations,
1926 // which allow you to manage message acknowledgments in bulk. That is, you can
1927 // set the acknowledgment state of messages in an existing subscription to the
1928 // state captured by a snapshot.
1929 // If the snapshot already exists, returns ALREADY_EXISTS.
1930 // If the requested subscription doesn’t exist, returns NOT_FOUND.
1931 // If the backlog in the subscription is too old – and the resulting snapshot
1932 // would expire in less than 1 hour – then FAILED_PRECONDITION is returned.
1933 // See also the Snapshot.expire_time field. If the name is not provided in
1934 // the request, the server will assign a random
1935 // name for this snapshot on the same project as the subscription, conforming
1936 // to the [resource name format]
1937 // (https://cloud.google.com/pubsub/docs/pubsub-basics#resource_names (at https://cloud.google.com/pubsub/docs/pubsub-basics#resource_names)). The
1938 // generated name is populated in the returned Snapshot object. Note that for
1939 // REST API requests, you must specify a name in the request.
1940 func (c *subscriptionAdminRESTClient) CreateSnapshot(ctx context.Context, req *pubsubpb.CreateSnapshotRequest, opts ...gax.CallOption) (*pubsubpb.Snapshot, error) {
1941 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1942 jsonReq, err := m.Marshal(req)
1943 if err != nil {
1944 return nil, err
1945 }
1946
1947 baseUrl, err := url.Parse(c.endpoint)
1948 if err != nil {
1949 return nil, err
1950 }
1951 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
1952
1953 params := url.Values{}
1954 params.Add("$alt", "json;enum-encoding=int")
1955
1956 baseUrl.RawQuery = params.Encode()
1957
1958 // Build HTTP headers from client and context metadata.
1959 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1960
1961 hds = append(c.xGoogHeaders, hds...)
1962 hds = append(hds, "Content-Type", "application/json")
1963 headers := gax.BuildHeaders(ctx, hds...)
1964 opts = append((*c.CallOptions).CreateSnapshot[0:len((*c.CallOptions).CreateSnapshot):len((*c.CallOptions).CreateSnapshot)], opts...)
1965 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1966 resp := &pubsubpb.Snapshot{}
1967 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1968 if settings.Path != "" {
1969 baseUrl.Path = settings.Path
1970 }
1971 httpReq, err := http.NewRequest("PUT", baseUrl.String(), bytes.NewReader(jsonReq))
1972 if err != nil {
1973 return err
1974 }
1975 httpReq = httpReq.WithContext(ctx)
1976 httpReq.Header = headers
1977
1978 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateSnapshot")
1979 if err != nil {
1980 return err
1981 }
1982
1983 if err := unm.Unmarshal(buf, resp); err != nil {
1984 return err
1985 }
1986
1987 return nil
1988 }, opts...)
1989 if e != nil {
1990 return nil, e
1991 }
1992 return resp, nil
1993 }
1994
1995 // UpdateSnapshot updates an existing snapshot by updating the fields specified in the update
1996 // mask. Snapshots are used in
1997 // Seek (at https://cloud.google.com/pubsub/docs/replay-overview) operations,
1998 // which allow you to manage message acknowledgments in bulk. That is, you can
1999 // set the acknowledgment state of messages in an existing subscription to the
2000 // state captured by a snapshot.
2001 func (c *subscriptionAdminRESTClient) UpdateSnapshot(ctx context.Context, req *pubsubpb.UpdateSnapshotRequest, opts ...gax.CallOption) (*pubsubpb.Snapshot, error) {
2002 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
2003 jsonReq, err := m.Marshal(req)
2004 if err != nil {
2005 return nil, err
2006 }
2007
2008 baseUrl, err := url.Parse(c.endpoint)
2009 if err != nil {
2010 return nil, err
2011 }
2012 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetSnapshot().GetName())
2013
2014 params := url.Values{}
2015 params.Add("$alt", "json;enum-encoding=int")
2016
2017 baseUrl.RawQuery = params.Encode()
2018
2019 // Build HTTP headers from client and context metadata.
2020 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "snapshot.name", url.QueryEscape(req.GetSnapshot().GetName()))}
2021
2022 hds = append(c.xGoogHeaders, hds...)
2023 hds = append(hds, "Content-Type", "application/json")
2024 headers := gax.BuildHeaders(ctx, hds...)
2025 opts = append((*c.CallOptions).UpdateSnapshot[0:len((*c.CallOptions).UpdateSnapshot):len((*c.CallOptions).UpdateSnapshot)], opts...)
2026 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2027 resp := &pubsubpb.Snapshot{}
2028 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2029 if settings.Path != "" {
2030 baseUrl.Path = settings.Path
2031 }
2032 httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
2033 if err != nil {
2034 return err
2035 }
2036 httpReq = httpReq.WithContext(ctx)
2037 httpReq.Header = headers
2038
2039 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateSnapshot")
2040 if err != nil {
2041 return err
2042 }
2043
2044 if err := unm.Unmarshal(buf, resp); err != nil {
2045 return err
2046 }
2047
2048 return nil
2049 }, opts...)
2050 if e != nil {
2051 return nil, e
2052 }
2053 return resp, nil
2054 }
2055
2056 // DeleteSnapshot removes an existing snapshot. Snapshots are used in [Seek]
2057 // (https://cloud.google.com/pubsub/docs/replay-overview (at https://cloud.google.com/pubsub/docs/replay-overview)) operations, which
2058 // allow you to manage message acknowledgments in bulk. That is, you can set
2059 // the acknowledgment state of messages in an existing subscription to the
2060 // state captured by a snapshot.
2061 // When the snapshot is deleted, all messages retained in the snapshot
2062 // are immediately dropped. After a snapshot is deleted, a new one may be
2063 // created with the same name, but the new one has no association with the old
2064 // snapshot or its subscription, unless the same subscription is specified.
2065 func (c *subscriptionAdminRESTClient) DeleteSnapshot(ctx context.Context, req *pubsubpb.DeleteSnapshotRequest, opts ...gax.CallOption) error {
2066 baseUrl, err := url.Parse(c.endpoint)
2067 if err != nil {
2068 return err
2069 }
2070 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetSnapshot())
2071
2072 params := url.Values{}
2073 params.Add("$alt", "json;enum-encoding=int")
2074
2075 baseUrl.RawQuery = params.Encode()
2076
2077 // Build HTTP headers from client and context metadata.
2078 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "snapshot", url.QueryEscape(req.GetSnapshot()))}
2079
2080 hds = append(c.xGoogHeaders, hds...)
2081 hds = append(hds, "Content-Type", "application/json")
2082 headers := gax.BuildHeaders(ctx, hds...)
2083 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2084 if settings.Path != "" {
2085 baseUrl.Path = settings.Path
2086 }
2087 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
2088 if err != nil {
2089 return err
2090 }
2091 httpReq = httpReq.WithContext(ctx)
2092 httpReq.Header = headers
2093
2094 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteSnapshot")
2095 return err
2096 }, opts...)
2097 }
2098
2099 // Seek seeks an existing subscription to a point in time or to a given snapshot,
2100 // whichever is provided in the request. Snapshots are used in [Seek]
2101 // (https://cloud.google.com/pubsub/docs/replay-overview (at https://cloud.google.com/pubsub/docs/replay-overview)) operations, which
2102 // allow you to manage message acknowledgments in bulk. That is, you can set
2103 // the acknowledgment state of messages in an existing subscription to the
2104 // state captured by a snapshot. Note that both the subscription and the
2105 // snapshot must be on the same topic.
2106 func (c *subscriptionAdminRESTClient) Seek(ctx context.Context, req *pubsubpb.SeekRequest, opts ...gax.CallOption) (*pubsubpb.SeekResponse, error) {
2107 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
2108 jsonReq, err := m.Marshal(req)
2109 if err != nil {
2110 return nil, err
2111 }
2112
2113 baseUrl, err := url.Parse(c.endpoint)
2114 if err != nil {
2115 return nil, err
2116 }
2117 baseUrl.Path += fmt.Sprintf("/v1/%v:seek", req.GetSubscription())
2118
2119 params := url.Values{}
2120 params.Add("$alt", "json;enum-encoding=int")
2121
2122 baseUrl.RawQuery = params.Encode()
2123
2124 // Build HTTP headers from client and context metadata.
2125 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "subscription", url.QueryEscape(req.GetSubscription()))}
2126
2127 hds = append(c.xGoogHeaders, hds...)
2128 hds = append(hds, "Content-Type", "application/json")
2129 headers := gax.BuildHeaders(ctx, hds...)
2130 opts = append((*c.CallOptions).Seek[0:len((*c.CallOptions).Seek):len((*c.CallOptions).Seek)], opts...)
2131 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2132 resp := &pubsubpb.SeekResponse{}
2133 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2134 if settings.Path != "" {
2135 baseUrl.Path = settings.Path
2136 }
2137 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
2138 if err != nil {
2139 return err
2140 }
2141 httpReq = httpReq.WithContext(ctx)
2142 httpReq.Header = headers
2143
2144 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "Seek")
2145 if err != nil {
2146 return err
2147 }
2148
2149 if err := unm.Unmarshal(buf, resp); err != nil {
2150 return err
2151 }
2152
2153 return nil
2154 }, opts...)
2155 if e != nil {
2156 return nil, e
2157 }
2158 return resp, nil
2159 }
2160
2161 // GetIamPolicy gets the access control policy for a resource. Returns an empty policy
2162 // if the resource exists and does not have a policy set.
2163 func (c *subscriptionAdminRESTClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
2164 baseUrl, err := url.Parse(c.endpoint)
2165 if err != nil {
2166 return nil, err
2167 }
2168 baseUrl.Path += fmt.Sprintf("/v1/%v:getIamPolicy", req.GetResource())
2169
2170 params := url.Values{}
2171 params.Add("$alt", "json;enum-encoding=int")
2172 if req.GetOptions().GetRequestedPolicyVersion() != 0 {
2173 params.Add("options.requestedPolicyVersion", fmt.Sprintf("%v", req.GetOptions().GetRequestedPolicyVersion()))
2174 }
2175
2176 baseUrl.RawQuery = params.Encode()
2177
2178 // Build HTTP headers from client and context metadata.
2179 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
2180
2181 hds = append(c.xGoogHeaders, hds...)
2182 hds = append(hds, "Content-Type", "application/json")
2183 headers := gax.BuildHeaders(ctx, hds...)
2184 opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
2185 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2186 resp := &iampb.Policy{}
2187 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2188 if settings.Path != "" {
2189 baseUrl.Path = settings.Path
2190 }
2191 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
2192 if err != nil {
2193 return err
2194 }
2195 httpReq = httpReq.WithContext(ctx)
2196 httpReq.Header = headers
2197
2198 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetIamPolicy")
2199 if err != nil {
2200 return err
2201 }
2202
2203 if err := unm.Unmarshal(buf, resp); err != nil {
2204 return err
2205 }
2206
2207 return nil
2208 }, opts...)
2209 if e != nil {
2210 return nil, e
2211 }
2212 return resp, nil
2213 }
2214
2215 // SetIamPolicy sets the access control policy on the specified resource. Replaces
2216 // any existing policy.
2217 //
2218 // Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED
2219 // errors.
2220 func (c *subscriptionAdminRESTClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, 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:setIamPolicy", req.GetResource())
2232
2233 params := url.Values{}
2234 params.Add("$alt", "json;enum-encoding=int")
2235
2236 baseUrl.RawQuery = params.Encode()
2237
2238 // Build HTTP headers from client and context metadata.
2239 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
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).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
2245 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2246 resp := &iampb.Policy{}
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 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "SetIamPolicy")
2259 if err != nil {
2260 return err
2261 }
2262
2263 if err := unm.Unmarshal(buf, resp); err != nil {
2264 return err
2265 }
2266
2267 return nil
2268 }, opts...)
2269 if e != nil {
2270 return nil, e
2271 }
2272 return resp, nil
2273 }
2274
2275 // TestIamPermissions returns permissions that a caller has on the specified resource. If the
2276 // resource does not exist, this will return an empty set of
2277 // permissions, not a NOT_FOUND error.
2278 //
2279 // Note: This operation is designed to be used for building
2280 // permission-aware UIs and command-line tools, not for authorization
2281 // checking. This operation may “fail open” without warning.
2282 func (c *subscriptionAdminRESTClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
2283 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
2284 jsonReq, err := m.Marshal(req)
2285 if err != nil {
2286 return nil, err
2287 }
2288
2289 baseUrl, err := url.Parse(c.endpoint)
2290 if err != nil {
2291 return nil, err
2292 }
2293 baseUrl.Path += fmt.Sprintf("/v1/%v:testIamPermissions", req.GetResource())
2294
2295 params := url.Values{}
2296 params.Add("$alt", "json;enum-encoding=int")
2297
2298 baseUrl.RawQuery = params.Encode()
2299
2300 // Build HTTP headers from client and context metadata.
2301 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
2302
2303 hds = append(c.xGoogHeaders, hds...)
2304 hds = append(hds, "Content-Type", "application/json")
2305 headers := gax.BuildHeaders(ctx, hds...)
2306 opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...)
2307 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2308 resp := &iampb.TestIamPermissionsResponse{}
2309 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2310 if settings.Path != "" {
2311 baseUrl.Path = settings.Path
2312 }
2313 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
2314 if err != nil {
2315 return err
2316 }
2317 httpReq = httpReq.WithContext(ctx)
2318 httpReq.Header = headers
2319
2320 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "TestIamPermissions")
2321 if err != nil {
2322 return err
2323 }
2324
2325 if err := unm.Unmarshal(buf, resp); err != nil {
2326 return err
2327 }
2328
2329 return nil
2330 }, opts...)
2331 if e != nil {
2332 return nil, e
2333 }
2334 return resp, nil
2335 }