1# -*- coding: utf-8 -*-
2# Copyright 2022 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: gapic_v1.method.wrap_method(
145 self.create_bucket,
146 default_timeout=None,
147 client_info=client_info,
148 ),
149 self.update_bucket: gapic_v1.method.wrap_method(
150 self.update_bucket,
151 default_timeout=None,
152 client_info=client_info,
153 ),
154 self.delete_bucket: gapic_v1.method.wrap_method(
155 self.delete_bucket,
156 default_timeout=None,
157 client_info=client_info,
158 ),
159 self.undelete_bucket: gapic_v1.method.wrap_method(
160 self.undelete_bucket,
161 default_timeout=None,
162 client_info=client_info,
163 ),
164 self.list_views: gapic_v1.method.wrap_method(
165 self.list_views,
166 default_timeout=None,
167 client_info=client_info,
168 ),
169 self.get_view: gapic_v1.method.wrap_method(
170 self.get_view,
171 default_timeout=None,
172 client_info=client_info,
173 ),
174 self.create_view: gapic_v1.method.wrap_method(
175 self.create_view,
176 default_timeout=None,
177 client_info=client_info,
178 ),
179 self.update_view: gapic_v1.method.wrap_method(
180 self.update_view,
181 default_timeout=None,
182 client_info=client_info,
183 ),
184 self.delete_view: gapic_v1.method.wrap_method(
185 self.delete_view,
186 default_timeout=None,
187 client_info=client_info,
188 ),
189 self.list_sinks: gapic_v1.method.wrap_method(
190 self.list_sinks,
191 default_retry=retries.Retry(
192 initial=0.1,
193 maximum=60.0,
194 multiplier=1.3,
195 predicate=retries.if_exception_type(
196 core_exceptions.DeadlineExceeded,
197 core_exceptions.InternalServerError,
198 core_exceptions.ServiceUnavailable,
199 ),
200 deadline=60.0,
201 ),
202 default_timeout=60.0,
203 client_info=client_info,
204 ),
205 self.get_sink: gapic_v1.method.wrap_method(
206 self.get_sink,
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.create_sink: gapic_v1.method.wrap_method(
222 self.create_sink,
223 default_timeout=120.0,
224 client_info=client_info,
225 ),
226 self.update_sink: gapic_v1.method.wrap_method(
227 self.update_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.delete_sink: gapic_v1.method.wrap_method(
243 self.delete_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.list_exclusions: gapic_v1.method.wrap_method(
259 self.list_exclusions,
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.get_exclusion: gapic_v1.method.wrap_method(
275 self.get_exclusion,
276 default_retry=retries.Retry(
277 initial=0.1,
278 maximum=60.0,
279 multiplier=1.3,
280 predicate=retries.if_exception_type(
281 core_exceptions.DeadlineExceeded,
282 core_exceptions.InternalServerError,
283 core_exceptions.ServiceUnavailable,
284 ),
285 deadline=60.0,
286 ),
287 default_timeout=60.0,
288 client_info=client_info,
289 ),
290 self.create_exclusion: gapic_v1.method.wrap_method(
291 self.create_exclusion,
292 default_timeout=120.0,
293 client_info=client_info,
294 ),
295 self.update_exclusion: gapic_v1.method.wrap_method(
296 self.update_exclusion,
297 default_timeout=120.0,
298 client_info=client_info,
299 ),
300 self.delete_exclusion: gapic_v1.method.wrap_method(
301 self.delete_exclusion,
302 default_retry=retries.Retry(
303 initial=0.1,
304 maximum=60.0,
305 multiplier=1.3,
306 predicate=retries.if_exception_type(
307 core_exceptions.DeadlineExceeded,
308 core_exceptions.InternalServerError,
309 core_exceptions.ServiceUnavailable,
310 ),
311 deadline=60.0,
312 ),
313 default_timeout=60.0,
314 client_info=client_info,
315 ),
316 self.get_cmek_settings: gapic_v1.method.wrap_method(
317 self.get_cmek_settings,
318 default_timeout=None,
319 client_info=client_info,
320 ),
321 self.update_cmek_settings: gapic_v1.method.wrap_method(
322 self.update_cmek_settings,
323 default_timeout=None,
324 client_info=client_info,
325 ),
326 self.get_settings: gapic_v1.method.wrap_method(
327 self.get_settings,
328 default_timeout=None,
329 client_info=client_info,
330 ),
331 self.update_settings: gapic_v1.method.wrap_method(
332 self.update_settings,
333 default_timeout=None,
334 client_info=client_info,
335 ),
336 self.copy_log_entries: gapic_v1.method.wrap_method(
337 self.copy_log_entries,
338 default_timeout=None,
339 client_info=client_info,
340 ),
341 }
342
343 def close(self):
344 """Closes resources associated with the transport.
345
346 .. warning::
347 Only call this method if the transport is NOT shared
348 with other clients - this may cause errors in other clients!
349 """
350 raise NotImplementedError()
351
352 @property
353 def operations_client(self):
354 """Return the client designed to process long-running operations."""
355 raise NotImplementedError()
356
357 @property
358 def list_buckets(
359 self,
360 ) -> Callable[
361 [logging_config.ListBucketsRequest],
362 Union[
363 logging_config.ListBucketsResponse,
364 Awaitable[logging_config.ListBucketsResponse],
365 ],
366 ]:
367 raise NotImplementedError()
368
369 @property
370 def get_bucket(
371 self,
372 ) -> Callable[
373 [logging_config.GetBucketRequest],
374 Union[logging_config.LogBucket, Awaitable[logging_config.LogBucket]],
375 ]:
376 raise NotImplementedError()
377
378 @property
379 def create_bucket(
380 self,
381 ) -> Callable[
382 [logging_config.CreateBucketRequest],
383 Union[logging_config.LogBucket, Awaitable[logging_config.LogBucket]],
384 ]:
385 raise NotImplementedError()
386
387 @property
388 def update_bucket(
389 self,
390 ) -> Callable[
391 [logging_config.UpdateBucketRequest],
392 Union[logging_config.LogBucket, Awaitable[logging_config.LogBucket]],
393 ]:
394 raise NotImplementedError()
395
396 @property
397 def delete_bucket(
398 self,
399 ) -> Callable[
400 [logging_config.DeleteBucketRequest],
401 Union[empty_pb2.Empty, Awaitable[empty_pb2.Empty]],
402 ]:
403 raise NotImplementedError()
404
405 @property
406 def undelete_bucket(
407 self,
408 ) -> Callable[
409 [logging_config.UndeleteBucketRequest],
410 Union[empty_pb2.Empty, Awaitable[empty_pb2.Empty]],
411 ]:
412 raise NotImplementedError()
413
414 @property
415 def list_views(
416 self,
417 ) -> Callable[
418 [logging_config.ListViewsRequest],
419 Union[
420 logging_config.ListViewsResponse,
421 Awaitable[logging_config.ListViewsResponse],
422 ],
423 ]:
424 raise NotImplementedError()
425
426 @property
427 def get_view(
428 self,
429 ) -> Callable[
430 [logging_config.GetViewRequest],
431 Union[logging_config.LogView, Awaitable[logging_config.LogView]],
432 ]:
433 raise NotImplementedError()
434
435 @property
436 def create_view(
437 self,
438 ) -> Callable[
439 [logging_config.CreateViewRequest],
440 Union[logging_config.LogView, Awaitable[logging_config.LogView]],
441 ]:
442 raise NotImplementedError()
443
444 @property
445 def update_view(
446 self,
447 ) -> Callable[
448 [logging_config.UpdateViewRequest],
449 Union[logging_config.LogView, Awaitable[logging_config.LogView]],
450 ]:
451 raise NotImplementedError()
452
453 @property
454 def delete_view(
455 self,
456 ) -> Callable[
457 [logging_config.DeleteViewRequest],
458 Union[empty_pb2.Empty, Awaitable[empty_pb2.Empty]],
459 ]:
460 raise NotImplementedError()
461
462 @property
463 def list_sinks(
464 self,
465 ) -> Callable[
466 [logging_config.ListSinksRequest],
467 Union[
468 logging_config.ListSinksResponse,
469 Awaitable[logging_config.ListSinksResponse],
470 ],
471 ]:
472 raise NotImplementedError()
473
474 @property
475 def get_sink(
476 self,
477 ) -> Callable[
478 [logging_config.GetSinkRequest],
479 Union[logging_config.LogSink, Awaitable[logging_config.LogSink]],
480 ]:
481 raise NotImplementedError()
482
483 @property
484 def create_sink(
485 self,
486 ) -> Callable[
487 [logging_config.CreateSinkRequest],
488 Union[logging_config.LogSink, Awaitable[logging_config.LogSink]],
489 ]:
490 raise NotImplementedError()
491
492 @property
493 def update_sink(
494 self,
495 ) -> Callable[
496 [logging_config.UpdateSinkRequest],
497 Union[logging_config.LogSink, Awaitable[logging_config.LogSink]],
498 ]:
499 raise NotImplementedError()
500
501 @property
502 def delete_sink(
503 self,
504 ) -> Callable[
505 [logging_config.DeleteSinkRequest],
506 Union[empty_pb2.Empty, Awaitable[empty_pb2.Empty]],
507 ]:
508 raise NotImplementedError()
509
510 @property
511 def list_exclusions(
512 self,
513 ) -> Callable[
514 [logging_config.ListExclusionsRequest],
515 Union[
516 logging_config.ListExclusionsResponse,
517 Awaitable[logging_config.ListExclusionsResponse],
518 ],
519 ]:
520 raise NotImplementedError()
521
522 @property
523 def get_exclusion(
524 self,
525 ) -> Callable[
526 [logging_config.GetExclusionRequest],
527 Union[logging_config.LogExclusion, Awaitable[logging_config.LogExclusion]],
528 ]:
529 raise NotImplementedError()
530
531 @property
532 def create_exclusion(
533 self,
534 ) -> Callable[
535 [logging_config.CreateExclusionRequest],
536 Union[logging_config.LogExclusion, Awaitable[logging_config.LogExclusion]],
537 ]:
538 raise NotImplementedError()
539
540 @property
541 def update_exclusion(
542 self,
543 ) -> Callable[
544 [logging_config.UpdateExclusionRequest],
545 Union[logging_config.LogExclusion, Awaitable[logging_config.LogExclusion]],
546 ]:
547 raise NotImplementedError()
548
549 @property
550 def delete_exclusion(
551 self,
552 ) -> Callable[
553 [logging_config.DeleteExclusionRequest],
554 Union[empty_pb2.Empty, Awaitable[empty_pb2.Empty]],
555 ]:
556 raise NotImplementedError()
557
558 @property
559 def get_cmek_settings(
560 self,
561 ) -> Callable[
562 [logging_config.GetCmekSettingsRequest],
563 Union[logging_config.CmekSettings, Awaitable[logging_config.CmekSettings]],
564 ]:
565 raise NotImplementedError()
566
567 @property
568 def update_cmek_settings(
569 self,
570 ) -> Callable[
571 [logging_config.UpdateCmekSettingsRequest],
572 Union[logging_config.CmekSettings, Awaitable[logging_config.CmekSettings]],
573 ]:
574 raise NotImplementedError()
575
576 @property
577 def get_settings(
578 self,
579 ) -> Callable[
580 [logging_config.GetSettingsRequest],
581 Union[logging_config.Settings, Awaitable[logging_config.Settings]],
582 ]:
583 raise NotImplementedError()
584
585 @property
586 def update_settings(
587 self,
588 ) -> Callable[
589 [logging_config.UpdateSettingsRequest],
590 Union[logging_config.Settings, Awaitable[logging_config.Settings]],
591 ]:
592 raise NotImplementedError()
593
594 @property
595 def copy_log_entries(
596 self,
597 ) -> Callable[
598 [logging_config.CopyLogEntriesRequest],
599 Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]],
600 ]:
601 raise NotImplementedError()
602
603 @property
604 def kind(self) -> str:
605 raise NotImplementedError()
606
607
608__all__ = ("ConfigServiceV2Transport",)