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 abc
17from typing import Awaitable, Callable, Dict, Optional, Sequence, Union
18
19from google.cloud.logging_v2 import gapic_version as package_version
20
21import google.auth # type: ignore
22import google.api_core
23from google.api_core import exceptions as core_exceptions
24from google.api_core import gapic_v1
25from google.api_core import retry as retries
26from google.api_core import operations_v1
27from google.auth import credentials as ga_credentials # type: ignore
28from google.oauth2 import service_account # type: ignore
29import google.protobuf
30
31from google.cloud.logging_v2.types import logging_config
32from google.longrunning import operations_pb2 # type: ignore
33import google.protobuf.empty_pb2 as empty_pb2 # type: ignore
34
35DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
36 gapic_version=package_version.__version__
37)
38
39if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER
40 DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__
41
42
43class ConfigServiceV2Transport(abc.ABC):
44 """Abstract transport class for ConfigServiceV2."""
45
46 AUTH_SCOPES = (
47 "https://www.googleapis.com/auth/cloud-platform",
48 "https://www.googleapis.com/auth/cloud-platform.read-only",
49 "https://www.googleapis.com/auth/logging.admin",
50 "https://www.googleapis.com/auth/logging.read",
51 )
52
53 DEFAULT_HOST: str = "logging.googleapis.com"
54
55 def __init__(
56 self,
57 *,
58 host: str = DEFAULT_HOST,
59 credentials: Optional[ga_credentials.Credentials] = None,
60 credentials_file: Optional[str] = None,
61 scopes: Optional[Sequence[str]] = None,
62 quota_project_id: Optional[str] = None,
63 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
64 always_use_jwt_access: Optional[bool] = False,
65 api_audience: Optional[str] = None,
66 **kwargs,
67 ) -> None:
68 """Instantiate the transport.
69
70 Args:
71 host (Optional[str]):
72 The hostname to connect to (default: 'logging.googleapis.com').
73 credentials (Optional[google.auth.credentials.Credentials]): The
74 authorization credentials to attach to requests. These
75 credentials identify the application to the service; if none
76 are specified, the client will attempt to ascertain the
77 credentials from the environment.
78 credentials_file (Optional[str]): Deprecated. A file with credentials that can
79 be loaded with :func:`google.auth.load_credentials_from_file`.
80 This argument is mutually exclusive with credentials. This argument will be
81 removed in the next major version of this library.
82 scopes (Optional[Sequence[str]]): A list of scopes.
83 quota_project_id (Optional[str]): An optional project to use for billing
84 and quota.
85 client_info (google.api_core.gapic_v1.client_info.ClientInfo):
86 The client info used to send a user-agent string along with
87 API requests. If ``None``, then default info will be used.
88 Generally, you only need to set this if you're developing
89 your own client library.
90 always_use_jwt_access (Optional[bool]): Whether self signed JWT should
91 be used for service account credentials.
92 """
93
94 # Save the scopes.
95 self._scopes = scopes
96 if not hasattr(self, "_ignore_credentials"):
97 self._ignore_credentials: bool = False
98
99 # If no credentials are provided, then determine the appropriate
100 # defaults.
101 if credentials and credentials_file:
102 raise core_exceptions.DuplicateCredentialArgs(
103 "'credentials_file' and 'credentials' are mutually exclusive"
104 )
105
106 if credentials_file is not None:
107 credentials, _ = google.auth.load_credentials_from_file(
108 credentials_file,
109 scopes=scopes,
110 quota_project_id=quota_project_id,
111 default_scopes=self.AUTH_SCOPES,
112 )
113 elif credentials is None and not self._ignore_credentials:
114 credentials, _ = google.auth.default(
115 scopes=scopes,
116 quota_project_id=quota_project_id,
117 default_scopes=self.AUTH_SCOPES,
118 )
119 # Don't apply audience if the credentials file passed from user.
120 if hasattr(credentials, "with_gdch_audience"):
121 credentials = credentials.with_gdch_audience(
122 api_audience if api_audience else host
123 )
124
125 # If the credentials are service account credentials, then always try to use self signed JWT.
126 if (
127 always_use_jwt_access
128 and isinstance(credentials, service_account.Credentials)
129 and hasattr(service_account.Credentials, "with_always_use_jwt_access")
130 ):
131 credentials = credentials.with_always_use_jwt_access(True)
132
133 # Save the credentials.
134 self._credentials = credentials
135
136 # Save the hostname. Default to port 443 (HTTPS) if none is specified.
137 if ":" not in host:
138 host += ":443"
139 self._host = host
140
141 @property
142 def host(self):
143 return self._host
144
145 def _prep_wrapped_messages(self, client_info):
146 # Precompute the wrapped methods.
147 self._wrapped_methods = {
148 self.list_buckets: gapic_v1.method.wrap_method(
149 self.list_buckets,
150 default_timeout=None,
151 client_info=client_info,
152 ),
153 self.get_bucket: gapic_v1.method.wrap_method(
154 self.get_bucket,
155 default_timeout=None,
156 client_info=client_info,
157 ),
158 self.create_bucket_async: gapic_v1.method.wrap_method(
159 self.create_bucket_async,
160 default_timeout=None,
161 client_info=client_info,
162 ),
163 self.update_bucket_async: gapic_v1.method.wrap_method(
164 self.update_bucket_async,
165 default_timeout=None,
166 client_info=client_info,
167 ),
168 self.create_bucket: gapic_v1.method.wrap_method(
169 self.create_bucket,
170 default_timeout=None,
171 client_info=client_info,
172 ),
173 self.update_bucket: gapic_v1.method.wrap_method(
174 self.update_bucket,
175 default_timeout=None,
176 client_info=client_info,
177 ),
178 self.delete_bucket: gapic_v1.method.wrap_method(
179 self.delete_bucket,
180 default_timeout=None,
181 client_info=client_info,
182 ),
183 self.undelete_bucket: gapic_v1.method.wrap_method(
184 self.undelete_bucket,
185 default_timeout=None,
186 client_info=client_info,
187 ),
188 self.list_views: gapic_v1.method.wrap_method(
189 self.list_views,
190 default_timeout=None,
191 client_info=client_info,
192 ),
193 self.get_view: gapic_v1.method.wrap_method(
194 self.get_view,
195 default_timeout=None,
196 client_info=client_info,
197 ),
198 self.create_view: gapic_v1.method.wrap_method(
199 self.create_view,
200 default_timeout=None,
201 client_info=client_info,
202 ),
203 self.update_view: gapic_v1.method.wrap_method(
204 self.update_view,
205 default_timeout=None,
206 client_info=client_info,
207 ),
208 self.delete_view: gapic_v1.method.wrap_method(
209 self.delete_view,
210 default_timeout=None,
211 client_info=client_info,
212 ),
213 self.list_sinks: gapic_v1.method.wrap_method(
214 self.list_sinks,
215 default_retry=retries.Retry(
216 initial=0.1,
217 maximum=60.0,
218 multiplier=1.3,
219 predicate=retries.if_exception_type(
220 core_exceptions.DeadlineExceeded,
221 core_exceptions.InternalServerError,
222 core_exceptions.ServiceUnavailable,
223 ),
224 deadline=60.0,
225 ),
226 default_timeout=60.0,
227 client_info=client_info,
228 ),
229 self.get_sink: gapic_v1.method.wrap_method(
230 self.get_sink,
231 default_retry=retries.Retry(
232 initial=0.1,
233 maximum=60.0,
234 multiplier=1.3,
235 predicate=retries.if_exception_type(
236 core_exceptions.DeadlineExceeded,
237 core_exceptions.InternalServerError,
238 core_exceptions.ServiceUnavailable,
239 ),
240 deadline=60.0,
241 ),
242 default_timeout=60.0,
243 client_info=client_info,
244 ),
245 self.create_sink: gapic_v1.method.wrap_method(
246 self.create_sink,
247 default_timeout=120.0,
248 client_info=client_info,
249 ),
250 self.update_sink: gapic_v1.method.wrap_method(
251 self.update_sink,
252 default_retry=retries.Retry(
253 initial=0.1,
254 maximum=60.0,
255 multiplier=1.3,
256 predicate=retries.if_exception_type(
257 core_exceptions.DeadlineExceeded,
258 core_exceptions.InternalServerError,
259 core_exceptions.ServiceUnavailable,
260 ),
261 deadline=60.0,
262 ),
263 default_timeout=60.0,
264 client_info=client_info,
265 ),
266 self.delete_sink: gapic_v1.method.wrap_method(
267 self.delete_sink,
268 default_retry=retries.Retry(
269 initial=0.1,
270 maximum=60.0,
271 multiplier=1.3,
272 predicate=retries.if_exception_type(
273 core_exceptions.DeadlineExceeded,
274 core_exceptions.InternalServerError,
275 core_exceptions.ServiceUnavailable,
276 ),
277 deadline=60.0,
278 ),
279 default_timeout=60.0,
280 client_info=client_info,
281 ),
282 self.create_link: gapic_v1.method.wrap_method(
283 self.create_link,
284 default_timeout=None,
285 client_info=client_info,
286 ),
287 self.delete_link: gapic_v1.method.wrap_method(
288 self.delete_link,
289 default_timeout=None,
290 client_info=client_info,
291 ),
292 self.list_links: gapic_v1.method.wrap_method(
293 self.list_links,
294 default_timeout=None,
295 client_info=client_info,
296 ),
297 self.get_link: gapic_v1.method.wrap_method(
298 self.get_link,
299 default_timeout=None,
300 client_info=client_info,
301 ),
302 self.list_exclusions: gapic_v1.method.wrap_method(
303 self.list_exclusions,
304 default_retry=retries.Retry(
305 initial=0.1,
306 maximum=60.0,
307 multiplier=1.3,
308 predicate=retries.if_exception_type(
309 core_exceptions.DeadlineExceeded,
310 core_exceptions.InternalServerError,
311 core_exceptions.ServiceUnavailable,
312 ),
313 deadline=60.0,
314 ),
315 default_timeout=60.0,
316 client_info=client_info,
317 ),
318 self.get_exclusion: gapic_v1.method.wrap_method(
319 self.get_exclusion,
320 default_retry=retries.Retry(
321 initial=0.1,
322 maximum=60.0,
323 multiplier=1.3,
324 predicate=retries.if_exception_type(
325 core_exceptions.DeadlineExceeded,
326 core_exceptions.InternalServerError,
327 core_exceptions.ServiceUnavailable,
328 ),
329 deadline=60.0,
330 ),
331 default_timeout=60.0,
332 client_info=client_info,
333 ),
334 self.create_exclusion: gapic_v1.method.wrap_method(
335 self.create_exclusion,
336 default_timeout=120.0,
337 client_info=client_info,
338 ),
339 self.update_exclusion: gapic_v1.method.wrap_method(
340 self.update_exclusion,
341 default_timeout=120.0,
342 client_info=client_info,
343 ),
344 self.delete_exclusion: gapic_v1.method.wrap_method(
345 self.delete_exclusion,
346 default_retry=retries.Retry(
347 initial=0.1,
348 maximum=60.0,
349 multiplier=1.3,
350 predicate=retries.if_exception_type(
351 core_exceptions.DeadlineExceeded,
352 core_exceptions.InternalServerError,
353 core_exceptions.ServiceUnavailable,
354 ),
355 deadline=60.0,
356 ),
357 default_timeout=60.0,
358 client_info=client_info,
359 ),
360 self.get_cmek_settings: gapic_v1.method.wrap_method(
361 self.get_cmek_settings,
362 default_timeout=None,
363 client_info=client_info,
364 ),
365 self.update_cmek_settings: gapic_v1.method.wrap_method(
366 self.update_cmek_settings,
367 default_timeout=None,
368 client_info=client_info,
369 ),
370 self.get_settings: gapic_v1.method.wrap_method(
371 self.get_settings,
372 default_timeout=None,
373 client_info=client_info,
374 ),
375 self.update_settings: gapic_v1.method.wrap_method(
376 self.update_settings,
377 default_timeout=None,
378 client_info=client_info,
379 ),
380 self.copy_log_entries: gapic_v1.method.wrap_method(
381 self.copy_log_entries,
382 default_timeout=None,
383 client_info=client_info,
384 ),
385 self.cancel_operation: gapic_v1.method.wrap_method(
386 self.cancel_operation,
387 default_timeout=None,
388 client_info=client_info,
389 ),
390 self.get_operation: gapic_v1.method.wrap_method(
391 self.get_operation,
392 default_timeout=None,
393 client_info=client_info,
394 ),
395 self.list_operations: gapic_v1.method.wrap_method(
396 self.list_operations,
397 default_timeout=None,
398 client_info=client_info,
399 ),
400 }
401
402 def close(self):
403 """Closes resources associated with the transport.
404
405 .. warning::
406 Only call this method if the transport is NOT shared
407 with other clients - this may cause errors in other clients!
408 """
409 raise NotImplementedError()
410
411 @property
412 def operations_client(self):
413 """Return the client designed to process long-running operations."""
414 raise NotImplementedError()
415
416 @property
417 def list_buckets(
418 self,
419 ) -> Callable[
420 [logging_config.ListBucketsRequest],
421 Union[
422 logging_config.ListBucketsResponse,
423 Awaitable[logging_config.ListBucketsResponse],
424 ],
425 ]:
426 raise NotImplementedError()
427
428 @property
429 def get_bucket(
430 self,
431 ) -> Callable[
432 [logging_config.GetBucketRequest],
433 Union[logging_config.LogBucket, Awaitable[logging_config.LogBucket]],
434 ]:
435 raise NotImplementedError()
436
437 @property
438 def create_bucket_async(
439 self,
440 ) -> Callable[
441 [logging_config.CreateBucketRequest],
442 Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]],
443 ]:
444 raise NotImplementedError()
445
446 @property
447 def update_bucket_async(
448 self,
449 ) -> Callable[
450 [logging_config.UpdateBucketRequest],
451 Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]],
452 ]:
453 raise NotImplementedError()
454
455 @property
456 def create_bucket(
457 self,
458 ) -> Callable[
459 [logging_config.CreateBucketRequest],
460 Union[logging_config.LogBucket, Awaitable[logging_config.LogBucket]],
461 ]:
462 raise NotImplementedError()
463
464 @property
465 def update_bucket(
466 self,
467 ) -> Callable[
468 [logging_config.UpdateBucketRequest],
469 Union[logging_config.LogBucket, Awaitable[logging_config.LogBucket]],
470 ]:
471 raise NotImplementedError()
472
473 @property
474 def delete_bucket(
475 self,
476 ) -> Callable[
477 [logging_config.DeleteBucketRequest],
478 Union[empty_pb2.Empty, Awaitable[empty_pb2.Empty]],
479 ]:
480 raise NotImplementedError()
481
482 @property
483 def undelete_bucket(
484 self,
485 ) -> Callable[
486 [logging_config.UndeleteBucketRequest],
487 Union[empty_pb2.Empty, Awaitable[empty_pb2.Empty]],
488 ]:
489 raise NotImplementedError()
490
491 @property
492 def list_views(
493 self,
494 ) -> Callable[
495 [logging_config.ListViewsRequest],
496 Union[
497 logging_config.ListViewsResponse,
498 Awaitable[logging_config.ListViewsResponse],
499 ],
500 ]:
501 raise NotImplementedError()
502
503 @property
504 def get_view(
505 self,
506 ) -> Callable[
507 [logging_config.GetViewRequest],
508 Union[logging_config.LogView, Awaitable[logging_config.LogView]],
509 ]:
510 raise NotImplementedError()
511
512 @property
513 def create_view(
514 self,
515 ) -> Callable[
516 [logging_config.CreateViewRequest],
517 Union[logging_config.LogView, Awaitable[logging_config.LogView]],
518 ]:
519 raise NotImplementedError()
520
521 @property
522 def update_view(
523 self,
524 ) -> Callable[
525 [logging_config.UpdateViewRequest],
526 Union[logging_config.LogView, Awaitable[logging_config.LogView]],
527 ]:
528 raise NotImplementedError()
529
530 @property
531 def delete_view(
532 self,
533 ) -> Callable[
534 [logging_config.DeleteViewRequest],
535 Union[empty_pb2.Empty, Awaitable[empty_pb2.Empty]],
536 ]:
537 raise NotImplementedError()
538
539 @property
540 def list_sinks(
541 self,
542 ) -> Callable[
543 [logging_config.ListSinksRequest],
544 Union[
545 logging_config.ListSinksResponse,
546 Awaitable[logging_config.ListSinksResponse],
547 ],
548 ]:
549 raise NotImplementedError()
550
551 @property
552 def get_sink(
553 self,
554 ) -> Callable[
555 [logging_config.GetSinkRequest],
556 Union[logging_config.LogSink, Awaitable[logging_config.LogSink]],
557 ]:
558 raise NotImplementedError()
559
560 @property
561 def create_sink(
562 self,
563 ) -> Callable[
564 [logging_config.CreateSinkRequest],
565 Union[logging_config.LogSink, Awaitable[logging_config.LogSink]],
566 ]:
567 raise NotImplementedError()
568
569 @property
570 def update_sink(
571 self,
572 ) -> Callable[
573 [logging_config.UpdateSinkRequest],
574 Union[logging_config.LogSink, Awaitable[logging_config.LogSink]],
575 ]:
576 raise NotImplementedError()
577
578 @property
579 def delete_sink(
580 self,
581 ) -> Callable[
582 [logging_config.DeleteSinkRequest],
583 Union[empty_pb2.Empty, Awaitable[empty_pb2.Empty]],
584 ]:
585 raise NotImplementedError()
586
587 @property
588 def create_link(
589 self,
590 ) -> Callable[
591 [logging_config.CreateLinkRequest],
592 Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]],
593 ]:
594 raise NotImplementedError()
595
596 @property
597 def delete_link(
598 self,
599 ) -> Callable[
600 [logging_config.DeleteLinkRequest],
601 Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]],
602 ]:
603 raise NotImplementedError()
604
605 @property
606 def list_links(
607 self,
608 ) -> Callable[
609 [logging_config.ListLinksRequest],
610 Union[
611 logging_config.ListLinksResponse,
612 Awaitable[logging_config.ListLinksResponse],
613 ],
614 ]:
615 raise NotImplementedError()
616
617 @property
618 def get_link(
619 self,
620 ) -> Callable[
621 [logging_config.GetLinkRequest],
622 Union[logging_config.Link, Awaitable[logging_config.Link]],
623 ]:
624 raise NotImplementedError()
625
626 @property
627 def list_exclusions(
628 self,
629 ) -> Callable[
630 [logging_config.ListExclusionsRequest],
631 Union[
632 logging_config.ListExclusionsResponse,
633 Awaitable[logging_config.ListExclusionsResponse],
634 ],
635 ]:
636 raise NotImplementedError()
637
638 @property
639 def get_exclusion(
640 self,
641 ) -> Callable[
642 [logging_config.GetExclusionRequest],
643 Union[logging_config.LogExclusion, Awaitable[logging_config.LogExclusion]],
644 ]:
645 raise NotImplementedError()
646
647 @property
648 def create_exclusion(
649 self,
650 ) -> Callable[
651 [logging_config.CreateExclusionRequest],
652 Union[logging_config.LogExclusion, Awaitable[logging_config.LogExclusion]],
653 ]:
654 raise NotImplementedError()
655
656 @property
657 def update_exclusion(
658 self,
659 ) -> Callable[
660 [logging_config.UpdateExclusionRequest],
661 Union[logging_config.LogExclusion, Awaitable[logging_config.LogExclusion]],
662 ]:
663 raise NotImplementedError()
664
665 @property
666 def delete_exclusion(
667 self,
668 ) -> Callable[
669 [logging_config.DeleteExclusionRequest],
670 Union[empty_pb2.Empty, Awaitable[empty_pb2.Empty]],
671 ]:
672 raise NotImplementedError()
673
674 @property
675 def get_cmek_settings(
676 self,
677 ) -> Callable[
678 [logging_config.GetCmekSettingsRequest],
679 Union[logging_config.CmekSettings, Awaitable[logging_config.CmekSettings]],
680 ]:
681 raise NotImplementedError()
682
683 @property
684 def update_cmek_settings(
685 self,
686 ) -> Callable[
687 [logging_config.UpdateCmekSettingsRequest],
688 Union[logging_config.CmekSettings, Awaitable[logging_config.CmekSettings]],
689 ]:
690 raise NotImplementedError()
691
692 @property
693 def get_settings(
694 self,
695 ) -> Callable[
696 [logging_config.GetSettingsRequest],
697 Union[logging_config.Settings, Awaitable[logging_config.Settings]],
698 ]:
699 raise NotImplementedError()
700
701 @property
702 def update_settings(
703 self,
704 ) -> Callable[
705 [logging_config.UpdateSettingsRequest],
706 Union[logging_config.Settings, Awaitable[logging_config.Settings]],
707 ]:
708 raise NotImplementedError()
709
710 @property
711 def copy_log_entries(
712 self,
713 ) -> Callable[
714 [logging_config.CopyLogEntriesRequest],
715 Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]],
716 ]:
717 raise NotImplementedError()
718
719 @property
720 def list_operations(
721 self,
722 ) -> Callable[
723 [operations_pb2.ListOperationsRequest],
724 Union[
725 operations_pb2.ListOperationsResponse,
726 Awaitable[operations_pb2.ListOperationsResponse],
727 ],
728 ]:
729 raise NotImplementedError()
730
731 @property
732 def get_operation(
733 self,
734 ) -> Callable[
735 [operations_pb2.GetOperationRequest],
736 Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]],
737 ]:
738 raise NotImplementedError()
739
740 @property
741 def cancel_operation(
742 self,
743 ) -> Callable[[operations_pb2.CancelOperationRequest], None,]:
744 raise NotImplementedError()
745
746 @property
747 def kind(self) -> str:
748 raise NotImplementedError()
749
750
751__all__ = ("ConfigServiceV2Transport",)