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