1# -*- coding: utf-8 -*-
2# Copyright 2025 Google LLC
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16import json # type: ignore
17from google.api_core import path_template
18from google.api_core import gapic_v1
19
20from google.protobuf import json_format
21from google.iam.v1 import iam_policy_pb2 # type: ignore
22from google.iam.v1 import policy_pb2 # type: ignore
23from .base import SubscriberTransport, DEFAULT_CLIENT_INFO
24
25import re
26from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union
27
28
29from google.protobuf import empty_pb2 # type: ignore
30from google.pubsub_v1.types import pubsub
31
32
33class _BaseSubscriberRestTransport(SubscriberTransport):
34 """Base REST backend transport for Subscriber.
35
36 Note: This class is not meant to be used directly. Use its sync and
37 async sub-classes instead.
38
39 This class defines the same methods as the primary client, so the
40 primary client can load the underlying transport implementation
41 and call it.
42
43 It sends JSON representations of protocol buffers over HTTP/1.1
44 """
45
46 def __init__(
47 self,
48 *,
49 host: str = "pubsub.googleapis.com",
50 credentials: Optional[Any] = None,
51 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
52 always_use_jwt_access: Optional[bool] = False,
53 url_scheme: str = "https",
54 api_audience: Optional[str] = None,
55 ) -> None:
56 """Instantiate the transport.
57 Args:
58 host (Optional[str]):
59 The hostname to connect to (default: 'pubsub.googleapis.com').
60 credentials (Optional[Any]): The
61 authorization credentials to attach to requests. These
62 credentials identify the application to the service; if none
63 are specified, the client will attempt to ascertain the
64 credentials from the environment.
65 client_info (google.api_core.gapic_v1.client_info.ClientInfo):
66 The client info used to send a user-agent string along with
67 API requests. If ``None``, then default info will be used.
68 Generally, you only need to set this if you are developing
69 your own client library.
70 always_use_jwt_access (Optional[bool]): Whether self signed JWT should
71 be used for service account credentials.
72 url_scheme: the protocol scheme for the API endpoint. Normally
73 "https", but for testing or local servers,
74 "http" can be specified.
75 """
76 # Run the base constructor
77 maybe_url_match = re.match("^(?P<scheme>http(?:s)?://)?(?P<host>.*)$", host)
78 if maybe_url_match is None:
79 raise ValueError(
80 f"Unexpected hostname structure: {host}"
81 ) # pragma: NO COVER
82
83 url_match_items = maybe_url_match.groupdict()
84
85 host = f"{url_scheme}://{host}" if not url_match_items["scheme"] else host
86
87 super().__init__(
88 host=host,
89 credentials=credentials,
90 client_info=client_info,
91 always_use_jwt_access=always_use_jwt_access,
92 api_audience=api_audience,
93 )
94
95 class _BaseAcknowledge:
96 def __hash__(self): # pragma: NO COVER
97 return NotImplementedError("__hash__ must be implemented.")
98
99 __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {}
100
101 @classmethod
102 def _get_unset_required_fields(cls, message_dict):
103 return {
104 k: v
105 for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items()
106 if k not in message_dict
107 }
108
109 @staticmethod
110 def _get_http_options():
111 http_options: List[Dict[str, str]] = [
112 {
113 "method": "post",
114 "uri": "/v1/{subscription=projects/*/subscriptions/*}:acknowledge",
115 "body": "*",
116 },
117 ]
118 return http_options
119
120 @staticmethod
121 def _get_transcoded_request(http_options, request):
122 pb_request = pubsub.AcknowledgeRequest.pb(request)
123 transcoded_request = path_template.transcode(http_options, pb_request)
124 return transcoded_request
125
126 @staticmethod
127 def _get_request_body_json(transcoded_request):
128 # Jsonify the request body
129
130 body = json_format.MessageToJson(
131 transcoded_request["body"], use_integers_for_enums=True
132 )
133 return body
134
135 @staticmethod
136 def _get_query_params_json(transcoded_request):
137 query_params = json.loads(
138 json_format.MessageToJson(
139 transcoded_request["query_params"],
140 use_integers_for_enums=True,
141 )
142 )
143 query_params.update(
144 _BaseSubscriberRestTransport._BaseAcknowledge._get_unset_required_fields(
145 query_params
146 )
147 )
148
149 query_params["$alt"] = "json;enum-encoding=int"
150 return query_params
151
152 class _BaseCreateSnapshot:
153 def __hash__(self): # pragma: NO COVER
154 return NotImplementedError("__hash__ must be implemented.")
155
156 __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {}
157
158 @classmethod
159 def _get_unset_required_fields(cls, message_dict):
160 return {
161 k: v
162 for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items()
163 if k not in message_dict
164 }
165
166 @staticmethod
167 def _get_http_options():
168 http_options: List[Dict[str, str]] = [
169 {
170 "method": "put",
171 "uri": "/v1/{name=projects/*/snapshots/*}",
172 "body": "*",
173 },
174 ]
175 return http_options
176
177 @staticmethod
178 def _get_transcoded_request(http_options, request):
179 pb_request = pubsub.CreateSnapshotRequest.pb(request)
180 transcoded_request = path_template.transcode(http_options, pb_request)
181 return transcoded_request
182
183 @staticmethod
184 def _get_request_body_json(transcoded_request):
185 # Jsonify the request body
186
187 body = json_format.MessageToJson(
188 transcoded_request["body"], use_integers_for_enums=True
189 )
190 return body
191
192 @staticmethod
193 def _get_query_params_json(transcoded_request):
194 query_params = json.loads(
195 json_format.MessageToJson(
196 transcoded_request["query_params"],
197 use_integers_for_enums=True,
198 )
199 )
200 query_params.update(
201 _BaseSubscriberRestTransport._BaseCreateSnapshot._get_unset_required_fields(
202 query_params
203 )
204 )
205
206 query_params["$alt"] = "json;enum-encoding=int"
207 return query_params
208
209 class _BaseCreateSubscription:
210 def __hash__(self): # pragma: NO COVER
211 return NotImplementedError("__hash__ must be implemented.")
212
213 __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {}
214
215 @classmethod
216 def _get_unset_required_fields(cls, message_dict):
217 return {
218 k: v
219 for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items()
220 if k not in message_dict
221 }
222
223 @staticmethod
224 def _get_http_options():
225 http_options: List[Dict[str, str]] = [
226 {
227 "method": "put",
228 "uri": "/v1/{name=projects/*/subscriptions/*}",
229 "body": "*",
230 },
231 ]
232 return http_options
233
234 @staticmethod
235 def _get_transcoded_request(http_options, request):
236 pb_request = pubsub.Subscription.pb(request)
237 transcoded_request = path_template.transcode(http_options, pb_request)
238 return transcoded_request
239
240 @staticmethod
241 def _get_request_body_json(transcoded_request):
242 # Jsonify the request body
243
244 body = json_format.MessageToJson(
245 transcoded_request["body"], use_integers_for_enums=True
246 )
247 return body
248
249 @staticmethod
250 def _get_query_params_json(transcoded_request):
251 query_params = json.loads(
252 json_format.MessageToJson(
253 transcoded_request["query_params"],
254 use_integers_for_enums=True,
255 )
256 )
257 query_params.update(
258 _BaseSubscriberRestTransport._BaseCreateSubscription._get_unset_required_fields(
259 query_params
260 )
261 )
262
263 query_params["$alt"] = "json;enum-encoding=int"
264 return query_params
265
266 class _BaseDeleteSnapshot:
267 def __hash__(self): # pragma: NO COVER
268 return NotImplementedError("__hash__ must be implemented.")
269
270 __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {}
271
272 @classmethod
273 def _get_unset_required_fields(cls, message_dict):
274 return {
275 k: v
276 for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items()
277 if k not in message_dict
278 }
279
280 @staticmethod
281 def _get_http_options():
282 http_options: List[Dict[str, str]] = [
283 {
284 "method": "delete",
285 "uri": "/v1/{snapshot=projects/*/snapshots/*}",
286 },
287 ]
288 return http_options
289
290 @staticmethod
291 def _get_transcoded_request(http_options, request):
292 pb_request = pubsub.DeleteSnapshotRequest.pb(request)
293 transcoded_request = path_template.transcode(http_options, pb_request)
294 return transcoded_request
295
296 @staticmethod
297 def _get_query_params_json(transcoded_request):
298 query_params = json.loads(
299 json_format.MessageToJson(
300 transcoded_request["query_params"],
301 use_integers_for_enums=True,
302 )
303 )
304 query_params.update(
305 _BaseSubscriberRestTransport._BaseDeleteSnapshot._get_unset_required_fields(
306 query_params
307 )
308 )
309
310 query_params["$alt"] = "json;enum-encoding=int"
311 return query_params
312
313 class _BaseDeleteSubscription:
314 def __hash__(self): # pragma: NO COVER
315 return NotImplementedError("__hash__ must be implemented.")
316
317 __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {}
318
319 @classmethod
320 def _get_unset_required_fields(cls, message_dict):
321 return {
322 k: v
323 for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items()
324 if k not in message_dict
325 }
326
327 @staticmethod
328 def _get_http_options():
329 http_options: List[Dict[str, str]] = [
330 {
331 "method": "delete",
332 "uri": "/v1/{subscription=projects/*/subscriptions/*}",
333 },
334 ]
335 return http_options
336
337 @staticmethod
338 def _get_transcoded_request(http_options, request):
339 pb_request = pubsub.DeleteSubscriptionRequest.pb(request)
340 transcoded_request = path_template.transcode(http_options, pb_request)
341 return transcoded_request
342
343 @staticmethod
344 def _get_query_params_json(transcoded_request):
345 query_params = json.loads(
346 json_format.MessageToJson(
347 transcoded_request["query_params"],
348 use_integers_for_enums=True,
349 )
350 )
351 query_params.update(
352 _BaseSubscriberRestTransport._BaseDeleteSubscription._get_unset_required_fields(
353 query_params
354 )
355 )
356
357 query_params["$alt"] = "json;enum-encoding=int"
358 return query_params
359
360 class _BaseGetSnapshot:
361 def __hash__(self): # pragma: NO COVER
362 return NotImplementedError("__hash__ must be implemented.")
363
364 __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {}
365
366 @classmethod
367 def _get_unset_required_fields(cls, message_dict):
368 return {
369 k: v
370 for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items()
371 if k not in message_dict
372 }
373
374 @staticmethod
375 def _get_http_options():
376 http_options: List[Dict[str, str]] = [
377 {
378 "method": "get",
379 "uri": "/v1/{snapshot=projects/*/snapshots/*}",
380 },
381 ]
382 return http_options
383
384 @staticmethod
385 def _get_transcoded_request(http_options, request):
386 pb_request = pubsub.GetSnapshotRequest.pb(request)
387 transcoded_request = path_template.transcode(http_options, pb_request)
388 return transcoded_request
389
390 @staticmethod
391 def _get_query_params_json(transcoded_request):
392 query_params = json.loads(
393 json_format.MessageToJson(
394 transcoded_request["query_params"],
395 use_integers_for_enums=True,
396 )
397 )
398 query_params.update(
399 _BaseSubscriberRestTransport._BaseGetSnapshot._get_unset_required_fields(
400 query_params
401 )
402 )
403
404 query_params["$alt"] = "json;enum-encoding=int"
405 return query_params
406
407 class _BaseGetSubscription:
408 def __hash__(self): # pragma: NO COVER
409 return NotImplementedError("__hash__ must be implemented.")
410
411 __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {}
412
413 @classmethod
414 def _get_unset_required_fields(cls, message_dict):
415 return {
416 k: v
417 for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items()
418 if k not in message_dict
419 }
420
421 @staticmethod
422 def _get_http_options():
423 http_options: List[Dict[str, str]] = [
424 {
425 "method": "get",
426 "uri": "/v1/{subscription=projects/*/subscriptions/*}",
427 },
428 ]
429 return http_options
430
431 @staticmethod
432 def _get_transcoded_request(http_options, request):
433 pb_request = pubsub.GetSubscriptionRequest.pb(request)
434 transcoded_request = path_template.transcode(http_options, pb_request)
435 return transcoded_request
436
437 @staticmethod
438 def _get_query_params_json(transcoded_request):
439 query_params = json.loads(
440 json_format.MessageToJson(
441 transcoded_request["query_params"],
442 use_integers_for_enums=True,
443 )
444 )
445 query_params.update(
446 _BaseSubscriberRestTransport._BaseGetSubscription._get_unset_required_fields(
447 query_params
448 )
449 )
450
451 query_params["$alt"] = "json;enum-encoding=int"
452 return query_params
453
454 class _BaseListSnapshots:
455 def __hash__(self): # pragma: NO COVER
456 return NotImplementedError("__hash__ must be implemented.")
457
458 __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {}
459
460 @classmethod
461 def _get_unset_required_fields(cls, message_dict):
462 return {
463 k: v
464 for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items()
465 if k not in message_dict
466 }
467
468 @staticmethod
469 def _get_http_options():
470 http_options: List[Dict[str, str]] = [
471 {
472 "method": "get",
473 "uri": "/v1/{project=projects/*}/snapshots",
474 },
475 ]
476 return http_options
477
478 @staticmethod
479 def _get_transcoded_request(http_options, request):
480 pb_request = pubsub.ListSnapshotsRequest.pb(request)
481 transcoded_request = path_template.transcode(http_options, pb_request)
482 return transcoded_request
483
484 @staticmethod
485 def _get_query_params_json(transcoded_request):
486 query_params = json.loads(
487 json_format.MessageToJson(
488 transcoded_request["query_params"],
489 use_integers_for_enums=True,
490 )
491 )
492 query_params.update(
493 _BaseSubscriberRestTransport._BaseListSnapshots._get_unset_required_fields(
494 query_params
495 )
496 )
497
498 query_params["$alt"] = "json;enum-encoding=int"
499 return query_params
500
501 class _BaseListSubscriptions:
502 def __hash__(self): # pragma: NO COVER
503 return NotImplementedError("__hash__ must be implemented.")
504
505 __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {}
506
507 @classmethod
508 def _get_unset_required_fields(cls, message_dict):
509 return {
510 k: v
511 for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items()
512 if k not in message_dict
513 }
514
515 @staticmethod
516 def _get_http_options():
517 http_options: List[Dict[str, str]] = [
518 {
519 "method": "get",
520 "uri": "/v1/{project=projects/*}/subscriptions",
521 },
522 ]
523 return http_options
524
525 @staticmethod
526 def _get_transcoded_request(http_options, request):
527 pb_request = pubsub.ListSubscriptionsRequest.pb(request)
528 transcoded_request = path_template.transcode(http_options, pb_request)
529 return transcoded_request
530
531 @staticmethod
532 def _get_query_params_json(transcoded_request):
533 query_params = json.loads(
534 json_format.MessageToJson(
535 transcoded_request["query_params"],
536 use_integers_for_enums=True,
537 )
538 )
539 query_params.update(
540 _BaseSubscriberRestTransport._BaseListSubscriptions._get_unset_required_fields(
541 query_params
542 )
543 )
544
545 query_params["$alt"] = "json;enum-encoding=int"
546 return query_params
547
548 class _BaseModifyAckDeadline:
549 def __hash__(self): # pragma: NO COVER
550 return NotImplementedError("__hash__ must be implemented.")
551
552 __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {}
553
554 @classmethod
555 def _get_unset_required_fields(cls, message_dict):
556 return {
557 k: v
558 for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items()
559 if k not in message_dict
560 }
561
562 @staticmethod
563 def _get_http_options():
564 http_options: List[Dict[str, str]] = [
565 {
566 "method": "post",
567 "uri": "/v1/{subscription=projects/*/subscriptions/*}:modifyAckDeadline",
568 "body": "*",
569 },
570 ]
571 return http_options
572
573 @staticmethod
574 def _get_transcoded_request(http_options, request):
575 pb_request = pubsub.ModifyAckDeadlineRequest.pb(request)
576 transcoded_request = path_template.transcode(http_options, pb_request)
577 return transcoded_request
578
579 @staticmethod
580 def _get_request_body_json(transcoded_request):
581 # Jsonify the request body
582
583 body = json_format.MessageToJson(
584 transcoded_request["body"], use_integers_for_enums=True
585 )
586 return body
587
588 @staticmethod
589 def _get_query_params_json(transcoded_request):
590 query_params = json.loads(
591 json_format.MessageToJson(
592 transcoded_request["query_params"],
593 use_integers_for_enums=True,
594 )
595 )
596 query_params.update(
597 _BaseSubscriberRestTransport._BaseModifyAckDeadline._get_unset_required_fields(
598 query_params
599 )
600 )
601
602 query_params["$alt"] = "json;enum-encoding=int"
603 return query_params
604
605 class _BaseModifyPushConfig:
606 def __hash__(self): # pragma: NO COVER
607 return NotImplementedError("__hash__ must be implemented.")
608
609 __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {}
610
611 @classmethod
612 def _get_unset_required_fields(cls, message_dict):
613 return {
614 k: v
615 for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items()
616 if k not in message_dict
617 }
618
619 @staticmethod
620 def _get_http_options():
621 http_options: List[Dict[str, str]] = [
622 {
623 "method": "post",
624 "uri": "/v1/{subscription=projects/*/subscriptions/*}:modifyPushConfig",
625 "body": "*",
626 },
627 ]
628 return http_options
629
630 @staticmethod
631 def _get_transcoded_request(http_options, request):
632 pb_request = pubsub.ModifyPushConfigRequest.pb(request)
633 transcoded_request = path_template.transcode(http_options, pb_request)
634 return transcoded_request
635
636 @staticmethod
637 def _get_request_body_json(transcoded_request):
638 # Jsonify the request body
639
640 body = json_format.MessageToJson(
641 transcoded_request["body"], use_integers_for_enums=True
642 )
643 return body
644
645 @staticmethod
646 def _get_query_params_json(transcoded_request):
647 query_params = json.loads(
648 json_format.MessageToJson(
649 transcoded_request["query_params"],
650 use_integers_for_enums=True,
651 )
652 )
653 query_params.update(
654 _BaseSubscriberRestTransport._BaseModifyPushConfig._get_unset_required_fields(
655 query_params
656 )
657 )
658
659 query_params["$alt"] = "json;enum-encoding=int"
660 return query_params
661
662 class _BasePull:
663 def __hash__(self): # pragma: NO COVER
664 return NotImplementedError("__hash__ must be implemented.")
665
666 __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {}
667
668 @classmethod
669 def _get_unset_required_fields(cls, message_dict):
670 return {
671 k: v
672 for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items()
673 if k not in message_dict
674 }
675
676 @staticmethod
677 def _get_http_options():
678 http_options: List[Dict[str, str]] = [
679 {
680 "method": "post",
681 "uri": "/v1/{subscription=projects/*/subscriptions/*}:pull",
682 "body": "*",
683 },
684 ]
685 return http_options
686
687 @staticmethod
688 def _get_transcoded_request(http_options, request):
689 pb_request = pubsub.PullRequest.pb(request)
690 transcoded_request = path_template.transcode(http_options, pb_request)
691 return transcoded_request
692
693 @staticmethod
694 def _get_request_body_json(transcoded_request):
695 # Jsonify the request body
696
697 body = json_format.MessageToJson(
698 transcoded_request["body"], use_integers_for_enums=True
699 )
700 return body
701
702 @staticmethod
703 def _get_query_params_json(transcoded_request):
704 query_params = json.loads(
705 json_format.MessageToJson(
706 transcoded_request["query_params"],
707 use_integers_for_enums=True,
708 )
709 )
710 query_params.update(
711 _BaseSubscriberRestTransport._BasePull._get_unset_required_fields(
712 query_params
713 )
714 )
715
716 query_params["$alt"] = "json;enum-encoding=int"
717 return query_params
718
719 class _BaseSeek:
720 def __hash__(self): # pragma: NO COVER
721 return NotImplementedError("__hash__ must be implemented.")
722
723 __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {}
724
725 @classmethod
726 def _get_unset_required_fields(cls, message_dict):
727 return {
728 k: v
729 for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items()
730 if k not in message_dict
731 }
732
733 @staticmethod
734 def _get_http_options():
735 http_options: List[Dict[str, str]] = [
736 {
737 "method": "post",
738 "uri": "/v1/{subscription=projects/*/subscriptions/*}:seek",
739 "body": "*",
740 },
741 ]
742 return http_options
743
744 @staticmethod
745 def _get_transcoded_request(http_options, request):
746 pb_request = pubsub.SeekRequest.pb(request)
747 transcoded_request = path_template.transcode(http_options, pb_request)
748 return transcoded_request
749
750 @staticmethod
751 def _get_request_body_json(transcoded_request):
752 # Jsonify the request body
753
754 body = json_format.MessageToJson(
755 transcoded_request["body"], use_integers_for_enums=True
756 )
757 return body
758
759 @staticmethod
760 def _get_query_params_json(transcoded_request):
761 query_params = json.loads(
762 json_format.MessageToJson(
763 transcoded_request["query_params"],
764 use_integers_for_enums=True,
765 )
766 )
767 query_params.update(
768 _BaseSubscriberRestTransport._BaseSeek._get_unset_required_fields(
769 query_params
770 )
771 )
772
773 query_params["$alt"] = "json;enum-encoding=int"
774 return query_params
775
776 class _BaseStreamingPull:
777 def __hash__(self): # pragma: NO COVER
778 return NotImplementedError("__hash__ must be implemented.")
779
780 class _BaseUpdateSnapshot:
781 def __hash__(self): # pragma: NO COVER
782 return NotImplementedError("__hash__ must be implemented.")
783
784 __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {}
785
786 @classmethod
787 def _get_unset_required_fields(cls, message_dict):
788 return {
789 k: v
790 for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items()
791 if k not in message_dict
792 }
793
794 @staticmethod
795 def _get_http_options():
796 http_options: List[Dict[str, str]] = [
797 {
798 "method": "patch",
799 "uri": "/v1/{snapshot.name=projects/*/snapshots/*}",
800 "body": "*",
801 },
802 ]
803 return http_options
804
805 @staticmethod
806 def _get_transcoded_request(http_options, request):
807 pb_request = pubsub.UpdateSnapshotRequest.pb(request)
808 transcoded_request = path_template.transcode(http_options, pb_request)
809 return transcoded_request
810
811 @staticmethod
812 def _get_request_body_json(transcoded_request):
813 # Jsonify the request body
814
815 body = json_format.MessageToJson(
816 transcoded_request["body"], use_integers_for_enums=True
817 )
818 return body
819
820 @staticmethod
821 def _get_query_params_json(transcoded_request):
822 query_params = json.loads(
823 json_format.MessageToJson(
824 transcoded_request["query_params"],
825 use_integers_for_enums=True,
826 )
827 )
828 query_params.update(
829 _BaseSubscriberRestTransport._BaseUpdateSnapshot._get_unset_required_fields(
830 query_params
831 )
832 )
833
834 query_params["$alt"] = "json;enum-encoding=int"
835 return query_params
836
837 class _BaseUpdateSubscription:
838 def __hash__(self): # pragma: NO COVER
839 return NotImplementedError("__hash__ must be implemented.")
840
841 __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {}
842
843 @classmethod
844 def _get_unset_required_fields(cls, message_dict):
845 return {
846 k: v
847 for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items()
848 if k not in message_dict
849 }
850
851 @staticmethod
852 def _get_http_options():
853 http_options: List[Dict[str, str]] = [
854 {
855 "method": "patch",
856 "uri": "/v1/{subscription.name=projects/*/subscriptions/*}",
857 "body": "*",
858 },
859 ]
860 return http_options
861
862 @staticmethod
863 def _get_transcoded_request(http_options, request):
864 pb_request = pubsub.UpdateSubscriptionRequest.pb(request)
865 transcoded_request = path_template.transcode(http_options, pb_request)
866 return transcoded_request
867
868 @staticmethod
869 def _get_request_body_json(transcoded_request):
870 # Jsonify the request body
871
872 body = json_format.MessageToJson(
873 transcoded_request["body"], use_integers_for_enums=True
874 )
875 return body
876
877 @staticmethod
878 def _get_query_params_json(transcoded_request):
879 query_params = json.loads(
880 json_format.MessageToJson(
881 transcoded_request["query_params"],
882 use_integers_for_enums=True,
883 )
884 )
885 query_params.update(
886 _BaseSubscriberRestTransport._BaseUpdateSubscription._get_unset_required_fields(
887 query_params
888 )
889 )
890
891 query_params["$alt"] = "json;enum-encoding=int"
892 return query_params
893
894 class _BaseGetIamPolicy:
895 def __hash__(self): # pragma: NO COVER
896 return NotImplementedError("__hash__ must be implemented.")
897
898 @staticmethod
899 def _get_http_options():
900 http_options: List[Dict[str, str]] = [
901 {
902 "method": "get",
903 "uri": "/v1/{resource=projects/*/topics/*}:getIamPolicy",
904 },
905 {
906 "method": "get",
907 "uri": "/v1/{resource=projects/*/subscriptions/*}:getIamPolicy",
908 },
909 {
910 "method": "get",
911 "uri": "/v1/{resource=projects/*/snapshots/*}:getIamPolicy",
912 },
913 {
914 "method": "get",
915 "uri": "/v1/{resource=projects/*/schemas/*}:getIamPolicy",
916 },
917 ]
918 return http_options
919
920 @staticmethod
921 def _get_transcoded_request(http_options, request):
922 request_kwargs = json_format.MessageToDict(request)
923 transcoded_request = path_template.transcode(http_options, **request_kwargs)
924 return transcoded_request
925
926 @staticmethod
927 def _get_query_params_json(transcoded_request):
928 query_params = json.loads(json.dumps(transcoded_request["query_params"]))
929 return query_params
930
931 class _BaseSetIamPolicy:
932 def __hash__(self): # pragma: NO COVER
933 return NotImplementedError("__hash__ must be implemented.")
934
935 @staticmethod
936 def _get_http_options():
937 http_options: List[Dict[str, str]] = [
938 {
939 "method": "post",
940 "uri": "/v1/{resource=projects/*/topics/*}:setIamPolicy",
941 "body": "*",
942 },
943 {
944 "method": "post",
945 "uri": "/v1/{resource=projects/*/subscriptions/*}:setIamPolicy",
946 "body": "*",
947 },
948 {
949 "method": "post",
950 "uri": "/v1/{resource=projects/*/snapshots/*}:setIamPolicy",
951 "body": "*",
952 },
953 {
954 "method": "post",
955 "uri": "/v1/{resource=projects/*/schemas/*}:setIamPolicy",
956 "body": "*",
957 },
958 ]
959 return http_options
960
961 @staticmethod
962 def _get_transcoded_request(http_options, request):
963 request_kwargs = json_format.MessageToDict(request)
964 transcoded_request = path_template.transcode(http_options, **request_kwargs)
965 return transcoded_request
966
967 @staticmethod
968 def _get_request_body_json(transcoded_request):
969 body = json.dumps(transcoded_request["body"])
970 return body
971
972 @staticmethod
973 def _get_query_params_json(transcoded_request):
974 query_params = json.loads(json.dumps(transcoded_request["query_params"]))
975 return query_params
976
977 class _BaseTestIamPermissions:
978 def __hash__(self): # pragma: NO COVER
979 return NotImplementedError("__hash__ must be implemented.")
980
981 @staticmethod
982 def _get_http_options():
983 http_options: List[Dict[str, str]] = [
984 {
985 "method": "post",
986 "uri": "/v1/{resource=projects/*/subscriptions/*}:testIamPermissions",
987 "body": "*",
988 },
989 {
990 "method": "post",
991 "uri": "/v1/{resource=projects/*/topics/*}:testIamPermissions",
992 "body": "*",
993 },
994 {
995 "method": "post",
996 "uri": "/v1/{resource=projects/*/snapshots/*}:testIamPermissions",
997 "body": "*",
998 },
999 {
1000 "method": "post",
1001 "uri": "/v1/{resource=projects/*/schemas/*}:testIamPermissions",
1002 "body": "*",
1003 },
1004 ]
1005 return http_options
1006
1007 @staticmethod
1008 def _get_transcoded_request(http_options, request):
1009 request_kwargs = json_format.MessageToDict(request)
1010 transcoded_request = path_template.transcode(http_options, **request_kwargs)
1011 return transcoded_request
1012
1013 @staticmethod
1014 def _get_request_body_json(transcoded_request):
1015 body = json.dumps(transcoded_request["body"])
1016 return body
1017
1018 @staticmethod
1019 def _get_query_params_json(transcoded_request):
1020 query_params = json.loads(json.dumps(transcoded_request["query_params"]))
1021 return query_params
1022
1023
1024__all__ = ("_BaseSubscriberRestTransport",)