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