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 logging
17import json # type: ignore
18
19from google.auth.transport.requests import AuthorizedSession # type: ignore
20from google.auth import credentials as ga_credentials # type: ignore
21from google.api_core import exceptions as core_exceptions
22from google.api_core import retry as retries
23from google.api_core import rest_helpers
24from google.api_core import rest_streaming
25from google.api_core import gapic_v1
26import google.protobuf
27
28from google.protobuf import json_format
29from google.cloud.location import locations_pb2 # type: ignore
30
31from requests import __version__ as requests_version
32import dataclasses
33from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union
34import warnings
35
36
37from google.cloud.firestore_v1.types import document
38from google.cloud.firestore_v1.types import document as gf_document
39from google.cloud.firestore_v1.types import firestore
40from google.protobuf import empty_pb2 # type: ignore
41from google.longrunning import operations_pb2 # type: ignore
42
43
44from .rest_base import _BaseFirestoreRestTransport
45from .base import DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO
46
47try:
48 OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None]
49except AttributeError: # pragma: NO COVER
50 OptionalRetry = Union[retries.Retry, object, None] # type: ignore
51
52try:
53 from google.api_core import client_logging # type: ignore
54
55 CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER
56except ImportError: # pragma: NO COVER
57 CLIENT_LOGGING_SUPPORTED = False
58
59_LOGGER = logging.getLogger(__name__)
60
61DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
62 gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version,
63 grpc_version=None,
64 rest_version=f"requests@{requests_version}",
65)
66
67if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER
68 DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__
69
70
71class FirestoreRestInterceptor:
72 """Interceptor for Firestore.
73
74 Interceptors are used to manipulate requests, request metadata, and responses
75 in arbitrary ways.
76 Example use cases include:
77 * Logging
78 * Verifying requests according to service or custom semantics
79 * Stripping extraneous information from responses
80
81 These use cases and more can be enabled by injecting an
82 instance of a custom subclass when constructing the FirestoreRestTransport.
83
84 .. code-block:: python
85 class MyCustomFirestoreInterceptor(FirestoreRestInterceptor):
86 def pre_batch_get_documents(self, request, metadata):
87 logging.log(f"Received request: {request}")
88 return request, metadata
89
90 def post_batch_get_documents(self, response):
91 logging.log(f"Received response: {response}")
92 return response
93
94 def pre_batch_write(self, request, metadata):
95 logging.log(f"Received request: {request}")
96 return request, metadata
97
98 def post_batch_write(self, response):
99 logging.log(f"Received response: {response}")
100 return response
101
102 def pre_begin_transaction(self, request, metadata):
103 logging.log(f"Received request: {request}")
104 return request, metadata
105
106 def post_begin_transaction(self, response):
107 logging.log(f"Received response: {response}")
108 return response
109
110 def pre_commit(self, request, metadata):
111 logging.log(f"Received request: {request}")
112 return request, metadata
113
114 def post_commit(self, response):
115 logging.log(f"Received response: {response}")
116 return response
117
118 def pre_create_document(self, request, metadata):
119 logging.log(f"Received request: {request}")
120 return request, metadata
121
122 def post_create_document(self, response):
123 logging.log(f"Received response: {response}")
124 return response
125
126 def pre_delete_document(self, request, metadata):
127 logging.log(f"Received request: {request}")
128 return request, metadata
129
130 def pre_execute_pipeline(self, request, metadata):
131 logging.log(f"Received request: {request}")
132 return request, metadata
133
134 def post_execute_pipeline(self, response):
135 logging.log(f"Received response: {response}")
136 return response
137
138 def pre_get_document(self, request, metadata):
139 logging.log(f"Received request: {request}")
140 return request, metadata
141
142 def post_get_document(self, response):
143 logging.log(f"Received response: {response}")
144 return response
145
146 def pre_list_collection_ids(self, request, metadata):
147 logging.log(f"Received request: {request}")
148 return request, metadata
149
150 def post_list_collection_ids(self, response):
151 logging.log(f"Received response: {response}")
152 return response
153
154 def pre_list_documents(self, request, metadata):
155 logging.log(f"Received request: {request}")
156 return request, metadata
157
158 def post_list_documents(self, response):
159 logging.log(f"Received response: {response}")
160 return response
161
162 def pre_partition_query(self, request, metadata):
163 logging.log(f"Received request: {request}")
164 return request, metadata
165
166 def post_partition_query(self, response):
167 logging.log(f"Received response: {response}")
168 return response
169
170 def pre_rollback(self, request, metadata):
171 logging.log(f"Received request: {request}")
172 return request, metadata
173
174 def pre_run_aggregation_query(self, request, metadata):
175 logging.log(f"Received request: {request}")
176 return request, metadata
177
178 def post_run_aggregation_query(self, response):
179 logging.log(f"Received response: {response}")
180 return response
181
182 def pre_run_query(self, request, metadata):
183 logging.log(f"Received request: {request}")
184 return request, metadata
185
186 def post_run_query(self, response):
187 logging.log(f"Received response: {response}")
188 return response
189
190 def pre_update_document(self, request, metadata):
191 logging.log(f"Received request: {request}")
192 return request, metadata
193
194 def post_update_document(self, response):
195 logging.log(f"Received response: {response}")
196 return response
197
198 transport = FirestoreRestTransport(interceptor=MyCustomFirestoreInterceptor())
199 client = FirestoreClient(transport=transport)
200
201
202 """
203
204 def pre_batch_get_documents(
205 self,
206 request: firestore.BatchGetDocumentsRequest,
207 metadata: Sequence[Tuple[str, Union[str, bytes]]],
208 ) -> Tuple[
209 firestore.BatchGetDocumentsRequest, Sequence[Tuple[str, Union[str, bytes]]]
210 ]:
211 """Pre-rpc interceptor for batch_get_documents
212
213 Override in a subclass to manipulate the request or metadata
214 before they are sent to the Firestore server.
215 """
216 return request, metadata
217
218 def post_batch_get_documents(
219 self, response: rest_streaming.ResponseIterator
220 ) -> rest_streaming.ResponseIterator:
221 """Post-rpc interceptor for batch_get_documents
222
223 DEPRECATED. Please use the `post_batch_get_documents_with_metadata`
224 interceptor instead.
225
226 Override in a subclass to read or manipulate the response
227 after it is returned by the Firestore server but before
228 it is returned to user code. This `post_batch_get_documents` interceptor runs
229 before the `post_batch_get_documents_with_metadata` interceptor.
230 """
231 return response
232
233 def post_batch_get_documents_with_metadata(
234 self,
235 response: rest_streaming.ResponseIterator,
236 metadata: Sequence[Tuple[str, Union[str, bytes]]],
237 ) -> Tuple[
238 rest_streaming.ResponseIterator, Sequence[Tuple[str, Union[str, bytes]]]
239 ]:
240 """Post-rpc interceptor for batch_get_documents
241
242 Override in a subclass to read or manipulate the response or metadata after it
243 is returned by the Firestore server but before it is returned to user code.
244
245 We recommend only using this `post_batch_get_documents_with_metadata`
246 interceptor in new development instead of the `post_batch_get_documents` interceptor.
247 When both interceptors are used, this `post_batch_get_documents_with_metadata` interceptor runs after the
248 `post_batch_get_documents` interceptor. The (possibly modified) response returned by
249 `post_batch_get_documents` will be passed to
250 `post_batch_get_documents_with_metadata`.
251 """
252 return response, metadata
253
254 def pre_batch_write(
255 self,
256 request: firestore.BatchWriteRequest,
257 metadata: Sequence[Tuple[str, Union[str, bytes]]],
258 ) -> Tuple[firestore.BatchWriteRequest, Sequence[Tuple[str, Union[str, bytes]]]]:
259 """Pre-rpc interceptor for batch_write
260
261 Override in a subclass to manipulate the request or metadata
262 before they are sent to the Firestore server.
263 """
264 return request, metadata
265
266 def post_batch_write(
267 self, response: firestore.BatchWriteResponse
268 ) -> firestore.BatchWriteResponse:
269 """Post-rpc interceptor for batch_write
270
271 DEPRECATED. Please use the `post_batch_write_with_metadata`
272 interceptor instead.
273
274 Override in a subclass to read or manipulate the response
275 after it is returned by the Firestore server but before
276 it is returned to user code. This `post_batch_write` interceptor runs
277 before the `post_batch_write_with_metadata` interceptor.
278 """
279 return response
280
281 def post_batch_write_with_metadata(
282 self,
283 response: firestore.BatchWriteResponse,
284 metadata: Sequence[Tuple[str, Union[str, bytes]]],
285 ) -> Tuple[firestore.BatchWriteResponse, Sequence[Tuple[str, Union[str, bytes]]]]:
286 """Post-rpc interceptor for batch_write
287
288 Override in a subclass to read or manipulate the response or metadata after it
289 is returned by the Firestore server but before it is returned to user code.
290
291 We recommend only using this `post_batch_write_with_metadata`
292 interceptor in new development instead of the `post_batch_write` interceptor.
293 When both interceptors are used, this `post_batch_write_with_metadata` interceptor runs after the
294 `post_batch_write` interceptor. The (possibly modified) response returned by
295 `post_batch_write` will be passed to
296 `post_batch_write_with_metadata`.
297 """
298 return response, metadata
299
300 def pre_begin_transaction(
301 self,
302 request: firestore.BeginTransactionRequest,
303 metadata: Sequence[Tuple[str, Union[str, bytes]]],
304 ) -> Tuple[
305 firestore.BeginTransactionRequest, Sequence[Tuple[str, Union[str, bytes]]]
306 ]:
307 """Pre-rpc interceptor for begin_transaction
308
309 Override in a subclass to manipulate the request or metadata
310 before they are sent to the Firestore server.
311 """
312 return request, metadata
313
314 def post_begin_transaction(
315 self, response: firestore.BeginTransactionResponse
316 ) -> firestore.BeginTransactionResponse:
317 """Post-rpc interceptor for begin_transaction
318
319 DEPRECATED. Please use the `post_begin_transaction_with_metadata`
320 interceptor instead.
321
322 Override in a subclass to read or manipulate the response
323 after it is returned by the Firestore server but before
324 it is returned to user code. This `post_begin_transaction` interceptor runs
325 before the `post_begin_transaction_with_metadata` interceptor.
326 """
327 return response
328
329 def post_begin_transaction_with_metadata(
330 self,
331 response: firestore.BeginTransactionResponse,
332 metadata: Sequence[Tuple[str, Union[str, bytes]]],
333 ) -> Tuple[
334 firestore.BeginTransactionResponse, Sequence[Tuple[str, Union[str, bytes]]]
335 ]:
336 """Post-rpc interceptor for begin_transaction
337
338 Override in a subclass to read or manipulate the response or metadata after it
339 is returned by the Firestore server but before it is returned to user code.
340
341 We recommend only using this `post_begin_transaction_with_metadata`
342 interceptor in new development instead of the `post_begin_transaction` interceptor.
343 When both interceptors are used, this `post_begin_transaction_with_metadata` interceptor runs after the
344 `post_begin_transaction` interceptor. The (possibly modified) response returned by
345 `post_begin_transaction` will be passed to
346 `post_begin_transaction_with_metadata`.
347 """
348 return response, metadata
349
350 def pre_commit(
351 self,
352 request: firestore.CommitRequest,
353 metadata: Sequence[Tuple[str, Union[str, bytes]]],
354 ) -> Tuple[firestore.CommitRequest, Sequence[Tuple[str, Union[str, bytes]]]]:
355 """Pre-rpc interceptor for commit
356
357 Override in a subclass to manipulate the request or metadata
358 before they are sent to the Firestore server.
359 """
360 return request, metadata
361
362 def post_commit(
363 self, response: firestore.CommitResponse
364 ) -> firestore.CommitResponse:
365 """Post-rpc interceptor for commit
366
367 DEPRECATED. Please use the `post_commit_with_metadata`
368 interceptor instead.
369
370 Override in a subclass to read or manipulate the response
371 after it is returned by the Firestore server but before
372 it is returned to user code. This `post_commit` interceptor runs
373 before the `post_commit_with_metadata` interceptor.
374 """
375 return response
376
377 def post_commit_with_metadata(
378 self,
379 response: firestore.CommitResponse,
380 metadata: Sequence[Tuple[str, Union[str, bytes]]],
381 ) -> Tuple[firestore.CommitResponse, Sequence[Tuple[str, Union[str, bytes]]]]:
382 """Post-rpc interceptor for commit
383
384 Override in a subclass to read or manipulate the response or metadata after it
385 is returned by the Firestore server but before it is returned to user code.
386
387 We recommend only using this `post_commit_with_metadata`
388 interceptor in new development instead of the `post_commit` interceptor.
389 When both interceptors are used, this `post_commit_with_metadata` interceptor runs after the
390 `post_commit` interceptor. The (possibly modified) response returned by
391 `post_commit` will be passed to
392 `post_commit_with_metadata`.
393 """
394 return response, metadata
395
396 def pre_create_document(
397 self,
398 request: firestore.CreateDocumentRequest,
399 metadata: Sequence[Tuple[str, Union[str, bytes]]],
400 ) -> Tuple[
401 firestore.CreateDocumentRequest, Sequence[Tuple[str, Union[str, bytes]]]
402 ]:
403 """Pre-rpc interceptor for create_document
404
405 Override in a subclass to manipulate the request or metadata
406 before they are sent to the Firestore server.
407 """
408 return request, metadata
409
410 def post_create_document(self, response: document.Document) -> document.Document:
411 """Post-rpc interceptor for create_document
412
413 DEPRECATED. Please use the `post_create_document_with_metadata`
414 interceptor instead.
415
416 Override in a subclass to read or manipulate the response
417 after it is returned by the Firestore server but before
418 it is returned to user code. This `post_create_document` interceptor runs
419 before the `post_create_document_with_metadata` interceptor.
420 """
421 return response
422
423 def post_create_document_with_metadata(
424 self,
425 response: document.Document,
426 metadata: Sequence[Tuple[str, Union[str, bytes]]],
427 ) -> Tuple[document.Document, Sequence[Tuple[str, Union[str, bytes]]]]:
428 """Post-rpc interceptor for create_document
429
430 Override in a subclass to read or manipulate the response or metadata after it
431 is returned by the Firestore server but before it is returned to user code.
432
433 We recommend only using this `post_create_document_with_metadata`
434 interceptor in new development instead of the `post_create_document` interceptor.
435 When both interceptors are used, this `post_create_document_with_metadata` interceptor runs after the
436 `post_create_document` interceptor. The (possibly modified) response returned by
437 `post_create_document` will be passed to
438 `post_create_document_with_metadata`.
439 """
440 return response, metadata
441
442 def pre_delete_document(
443 self,
444 request: firestore.DeleteDocumentRequest,
445 metadata: Sequence[Tuple[str, Union[str, bytes]]],
446 ) -> Tuple[
447 firestore.DeleteDocumentRequest, Sequence[Tuple[str, Union[str, bytes]]]
448 ]:
449 """Pre-rpc interceptor for delete_document
450
451 Override in a subclass to manipulate the request or metadata
452 before they are sent to the Firestore server.
453 """
454 return request, metadata
455
456 def pre_execute_pipeline(
457 self,
458 request: firestore.ExecutePipelineRequest,
459 metadata: Sequence[Tuple[str, Union[str, bytes]]],
460 ) -> Tuple[
461 firestore.ExecutePipelineRequest, Sequence[Tuple[str, Union[str, bytes]]]
462 ]:
463 """Pre-rpc interceptor for execute_pipeline
464
465 Override in a subclass to manipulate the request or metadata
466 before they are sent to the Firestore server.
467 """
468 return request, metadata
469
470 def post_execute_pipeline(
471 self, response: rest_streaming.ResponseIterator
472 ) -> rest_streaming.ResponseIterator:
473 """Post-rpc interceptor for execute_pipeline
474
475 DEPRECATED. Please use the `post_execute_pipeline_with_metadata`
476 interceptor instead.
477
478 Override in a subclass to read or manipulate the response
479 after it is returned by the Firestore server but before
480 it is returned to user code. This `post_execute_pipeline` interceptor runs
481 before the `post_execute_pipeline_with_metadata` interceptor.
482 """
483 return response
484
485 def post_execute_pipeline_with_metadata(
486 self,
487 response: rest_streaming.ResponseIterator,
488 metadata: Sequence[Tuple[str, Union[str, bytes]]],
489 ) -> Tuple[
490 rest_streaming.ResponseIterator, Sequence[Tuple[str, Union[str, bytes]]]
491 ]:
492 """Post-rpc interceptor for execute_pipeline
493
494 Override in a subclass to read or manipulate the response or metadata after it
495 is returned by the Firestore server but before it is returned to user code.
496
497 We recommend only using this `post_execute_pipeline_with_metadata`
498 interceptor in new development instead of the `post_execute_pipeline` interceptor.
499 When both interceptors are used, this `post_execute_pipeline_with_metadata` interceptor runs after the
500 `post_execute_pipeline` interceptor. The (possibly modified) response returned by
501 `post_execute_pipeline` will be passed to
502 `post_execute_pipeline_with_metadata`.
503 """
504 return response, metadata
505
506 def pre_get_document(
507 self,
508 request: firestore.GetDocumentRequest,
509 metadata: Sequence[Tuple[str, Union[str, bytes]]],
510 ) -> Tuple[firestore.GetDocumentRequest, Sequence[Tuple[str, Union[str, bytes]]]]:
511 """Pre-rpc interceptor for get_document
512
513 Override in a subclass to manipulate the request or metadata
514 before they are sent to the Firestore server.
515 """
516 return request, metadata
517
518 def post_get_document(self, response: document.Document) -> document.Document:
519 """Post-rpc interceptor for get_document
520
521 DEPRECATED. Please use the `post_get_document_with_metadata`
522 interceptor instead.
523
524 Override in a subclass to read or manipulate the response
525 after it is returned by the Firestore server but before
526 it is returned to user code. This `post_get_document` interceptor runs
527 before the `post_get_document_with_metadata` interceptor.
528 """
529 return response
530
531 def post_get_document_with_metadata(
532 self,
533 response: document.Document,
534 metadata: Sequence[Tuple[str, Union[str, bytes]]],
535 ) -> Tuple[document.Document, Sequence[Tuple[str, Union[str, bytes]]]]:
536 """Post-rpc interceptor for get_document
537
538 Override in a subclass to read or manipulate the response or metadata after it
539 is returned by the Firestore server but before it is returned to user code.
540
541 We recommend only using this `post_get_document_with_metadata`
542 interceptor in new development instead of the `post_get_document` interceptor.
543 When both interceptors are used, this `post_get_document_with_metadata` interceptor runs after the
544 `post_get_document` interceptor. The (possibly modified) response returned by
545 `post_get_document` will be passed to
546 `post_get_document_with_metadata`.
547 """
548 return response, metadata
549
550 def pre_list_collection_ids(
551 self,
552 request: firestore.ListCollectionIdsRequest,
553 metadata: Sequence[Tuple[str, Union[str, bytes]]],
554 ) -> Tuple[
555 firestore.ListCollectionIdsRequest, Sequence[Tuple[str, Union[str, bytes]]]
556 ]:
557 """Pre-rpc interceptor for list_collection_ids
558
559 Override in a subclass to manipulate the request or metadata
560 before they are sent to the Firestore server.
561 """
562 return request, metadata
563
564 def post_list_collection_ids(
565 self, response: firestore.ListCollectionIdsResponse
566 ) -> firestore.ListCollectionIdsResponse:
567 """Post-rpc interceptor for list_collection_ids
568
569 DEPRECATED. Please use the `post_list_collection_ids_with_metadata`
570 interceptor instead.
571
572 Override in a subclass to read or manipulate the response
573 after it is returned by the Firestore server but before
574 it is returned to user code. This `post_list_collection_ids` interceptor runs
575 before the `post_list_collection_ids_with_metadata` interceptor.
576 """
577 return response
578
579 def post_list_collection_ids_with_metadata(
580 self,
581 response: firestore.ListCollectionIdsResponse,
582 metadata: Sequence[Tuple[str, Union[str, bytes]]],
583 ) -> Tuple[
584 firestore.ListCollectionIdsResponse, Sequence[Tuple[str, Union[str, bytes]]]
585 ]:
586 """Post-rpc interceptor for list_collection_ids
587
588 Override in a subclass to read or manipulate the response or metadata after it
589 is returned by the Firestore server but before it is returned to user code.
590
591 We recommend only using this `post_list_collection_ids_with_metadata`
592 interceptor in new development instead of the `post_list_collection_ids` interceptor.
593 When both interceptors are used, this `post_list_collection_ids_with_metadata` interceptor runs after the
594 `post_list_collection_ids` interceptor. The (possibly modified) response returned by
595 `post_list_collection_ids` will be passed to
596 `post_list_collection_ids_with_metadata`.
597 """
598 return response, metadata
599
600 def pre_list_documents(
601 self,
602 request: firestore.ListDocumentsRequest,
603 metadata: Sequence[Tuple[str, Union[str, bytes]]],
604 ) -> Tuple[firestore.ListDocumentsRequest, Sequence[Tuple[str, Union[str, bytes]]]]:
605 """Pre-rpc interceptor for list_documents
606
607 Override in a subclass to manipulate the request or metadata
608 before they are sent to the Firestore server.
609 """
610 return request, metadata
611
612 def post_list_documents(
613 self, response: firestore.ListDocumentsResponse
614 ) -> firestore.ListDocumentsResponse:
615 """Post-rpc interceptor for list_documents
616
617 DEPRECATED. Please use the `post_list_documents_with_metadata`
618 interceptor instead.
619
620 Override in a subclass to read or manipulate the response
621 after it is returned by the Firestore server but before
622 it is returned to user code. This `post_list_documents` interceptor runs
623 before the `post_list_documents_with_metadata` interceptor.
624 """
625 return response
626
627 def post_list_documents_with_metadata(
628 self,
629 response: firestore.ListDocumentsResponse,
630 metadata: Sequence[Tuple[str, Union[str, bytes]]],
631 ) -> Tuple[
632 firestore.ListDocumentsResponse, Sequence[Tuple[str, Union[str, bytes]]]
633 ]:
634 """Post-rpc interceptor for list_documents
635
636 Override in a subclass to read or manipulate the response or metadata after it
637 is returned by the Firestore server but before it is returned to user code.
638
639 We recommend only using this `post_list_documents_with_metadata`
640 interceptor in new development instead of the `post_list_documents` interceptor.
641 When both interceptors are used, this `post_list_documents_with_metadata` interceptor runs after the
642 `post_list_documents` interceptor. The (possibly modified) response returned by
643 `post_list_documents` will be passed to
644 `post_list_documents_with_metadata`.
645 """
646 return response, metadata
647
648 def pre_partition_query(
649 self,
650 request: firestore.PartitionQueryRequest,
651 metadata: Sequence[Tuple[str, Union[str, bytes]]],
652 ) -> Tuple[
653 firestore.PartitionQueryRequest, Sequence[Tuple[str, Union[str, bytes]]]
654 ]:
655 """Pre-rpc interceptor for partition_query
656
657 Override in a subclass to manipulate the request or metadata
658 before they are sent to the Firestore server.
659 """
660 return request, metadata
661
662 def post_partition_query(
663 self, response: firestore.PartitionQueryResponse
664 ) -> firestore.PartitionQueryResponse:
665 """Post-rpc interceptor for partition_query
666
667 DEPRECATED. Please use the `post_partition_query_with_metadata`
668 interceptor instead.
669
670 Override in a subclass to read or manipulate the response
671 after it is returned by the Firestore server but before
672 it is returned to user code. This `post_partition_query` interceptor runs
673 before the `post_partition_query_with_metadata` interceptor.
674 """
675 return response
676
677 def post_partition_query_with_metadata(
678 self,
679 response: firestore.PartitionQueryResponse,
680 metadata: Sequence[Tuple[str, Union[str, bytes]]],
681 ) -> Tuple[
682 firestore.PartitionQueryResponse, Sequence[Tuple[str, Union[str, bytes]]]
683 ]:
684 """Post-rpc interceptor for partition_query
685
686 Override in a subclass to read or manipulate the response or metadata after it
687 is returned by the Firestore server but before it is returned to user code.
688
689 We recommend only using this `post_partition_query_with_metadata`
690 interceptor in new development instead of the `post_partition_query` interceptor.
691 When both interceptors are used, this `post_partition_query_with_metadata` interceptor runs after the
692 `post_partition_query` interceptor. The (possibly modified) response returned by
693 `post_partition_query` will be passed to
694 `post_partition_query_with_metadata`.
695 """
696 return response, metadata
697
698 def pre_rollback(
699 self,
700 request: firestore.RollbackRequest,
701 metadata: Sequence[Tuple[str, Union[str, bytes]]],
702 ) -> Tuple[firestore.RollbackRequest, Sequence[Tuple[str, Union[str, bytes]]]]:
703 """Pre-rpc interceptor for rollback
704
705 Override in a subclass to manipulate the request or metadata
706 before they are sent to the Firestore server.
707 """
708 return request, metadata
709
710 def pre_run_aggregation_query(
711 self,
712 request: firestore.RunAggregationQueryRequest,
713 metadata: Sequence[Tuple[str, Union[str, bytes]]],
714 ) -> Tuple[
715 firestore.RunAggregationQueryRequest, Sequence[Tuple[str, Union[str, bytes]]]
716 ]:
717 """Pre-rpc interceptor for run_aggregation_query
718
719 Override in a subclass to manipulate the request or metadata
720 before they are sent to the Firestore server.
721 """
722 return request, metadata
723
724 def post_run_aggregation_query(
725 self, response: rest_streaming.ResponseIterator
726 ) -> rest_streaming.ResponseIterator:
727 """Post-rpc interceptor for run_aggregation_query
728
729 DEPRECATED. Please use the `post_run_aggregation_query_with_metadata`
730 interceptor instead.
731
732 Override in a subclass to read or manipulate the response
733 after it is returned by the Firestore server but before
734 it is returned to user code. This `post_run_aggregation_query` interceptor runs
735 before the `post_run_aggregation_query_with_metadata` interceptor.
736 """
737 return response
738
739 def post_run_aggregation_query_with_metadata(
740 self,
741 response: rest_streaming.ResponseIterator,
742 metadata: Sequence[Tuple[str, Union[str, bytes]]],
743 ) -> Tuple[
744 rest_streaming.ResponseIterator, Sequence[Tuple[str, Union[str, bytes]]]
745 ]:
746 """Post-rpc interceptor for run_aggregation_query
747
748 Override in a subclass to read or manipulate the response or metadata after it
749 is returned by the Firestore server but before it is returned to user code.
750
751 We recommend only using this `post_run_aggregation_query_with_metadata`
752 interceptor in new development instead of the `post_run_aggregation_query` interceptor.
753 When both interceptors are used, this `post_run_aggregation_query_with_metadata` interceptor runs after the
754 `post_run_aggregation_query` interceptor. The (possibly modified) response returned by
755 `post_run_aggregation_query` will be passed to
756 `post_run_aggregation_query_with_metadata`.
757 """
758 return response, metadata
759
760 def pre_run_query(
761 self,
762 request: firestore.RunQueryRequest,
763 metadata: Sequence[Tuple[str, Union[str, bytes]]],
764 ) -> Tuple[firestore.RunQueryRequest, Sequence[Tuple[str, Union[str, bytes]]]]:
765 """Pre-rpc interceptor for run_query
766
767 Override in a subclass to manipulate the request or metadata
768 before they are sent to the Firestore server.
769 """
770 return request, metadata
771
772 def post_run_query(
773 self, response: rest_streaming.ResponseIterator
774 ) -> rest_streaming.ResponseIterator:
775 """Post-rpc interceptor for run_query
776
777 DEPRECATED. Please use the `post_run_query_with_metadata`
778 interceptor instead.
779
780 Override in a subclass to read or manipulate the response
781 after it is returned by the Firestore server but before
782 it is returned to user code. This `post_run_query` interceptor runs
783 before the `post_run_query_with_metadata` interceptor.
784 """
785 return response
786
787 def post_run_query_with_metadata(
788 self,
789 response: rest_streaming.ResponseIterator,
790 metadata: Sequence[Tuple[str, Union[str, bytes]]],
791 ) -> Tuple[
792 rest_streaming.ResponseIterator, Sequence[Tuple[str, Union[str, bytes]]]
793 ]:
794 """Post-rpc interceptor for run_query
795
796 Override in a subclass to read or manipulate the response or metadata after it
797 is returned by the Firestore server but before it is returned to user code.
798
799 We recommend only using this `post_run_query_with_metadata`
800 interceptor in new development instead of the `post_run_query` interceptor.
801 When both interceptors are used, this `post_run_query_with_metadata` interceptor runs after the
802 `post_run_query` interceptor. The (possibly modified) response returned by
803 `post_run_query` will be passed to
804 `post_run_query_with_metadata`.
805 """
806 return response, metadata
807
808 def pre_update_document(
809 self,
810 request: firestore.UpdateDocumentRequest,
811 metadata: Sequence[Tuple[str, Union[str, bytes]]],
812 ) -> Tuple[
813 firestore.UpdateDocumentRequest, Sequence[Tuple[str, Union[str, bytes]]]
814 ]:
815 """Pre-rpc interceptor for update_document
816
817 Override in a subclass to manipulate the request or metadata
818 before they are sent to the Firestore server.
819 """
820 return request, metadata
821
822 def post_update_document(
823 self, response: gf_document.Document
824 ) -> gf_document.Document:
825 """Post-rpc interceptor for update_document
826
827 DEPRECATED. Please use the `post_update_document_with_metadata`
828 interceptor instead.
829
830 Override in a subclass to read or manipulate the response
831 after it is returned by the Firestore server but before
832 it is returned to user code. This `post_update_document` interceptor runs
833 before the `post_update_document_with_metadata` interceptor.
834 """
835 return response
836
837 def post_update_document_with_metadata(
838 self,
839 response: gf_document.Document,
840 metadata: Sequence[Tuple[str, Union[str, bytes]]],
841 ) -> Tuple[gf_document.Document, Sequence[Tuple[str, Union[str, bytes]]]]:
842 """Post-rpc interceptor for update_document
843
844 Override in a subclass to read or manipulate the response or metadata after it
845 is returned by the Firestore server but before it is returned to user code.
846
847 We recommend only using this `post_update_document_with_metadata`
848 interceptor in new development instead of the `post_update_document` interceptor.
849 When both interceptors are used, this `post_update_document_with_metadata` interceptor runs after the
850 `post_update_document` interceptor. The (possibly modified) response returned by
851 `post_update_document` will be passed to
852 `post_update_document_with_metadata`.
853 """
854 return response, metadata
855
856 def pre_cancel_operation(
857 self,
858 request: operations_pb2.CancelOperationRequest,
859 metadata: Sequence[Tuple[str, Union[str, bytes]]],
860 ) -> Tuple[
861 operations_pb2.CancelOperationRequest, Sequence[Tuple[str, Union[str, bytes]]]
862 ]:
863 """Pre-rpc interceptor for cancel_operation
864
865 Override in a subclass to manipulate the request or metadata
866 before they are sent to the Firestore server.
867 """
868 return request, metadata
869
870 def post_cancel_operation(self, response: None) -> None:
871 """Post-rpc interceptor for cancel_operation
872
873 Override in a subclass to manipulate the response
874 after it is returned by the Firestore server but before
875 it is returned to user code.
876 """
877 return response
878
879 def pre_delete_operation(
880 self,
881 request: operations_pb2.DeleteOperationRequest,
882 metadata: Sequence[Tuple[str, Union[str, bytes]]],
883 ) -> Tuple[
884 operations_pb2.DeleteOperationRequest, Sequence[Tuple[str, Union[str, bytes]]]
885 ]:
886 """Pre-rpc interceptor for delete_operation
887
888 Override in a subclass to manipulate the request or metadata
889 before they are sent to the Firestore server.
890 """
891 return request, metadata
892
893 def post_delete_operation(self, response: None) -> None:
894 """Post-rpc interceptor for delete_operation
895
896 Override in a subclass to manipulate the response
897 after it is returned by the Firestore server but before
898 it is returned to user code.
899 """
900 return response
901
902 def pre_get_operation(
903 self,
904 request: operations_pb2.GetOperationRequest,
905 metadata: Sequence[Tuple[str, Union[str, bytes]]],
906 ) -> Tuple[
907 operations_pb2.GetOperationRequest, Sequence[Tuple[str, Union[str, bytes]]]
908 ]:
909 """Pre-rpc interceptor for get_operation
910
911 Override in a subclass to manipulate the request or metadata
912 before they are sent to the Firestore server.
913 """
914 return request, metadata
915
916 def post_get_operation(
917 self, response: operations_pb2.Operation
918 ) -> operations_pb2.Operation:
919 """Post-rpc interceptor for get_operation
920
921 Override in a subclass to manipulate the response
922 after it is returned by the Firestore server but before
923 it is returned to user code.
924 """
925 return response
926
927 def pre_list_operations(
928 self,
929 request: operations_pb2.ListOperationsRequest,
930 metadata: Sequence[Tuple[str, Union[str, bytes]]],
931 ) -> Tuple[
932 operations_pb2.ListOperationsRequest, Sequence[Tuple[str, Union[str, bytes]]]
933 ]:
934 """Pre-rpc interceptor for list_operations
935
936 Override in a subclass to manipulate the request or metadata
937 before they are sent to the Firestore server.
938 """
939 return request, metadata
940
941 def post_list_operations(
942 self, response: operations_pb2.ListOperationsResponse
943 ) -> operations_pb2.ListOperationsResponse:
944 """Post-rpc interceptor for list_operations
945
946 Override in a subclass to manipulate the response
947 after it is returned by the Firestore server but before
948 it is returned to user code.
949 """
950 return response
951
952
953@dataclasses.dataclass
954class FirestoreRestStub:
955 _session: AuthorizedSession
956 _host: str
957 _interceptor: FirestoreRestInterceptor
958
959
960class FirestoreRestTransport(_BaseFirestoreRestTransport):
961 """REST backend synchronous transport for Firestore.
962
963 The Cloud Firestore service.
964
965 Cloud Firestore is a fast, fully managed, serverless,
966 cloud-native NoSQL document database that simplifies storing,
967 syncing, and querying data for your mobile, web, and IoT apps at
968 global scale. Its client libraries provide live synchronization
969 and offline support, while its security features and
970 integrations with Firebase and Google Cloud Platform accelerate
971 building truly serverless apps.
972
973 This class defines the same methods as the primary client, so the
974 primary client can load the underlying transport implementation
975 and call it.
976
977 It sends JSON representations of protocol buffers over HTTP/1.1
978 """
979
980 def __init__(
981 self,
982 *,
983 host: str = "firestore.googleapis.com",
984 credentials: Optional[ga_credentials.Credentials] = None,
985 credentials_file: Optional[str] = None,
986 scopes: Optional[Sequence[str]] = None,
987 client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None,
988 quota_project_id: Optional[str] = None,
989 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
990 always_use_jwt_access: Optional[bool] = False,
991 url_scheme: str = "https",
992 interceptor: Optional[FirestoreRestInterceptor] = None,
993 api_audience: Optional[str] = None,
994 ) -> None:
995 """Instantiate the transport.
996
997 Args:
998 host (Optional[str]):
999 The hostname to connect to (default: 'firestore.googleapis.com').
1000 credentials (Optional[google.auth.credentials.Credentials]): The
1001 authorization credentials to attach to requests. These
1002 credentials identify the application to the service; if none
1003 are specified, the client will attempt to ascertain the
1004 credentials from the environment.
1005
1006 credentials_file (Optional[str]): Deprecated. A file with credentials that can
1007 be loaded with :func:`google.auth.load_credentials_from_file`.
1008 This argument is ignored if ``channel`` is provided. This argument will be
1009 removed in the next major version of this library.
1010 scopes (Optional(Sequence[str])): A list of scopes. This argument is
1011 ignored if ``channel`` is provided.
1012 client_cert_source_for_mtls (Callable[[], Tuple[bytes, bytes]]): Client
1013 certificate to configure mutual TLS HTTP channel. It is ignored
1014 if ``channel`` is provided.
1015 quota_project_id (Optional[str]): An optional project to use for billing
1016 and quota.
1017 client_info (google.api_core.gapic_v1.client_info.ClientInfo):
1018 The client info used to send a user-agent string along with
1019 API requests. If ``None``, then default info will be used.
1020 Generally, you only need to set this if you are developing
1021 your own client library.
1022 always_use_jwt_access (Optional[bool]): Whether self signed JWT should
1023 be used for service account credentials.
1024 url_scheme: the protocol scheme for the API endpoint. Normally
1025 "https", but for testing or local servers,
1026 "http" can be specified.
1027 """
1028 # Run the base constructor
1029 # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc.
1030 # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the
1031 # credentials object
1032 super().__init__(
1033 host=host,
1034 credentials=credentials,
1035 client_info=client_info,
1036 always_use_jwt_access=always_use_jwt_access,
1037 url_scheme=url_scheme,
1038 api_audience=api_audience,
1039 )
1040 self._session = AuthorizedSession(
1041 self._credentials, default_host=self.DEFAULT_HOST
1042 )
1043 if client_cert_source_for_mtls:
1044 self._session.configure_mtls_channel(client_cert_source_for_mtls)
1045 self._interceptor = interceptor or FirestoreRestInterceptor()
1046 self._prep_wrapped_messages(client_info)
1047
1048 class _BatchGetDocuments(
1049 _BaseFirestoreRestTransport._BaseBatchGetDocuments, FirestoreRestStub
1050 ):
1051 def __hash__(self):
1052 return hash("FirestoreRestTransport.BatchGetDocuments")
1053
1054 @staticmethod
1055 def _get_response(
1056 host,
1057 metadata,
1058 query_params,
1059 session,
1060 timeout,
1061 transcoded_request,
1062 body=None,
1063 ):
1064 uri = transcoded_request["uri"]
1065 method = transcoded_request["method"]
1066 headers = dict(metadata)
1067 headers["Content-Type"] = "application/json"
1068 response = getattr(session, method)(
1069 "{host}{uri}".format(host=host, uri=uri),
1070 timeout=timeout,
1071 headers=headers,
1072 params=rest_helpers.flatten_query_params(query_params, strict=True),
1073 data=body,
1074 stream=True,
1075 )
1076 return response
1077
1078 def __call__(
1079 self,
1080 request: firestore.BatchGetDocumentsRequest,
1081 *,
1082 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1083 timeout: Optional[float] = None,
1084 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1085 ) -> rest_streaming.ResponseIterator:
1086 r"""Call the batch get documents method over HTTP.
1087
1088 Args:
1089 request (~.firestore.BatchGetDocumentsRequest):
1090 The request object. The request for
1091 [Firestore.BatchGetDocuments][google.firestore.v1.Firestore.BatchGetDocuments].
1092 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1093 should be retried.
1094 timeout (float): The timeout for this request.
1095 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1096 sent along with the request as metadata. Normally, each value must be of type `str`,
1097 but for metadata keys ending with the suffix `-bin`, the corresponding values must
1098 be of type `bytes`.
1099
1100 Returns:
1101 ~.firestore.BatchGetDocumentsResponse:
1102 The streamed response for
1103 [Firestore.BatchGetDocuments][google.firestore.v1.Firestore.BatchGetDocuments].
1104
1105 """
1106
1107 http_options = (
1108 _BaseFirestoreRestTransport._BaseBatchGetDocuments._get_http_options()
1109 )
1110
1111 request, metadata = self._interceptor.pre_batch_get_documents(
1112 request, metadata
1113 )
1114 transcoded_request = _BaseFirestoreRestTransport._BaseBatchGetDocuments._get_transcoded_request(
1115 http_options, request
1116 )
1117
1118 body = _BaseFirestoreRestTransport._BaseBatchGetDocuments._get_request_body_json(
1119 transcoded_request
1120 )
1121
1122 # Jsonify the query params
1123 query_params = _BaseFirestoreRestTransport._BaseBatchGetDocuments._get_query_params_json(
1124 transcoded_request
1125 )
1126
1127 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1128 logging.DEBUG
1129 ): # pragma: NO COVER
1130 request_url = "{host}{uri}".format(
1131 host=self._host, uri=transcoded_request["uri"]
1132 )
1133 method = transcoded_request["method"]
1134 try:
1135 request_payload = type(request).to_json(request)
1136 except:
1137 request_payload = None
1138 http_request = {
1139 "payload": request_payload,
1140 "requestMethod": method,
1141 "requestUrl": request_url,
1142 "headers": dict(metadata),
1143 }
1144 _LOGGER.debug(
1145 f"Sending request for google.firestore_v1.FirestoreClient.BatchGetDocuments",
1146 extra={
1147 "serviceName": "google.firestore.v1.Firestore",
1148 "rpcName": "BatchGetDocuments",
1149 "httpRequest": http_request,
1150 "metadata": http_request["headers"],
1151 },
1152 )
1153
1154 # Send the request
1155 response = FirestoreRestTransport._BatchGetDocuments._get_response(
1156 self._host,
1157 metadata,
1158 query_params,
1159 self._session,
1160 timeout,
1161 transcoded_request,
1162 body,
1163 )
1164
1165 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
1166 # subclass.
1167 if response.status_code >= 400:
1168 raise core_exceptions.from_http_response(response)
1169
1170 # Return the response
1171 resp = rest_streaming.ResponseIterator(
1172 response, firestore.BatchGetDocumentsResponse
1173 )
1174
1175 resp = self._interceptor.post_batch_get_documents(resp)
1176 response_metadata = [(k, str(v)) for k, v in response.headers.items()]
1177 resp, _ = self._interceptor.post_batch_get_documents_with_metadata(
1178 resp, response_metadata
1179 )
1180 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1181 logging.DEBUG
1182 ): # pragma: NO COVER
1183 http_response = {
1184 "headers": dict(response.headers),
1185 "status": response.status_code,
1186 }
1187 _LOGGER.debug(
1188 "Received response for google.firestore_v1.FirestoreClient.batch_get_documents",
1189 extra={
1190 "serviceName": "google.firestore.v1.Firestore",
1191 "rpcName": "BatchGetDocuments",
1192 "metadata": http_response["headers"],
1193 "httpResponse": http_response,
1194 },
1195 )
1196 return resp
1197
1198 class _BatchWrite(_BaseFirestoreRestTransport._BaseBatchWrite, FirestoreRestStub):
1199 def __hash__(self):
1200 return hash("FirestoreRestTransport.BatchWrite")
1201
1202 @staticmethod
1203 def _get_response(
1204 host,
1205 metadata,
1206 query_params,
1207 session,
1208 timeout,
1209 transcoded_request,
1210 body=None,
1211 ):
1212 uri = transcoded_request["uri"]
1213 method = transcoded_request["method"]
1214 headers = dict(metadata)
1215 headers["Content-Type"] = "application/json"
1216 response = getattr(session, method)(
1217 "{host}{uri}".format(host=host, uri=uri),
1218 timeout=timeout,
1219 headers=headers,
1220 params=rest_helpers.flatten_query_params(query_params, strict=True),
1221 data=body,
1222 )
1223 return response
1224
1225 def __call__(
1226 self,
1227 request: firestore.BatchWriteRequest,
1228 *,
1229 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1230 timeout: Optional[float] = None,
1231 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1232 ) -> firestore.BatchWriteResponse:
1233 r"""Call the batch write method over HTTP.
1234
1235 Args:
1236 request (~.firestore.BatchWriteRequest):
1237 The request object. The request for
1238 [Firestore.BatchWrite][google.firestore.v1.Firestore.BatchWrite].
1239 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1240 should be retried.
1241 timeout (float): The timeout for this request.
1242 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1243 sent along with the request as metadata. Normally, each value must be of type `str`,
1244 but for metadata keys ending with the suffix `-bin`, the corresponding values must
1245 be of type `bytes`.
1246
1247 Returns:
1248 ~.firestore.BatchWriteResponse:
1249 The response from
1250 [Firestore.BatchWrite][google.firestore.v1.Firestore.BatchWrite].
1251
1252 """
1253
1254 http_options = (
1255 _BaseFirestoreRestTransport._BaseBatchWrite._get_http_options()
1256 )
1257
1258 request, metadata = self._interceptor.pre_batch_write(request, metadata)
1259 transcoded_request = (
1260 _BaseFirestoreRestTransport._BaseBatchWrite._get_transcoded_request(
1261 http_options, request
1262 )
1263 )
1264
1265 body = _BaseFirestoreRestTransport._BaseBatchWrite._get_request_body_json(
1266 transcoded_request
1267 )
1268
1269 # Jsonify the query params
1270 query_params = (
1271 _BaseFirestoreRestTransport._BaseBatchWrite._get_query_params_json(
1272 transcoded_request
1273 )
1274 )
1275
1276 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1277 logging.DEBUG
1278 ): # pragma: NO COVER
1279 request_url = "{host}{uri}".format(
1280 host=self._host, uri=transcoded_request["uri"]
1281 )
1282 method = transcoded_request["method"]
1283 try:
1284 request_payload = type(request).to_json(request)
1285 except:
1286 request_payload = None
1287 http_request = {
1288 "payload": request_payload,
1289 "requestMethod": method,
1290 "requestUrl": request_url,
1291 "headers": dict(metadata),
1292 }
1293 _LOGGER.debug(
1294 f"Sending request for google.firestore_v1.FirestoreClient.BatchWrite",
1295 extra={
1296 "serviceName": "google.firestore.v1.Firestore",
1297 "rpcName": "BatchWrite",
1298 "httpRequest": http_request,
1299 "metadata": http_request["headers"],
1300 },
1301 )
1302
1303 # Send the request
1304 response = FirestoreRestTransport._BatchWrite._get_response(
1305 self._host,
1306 metadata,
1307 query_params,
1308 self._session,
1309 timeout,
1310 transcoded_request,
1311 body,
1312 )
1313
1314 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
1315 # subclass.
1316 if response.status_code >= 400:
1317 raise core_exceptions.from_http_response(response)
1318
1319 # Return the response
1320 resp = firestore.BatchWriteResponse()
1321 pb_resp = firestore.BatchWriteResponse.pb(resp)
1322
1323 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
1324
1325 resp = self._interceptor.post_batch_write(resp)
1326 response_metadata = [(k, str(v)) for k, v in response.headers.items()]
1327 resp, _ = self._interceptor.post_batch_write_with_metadata(
1328 resp, response_metadata
1329 )
1330 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1331 logging.DEBUG
1332 ): # pragma: NO COVER
1333 try:
1334 response_payload = firestore.BatchWriteResponse.to_json(response)
1335 except:
1336 response_payload = None
1337 http_response = {
1338 "payload": response_payload,
1339 "headers": dict(response.headers),
1340 "status": response.status_code,
1341 }
1342 _LOGGER.debug(
1343 "Received response for google.firestore_v1.FirestoreClient.batch_write",
1344 extra={
1345 "serviceName": "google.firestore.v1.Firestore",
1346 "rpcName": "BatchWrite",
1347 "metadata": http_response["headers"],
1348 "httpResponse": http_response,
1349 },
1350 )
1351 return resp
1352
1353 class _BeginTransaction(
1354 _BaseFirestoreRestTransport._BaseBeginTransaction, FirestoreRestStub
1355 ):
1356 def __hash__(self):
1357 return hash("FirestoreRestTransport.BeginTransaction")
1358
1359 @staticmethod
1360 def _get_response(
1361 host,
1362 metadata,
1363 query_params,
1364 session,
1365 timeout,
1366 transcoded_request,
1367 body=None,
1368 ):
1369 uri = transcoded_request["uri"]
1370 method = transcoded_request["method"]
1371 headers = dict(metadata)
1372 headers["Content-Type"] = "application/json"
1373 response = getattr(session, method)(
1374 "{host}{uri}".format(host=host, uri=uri),
1375 timeout=timeout,
1376 headers=headers,
1377 params=rest_helpers.flatten_query_params(query_params, strict=True),
1378 data=body,
1379 )
1380 return response
1381
1382 def __call__(
1383 self,
1384 request: firestore.BeginTransactionRequest,
1385 *,
1386 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1387 timeout: Optional[float] = None,
1388 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1389 ) -> firestore.BeginTransactionResponse:
1390 r"""Call the begin transaction method over HTTP.
1391
1392 Args:
1393 request (~.firestore.BeginTransactionRequest):
1394 The request object. The request for
1395 [Firestore.BeginTransaction][google.firestore.v1.Firestore.BeginTransaction].
1396 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1397 should be retried.
1398 timeout (float): The timeout for this request.
1399 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1400 sent along with the request as metadata. Normally, each value must be of type `str`,
1401 but for metadata keys ending with the suffix `-bin`, the corresponding values must
1402 be of type `bytes`.
1403
1404 Returns:
1405 ~.firestore.BeginTransactionResponse:
1406 The response for
1407 [Firestore.BeginTransaction][google.firestore.v1.Firestore.BeginTransaction].
1408
1409 """
1410
1411 http_options = (
1412 _BaseFirestoreRestTransport._BaseBeginTransaction._get_http_options()
1413 )
1414
1415 request, metadata = self._interceptor.pre_begin_transaction(
1416 request, metadata
1417 )
1418 transcoded_request = _BaseFirestoreRestTransport._BaseBeginTransaction._get_transcoded_request(
1419 http_options, request
1420 )
1421
1422 body = _BaseFirestoreRestTransport._BaseBeginTransaction._get_request_body_json(
1423 transcoded_request
1424 )
1425
1426 # Jsonify the query params
1427 query_params = _BaseFirestoreRestTransport._BaseBeginTransaction._get_query_params_json(
1428 transcoded_request
1429 )
1430
1431 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1432 logging.DEBUG
1433 ): # pragma: NO COVER
1434 request_url = "{host}{uri}".format(
1435 host=self._host, uri=transcoded_request["uri"]
1436 )
1437 method = transcoded_request["method"]
1438 try:
1439 request_payload = type(request).to_json(request)
1440 except:
1441 request_payload = None
1442 http_request = {
1443 "payload": request_payload,
1444 "requestMethod": method,
1445 "requestUrl": request_url,
1446 "headers": dict(metadata),
1447 }
1448 _LOGGER.debug(
1449 f"Sending request for google.firestore_v1.FirestoreClient.BeginTransaction",
1450 extra={
1451 "serviceName": "google.firestore.v1.Firestore",
1452 "rpcName": "BeginTransaction",
1453 "httpRequest": http_request,
1454 "metadata": http_request["headers"],
1455 },
1456 )
1457
1458 # Send the request
1459 response = FirestoreRestTransport._BeginTransaction._get_response(
1460 self._host,
1461 metadata,
1462 query_params,
1463 self._session,
1464 timeout,
1465 transcoded_request,
1466 body,
1467 )
1468
1469 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
1470 # subclass.
1471 if response.status_code >= 400:
1472 raise core_exceptions.from_http_response(response)
1473
1474 # Return the response
1475 resp = firestore.BeginTransactionResponse()
1476 pb_resp = firestore.BeginTransactionResponse.pb(resp)
1477
1478 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
1479
1480 resp = self._interceptor.post_begin_transaction(resp)
1481 response_metadata = [(k, str(v)) for k, v in response.headers.items()]
1482 resp, _ = self._interceptor.post_begin_transaction_with_metadata(
1483 resp, response_metadata
1484 )
1485 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1486 logging.DEBUG
1487 ): # pragma: NO COVER
1488 try:
1489 response_payload = firestore.BeginTransactionResponse.to_json(
1490 response
1491 )
1492 except:
1493 response_payload = None
1494 http_response = {
1495 "payload": response_payload,
1496 "headers": dict(response.headers),
1497 "status": response.status_code,
1498 }
1499 _LOGGER.debug(
1500 "Received response for google.firestore_v1.FirestoreClient.begin_transaction",
1501 extra={
1502 "serviceName": "google.firestore.v1.Firestore",
1503 "rpcName": "BeginTransaction",
1504 "metadata": http_response["headers"],
1505 "httpResponse": http_response,
1506 },
1507 )
1508 return resp
1509
1510 class _Commit(_BaseFirestoreRestTransport._BaseCommit, FirestoreRestStub):
1511 def __hash__(self):
1512 return hash("FirestoreRestTransport.Commit")
1513
1514 @staticmethod
1515 def _get_response(
1516 host,
1517 metadata,
1518 query_params,
1519 session,
1520 timeout,
1521 transcoded_request,
1522 body=None,
1523 ):
1524 uri = transcoded_request["uri"]
1525 method = transcoded_request["method"]
1526 headers = dict(metadata)
1527 headers["Content-Type"] = "application/json"
1528 response = getattr(session, method)(
1529 "{host}{uri}".format(host=host, uri=uri),
1530 timeout=timeout,
1531 headers=headers,
1532 params=rest_helpers.flatten_query_params(query_params, strict=True),
1533 data=body,
1534 )
1535 return response
1536
1537 def __call__(
1538 self,
1539 request: firestore.CommitRequest,
1540 *,
1541 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1542 timeout: Optional[float] = None,
1543 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1544 ) -> firestore.CommitResponse:
1545 r"""Call the commit method over HTTP.
1546
1547 Args:
1548 request (~.firestore.CommitRequest):
1549 The request object. The request for
1550 [Firestore.Commit][google.firestore.v1.Firestore.Commit].
1551 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1552 should be retried.
1553 timeout (float): The timeout for this request.
1554 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1555 sent along with the request as metadata. Normally, each value must be of type `str`,
1556 but for metadata keys ending with the suffix `-bin`, the corresponding values must
1557 be of type `bytes`.
1558
1559 Returns:
1560 ~.firestore.CommitResponse:
1561 The response for
1562 [Firestore.Commit][google.firestore.v1.Firestore.Commit].
1563
1564 """
1565
1566 http_options = _BaseFirestoreRestTransport._BaseCommit._get_http_options()
1567
1568 request, metadata = self._interceptor.pre_commit(request, metadata)
1569 transcoded_request = (
1570 _BaseFirestoreRestTransport._BaseCommit._get_transcoded_request(
1571 http_options, request
1572 )
1573 )
1574
1575 body = _BaseFirestoreRestTransport._BaseCommit._get_request_body_json(
1576 transcoded_request
1577 )
1578
1579 # Jsonify the query params
1580 query_params = (
1581 _BaseFirestoreRestTransport._BaseCommit._get_query_params_json(
1582 transcoded_request
1583 )
1584 )
1585
1586 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1587 logging.DEBUG
1588 ): # pragma: NO COVER
1589 request_url = "{host}{uri}".format(
1590 host=self._host, uri=transcoded_request["uri"]
1591 )
1592 method = transcoded_request["method"]
1593 try:
1594 request_payload = type(request).to_json(request)
1595 except:
1596 request_payload = None
1597 http_request = {
1598 "payload": request_payload,
1599 "requestMethod": method,
1600 "requestUrl": request_url,
1601 "headers": dict(metadata),
1602 }
1603 _LOGGER.debug(
1604 f"Sending request for google.firestore_v1.FirestoreClient.Commit",
1605 extra={
1606 "serviceName": "google.firestore.v1.Firestore",
1607 "rpcName": "Commit",
1608 "httpRequest": http_request,
1609 "metadata": http_request["headers"],
1610 },
1611 )
1612
1613 # Send the request
1614 response = FirestoreRestTransport._Commit._get_response(
1615 self._host,
1616 metadata,
1617 query_params,
1618 self._session,
1619 timeout,
1620 transcoded_request,
1621 body,
1622 )
1623
1624 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
1625 # subclass.
1626 if response.status_code >= 400:
1627 raise core_exceptions.from_http_response(response)
1628
1629 # Return the response
1630 resp = firestore.CommitResponse()
1631 pb_resp = firestore.CommitResponse.pb(resp)
1632
1633 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
1634
1635 resp = self._interceptor.post_commit(resp)
1636 response_metadata = [(k, str(v)) for k, v in response.headers.items()]
1637 resp, _ = self._interceptor.post_commit_with_metadata(
1638 resp, response_metadata
1639 )
1640 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1641 logging.DEBUG
1642 ): # pragma: NO COVER
1643 try:
1644 response_payload = firestore.CommitResponse.to_json(response)
1645 except:
1646 response_payload = None
1647 http_response = {
1648 "payload": response_payload,
1649 "headers": dict(response.headers),
1650 "status": response.status_code,
1651 }
1652 _LOGGER.debug(
1653 "Received response for google.firestore_v1.FirestoreClient.commit",
1654 extra={
1655 "serviceName": "google.firestore.v1.Firestore",
1656 "rpcName": "Commit",
1657 "metadata": http_response["headers"],
1658 "httpResponse": http_response,
1659 },
1660 )
1661 return resp
1662
1663 class _CreateDocument(
1664 _BaseFirestoreRestTransport._BaseCreateDocument, FirestoreRestStub
1665 ):
1666 def __hash__(self):
1667 return hash("FirestoreRestTransport.CreateDocument")
1668
1669 @staticmethod
1670 def _get_response(
1671 host,
1672 metadata,
1673 query_params,
1674 session,
1675 timeout,
1676 transcoded_request,
1677 body=None,
1678 ):
1679 uri = transcoded_request["uri"]
1680 method = transcoded_request["method"]
1681 headers = dict(metadata)
1682 headers["Content-Type"] = "application/json"
1683 response = getattr(session, method)(
1684 "{host}{uri}".format(host=host, uri=uri),
1685 timeout=timeout,
1686 headers=headers,
1687 params=rest_helpers.flatten_query_params(query_params, strict=True),
1688 data=body,
1689 )
1690 return response
1691
1692 def __call__(
1693 self,
1694 request: firestore.CreateDocumentRequest,
1695 *,
1696 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1697 timeout: Optional[float] = None,
1698 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1699 ) -> document.Document:
1700 r"""Call the create document method over HTTP.
1701
1702 Args:
1703 request (~.firestore.CreateDocumentRequest):
1704 The request object. The request for
1705 [Firestore.CreateDocument][google.firestore.v1.Firestore.CreateDocument].
1706 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1707 should be retried.
1708 timeout (float): The timeout for this request.
1709 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1710 sent along with the request as metadata. Normally, each value must be of type `str`,
1711 but for metadata keys ending with the suffix `-bin`, the corresponding values must
1712 be of type `bytes`.
1713
1714 Returns:
1715 ~.document.Document:
1716 A Firestore document.
1717
1718 Must not exceed 1 MiB - 4 bytes.
1719
1720 """
1721
1722 http_options = (
1723 _BaseFirestoreRestTransport._BaseCreateDocument._get_http_options()
1724 )
1725
1726 request, metadata = self._interceptor.pre_create_document(request, metadata)
1727 transcoded_request = (
1728 _BaseFirestoreRestTransport._BaseCreateDocument._get_transcoded_request(
1729 http_options, request
1730 )
1731 )
1732
1733 body = (
1734 _BaseFirestoreRestTransport._BaseCreateDocument._get_request_body_json(
1735 transcoded_request
1736 )
1737 )
1738
1739 # Jsonify the query params
1740 query_params = (
1741 _BaseFirestoreRestTransport._BaseCreateDocument._get_query_params_json(
1742 transcoded_request
1743 )
1744 )
1745
1746 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1747 logging.DEBUG
1748 ): # pragma: NO COVER
1749 request_url = "{host}{uri}".format(
1750 host=self._host, uri=transcoded_request["uri"]
1751 )
1752 method = transcoded_request["method"]
1753 try:
1754 request_payload = type(request).to_json(request)
1755 except:
1756 request_payload = None
1757 http_request = {
1758 "payload": request_payload,
1759 "requestMethod": method,
1760 "requestUrl": request_url,
1761 "headers": dict(metadata),
1762 }
1763 _LOGGER.debug(
1764 f"Sending request for google.firestore_v1.FirestoreClient.CreateDocument",
1765 extra={
1766 "serviceName": "google.firestore.v1.Firestore",
1767 "rpcName": "CreateDocument",
1768 "httpRequest": http_request,
1769 "metadata": http_request["headers"],
1770 },
1771 )
1772
1773 # Send the request
1774 response = FirestoreRestTransport._CreateDocument._get_response(
1775 self._host,
1776 metadata,
1777 query_params,
1778 self._session,
1779 timeout,
1780 transcoded_request,
1781 body,
1782 )
1783
1784 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
1785 # subclass.
1786 if response.status_code >= 400:
1787 raise core_exceptions.from_http_response(response)
1788
1789 # Return the response
1790 resp = document.Document()
1791 pb_resp = document.Document.pb(resp)
1792
1793 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
1794
1795 resp = self._interceptor.post_create_document(resp)
1796 response_metadata = [(k, str(v)) for k, v in response.headers.items()]
1797 resp, _ = self._interceptor.post_create_document_with_metadata(
1798 resp, response_metadata
1799 )
1800 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1801 logging.DEBUG
1802 ): # pragma: NO COVER
1803 try:
1804 response_payload = document.Document.to_json(response)
1805 except:
1806 response_payload = None
1807 http_response = {
1808 "payload": response_payload,
1809 "headers": dict(response.headers),
1810 "status": response.status_code,
1811 }
1812 _LOGGER.debug(
1813 "Received response for google.firestore_v1.FirestoreClient.create_document",
1814 extra={
1815 "serviceName": "google.firestore.v1.Firestore",
1816 "rpcName": "CreateDocument",
1817 "metadata": http_response["headers"],
1818 "httpResponse": http_response,
1819 },
1820 )
1821 return resp
1822
1823 class _DeleteDocument(
1824 _BaseFirestoreRestTransport._BaseDeleteDocument, FirestoreRestStub
1825 ):
1826 def __hash__(self):
1827 return hash("FirestoreRestTransport.DeleteDocument")
1828
1829 @staticmethod
1830 def _get_response(
1831 host,
1832 metadata,
1833 query_params,
1834 session,
1835 timeout,
1836 transcoded_request,
1837 body=None,
1838 ):
1839 uri = transcoded_request["uri"]
1840 method = transcoded_request["method"]
1841 headers = dict(metadata)
1842 headers["Content-Type"] = "application/json"
1843 response = getattr(session, method)(
1844 "{host}{uri}".format(host=host, uri=uri),
1845 timeout=timeout,
1846 headers=headers,
1847 params=rest_helpers.flatten_query_params(query_params, strict=True),
1848 )
1849 return response
1850
1851 def __call__(
1852 self,
1853 request: firestore.DeleteDocumentRequest,
1854 *,
1855 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1856 timeout: Optional[float] = None,
1857 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1858 ):
1859 r"""Call the delete document method over HTTP.
1860
1861 Args:
1862 request (~.firestore.DeleteDocumentRequest):
1863 The request object. The request for
1864 [Firestore.DeleteDocument][google.firestore.v1.Firestore.DeleteDocument].
1865 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1866 should be retried.
1867 timeout (float): The timeout for this request.
1868 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1869 sent along with the request as metadata. Normally, each value must be of type `str`,
1870 but for metadata keys ending with the suffix `-bin`, the corresponding values must
1871 be of type `bytes`.
1872 """
1873
1874 http_options = (
1875 _BaseFirestoreRestTransport._BaseDeleteDocument._get_http_options()
1876 )
1877
1878 request, metadata = self._interceptor.pre_delete_document(request, metadata)
1879 transcoded_request = (
1880 _BaseFirestoreRestTransport._BaseDeleteDocument._get_transcoded_request(
1881 http_options, request
1882 )
1883 )
1884
1885 # Jsonify the query params
1886 query_params = (
1887 _BaseFirestoreRestTransport._BaseDeleteDocument._get_query_params_json(
1888 transcoded_request
1889 )
1890 )
1891
1892 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1893 logging.DEBUG
1894 ): # pragma: NO COVER
1895 request_url = "{host}{uri}".format(
1896 host=self._host, uri=transcoded_request["uri"]
1897 )
1898 method = transcoded_request["method"]
1899 try:
1900 request_payload = json_format.MessageToJson(request)
1901 except:
1902 request_payload = None
1903 http_request = {
1904 "payload": request_payload,
1905 "requestMethod": method,
1906 "requestUrl": request_url,
1907 "headers": dict(metadata),
1908 }
1909 _LOGGER.debug(
1910 f"Sending request for google.firestore_v1.FirestoreClient.DeleteDocument",
1911 extra={
1912 "serviceName": "google.firestore.v1.Firestore",
1913 "rpcName": "DeleteDocument",
1914 "httpRequest": http_request,
1915 "metadata": http_request["headers"],
1916 },
1917 )
1918
1919 # Send the request
1920 response = FirestoreRestTransport._DeleteDocument._get_response(
1921 self._host,
1922 metadata,
1923 query_params,
1924 self._session,
1925 timeout,
1926 transcoded_request,
1927 )
1928
1929 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
1930 # subclass.
1931 if response.status_code >= 400:
1932 raise core_exceptions.from_http_response(response)
1933
1934 class _ExecutePipeline(
1935 _BaseFirestoreRestTransport._BaseExecutePipeline, FirestoreRestStub
1936 ):
1937 def __hash__(self):
1938 return hash("FirestoreRestTransport.ExecutePipeline")
1939
1940 @staticmethod
1941 def _get_response(
1942 host,
1943 metadata,
1944 query_params,
1945 session,
1946 timeout,
1947 transcoded_request,
1948 body=None,
1949 ):
1950 uri = transcoded_request["uri"]
1951 method = transcoded_request["method"]
1952 headers = dict(metadata)
1953 headers["Content-Type"] = "application/json"
1954 response = getattr(session, method)(
1955 "{host}{uri}".format(host=host, uri=uri),
1956 timeout=timeout,
1957 headers=headers,
1958 params=rest_helpers.flatten_query_params(query_params, strict=True),
1959 data=body,
1960 stream=True,
1961 )
1962 return response
1963
1964 def __call__(
1965 self,
1966 request: firestore.ExecutePipelineRequest,
1967 *,
1968 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1969 timeout: Optional[float] = None,
1970 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1971 ) -> rest_streaming.ResponseIterator:
1972 r"""Call the execute pipeline method over HTTP.
1973
1974 Args:
1975 request (~.firestore.ExecutePipelineRequest):
1976 The request object. The request for
1977 [Firestore.ExecutePipeline][google.firestore.v1.Firestore.ExecutePipeline].
1978 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1979 should be retried.
1980 timeout (float): The timeout for this request.
1981 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1982 sent along with the request as metadata. Normally, each value must be of type `str`,
1983 but for metadata keys ending with the suffix `-bin`, the corresponding values must
1984 be of type `bytes`.
1985
1986 Returns:
1987 ~.firestore.ExecutePipelineResponse:
1988 The response for [Firestore.Execute][].
1989 """
1990
1991 http_options = (
1992 _BaseFirestoreRestTransport._BaseExecutePipeline._get_http_options()
1993 )
1994
1995 request, metadata = self._interceptor.pre_execute_pipeline(
1996 request, metadata
1997 )
1998 transcoded_request = _BaseFirestoreRestTransport._BaseExecutePipeline._get_transcoded_request(
1999 http_options, request
2000 )
2001
2002 body = (
2003 _BaseFirestoreRestTransport._BaseExecutePipeline._get_request_body_json(
2004 transcoded_request
2005 )
2006 )
2007
2008 # Jsonify the query params
2009 query_params = (
2010 _BaseFirestoreRestTransport._BaseExecutePipeline._get_query_params_json(
2011 transcoded_request
2012 )
2013 )
2014
2015 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
2016 logging.DEBUG
2017 ): # pragma: NO COVER
2018 request_url = "{host}{uri}".format(
2019 host=self._host, uri=transcoded_request["uri"]
2020 )
2021 method = transcoded_request["method"]
2022 try:
2023 request_payload = type(request).to_json(request)
2024 except:
2025 request_payload = None
2026 http_request = {
2027 "payload": request_payload,
2028 "requestMethod": method,
2029 "requestUrl": request_url,
2030 "headers": dict(metadata),
2031 }
2032 _LOGGER.debug(
2033 f"Sending request for google.firestore_v1.FirestoreClient.ExecutePipeline",
2034 extra={
2035 "serviceName": "google.firestore.v1.Firestore",
2036 "rpcName": "ExecutePipeline",
2037 "httpRequest": http_request,
2038 "metadata": http_request["headers"],
2039 },
2040 )
2041
2042 # Send the request
2043 response = FirestoreRestTransport._ExecutePipeline._get_response(
2044 self._host,
2045 metadata,
2046 query_params,
2047 self._session,
2048 timeout,
2049 transcoded_request,
2050 body,
2051 )
2052
2053 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
2054 # subclass.
2055 if response.status_code >= 400:
2056 raise core_exceptions.from_http_response(response)
2057
2058 # Return the response
2059 resp = rest_streaming.ResponseIterator(
2060 response, firestore.ExecutePipelineResponse
2061 )
2062
2063 resp = self._interceptor.post_execute_pipeline(resp)
2064 response_metadata = [(k, str(v)) for k, v in response.headers.items()]
2065 resp, _ = self._interceptor.post_execute_pipeline_with_metadata(
2066 resp, response_metadata
2067 )
2068 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
2069 logging.DEBUG
2070 ): # pragma: NO COVER
2071 http_response = {
2072 "headers": dict(response.headers),
2073 "status": response.status_code,
2074 }
2075 _LOGGER.debug(
2076 "Received response for google.firestore_v1.FirestoreClient.execute_pipeline",
2077 extra={
2078 "serviceName": "google.firestore.v1.Firestore",
2079 "rpcName": "ExecutePipeline",
2080 "metadata": http_response["headers"],
2081 "httpResponse": http_response,
2082 },
2083 )
2084 return resp
2085
2086 class _GetDocument(_BaseFirestoreRestTransport._BaseGetDocument, FirestoreRestStub):
2087 def __hash__(self):
2088 return hash("FirestoreRestTransport.GetDocument")
2089
2090 @staticmethod
2091 def _get_response(
2092 host,
2093 metadata,
2094 query_params,
2095 session,
2096 timeout,
2097 transcoded_request,
2098 body=None,
2099 ):
2100 uri = transcoded_request["uri"]
2101 method = transcoded_request["method"]
2102 headers = dict(metadata)
2103 headers["Content-Type"] = "application/json"
2104 response = getattr(session, method)(
2105 "{host}{uri}".format(host=host, uri=uri),
2106 timeout=timeout,
2107 headers=headers,
2108 params=rest_helpers.flatten_query_params(query_params, strict=True),
2109 )
2110 return response
2111
2112 def __call__(
2113 self,
2114 request: firestore.GetDocumentRequest,
2115 *,
2116 retry: OptionalRetry = gapic_v1.method.DEFAULT,
2117 timeout: Optional[float] = None,
2118 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
2119 ) -> document.Document:
2120 r"""Call the get document method over HTTP.
2121
2122 Args:
2123 request (~.firestore.GetDocumentRequest):
2124 The request object. The request for
2125 [Firestore.GetDocument][google.firestore.v1.Firestore.GetDocument].
2126 retry (google.api_core.retry.Retry): Designation of what errors, if any,
2127 should be retried.
2128 timeout (float): The timeout for this request.
2129 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
2130 sent along with the request as metadata. Normally, each value must be of type `str`,
2131 but for metadata keys ending with the suffix `-bin`, the corresponding values must
2132 be of type `bytes`.
2133
2134 Returns:
2135 ~.document.Document:
2136 A Firestore document.
2137
2138 Must not exceed 1 MiB - 4 bytes.
2139
2140 """
2141
2142 http_options = (
2143 _BaseFirestoreRestTransport._BaseGetDocument._get_http_options()
2144 )
2145
2146 request, metadata = self._interceptor.pre_get_document(request, metadata)
2147 transcoded_request = (
2148 _BaseFirestoreRestTransport._BaseGetDocument._get_transcoded_request(
2149 http_options, request
2150 )
2151 )
2152
2153 # Jsonify the query params
2154 query_params = (
2155 _BaseFirestoreRestTransport._BaseGetDocument._get_query_params_json(
2156 transcoded_request
2157 )
2158 )
2159
2160 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
2161 logging.DEBUG
2162 ): # pragma: NO COVER
2163 request_url = "{host}{uri}".format(
2164 host=self._host, uri=transcoded_request["uri"]
2165 )
2166 method = transcoded_request["method"]
2167 try:
2168 request_payload = type(request).to_json(request)
2169 except:
2170 request_payload = None
2171 http_request = {
2172 "payload": request_payload,
2173 "requestMethod": method,
2174 "requestUrl": request_url,
2175 "headers": dict(metadata),
2176 }
2177 _LOGGER.debug(
2178 f"Sending request for google.firestore_v1.FirestoreClient.GetDocument",
2179 extra={
2180 "serviceName": "google.firestore.v1.Firestore",
2181 "rpcName": "GetDocument",
2182 "httpRequest": http_request,
2183 "metadata": http_request["headers"],
2184 },
2185 )
2186
2187 # Send the request
2188 response = FirestoreRestTransport._GetDocument._get_response(
2189 self._host,
2190 metadata,
2191 query_params,
2192 self._session,
2193 timeout,
2194 transcoded_request,
2195 )
2196
2197 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
2198 # subclass.
2199 if response.status_code >= 400:
2200 raise core_exceptions.from_http_response(response)
2201
2202 # Return the response
2203 resp = document.Document()
2204 pb_resp = document.Document.pb(resp)
2205
2206 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
2207
2208 resp = self._interceptor.post_get_document(resp)
2209 response_metadata = [(k, str(v)) for k, v in response.headers.items()]
2210 resp, _ = self._interceptor.post_get_document_with_metadata(
2211 resp, response_metadata
2212 )
2213 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
2214 logging.DEBUG
2215 ): # pragma: NO COVER
2216 try:
2217 response_payload = document.Document.to_json(response)
2218 except:
2219 response_payload = None
2220 http_response = {
2221 "payload": response_payload,
2222 "headers": dict(response.headers),
2223 "status": response.status_code,
2224 }
2225 _LOGGER.debug(
2226 "Received response for google.firestore_v1.FirestoreClient.get_document",
2227 extra={
2228 "serviceName": "google.firestore.v1.Firestore",
2229 "rpcName": "GetDocument",
2230 "metadata": http_response["headers"],
2231 "httpResponse": http_response,
2232 },
2233 )
2234 return resp
2235
2236 class _ListCollectionIds(
2237 _BaseFirestoreRestTransport._BaseListCollectionIds, FirestoreRestStub
2238 ):
2239 def __hash__(self):
2240 return hash("FirestoreRestTransport.ListCollectionIds")
2241
2242 @staticmethod
2243 def _get_response(
2244 host,
2245 metadata,
2246 query_params,
2247 session,
2248 timeout,
2249 transcoded_request,
2250 body=None,
2251 ):
2252 uri = transcoded_request["uri"]
2253 method = transcoded_request["method"]
2254 headers = dict(metadata)
2255 headers["Content-Type"] = "application/json"
2256 response = getattr(session, method)(
2257 "{host}{uri}".format(host=host, uri=uri),
2258 timeout=timeout,
2259 headers=headers,
2260 params=rest_helpers.flatten_query_params(query_params, strict=True),
2261 data=body,
2262 )
2263 return response
2264
2265 def __call__(
2266 self,
2267 request: firestore.ListCollectionIdsRequest,
2268 *,
2269 retry: OptionalRetry = gapic_v1.method.DEFAULT,
2270 timeout: Optional[float] = None,
2271 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
2272 ) -> firestore.ListCollectionIdsResponse:
2273 r"""Call the list collection ids method over HTTP.
2274
2275 Args:
2276 request (~.firestore.ListCollectionIdsRequest):
2277 The request object. The request for
2278 [Firestore.ListCollectionIds][google.firestore.v1.Firestore.ListCollectionIds].
2279 retry (google.api_core.retry.Retry): Designation of what errors, if any,
2280 should be retried.
2281 timeout (float): The timeout for this request.
2282 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
2283 sent along with the request as metadata. Normally, each value must be of type `str`,
2284 but for metadata keys ending with the suffix `-bin`, the corresponding values must
2285 be of type `bytes`.
2286
2287 Returns:
2288 ~.firestore.ListCollectionIdsResponse:
2289 The response from
2290 [Firestore.ListCollectionIds][google.firestore.v1.Firestore.ListCollectionIds].
2291
2292 """
2293
2294 http_options = (
2295 _BaseFirestoreRestTransport._BaseListCollectionIds._get_http_options()
2296 )
2297
2298 request, metadata = self._interceptor.pre_list_collection_ids(
2299 request, metadata
2300 )
2301 transcoded_request = _BaseFirestoreRestTransport._BaseListCollectionIds._get_transcoded_request(
2302 http_options, request
2303 )
2304
2305 body = _BaseFirestoreRestTransport._BaseListCollectionIds._get_request_body_json(
2306 transcoded_request
2307 )
2308
2309 # Jsonify the query params
2310 query_params = _BaseFirestoreRestTransport._BaseListCollectionIds._get_query_params_json(
2311 transcoded_request
2312 )
2313
2314 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
2315 logging.DEBUG
2316 ): # pragma: NO COVER
2317 request_url = "{host}{uri}".format(
2318 host=self._host, uri=transcoded_request["uri"]
2319 )
2320 method = transcoded_request["method"]
2321 try:
2322 request_payload = type(request).to_json(request)
2323 except:
2324 request_payload = None
2325 http_request = {
2326 "payload": request_payload,
2327 "requestMethod": method,
2328 "requestUrl": request_url,
2329 "headers": dict(metadata),
2330 }
2331 _LOGGER.debug(
2332 f"Sending request for google.firestore_v1.FirestoreClient.ListCollectionIds",
2333 extra={
2334 "serviceName": "google.firestore.v1.Firestore",
2335 "rpcName": "ListCollectionIds",
2336 "httpRequest": http_request,
2337 "metadata": http_request["headers"],
2338 },
2339 )
2340
2341 # Send the request
2342 response = FirestoreRestTransport._ListCollectionIds._get_response(
2343 self._host,
2344 metadata,
2345 query_params,
2346 self._session,
2347 timeout,
2348 transcoded_request,
2349 body,
2350 )
2351
2352 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
2353 # subclass.
2354 if response.status_code >= 400:
2355 raise core_exceptions.from_http_response(response)
2356
2357 # Return the response
2358 resp = firestore.ListCollectionIdsResponse()
2359 pb_resp = firestore.ListCollectionIdsResponse.pb(resp)
2360
2361 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
2362
2363 resp = self._interceptor.post_list_collection_ids(resp)
2364 response_metadata = [(k, str(v)) for k, v in response.headers.items()]
2365 resp, _ = self._interceptor.post_list_collection_ids_with_metadata(
2366 resp, response_metadata
2367 )
2368 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
2369 logging.DEBUG
2370 ): # pragma: NO COVER
2371 try:
2372 response_payload = firestore.ListCollectionIdsResponse.to_json(
2373 response
2374 )
2375 except:
2376 response_payload = None
2377 http_response = {
2378 "payload": response_payload,
2379 "headers": dict(response.headers),
2380 "status": response.status_code,
2381 }
2382 _LOGGER.debug(
2383 "Received response for google.firestore_v1.FirestoreClient.list_collection_ids",
2384 extra={
2385 "serviceName": "google.firestore.v1.Firestore",
2386 "rpcName": "ListCollectionIds",
2387 "metadata": http_response["headers"],
2388 "httpResponse": http_response,
2389 },
2390 )
2391 return resp
2392
2393 class _ListDocuments(
2394 _BaseFirestoreRestTransport._BaseListDocuments, FirestoreRestStub
2395 ):
2396 def __hash__(self):
2397 return hash("FirestoreRestTransport.ListDocuments")
2398
2399 @staticmethod
2400 def _get_response(
2401 host,
2402 metadata,
2403 query_params,
2404 session,
2405 timeout,
2406 transcoded_request,
2407 body=None,
2408 ):
2409 uri = transcoded_request["uri"]
2410 method = transcoded_request["method"]
2411 headers = dict(metadata)
2412 headers["Content-Type"] = "application/json"
2413 response = getattr(session, method)(
2414 "{host}{uri}".format(host=host, uri=uri),
2415 timeout=timeout,
2416 headers=headers,
2417 params=rest_helpers.flatten_query_params(query_params, strict=True),
2418 )
2419 return response
2420
2421 def __call__(
2422 self,
2423 request: firestore.ListDocumentsRequest,
2424 *,
2425 retry: OptionalRetry = gapic_v1.method.DEFAULT,
2426 timeout: Optional[float] = None,
2427 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
2428 ) -> firestore.ListDocumentsResponse:
2429 r"""Call the list documents method over HTTP.
2430
2431 Args:
2432 request (~.firestore.ListDocumentsRequest):
2433 The request object. The request for
2434 [Firestore.ListDocuments][google.firestore.v1.Firestore.ListDocuments].
2435 retry (google.api_core.retry.Retry): Designation of what errors, if any,
2436 should be retried.
2437 timeout (float): The timeout for this request.
2438 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
2439 sent along with the request as metadata. Normally, each value must be of type `str`,
2440 but for metadata keys ending with the suffix `-bin`, the corresponding values must
2441 be of type `bytes`.
2442
2443 Returns:
2444 ~.firestore.ListDocumentsResponse:
2445 The response for
2446 [Firestore.ListDocuments][google.firestore.v1.Firestore.ListDocuments].
2447
2448 """
2449
2450 http_options = (
2451 _BaseFirestoreRestTransport._BaseListDocuments._get_http_options()
2452 )
2453
2454 request, metadata = self._interceptor.pre_list_documents(request, metadata)
2455 transcoded_request = (
2456 _BaseFirestoreRestTransport._BaseListDocuments._get_transcoded_request(
2457 http_options, request
2458 )
2459 )
2460
2461 # Jsonify the query params
2462 query_params = (
2463 _BaseFirestoreRestTransport._BaseListDocuments._get_query_params_json(
2464 transcoded_request
2465 )
2466 )
2467
2468 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
2469 logging.DEBUG
2470 ): # pragma: NO COVER
2471 request_url = "{host}{uri}".format(
2472 host=self._host, uri=transcoded_request["uri"]
2473 )
2474 method = transcoded_request["method"]
2475 try:
2476 request_payload = type(request).to_json(request)
2477 except:
2478 request_payload = None
2479 http_request = {
2480 "payload": request_payload,
2481 "requestMethod": method,
2482 "requestUrl": request_url,
2483 "headers": dict(metadata),
2484 }
2485 _LOGGER.debug(
2486 f"Sending request for google.firestore_v1.FirestoreClient.ListDocuments",
2487 extra={
2488 "serviceName": "google.firestore.v1.Firestore",
2489 "rpcName": "ListDocuments",
2490 "httpRequest": http_request,
2491 "metadata": http_request["headers"],
2492 },
2493 )
2494
2495 # Send the request
2496 response = FirestoreRestTransport._ListDocuments._get_response(
2497 self._host,
2498 metadata,
2499 query_params,
2500 self._session,
2501 timeout,
2502 transcoded_request,
2503 )
2504
2505 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
2506 # subclass.
2507 if response.status_code >= 400:
2508 raise core_exceptions.from_http_response(response)
2509
2510 # Return the response
2511 resp = firestore.ListDocumentsResponse()
2512 pb_resp = firestore.ListDocumentsResponse.pb(resp)
2513
2514 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
2515
2516 resp = self._interceptor.post_list_documents(resp)
2517 response_metadata = [(k, str(v)) for k, v in response.headers.items()]
2518 resp, _ = self._interceptor.post_list_documents_with_metadata(
2519 resp, response_metadata
2520 )
2521 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
2522 logging.DEBUG
2523 ): # pragma: NO COVER
2524 try:
2525 response_payload = firestore.ListDocumentsResponse.to_json(response)
2526 except:
2527 response_payload = None
2528 http_response = {
2529 "payload": response_payload,
2530 "headers": dict(response.headers),
2531 "status": response.status_code,
2532 }
2533 _LOGGER.debug(
2534 "Received response for google.firestore_v1.FirestoreClient.list_documents",
2535 extra={
2536 "serviceName": "google.firestore.v1.Firestore",
2537 "rpcName": "ListDocuments",
2538 "metadata": http_response["headers"],
2539 "httpResponse": http_response,
2540 },
2541 )
2542 return resp
2543
2544 class _Listen(_BaseFirestoreRestTransport._BaseListen, FirestoreRestStub):
2545 def __hash__(self):
2546 return hash("FirestoreRestTransport.Listen")
2547
2548 def __call__(
2549 self,
2550 request: firestore.ListenRequest,
2551 *,
2552 retry: OptionalRetry = gapic_v1.method.DEFAULT,
2553 timeout: Optional[float] = None,
2554 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
2555 ) -> rest_streaming.ResponseIterator:
2556 raise NotImplementedError(
2557 "Method Listen is not available over REST transport"
2558 )
2559
2560 class _PartitionQuery(
2561 _BaseFirestoreRestTransport._BasePartitionQuery, FirestoreRestStub
2562 ):
2563 def __hash__(self):
2564 return hash("FirestoreRestTransport.PartitionQuery")
2565
2566 @staticmethod
2567 def _get_response(
2568 host,
2569 metadata,
2570 query_params,
2571 session,
2572 timeout,
2573 transcoded_request,
2574 body=None,
2575 ):
2576 uri = transcoded_request["uri"]
2577 method = transcoded_request["method"]
2578 headers = dict(metadata)
2579 headers["Content-Type"] = "application/json"
2580 response = getattr(session, method)(
2581 "{host}{uri}".format(host=host, uri=uri),
2582 timeout=timeout,
2583 headers=headers,
2584 params=rest_helpers.flatten_query_params(query_params, strict=True),
2585 data=body,
2586 )
2587 return response
2588
2589 def __call__(
2590 self,
2591 request: firestore.PartitionQueryRequest,
2592 *,
2593 retry: OptionalRetry = gapic_v1.method.DEFAULT,
2594 timeout: Optional[float] = None,
2595 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
2596 ) -> firestore.PartitionQueryResponse:
2597 r"""Call the partition query method over HTTP.
2598
2599 Args:
2600 request (~.firestore.PartitionQueryRequest):
2601 The request object. The request for
2602 [Firestore.PartitionQuery][google.firestore.v1.Firestore.PartitionQuery].
2603 retry (google.api_core.retry.Retry): Designation of what errors, if any,
2604 should be retried.
2605 timeout (float): The timeout for this request.
2606 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
2607 sent along with the request as metadata. Normally, each value must be of type `str`,
2608 but for metadata keys ending with the suffix `-bin`, the corresponding values must
2609 be of type `bytes`.
2610
2611 Returns:
2612 ~.firestore.PartitionQueryResponse:
2613 The response for
2614 [Firestore.PartitionQuery][google.firestore.v1.Firestore.PartitionQuery].
2615
2616 """
2617
2618 http_options = (
2619 _BaseFirestoreRestTransport._BasePartitionQuery._get_http_options()
2620 )
2621
2622 request, metadata = self._interceptor.pre_partition_query(request, metadata)
2623 transcoded_request = (
2624 _BaseFirestoreRestTransport._BasePartitionQuery._get_transcoded_request(
2625 http_options, request
2626 )
2627 )
2628
2629 body = (
2630 _BaseFirestoreRestTransport._BasePartitionQuery._get_request_body_json(
2631 transcoded_request
2632 )
2633 )
2634
2635 # Jsonify the query params
2636 query_params = (
2637 _BaseFirestoreRestTransport._BasePartitionQuery._get_query_params_json(
2638 transcoded_request
2639 )
2640 )
2641
2642 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
2643 logging.DEBUG
2644 ): # pragma: NO COVER
2645 request_url = "{host}{uri}".format(
2646 host=self._host, uri=transcoded_request["uri"]
2647 )
2648 method = transcoded_request["method"]
2649 try:
2650 request_payload = type(request).to_json(request)
2651 except:
2652 request_payload = None
2653 http_request = {
2654 "payload": request_payload,
2655 "requestMethod": method,
2656 "requestUrl": request_url,
2657 "headers": dict(metadata),
2658 }
2659 _LOGGER.debug(
2660 f"Sending request for google.firestore_v1.FirestoreClient.PartitionQuery",
2661 extra={
2662 "serviceName": "google.firestore.v1.Firestore",
2663 "rpcName": "PartitionQuery",
2664 "httpRequest": http_request,
2665 "metadata": http_request["headers"],
2666 },
2667 )
2668
2669 # Send the request
2670 response = FirestoreRestTransport._PartitionQuery._get_response(
2671 self._host,
2672 metadata,
2673 query_params,
2674 self._session,
2675 timeout,
2676 transcoded_request,
2677 body,
2678 )
2679
2680 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
2681 # subclass.
2682 if response.status_code >= 400:
2683 raise core_exceptions.from_http_response(response)
2684
2685 # Return the response
2686 resp = firestore.PartitionQueryResponse()
2687 pb_resp = firestore.PartitionQueryResponse.pb(resp)
2688
2689 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
2690
2691 resp = self._interceptor.post_partition_query(resp)
2692 response_metadata = [(k, str(v)) for k, v in response.headers.items()]
2693 resp, _ = self._interceptor.post_partition_query_with_metadata(
2694 resp, response_metadata
2695 )
2696 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
2697 logging.DEBUG
2698 ): # pragma: NO COVER
2699 try:
2700 response_payload = firestore.PartitionQueryResponse.to_json(
2701 response
2702 )
2703 except:
2704 response_payload = None
2705 http_response = {
2706 "payload": response_payload,
2707 "headers": dict(response.headers),
2708 "status": response.status_code,
2709 }
2710 _LOGGER.debug(
2711 "Received response for google.firestore_v1.FirestoreClient.partition_query",
2712 extra={
2713 "serviceName": "google.firestore.v1.Firestore",
2714 "rpcName": "PartitionQuery",
2715 "metadata": http_response["headers"],
2716 "httpResponse": http_response,
2717 },
2718 )
2719 return resp
2720
2721 class _Rollback(_BaseFirestoreRestTransport._BaseRollback, FirestoreRestStub):
2722 def __hash__(self):
2723 return hash("FirestoreRestTransport.Rollback")
2724
2725 @staticmethod
2726 def _get_response(
2727 host,
2728 metadata,
2729 query_params,
2730 session,
2731 timeout,
2732 transcoded_request,
2733 body=None,
2734 ):
2735 uri = transcoded_request["uri"]
2736 method = transcoded_request["method"]
2737 headers = dict(metadata)
2738 headers["Content-Type"] = "application/json"
2739 response = getattr(session, method)(
2740 "{host}{uri}".format(host=host, uri=uri),
2741 timeout=timeout,
2742 headers=headers,
2743 params=rest_helpers.flatten_query_params(query_params, strict=True),
2744 data=body,
2745 )
2746 return response
2747
2748 def __call__(
2749 self,
2750 request: firestore.RollbackRequest,
2751 *,
2752 retry: OptionalRetry = gapic_v1.method.DEFAULT,
2753 timeout: Optional[float] = None,
2754 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
2755 ):
2756 r"""Call the rollback method over HTTP.
2757
2758 Args:
2759 request (~.firestore.RollbackRequest):
2760 The request object. The request for
2761 [Firestore.Rollback][google.firestore.v1.Firestore.Rollback].
2762 retry (google.api_core.retry.Retry): Designation of what errors, if any,
2763 should be retried.
2764 timeout (float): The timeout for this request.
2765 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
2766 sent along with the request as metadata. Normally, each value must be of type `str`,
2767 but for metadata keys ending with the suffix `-bin`, the corresponding values must
2768 be of type `bytes`.
2769 """
2770
2771 http_options = _BaseFirestoreRestTransport._BaseRollback._get_http_options()
2772
2773 request, metadata = self._interceptor.pre_rollback(request, metadata)
2774 transcoded_request = (
2775 _BaseFirestoreRestTransport._BaseRollback._get_transcoded_request(
2776 http_options, request
2777 )
2778 )
2779
2780 body = _BaseFirestoreRestTransport._BaseRollback._get_request_body_json(
2781 transcoded_request
2782 )
2783
2784 # Jsonify the query params
2785 query_params = (
2786 _BaseFirestoreRestTransport._BaseRollback._get_query_params_json(
2787 transcoded_request
2788 )
2789 )
2790
2791 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
2792 logging.DEBUG
2793 ): # pragma: NO COVER
2794 request_url = "{host}{uri}".format(
2795 host=self._host, uri=transcoded_request["uri"]
2796 )
2797 method = transcoded_request["method"]
2798 try:
2799 request_payload = json_format.MessageToJson(request)
2800 except:
2801 request_payload = None
2802 http_request = {
2803 "payload": request_payload,
2804 "requestMethod": method,
2805 "requestUrl": request_url,
2806 "headers": dict(metadata),
2807 }
2808 _LOGGER.debug(
2809 f"Sending request for google.firestore_v1.FirestoreClient.Rollback",
2810 extra={
2811 "serviceName": "google.firestore.v1.Firestore",
2812 "rpcName": "Rollback",
2813 "httpRequest": http_request,
2814 "metadata": http_request["headers"],
2815 },
2816 )
2817
2818 # Send the request
2819 response = FirestoreRestTransport._Rollback._get_response(
2820 self._host,
2821 metadata,
2822 query_params,
2823 self._session,
2824 timeout,
2825 transcoded_request,
2826 body,
2827 )
2828
2829 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
2830 # subclass.
2831 if response.status_code >= 400:
2832 raise core_exceptions.from_http_response(response)
2833
2834 class _RunAggregationQuery(
2835 _BaseFirestoreRestTransport._BaseRunAggregationQuery, FirestoreRestStub
2836 ):
2837 def __hash__(self):
2838 return hash("FirestoreRestTransport.RunAggregationQuery")
2839
2840 @staticmethod
2841 def _get_response(
2842 host,
2843 metadata,
2844 query_params,
2845 session,
2846 timeout,
2847 transcoded_request,
2848 body=None,
2849 ):
2850 uri = transcoded_request["uri"]
2851 method = transcoded_request["method"]
2852 headers = dict(metadata)
2853 headers["Content-Type"] = "application/json"
2854 response = getattr(session, method)(
2855 "{host}{uri}".format(host=host, uri=uri),
2856 timeout=timeout,
2857 headers=headers,
2858 params=rest_helpers.flatten_query_params(query_params, strict=True),
2859 data=body,
2860 stream=True,
2861 )
2862 return response
2863
2864 def __call__(
2865 self,
2866 request: firestore.RunAggregationQueryRequest,
2867 *,
2868 retry: OptionalRetry = gapic_v1.method.DEFAULT,
2869 timeout: Optional[float] = None,
2870 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
2871 ) -> rest_streaming.ResponseIterator:
2872 r"""Call the run aggregation query method over HTTP.
2873
2874 Args:
2875 request (~.firestore.RunAggregationQueryRequest):
2876 The request object. The request for
2877 [Firestore.RunAggregationQuery][google.firestore.v1.Firestore.RunAggregationQuery].
2878 retry (google.api_core.retry.Retry): Designation of what errors, if any,
2879 should be retried.
2880 timeout (float): The timeout for this request.
2881 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
2882 sent along with the request as metadata. Normally, each value must be of type `str`,
2883 but for metadata keys ending with the suffix `-bin`, the corresponding values must
2884 be of type `bytes`.
2885
2886 Returns:
2887 ~.firestore.RunAggregationQueryResponse:
2888 The response for
2889 [Firestore.RunAggregationQuery][google.firestore.v1.Firestore.RunAggregationQuery].
2890
2891 """
2892
2893 http_options = (
2894 _BaseFirestoreRestTransport._BaseRunAggregationQuery._get_http_options()
2895 )
2896
2897 request, metadata = self._interceptor.pre_run_aggregation_query(
2898 request, metadata
2899 )
2900 transcoded_request = _BaseFirestoreRestTransport._BaseRunAggregationQuery._get_transcoded_request(
2901 http_options, request
2902 )
2903
2904 body = _BaseFirestoreRestTransport._BaseRunAggregationQuery._get_request_body_json(
2905 transcoded_request
2906 )
2907
2908 # Jsonify the query params
2909 query_params = _BaseFirestoreRestTransport._BaseRunAggregationQuery._get_query_params_json(
2910 transcoded_request
2911 )
2912
2913 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
2914 logging.DEBUG
2915 ): # pragma: NO COVER
2916 request_url = "{host}{uri}".format(
2917 host=self._host, uri=transcoded_request["uri"]
2918 )
2919 method = transcoded_request["method"]
2920 try:
2921 request_payload = type(request).to_json(request)
2922 except:
2923 request_payload = None
2924 http_request = {
2925 "payload": request_payload,
2926 "requestMethod": method,
2927 "requestUrl": request_url,
2928 "headers": dict(metadata),
2929 }
2930 _LOGGER.debug(
2931 f"Sending request for google.firestore_v1.FirestoreClient.RunAggregationQuery",
2932 extra={
2933 "serviceName": "google.firestore.v1.Firestore",
2934 "rpcName": "RunAggregationQuery",
2935 "httpRequest": http_request,
2936 "metadata": http_request["headers"],
2937 },
2938 )
2939
2940 # Send the request
2941 response = FirestoreRestTransport._RunAggregationQuery._get_response(
2942 self._host,
2943 metadata,
2944 query_params,
2945 self._session,
2946 timeout,
2947 transcoded_request,
2948 body,
2949 )
2950
2951 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
2952 # subclass.
2953 if response.status_code >= 400:
2954 raise core_exceptions.from_http_response(response)
2955
2956 # Return the response
2957 resp = rest_streaming.ResponseIterator(
2958 response, firestore.RunAggregationQueryResponse
2959 )
2960
2961 resp = self._interceptor.post_run_aggregation_query(resp)
2962 response_metadata = [(k, str(v)) for k, v in response.headers.items()]
2963 resp, _ = self._interceptor.post_run_aggregation_query_with_metadata(
2964 resp, response_metadata
2965 )
2966 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
2967 logging.DEBUG
2968 ): # pragma: NO COVER
2969 http_response = {
2970 "headers": dict(response.headers),
2971 "status": response.status_code,
2972 }
2973 _LOGGER.debug(
2974 "Received response for google.firestore_v1.FirestoreClient.run_aggregation_query",
2975 extra={
2976 "serviceName": "google.firestore.v1.Firestore",
2977 "rpcName": "RunAggregationQuery",
2978 "metadata": http_response["headers"],
2979 "httpResponse": http_response,
2980 },
2981 )
2982 return resp
2983
2984 class _RunQuery(_BaseFirestoreRestTransport._BaseRunQuery, FirestoreRestStub):
2985 def __hash__(self):
2986 return hash("FirestoreRestTransport.RunQuery")
2987
2988 @staticmethod
2989 def _get_response(
2990 host,
2991 metadata,
2992 query_params,
2993 session,
2994 timeout,
2995 transcoded_request,
2996 body=None,
2997 ):
2998 uri = transcoded_request["uri"]
2999 method = transcoded_request["method"]
3000 headers = dict(metadata)
3001 headers["Content-Type"] = "application/json"
3002 response = getattr(session, method)(
3003 "{host}{uri}".format(host=host, uri=uri),
3004 timeout=timeout,
3005 headers=headers,
3006 params=rest_helpers.flatten_query_params(query_params, strict=True),
3007 data=body,
3008 stream=True,
3009 )
3010 return response
3011
3012 def __call__(
3013 self,
3014 request: firestore.RunQueryRequest,
3015 *,
3016 retry: OptionalRetry = gapic_v1.method.DEFAULT,
3017 timeout: Optional[float] = None,
3018 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
3019 ) -> rest_streaming.ResponseIterator:
3020 r"""Call the run query method over HTTP.
3021
3022 Args:
3023 request (~.firestore.RunQueryRequest):
3024 The request object. The request for
3025 [Firestore.RunQuery][google.firestore.v1.Firestore.RunQuery].
3026 retry (google.api_core.retry.Retry): Designation of what errors, if any,
3027 should be retried.
3028 timeout (float): The timeout for this request.
3029 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
3030 sent along with the request as metadata. Normally, each value must be of type `str`,
3031 but for metadata keys ending with the suffix `-bin`, the corresponding values must
3032 be of type `bytes`.
3033
3034 Returns:
3035 ~.firestore.RunQueryResponse:
3036 The response for
3037 [Firestore.RunQuery][google.firestore.v1.Firestore.RunQuery].
3038
3039 """
3040
3041 http_options = _BaseFirestoreRestTransport._BaseRunQuery._get_http_options()
3042
3043 request, metadata = self._interceptor.pre_run_query(request, metadata)
3044 transcoded_request = (
3045 _BaseFirestoreRestTransport._BaseRunQuery._get_transcoded_request(
3046 http_options, request
3047 )
3048 )
3049
3050 body = _BaseFirestoreRestTransport._BaseRunQuery._get_request_body_json(
3051 transcoded_request
3052 )
3053
3054 # Jsonify the query params
3055 query_params = (
3056 _BaseFirestoreRestTransport._BaseRunQuery._get_query_params_json(
3057 transcoded_request
3058 )
3059 )
3060
3061 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
3062 logging.DEBUG
3063 ): # pragma: NO COVER
3064 request_url = "{host}{uri}".format(
3065 host=self._host, uri=transcoded_request["uri"]
3066 )
3067 method = transcoded_request["method"]
3068 try:
3069 request_payload = type(request).to_json(request)
3070 except:
3071 request_payload = None
3072 http_request = {
3073 "payload": request_payload,
3074 "requestMethod": method,
3075 "requestUrl": request_url,
3076 "headers": dict(metadata),
3077 }
3078 _LOGGER.debug(
3079 f"Sending request for google.firestore_v1.FirestoreClient.RunQuery",
3080 extra={
3081 "serviceName": "google.firestore.v1.Firestore",
3082 "rpcName": "RunQuery",
3083 "httpRequest": http_request,
3084 "metadata": http_request["headers"],
3085 },
3086 )
3087
3088 # Send the request
3089 response = FirestoreRestTransport._RunQuery._get_response(
3090 self._host,
3091 metadata,
3092 query_params,
3093 self._session,
3094 timeout,
3095 transcoded_request,
3096 body,
3097 )
3098
3099 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
3100 # subclass.
3101 if response.status_code >= 400:
3102 raise core_exceptions.from_http_response(response)
3103
3104 # Return the response
3105 resp = rest_streaming.ResponseIterator(response, firestore.RunQueryResponse)
3106
3107 resp = self._interceptor.post_run_query(resp)
3108 response_metadata = [(k, str(v)) for k, v in response.headers.items()]
3109 resp, _ = self._interceptor.post_run_query_with_metadata(
3110 resp, response_metadata
3111 )
3112 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
3113 logging.DEBUG
3114 ): # pragma: NO COVER
3115 http_response = {
3116 "headers": dict(response.headers),
3117 "status": response.status_code,
3118 }
3119 _LOGGER.debug(
3120 "Received response for google.firestore_v1.FirestoreClient.run_query",
3121 extra={
3122 "serviceName": "google.firestore.v1.Firestore",
3123 "rpcName": "RunQuery",
3124 "metadata": http_response["headers"],
3125 "httpResponse": http_response,
3126 },
3127 )
3128 return resp
3129
3130 class _UpdateDocument(
3131 _BaseFirestoreRestTransport._BaseUpdateDocument, FirestoreRestStub
3132 ):
3133 def __hash__(self):
3134 return hash("FirestoreRestTransport.UpdateDocument")
3135
3136 @staticmethod
3137 def _get_response(
3138 host,
3139 metadata,
3140 query_params,
3141 session,
3142 timeout,
3143 transcoded_request,
3144 body=None,
3145 ):
3146 uri = transcoded_request["uri"]
3147 method = transcoded_request["method"]
3148 headers = dict(metadata)
3149 headers["Content-Type"] = "application/json"
3150 response = getattr(session, method)(
3151 "{host}{uri}".format(host=host, uri=uri),
3152 timeout=timeout,
3153 headers=headers,
3154 params=rest_helpers.flatten_query_params(query_params, strict=True),
3155 data=body,
3156 )
3157 return response
3158
3159 def __call__(
3160 self,
3161 request: firestore.UpdateDocumentRequest,
3162 *,
3163 retry: OptionalRetry = gapic_v1.method.DEFAULT,
3164 timeout: Optional[float] = None,
3165 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
3166 ) -> gf_document.Document:
3167 r"""Call the update document method over HTTP.
3168
3169 Args:
3170 request (~.firestore.UpdateDocumentRequest):
3171 The request object. The request for
3172 [Firestore.UpdateDocument][google.firestore.v1.Firestore.UpdateDocument].
3173 retry (google.api_core.retry.Retry): Designation of what errors, if any,
3174 should be retried.
3175 timeout (float): The timeout for this request.
3176 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
3177 sent along with the request as metadata. Normally, each value must be of type `str`,
3178 but for metadata keys ending with the suffix `-bin`, the corresponding values must
3179 be of type `bytes`.
3180
3181 Returns:
3182 ~.gf_document.Document:
3183 A Firestore document.
3184
3185 Must not exceed 1 MiB - 4 bytes.
3186
3187 """
3188
3189 http_options = (
3190 _BaseFirestoreRestTransport._BaseUpdateDocument._get_http_options()
3191 )
3192
3193 request, metadata = self._interceptor.pre_update_document(request, metadata)
3194 transcoded_request = (
3195 _BaseFirestoreRestTransport._BaseUpdateDocument._get_transcoded_request(
3196 http_options, request
3197 )
3198 )
3199
3200 body = (
3201 _BaseFirestoreRestTransport._BaseUpdateDocument._get_request_body_json(
3202 transcoded_request
3203 )
3204 )
3205
3206 # Jsonify the query params
3207 query_params = (
3208 _BaseFirestoreRestTransport._BaseUpdateDocument._get_query_params_json(
3209 transcoded_request
3210 )
3211 )
3212
3213 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
3214 logging.DEBUG
3215 ): # pragma: NO COVER
3216 request_url = "{host}{uri}".format(
3217 host=self._host, uri=transcoded_request["uri"]
3218 )
3219 method = transcoded_request["method"]
3220 try:
3221 request_payload = type(request).to_json(request)
3222 except:
3223 request_payload = None
3224 http_request = {
3225 "payload": request_payload,
3226 "requestMethod": method,
3227 "requestUrl": request_url,
3228 "headers": dict(metadata),
3229 }
3230 _LOGGER.debug(
3231 f"Sending request for google.firestore_v1.FirestoreClient.UpdateDocument",
3232 extra={
3233 "serviceName": "google.firestore.v1.Firestore",
3234 "rpcName": "UpdateDocument",
3235 "httpRequest": http_request,
3236 "metadata": http_request["headers"],
3237 },
3238 )
3239
3240 # Send the request
3241 response = FirestoreRestTransport._UpdateDocument._get_response(
3242 self._host,
3243 metadata,
3244 query_params,
3245 self._session,
3246 timeout,
3247 transcoded_request,
3248 body,
3249 )
3250
3251 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
3252 # subclass.
3253 if response.status_code >= 400:
3254 raise core_exceptions.from_http_response(response)
3255
3256 # Return the response
3257 resp = gf_document.Document()
3258 pb_resp = gf_document.Document.pb(resp)
3259
3260 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
3261
3262 resp = self._interceptor.post_update_document(resp)
3263 response_metadata = [(k, str(v)) for k, v in response.headers.items()]
3264 resp, _ = self._interceptor.post_update_document_with_metadata(
3265 resp, response_metadata
3266 )
3267 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
3268 logging.DEBUG
3269 ): # pragma: NO COVER
3270 try:
3271 response_payload = gf_document.Document.to_json(response)
3272 except:
3273 response_payload = None
3274 http_response = {
3275 "payload": response_payload,
3276 "headers": dict(response.headers),
3277 "status": response.status_code,
3278 }
3279 _LOGGER.debug(
3280 "Received response for google.firestore_v1.FirestoreClient.update_document",
3281 extra={
3282 "serviceName": "google.firestore.v1.Firestore",
3283 "rpcName": "UpdateDocument",
3284 "metadata": http_response["headers"],
3285 "httpResponse": http_response,
3286 },
3287 )
3288 return resp
3289
3290 class _Write(_BaseFirestoreRestTransport._BaseWrite, FirestoreRestStub):
3291 def __hash__(self):
3292 return hash("FirestoreRestTransport.Write")
3293
3294 def __call__(
3295 self,
3296 request: firestore.WriteRequest,
3297 *,
3298 retry: OptionalRetry = gapic_v1.method.DEFAULT,
3299 timeout: Optional[float] = None,
3300 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
3301 ) -> rest_streaming.ResponseIterator:
3302 raise NotImplementedError(
3303 "Method Write is not available over REST transport"
3304 )
3305
3306 @property
3307 def batch_get_documents(
3308 self,
3309 ) -> Callable[
3310 [firestore.BatchGetDocumentsRequest], firestore.BatchGetDocumentsResponse
3311 ]:
3312 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3313 # In C++ this would require a dynamic_cast
3314 return self._BatchGetDocuments(self._session, self._host, self._interceptor) # type: ignore
3315
3316 @property
3317 def batch_write(
3318 self,
3319 ) -> Callable[[firestore.BatchWriteRequest], firestore.BatchWriteResponse]:
3320 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3321 # In C++ this would require a dynamic_cast
3322 return self._BatchWrite(self._session, self._host, self._interceptor) # type: ignore
3323
3324 @property
3325 def begin_transaction(
3326 self,
3327 ) -> Callable[
3328 [firestore.BeginTransactionRequest], firestore.BeginTransactionResponse
3329 ]:
3330 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3331 # In C++ this would require a dynamic_cast
3332 return self._BeginTransaction(self._session, self._host, self._interceptor) # type: ignore
3333
3334 @property
3335 def commit(self) -> Callable[[firestore.CommitRequest], firestore.CommitResponse]:
3336 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3337 # In C++ this would require a dynamic_cast
3338 return self._Commit(self._session, self._host, self._interceptor) # type: ignore
3339
3340 @property
3341 def create_document(
3342 self,
3343 ) -> Callable[[firestore.CreateDocumentRequest], document.Document]:
3344 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3345 # In C++ this would require a dynamic_cast
3346 return self._CreateDocument(self._session, self._host, self._interceptor) # type: ignore
3347
3348 @property
3349 def delete_document(
3350 self,
3351 ) -> Callable[[firestore.DeleteDocumentRequest], empty_pb2.Empty]:
3352 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3353 # In C++ this would require a dynamic_cast
3354 return self._DeleteDocument(self._session, self._host, self._interceptor) # type: ignore
3355
3356 @property
3357 def execute_pipeline(
3358 self,
3359 ) -> Callable[
3360 [firestore.ExecutePipelineRequest], firestore.ExecutePipelineResponse
3361 ]:
3362 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3363 # In C++ this would require a dynamic_cast
3364 return self._ExecutePipeline(self._session, self._host, self._interceptor) # type: ignore
3365
3366 @property
3367 def get_document(
3368 self,
3369 ) -> Callable[[firestore.GetDocumentRequest], document.Document]:
3370 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3371 # In C++ this would require a dynamic_cast
3372 return self._GetDocument(self._session, self._host, self._interceptor) # type: ignore
3373
3374 @property
3375 def list_collection_ids(
3376 self,
3377 ) -> Callable[
3378 [firestore.ListCollectionIdsRequest], firestore.ListCollectionIdsResponse
3379 ]:
3380 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3381 # In C++ this would require a dynamic_cast
3382 return self._ListCollectionIds(self._session, self._host, self._interceptor) # type: ignore
3383
3384 @property
3385 def list_documents(
3386 self,
3387 ) -> Callable[[firestore.ListDocumentsRequest], firestore.ListDocumentsResponse]:
3388 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3389 # In C++ this would require a dynamic_cast
3390 return self._ListDocuments(self._session, self._host, self._interceptor) # type: ignore
3391
3392 @property
3393 def listen(self) -> Callable[[firestore.ListenRequest], firestore.ListenResponse]:
3394 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3395 # In C++ this would require a dynamic_cast
3396 return self._Listen(self._session, self._host, self._interceptor) # type: ignore
3397
3398 @property
3399 def partition_query(
3400 self,
3401 ) -> Callable[[firestore.PartitionQueryRequest], firestore.PartitionQueryResponse]:
3402 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3403 # In C++ this would require a dynamic_cast
3404 return self._PartitionQuery(self._session, self._host, self._interceptor) # type: ignore
3405
3406 @property
3407 def rollback(self) -> Callable[[firestore.RollbackRequest], empty_pb2.Empty]:
3408 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3409 # In C++ this would require a dynamic_cast
3410 return self._Rollback(self._session, self._host, self._interceptor) # type: ignore
3411
3412 @property
3413 def run_aggregation_query(
3414 self,
3415 ) -> Callable[
3416 [firestore.RunAggregationQueryRequest], firestore.RunAggregationQueryResponse
3417 ]:
3418 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3419 # In C++ this would require a dynamic_cast
3420 return self._RunAggregationQuery(self._session, self._host, self._interceptor) # type: ignore
3421
3422 @property
3423 def run_query(
3424 self,
3425 ) -> Callable[[firestore.RunQueryRequest], firestore.RunQueryResponse]:
3426 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3427 # In C++ this would require a dynamic_cast
3428 return self._RunQuery(self._session, self._host, self._interceptor) # type: ignore
3429
3430 @property
3431 def update_document(
3432 self,
3433 ) -> Callable[[firestore.UpdateDocumentRequest], gf_document.Document]:
3434 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3435 # In C++ this would require a dynamic_cast
3436 return self._UpdateDocument(self._session, self._host, self._interceptor) # type: ignore
3437
3438 @property
3439 def write(self) -> Callable[[firestore.WriteRequest], firestore.WriteResponse]:
3440 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3441 # In C++ this would require a dynamic_cast
3442 return self._Write(self._session, self._host, self._interceptor) # type: ignore
3443
3444 @property
3445 def cancel_operation(self):
3446 return self._CancelOperation(self._session, self._host, self._interceptor) # type: ignore
3447
3448 class _CancelOperation(
3449 _BaseFirestoreRestTransport._BaseCancelOperation, FirestoreRestStub
3450 ):
3451 def __hash__(self):
3452 return hash("FirestoreRestTransport.CancelOperation")
3453
3454 @staticmethod
3455 def _get_response(
3456 host,
3457 metadata,
3458 query_params,
3459 session,
3460 timeout,
3461 transcoded_request,
3462 body=None,
3463 ):
3464 uri = transcoded_request["uri"]
3465 method = transcoded_request["method"]
3466 headers = dict(metadata)
3467 headers["Content-Type"] = "application/json"
3468 response = getattr(session, method)(
3469 "{host}{uri}".format(host=host, uri=uri),
3470 timeout=timeout,
3471 headers=headers,
3472 params=rest_helpers.flatten_query_params(query_params, strict=True),
3473 data=body,
3474 )
3475 return response
3476
3477 def __call__(
3478 self,
3479 request: operations_pb2.CancelOperationRequest,
3480 *,
3481 retry: OptionalRetry = gapic_v1.method.DEFAULT,
3482 timeout: Optional[float] = None,
3483 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
3484 ) -> None:
3485 r"""Call the cancel operation method over HTTP.
3486
3487 Args:
3488 request (operations_pb2.CancelOperationRequest):
3489 The request object for CancelOperation method.
3490 retry (google.api_core.retry.Retry): Designation of what errors, if any,
3491 should be retried.
3492 timeout (float): The timeout for this request.
3493 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
3494 sent along with the request as metadata. Normally, each value must be of type `str`,
3495 but for metadata keys ending with the suffix `-bin`, the corresponding values must
3496 be of type `bytes`.
3497 """
3498
3499 http_options = (
3500 _BaseFirestoreRestTransport._BaseCancelOperation._get_http_options()
3501 )
3502
3503 request, metadata = self._interceptor.pre_cancel_operation(
3504 request, metadata
3505 )
3506 transcoded_request = _BaseFirestoreRestTransport._BaseCancelOperation._get_transcoded_request(
3507 http_options, request
3508 )
3509
3510 body = (
3511 _BaseFirestoreRestTransport._BaseCancelOperation._get_request_body_json(
3512 transcoded_request
3513 )
3514 )
3515
3516 # Jsonify the query params
3517 query_params = (
3518 _BaseFirestoreRestTransport._BaseCancelOperation._get_query_params_json(
3519 transcoded_request
3520 )
3521 )
3522
3523 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
3524 logging.DEBUG
3525 ): # pragma: NO COVER
3526 request_url = "{host}{uri}".format(
3527 host=self._host, uri=transcoded_request["uri"]
3528 )
3529 method = transcoded_request["method"]
3530 try:
3531 request_payload = json_format.MessageToJson(request)
3532 except:
3533 request_payload = None
3534 http_request = {
3535 "payload": request_payload,
3536 "requestMethod": method,
3537 "requestUrl": request_url,
3538 "headers": dict(metadata),
3539 }
3540 _LOGGER.debug(
3541 f"Sending request for google.firestore_v1.FirestoreClient.CancelOperation",
3542 extra={
3543 "serviceName": "google.firestore.v1.Firestore",
3544 "rpcName": "CancelOperation",
3545 "httpRequest": http_request,
3546 "metadata": http_request["headers"],
3547 },
3548 )
3549
3550 # Send the request
3551 response = FirestoreRestTransport._CancelOperation._get_response(
3552 self._host,
3553 metadata,
3554 query_params,
3555 self._session,
3556 timeout,
3557 transcoded_request,
3558 body,
3559 )
3560
3561 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
3562 # subclass.
3563 if response.status_code >= 400:
3564 raise core_exceptions.from_http_response(response)
3565
3566 return self._interceptor.post_cancel_operation(None)
3567
3568 @property
3569 def delete_operation(self):
3570 return self._DeleteOperation(self._session, self._host, self._interceptor) # type: ignore
3571
3572 class _DeleteOperation(
3573 _BaseFirestoreRestTransport._BaseDeleteOperation, FirestoreRestStub
3574 ):
3575 def __hash__(self):
3576 return hash("FirestoreRestTransport.DeleteOperation")
3577
3578 @staticmethod
3579 def _get_response(
3580 host,
3581 metadata,
3582 query_params,
3583 session,
3584 timeout,
3585 transcoded_request,
3586 body=None,
3587 ):
3588 uri = transcoded_request["uri"]
3589 method = transcoded_request["method"]
3590 headers = dict(metadata)
3591 headers["Content-Type"] = "application/json"
3592 response = getattr(session, method)(
3593 "{host}{uri}".format(host=host, uri=uri),
3594 timeout=timeout,
3595 headers=headers,
3596 params=rest_helpers.flatten_query_params(query_params, strict=True),
3597 )
3598 return response
3599
3600 def __call__(
3601 self,
3602 request: operations_pb2.DeleteOperationRequest,
3603 *,
3604 retry: OptionalRetry = gapic_v1.method.DEFAULT,
3605 timeout: Optional[float] = None,
3606 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
3607 ) -> None:
3608 r"""Call the delete operation method over HTTP.
3609
3610 Args:
3611 request (operations_pb2.DeleteOperationRequest):
3612 The request object for DeleteOperation method.
3613 retry (google.api_core.retry.Retry): Designation of what errors, if any,
3614 should be retried.
3615 timeout (float): The timeout for this request.
3616 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
3617 sent along with the request as metadata. Normally, each value must be of type `str`,
3618 but for metadata keys ending with the suffix `-bin`, the corresponding values must
3619 be of type `bytes`.
3620 """
3621
3622 http_options = (
3623 _BaseFirestoreRestTransport._BaseDeleteOperation._get_http_options()
3624 )
3625
3626 request, metadata = self._interceptor.pre_delete_operation(
3627 request, metadata
3628 )
3629 transcoded_request = _BaseFirestoreRestTransport._BaseDeleteOperation._get_transcoded_request(
3630 http_options, request
3631 )
3632
3633 # Jsonify the query params
3634 query_params = (
3635 _BaseFirestoreRestTransport._BaseDeleteOperation._get_query_params_json(
3636 transcoded_request
3637 )
3638 )
3639
3640 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
3641 logging.DEBUG
3642 ): # pragma: NO COVER
3643 request_url = "{host}{uri}".format(
3644 host=self._host, uri=transcoded_request["uri"]
3645 )
3646 method = transcoded_request["method"]
3647 try:
3648 request_payload = json_format.MessageToJson(request)
3649 except:
3650 request_payload = None
3651 http_request = {
3652 "payload": request_payload,
3653 "requestMethod": method,
3654 "requestUrl": request_url,
3655 "headers": dict(metadata),
3656 }
3657 _LOGGER.debug(
3658 f"Sending request for google.firestore_v1.FirestoreClient.DeleteOperation",
3659 extra={
3660 "serviceName": "google.firestore.v1.Firestore",
3661 "rpcName": "DeleteOperation",
3662 "httpRequest": http_request,
3663 "metadata": http_request["headers"],
3664 },
3665 )
3666
3667 # Send the request
3668 response = FirestoreRestTransport._DeleteOperation._get_response(
3669 self._host,
3670 metadata,
3671 query_params,
3672 self._session,
3673 timeout,
3674 transcoded_request,
3675 )
3676
3677 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
3678 # subclass.
3679 if response.status_code >= 400:
3680 raise core_exceptions.from_http_response(response)
3681
3682 return self._interceptor.post_delete_operation(None)
3683
3684 @property
3685 def get_operation(self):
3686 return self._GetOperation(self._session, self._host, self._interceptor) # type: ignore
3687
3688 class _GetOperation(
3689 _BaseFirestoreRestTransport._BaseGetOperation, FirestoreRestStub
3690 ):
3691 def __hash__(self):
3692 return hash("FirestoreRestTransport.GetOperation")
3693
3694 @staticmethod
3695 def _get_response(
3696 host,
3697 metadata,
3698 query_params,
3699 session,
3700 timeout,
3701 transcoded_request,
3702 body=None,
3703 ):
3704 uri = transcoded_request["uri"]
3705 method = transcoded_request["method"]
3706 headers = dict(metadata)
3707 headers["Content-Type"] = "application/json"
3708 response = getattr(session, method)(
3709 "{host}{uri}".format(host=host, uri=uri),
3710 timeout=timeout,
3711 headers=headers,
3712 params=rest_helpers.flatten_query_params(query_params, strict=True),
3713 )
3714 return response
3715
3716 def __call__(
3717 self,
3718 request: operations_pb2.GetOperationRequest,
3719 *,
3720 retry: OptionalRetry = gapic_v1.method.DEFAULT,
3721 timeout: Optional[float] = None,
3722 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
3723 ) -> operations_pb2.Operation:
3724 r"""Call the get operation method over HTTP.
3725
3726 Args:
3727 request (operations_pb2.GetOperationRequest):
3728 The request object for GetOperation method.
3729 retry (google.api_core.retry.Retry): Designation of what errors, if any,
3730 should be retried.
3731 timeout (float): The timeout for this request.
3732 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
3733 sent along with the request as metadata. Normally, each value must be of type `str`,
3734 but for metadata keys ending with the suffix `-bin`, the corresponding values must
3735 be of type `bytes`.
3736
3737 Returns:
3738 operations_pb2.Operation: Response from GetOperation method.
3739 """
3740
3741 http_options = (
3742 _BaseFirestoreRestTransport._BaseGetOperation._get_http_options()
3743 )
3744
3745 request, metadata = self._interceptor.pre_get_operation(request, metadata)
3746 transcoded_request = (
3747 _BaseFirestoreRestTransport._BaseGetOperation._get_transcoded_request(
3748 http_options, request
3749 )
3750 )
3751
3752 # Jsonify the query params
3753 query_params = (
3754 _BaseFirestoreRestTransport._BaseGetOperation._get_query_params_json(
3755 transcoded_request
3756 )
3757 )
3758
3759 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
3760 logging.DEBUG
3761 ): # pragma: NO COVER
3762 request_url = "{host}{uri}".format(
3763 host=self._host, uri=transcoded_request["uri"]
3764 )
3765 method = transcoded_request["method"]
3766 try:
3767 request_payload = json_format.MessageToJson(request)
3768 except:
3769 request_payload = None
3770 http_request = {
3771 "payload": request_payload,
3772 "requestMethod": method,
3773 "requestUrl": request_url,
3774 "headers": dict(metadata),
3775 }
3776 _LOGGER.debug(
3777 f"Sending request for google.firestore_v1.FirestoreClient.GetOperation",
3778 extra={
3779 "serviceName": "google.firestore.v1.Firestore",
3780 "rpcName": "GetOperation",
3781 "httpRequest": http_request,
3782 "metadata": http_request["headers"],
3783 },
3784 )
3785
3786 # Send the request
3787 response = FirestoreRestTransport._GetOperation._get_response(
3788 self._host,
3789 metadata,
3790 query_params,
3791 self._session,
3792 timeout,
3793 transcoded_request,
3794 )
3795
3796 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
3797 # subclass.
3798 if response.status_code >= 400:
3799 raise core_exceptions.from_http_response(response)
3800
3801 content = response.content.decode("utf-8")
3802 resp = operations_pb2.Operation()
3803 resp = json_format.Parse(content, resp)
3804 resp = self._interceptor.post_get_operation(resp)
3805 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
3806 logging.DEBUG
3807 ): # pragma: NO COVER
3808 try:
3809 response_payload = json_format.MessageToJson(resp)
3810 except:
3811 response_payload = None
3812 http_response = {
3813 "payload": response_payload,
3814 "headers": dict(response.headers),
3815 "status": response.status_code,
3816 }
3817 _LOGGER.debug(
3818 "Received response for google.firestore_v1.FirestoreAsyncClient.GetOperation",
3819 extra={
3820 "serviceName": "google.firestore.v1.Firestore",
3821 "rpcName": "GetOperation",
3822 "httpResponse": http_response,
3823 "metadata": http_response["headers"],
3824 },
3825 )
3826 return resp
3827
3828 @property
3829 def list_operations(self):
3830 return self._ListOperations(self._session, self._host, self._interceptor) # type: ignore
3831
3832 class _ListOperations(
3833 _BaseFirestoreRestTransport._BaseListOperations, FirestoreRestStub
3834 ):
3835 def __hash__(self):
3836 return hash("FirestoreRestTransport.ListOperations")
3837
3838 @staticmethod
3839 def _get_response(
3840 host,
3841 metadata,
3842 query_params,
3843 session,
3844 timeout,
3845 transcoded_request,
3846 body=None,
3847 ):
3848 uri = transcoded_request["uri"]
3849 method = transcoded_request["method"]
3850 headers = dict(metadata)
3851 headers["Content-Type"] = "application/json"
3852 response = getattr(session, method)(
3853 "{host}{uri}".format(host=host, uri=uri),
3854 timeout=timeout,
3855 headers=headers,
3856 params=rest_helpers.flatten_query_params(query_params, strict=True),
3857 )
3858 return response
3859
3860 def __call__(
3861 self,
3862 request: operations_pb2.ListOperationsRequest,
3863 *,
3864 retry: OptionalRetry = gapic_v1.method.DEFAULT,
3865 timeout: Optional[float] = None,
3866 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
3867 ) -> operations_pb2.ListOperationsResponse:
3868 r"""Call the list operations method over HTTP.
3869
3870 Args:
3871 request (operations_pb2.ListOperationsRequest):
3872 The request object for ListOperations method.
3873 retry (google.api_core.retry.Retry): Designation of what errors, if any,
3874 should be retried.
3875 timeout (float): The timeout for this request.
3876 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
3877 sent along with the request as metadata. Normally, each value must be of type `str`,
3878 but for metadata keys ending with the suffix `-bin`, the corresponding values must
3879 be of type `bytes`.
3880
3881 Returns:
3882 operations_pb2.ListOperationsResponse: Response from ListOperations method.
3883 """
3884
3885 http_options = (
3886 _BaseFirestoreRestTransport._BaseListOperations._get_http_options()
3887 )
3888
3889 request, metadata = self._interceptor.pre_list_operations(request, metadata)
3890 transcoded_request = (
3891 _BaseFirestoreRestTransport._BaseListOperations._get_transcoded_request(
3892 http_options, request
3893 )
3894 )
3895
3896 # Jsonify the query params
3897 query_params = (
3898 _BaseFirestoreRestTransport._BaseListOperations._get_query_params_json(
3899 transcoded_request
3900 )
3901 )
3902
3903 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
3904 logging.DEBUG
3905 ): # pragma: NO COVER
3906 request_url = "{host}{uri}".format(
3907 host=self._host, uri=transcoded_request["uri"]
3908 )
3909 method = transcoded_request["method"]
3910 try:
3911 request_payload = json_format.MessageToJson(request)
3912 except:
3913 request_payload = None
3914 http_request = {
3915 "payload": request_payload,
3916 "requestMethod": method,
3917 "requestUrl": request_url,
3918 "headers": dict(metadata),
3919 }
3920 _LOGGER.debug(
3921 f"Sending request for google.firestore_v1.FirestoreClient.ListOperations",
3922 extra={
3923 "serviceName": "google.firestore.v1.Firestore",
3924 "rpcName": "ListOperations",
3925 "httpRequest": http_request,
3926 "metadata": http_request["headers"],
3927 },
3928 )
3929
3930 # Send the request
3931 response = FirestoreRestTransport._ListOperations._get_response(
3932 self._host,
3933 metadata,
3934 query_params,
3935 self._session,
3936 timeout,
3937 transcoded_request,
3938 )
3939
3940 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
3941 # subclass.
3942 if response.status_code >= 400:
3943 raise core_exceptions.from_http_response(response)
3944
3945 content = response.content.decode("utf-8")
3946 resp = operations_pb2.ListOperationsResponse()
3947 resp = json_format.Parse(content, resp)
3948 resp = self._interceptor.post_list_operations(resp)
3949 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
3950 logging.DEBUG
3951 ): # pragma: NO COVER
3952 try:
3953 response_payload = json_format.MessageToJson(resp)
3954 except:
3955 response_payload = None
3956 http_response = {
3957 "payload": response_payload,
3958 "headers": dict(response.headers),
3959 "status": response.status_code,
3960 }
3961 _LOGGER.debug(
3962 "Received response for google.firestore_v1.FirestoreAsyncClient.ListOperations",
3963 extra={
3964 "serviceName": "google.firestore.v1.Firestore",
3965 "rpcName": "ListOperations",
3966 "httpResponse": http_response,
3967 "metadata": http_response["headers"],
3968 },
3969 )
3970 return resp
3971
3972 @property
3973 def kind(self) -> str:
3974 return "rest"
3975
3976 def close(self):
3977 self._session.close()
3978
3979
3980__all__ = ("FirestoreRestTransport",)