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