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