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#
16from collections import OrderedDict
17import functools
18import re
19from typing import (
20 Dict,
21 Mapping,
22 MutableMapping,
23 MutableSequence,
24 Optional,
25 Sequence,
26 Tuple,
27 Type,
28 Union,
29)
30
31from google.cloud.logging_v2 import gapic_version as package_version
32
33from google.api_core.client_options import ClientOptions
34from google.api_core import exceptions as core_exceptions
35from google.api_core import gapic_v1
36from google.api_core import retry as retries
37from google.auth import credentials as ga_credentials # type: ignore
38from google.oauth2 import service_account # type: ignore
39
40try:
41 OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault]
42except AttributeError: # pragma: NO COVER
43 OptionalRetry = Union[retries.Retry, object] # type: ignore
44
45from google.api_core import operation # type: ignore
46from google.api_core import operation_async # type: ignore
47from google.cloud.logging_v2.services.config_service_v2 import pagers
48from google.cloud.logging_v2.types import logging_config
49from google.protobuf import field_mask_pb2 # type: ignore
50from google.protobuf import timestamp_pb2 # type: ignore
51from .transports.base import ConfigServiceV2Transport, DEFAULT_CLIENT_INFO
52from .transports.grpc_asyncio import ConfigServiceV2GrpcAsyncIOTransport
53from .client import ConfigServiceV2Client
54
55
56class ConfigServiceV2AsyncClient:
57 """Service for configuring sinks used to route log entries."""
58
59 _client: ConfigServiceV2Client
60
61 DEFAULT_ENDPOINT = ConfigServiceV2Client.DEFAULT_ENDPOINT
62 DEFAULT_MTLS_ENDPOINT = ConfigServiceV2Client.DEFAULT_MTLS_ENDPOINT
63
64 cmek_settings_path = staticmethod(ConfigServiceV2Client.cmek_settings_path)
65 parse_cmek_settings_path = staticmethod(
66 ConfigServiceV2Client.parse_cmek_settings_path
67 )
68 log_bucket_path = staticmethod(ConfigServiceV2Client.log_bucket_path)
69 parse_log_bucket_path = staticmethod(ConfigServiceV2Client.parse_log_bucket_path)
70 log_exclusion_path = staticmethod(ConfigServiceV2Client.log_exclusion_path)
71 parse_log_exclusion_path = staticmethod(
72 ConfigServiceV2Client.parse_log_exclusion_path
73 )
74 log_sink_path = staticmethod(ConfigServiceV2Client.log_sink_path)
75 parse_log_sink_path = staticmethod(ConfigServiceV2Client.parse_log_sink_path)
76 log_view_path = staticmethod(ConfigServiceV2Client.log_view_path)
77 parse_log_view_path = staticmethod(ConfigServiceV2Client.parse_log_view_path)
78 settings_path = staticmethod(ConfigServiceV2Client.settings_path)
79 parse_settings_path = staticmethod(ConfigServiceV2Client.parse_settings_path)
80 common_billing_account_path = staticmethod(
81 ConfigServiceV2Client.common_billing_account_path
82 )
83 parse_common_billing_account_path = staticmethod(
84 ConfigServiceV2Client.parse_common_billing_account_path
85 )
86 common_folder_path = staticmethod(ConfigServiceV2Client.common_folder_path)
87 parse_common_folder_path = staticmethod(
88 ConfigServiceV2Client.parse_common_folder_path
89 )
90 common_organization_path = staticmethod(
91 ConfigServiceV2Client.common_organization_path
92 )
93 parse_common_organization_path = staticmethod(
94 ConfigServiceV2Client.parse_common_organization_path
95 )
96 common_project_path = staticmethod(ConfigServiceV2Client.common_project_path)
97 parse_common_project_path = staticmethod(
98 ConfigServiceV2Client.parse_common_project_path
99 )
100 common_location_path = staticmethod(ConfigServiceV2Client.common_location_path)
101 parse_common_location_path = staticmethod(
102 ConfigServiceV2Client.parse_common_location_path
103 )
104
105 @classmethod
106 def from_service_account_info(cls, info: dict, *args, **kwargs):
107 """Creates an instance of this client using the provided credentials
108 info.
109
110 Args:
111 info (dict): The service account private key info.
112 args: Additional arguments to pass to the constructor.
113 kwargs: Additional arguments to pass to the constructor.
114
115 Returns:
116 ConfigServiceV2AsyncClient: The constructed client.
117 """
118 return ConfigServiceV2Client.from_service_account_info.__func__(ConfigServiceV2AsyncClient, info, *args, **kwargs) # type: ignore
119
120 @classmethod
121 def from_service_account_file(cls, filename: str, *args, **kwargs):
122 """Creates an instance of this client using the provided credentials
123 file.
124
125 Args:
126 filename (str): The path to the service account private key json
127 file.
128 args: Additional arguments to pass to the constructor.
129 kwargs: Additional arguments to pass to the constructor.
130
131 Returns:
132 ConfigServiceV2AsyncClient: The constructed client.
133 """
134 return ConfigServiceV2Client.from_service_account_file.__func__(ConfigServiceV2AsyncClient, filename, *args, **kwargs) # type: ignore
135
136 from_service_account_json = from_service_account_file
137
138 @classmethod
139 def get_mtls_endpoint_and_cert_source(
140 cls, client_options: Optional[ClientOptions] = None
141 ):
142 """Return the API endpoint and client cert source for mutual TLS.
143
144 The client cert source is determined in the following order:
145 (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the
146 client cert source is None.
147 (2) if `client_options.client_cert_source` is provided, use the provided one; if the
148 default client cert source exists, use the default one; otherwise the client cert
149 source is None.
150
151 The API endpoint is determined in the following order:
152 (1) if `client_options.api_endpoint` if provided, use the provided one.
153 (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the
154 default mTLS endpoint; if the environment variable is "never", use the default API
155 endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise
156 use the default API endpoint.
157
158 More details can be found at https://google.aip.dev/auth/4114.
159
160 Args:
161 client_options (google.api_core.client_options.ClientOptions): Custom options for the
162 client. Only the `api_endpoint` and `client_cert_source` properties may be used
163 in this method.
164
165 Returns:
166 Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the
167 client cert source to use.
168
169 Raises:
170 google.auth.exceptions.MutualTLSChannelError: If any errors happen.
171 """
172 return ConfigServiceV2Client.get_mtls_endpoint_and_cert_source(client_options) # type: ignore
173
174 @property
175 def transport(self) -> ConfigServiceV2Transport:
176 """Returns the transport used by the client instance.
177
178 Returns:
179 ConfigServiceV2Transport: The transport used by the client instance.
180 """
181 return self._client.transport
182
183 get_transport_class = functools.partial(
184 type(ConfigServiceV2Client).get_transport_class, type(ConfigServiceV2Client)
185 )
186
187 def __init__(
188 self,
189 *,
190 credentials: Optional[ga_credentials.Credentials] = None,
191 transport: Union[str, ConfigServiceV2Transport] = "grpc_asyncio",
192 client_options: Optional[ClientOptions] = None,
193 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
194 ) -> None:
195 """Instantiates the config service v2 client.
196
197 Args:
198 credentials (Optional[google.auth.credentials.Credentials]): The
199 authorization credentials to attach to requests. These
200 credentials identify the application to the service; if none
201 are specified, the client will attempt to ascertain the
202 credentials from the environment.
203 transport (Union[str, ~.ConfigServiceV2Transport]): The
204 transport to use. If set to None, a transport is chosen
205 automatically.
206 client_options (ClientOptions): Custom options for the client. It
207 won't take effect if a ``transport`` instance is provided.
208 (1) The ``api_endpoint`` property can be used to override the
209 default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT
210 environment variable can also be used to override the endpoint:
211 "always" (always use the default mTLS endpoint), "never" (always
212 use the default regular endpoint) and "auto" (auto switch to the
213 default mTLS endpoint if client certificate is present, this is
214 the default value). However, the ``api_endpoint`` property takes
215 precedence if provided.
216 (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable
217 is "true", then the ``client_cert_source`` property can be used
218 to provide client certificate for mutual TLS transport. If
219 not provided, the default SSL client certificate will be used if
220 present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not
221 set, no client certificate will be used.
222
223 Raises:
224 google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
225 creation failed for any reason.
226 """
227 self._client = ConfigServiceV2Client(
228 credentials=credentials,
229 transport=transport,
230 client_options=client_options,
231 client_info=client_info,
232 )
233
234 async def list_buckets(
235 self,
236 request: Optional[Union[logging_config.ListBucketsRequest, dict]] = None,
237 *,
238 parent: Optional[str] = None,
239 retry: OptionalRetry = gapic_v1.method.DEFAULT,
240 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
241 metadata: Sequence[Tuple[str, str]] = (),
242 ) -> pagers.ListBucketsAsyncPager:
243 r"""Lists log buckets.
244
245 .. code-block:: python
246
247 # This snippet has been automatically generated and should be regarded as a
248 # code template only.
249 # It will require modifications to work:
250 # - It may require correct/in-range values for request initialization.
251 # - It may require specifying regional endpoints when creating the service
252 # client as shown in:
253 # https://googleapis.dev/python/google-api-core/latest/client_options.html
254 from google.cloud import logging_v2
255
256 async def sample_list_buckets():
257 # Create a client
258 client = logging_v2.ConfigServiceV2AsyncClient()
259
260 # Initialize request argument(s)
261 request = logging_v2.ListBucketsRequest(
262 parent="parent_value",
263 )
264
265 # Make the request
266 page_result = client.list_buckets(request=request)
267
268 # Handle the response
269 async for response in page_result:
270 print(response)
271
272 Args:
273 request (Optional[Union[google.cloud.logging_v2.types.ListBucketsRequest, dict]]):
274 The request object. The parameters to ``ListBuckets``.
275 parent (:class:`str`):
276 Required. The parent resource whose buckets are to be
277 listed:
278
279 ::
280
281 "projects/[PROJECT_ID]/locations/[LOCATION_ID]"
282 "organizations/[ORGANIZATION_ID]/locations/[LOCATION_ID]"
283 "billingAccounts/[BILLING_ACCOUNT_ID]/locations/[LOCATION_ID]"
284 "folders/[FOLDER_ID]/locations/[LOCATION_ID]"
285
286 Note: The locations portion of the resource must be
287 specified, but supplying the character ``-`` in place of
288 [LOCATION_ID] will return all buckets.
289
290 This corresponds to the ``parent`` field
291 on the ``request`` instance; if ``request`` is provided, this
292 should not be set.
293 retry (google.api_core.retry.Retry): Designation of what errors, if any,
294 should be retried.
295 timeout (float): The timeout for this request.
296 metadata (Sequence[Tuple[str, str]]): Strings which should be
297 sent along with the request as metadata.
298
299 Returns:
300 google.cloud.logging_v2.services.config_service_v2.pagers.ListBucketsAsyncPager:
301 The response from ListBuckets.
302 Iterating over this object will yield
303 results and resolve additional pages
304 automatically.
305
306 """
307 # Create or coerce a protobuf request object.
308 # Quick check: If we got a request object, we should *not* have
309 # gotten any keyword arguments that map to the request.
310 has_flattened_params = any([parent])
311 if request is not None and has_flattened_params:
312 raise ValueError(
313 "If the `request` argument is set, then none of "
314 "the individual field arguments should be set."
315 )
316
317 request = logging_config.ListBucketsRequest(request)
318
319 # If we have keyword arguments corresponding to fields on the
320 # request, apply these.
321 if parent is not None:
322 request.parent = parent
323
324 # Wrap the RPC method; this adds retry and timeout information,
325 # and friendly error handling.
326 rpc = gapic_v1.method_async.wrap_method(
327 self._client._transport.list_buckets,
328 default_timeout=None,
329 client_info=DEFAULT_CLIENT_INFO,
330 )
331
332 # Certain fields should be provided within the metadata header;
333 # add these here.
334 metadata = tuple(metadata) + (
335 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
336 )
337
338 # Send the request.
339 response = await rpc(
340 request,
341 retry=retry,
342 timeout=timeout,
343 metadata=metadata,
344 )
345
346 # This method is paged; wrap the response in a pager, which provides
347 # an `__aiter__` convenience method.
348 response = pagers.ListBucketsAsyncPager(
349 method=rpc,
350 request=request,
351 response=response,
352 metadata=metadata,
353 )
354
355 # Done; return the response.
356 return response
357
358 async def get_bucket(
359 self,
360 request: Optional[Union[logging_config.GetBucketRequest, dict]] = None,
361 *,
362 retry: OptionalRetry = gapic_v1.method.DEFAULT,
363 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
364 metadata: Sequence[Tuple[str, str]] = (),
365 ) -> logging_config.LogBucket:
366 r"""Gets a log bucket.
367
368 .. code-block:: python
369
370 # This snippet has been automatically generated and should be regarded as a
371 # code template only.
372 # It will require modifications to work:
373 # - It may require correct/in-range values for request initialization.
374 # - It may require specifying regional endpoints when creating the service
375 # client as shown in:
376 # https://googleapis.dev/python/google-api-core/latest/client_options.html
377 from google.cloud import logging_v2
378
379 async def sample_get_bucket():
380 # Create a client
381 client = logging_v2.ConfigServiceV2AsyncClient()
382
383 # Initialize request argument(s)
384 request = logging_v2.GetBucketRequest(
385 name="name_value",
386 )
387
388 # Make the request
389 response = await client.get_bucket(request=request)
390
391 # Handle the response
392 print(response)
393
394 Args:
395 request (Optional[Union[google.cloud.logging_v2.types.GetBucketRequest, dict]]):
396 The request object. The parameters to ``GetBucket``.
397 retry (google.api_core.retry.Retry): Designation of what errors, if any,
398 should be retried.
399 timeout (float): The timeout for this request.
400 metadata (Sequence[Tuple[str, str]]): Strings which should be
401 sent along with the request as metadata.
402
403 Returns:
404 google.cloud.logging_v2.types.LogBucket:
405 Describes a repository in which log
406 entries are stored.
407
408 """
409 # Create or coerce a protobuf request object.
410 request = logging_config.GetBucketRequest(request)
411
412 # Wrap the RPC method; this adds retry and timeout information,
413 # and friendly error handling.
414 rpc = gapic_v1.method_async.wrap_method(
415 self._client._transport.get_bucket,
416 default_timeout=None,
417 client_info=DEFAULT_CLIENT_INFO,
418 )
419
420 # Certain fields should be provided within the metadata header;
421 # add these here.
422 metadata = tuple(metadata) + (
423 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
424 )
425
426 # Send the request.
427 response = await rpc(
428 request,
429 retry=retry,
430 timeout=timeout,
431 metadata=metadata,
432 )
433
434 # Done; return the response.
435 return response
436
437 async def create_bucket(
438 self,
439 request: Optional[Union[logging_config.CreateBucketRequest, dict]] = None,
440 *,
441 retry: OptionalRetry = gapic_v1.method.DEFAULT,
442 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
443 metadata: Sequence[Tuple[str, str]] = (),
444 ) -> logging_config.LogBucket:
445 r"""Creates a log bucket that can be used to store log
446 entries. After a bucket has been created, the bucket's
447 location cannot be changed.
448
449 .. code-block:: python
450
451 # This snippet has been automatically generated and should be regarded as a
452 # code template only.
453 # It will require modifications to work:
454 # - It may require correct/in-range values for request initialization.
455 # - It may require specifying regional endpoints when creating the service
456 # client as shown in:
457 # https://googleapis.dev/python/google-api-core/latest/client_options.html
458 from google.cloud import logging_v2
459
460 async def sample_create_bucket():
461 # Create a client
462 client = logging_v2.ConfigServiceV2AsyncClient()
463
464 # Initialize request argument(s)
465 request = logging_v2.CreateBucketRequest(
466 parent="parent_value",
467 bucket_id="bucket_id_value",
468 )
469
470 # Make the request
471 response = await client.create_bucket(request=request)
472
473 # Handle the response
474 print(response)
475
476 Args:
477 request (Optional[Union[google.cloud.logging_v2.types.CreateBucketRequest, dict]]):
478 The request object. The parameters to ``CreateBucket``.
479 retry (google.api_core.retry.Retry): Designation of what errors, if any,
480 should be retried.
481 timeout (float): The timeout for this request.
482 metadata (Sequence[Tuple[str, str]]): Strings which should be
483 sent along with the request as metadata.
484
485 Returns:
486 google.cloud.logging_v2.types.LogBucket:
487 Describes a repository in which log
488 entries are stored.
489
490 """
491 # Create or coerce a protobuf request object.
492 request = logging_config.CreateBucketRequest(request)
493
494 # Wrap the RPC method; this adds retry and timeout information,
495 # and friendly error handling.
496 rpc = gapic_v1.method_async.wrap_method(
497 self._client._transport.create_bucket,
498 default_timeout=None,
499 client_info=DEFAULT_CLIENT_INFO,
500 )
501
502 # Certain fields should be provided within the metadata header;
503 # add these here.
504 metadata = tuple(metadata) + (
505 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
506 )
507
508 # Send the request.
509 response = await rpc(
510 request,
511 retry=retry,
512 timeout=timeout,
513 metadata=metadata,
514 )
515
516 # Done; return the response.
517 return response
518
519 async def update_bucket(
520 self,
521 request: Optional[Union[logging_config.UpdateBucketRequest, dict]] = None,
522 *,
523 retry: OptionalRetry = gapic_v1.method.DEFAULT,
524 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
525 metadata: Sequence[Tuple[str, str]] = (),
526 ) -> logging_config.LogBucket:
527 r"""Updates a log bucket. This method replaces the following fields
528 in the existing bucket with values from the new bucket:
529 ``retention_period``
530
531 If the retention period is decreased and the bucket is locked,
532 ``FAILED_PRECONDITION`` will be returned.
533
534 If the bucket has a ``lifecycle_state`` of ``DELETE_REQUESTED``,
535 then ``FAILED_PRECONDITION`` will be returned.
536
537 After a bucket has been created, the bucket's location cannot be
538 changed.
539
540 .. code-block:: python
541
542 # This snippet has been automatically generated and should be regarded as a
543 # code template only.
544 # It will require modifications to work:
545 # - It may require correct/in-range values for request initialization.
546 # - It may require specifying regional endpoints when creating the service
547 # client as shown in:
548 # https://googleapis.dev/python/google-api-core/latest/client_options.html
549 from google.cloud import logging_v2
550
551 async def sample_update_bucket():
552 # Create a client
553 client = logging_v2.ConfigServiceV2AsyncClient()
554
555 # Initialize request argument(s)
556 request = logging_v2.UpdateBucketRequest(
557 name="name_value",
558 )
559
560 # Make the request
561 response = await client.update_bucket(request=request)
562
563 # Handle the response
564 print(response)
565
566 Args:
567 request (Optional[Union[google.cloud.logging_v2.types.UpdateBucketRequest, dict]]):
568 The request object. The parameters to ``UpdateBucket``.
569 retry (google.api_core.retry.Retry): Designation of what errors, if any,
570 should be retried.
571 timeout (float): The timeout for this request.
572 metadata (Sequence[Tuple[str, str]]): Strings which should be
573 sent along with the request as metadata.
574
575 Returns:
576 google.cloud.logging_v2.types.LogBucket:
577 Describes a repository in which log
578 entries are stored.
579
580 """
581 # Create or coerce a protobuf request object.
582 request = logging_config.UpdateBucketRequest(request)
583
584 # Wrap the RPC method; this adds retry and timeout information,
585 # and friendly error handling.
586 rpc = gapic_v1.method_async.wrap_method(
587 self._client._transport.update_bucket,
588 default_timeout=None,
589 client_info=DEFAULT_CLIENT_INFO,
590 )
591
592 # Certain fields should be provided within the metadata header;
593 # add these here.
594 metadata = tuple(metadata) + (
595 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
596 )
597
598 # Send the request.
599 response = await rpc(
600 request,
601 retry=retry,
602 timeout=timeout,
603 metadata=metadata,
604 )
605
606 # Done; return the response.
607 return response
608
609 async def delete_bucket(
610 self,
611 request: Optional[Union[logging_config.DeleteBucketRequest, dict]] = None,
612 *,
613 retry: OptionalRetry = gapic_v1.method.DEFAULT,
614 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
615 metadata: Sequence[Tuple[str, str]] = (),
616 ) -> None:
617 r"""Deletes a log bucket.
618
619 Changes the bucket's ``lifecycle_state`` to the
620 ``DELETE_REQUESTED`` state. After 7 days, the bucket will be
621 purged and all log entries in the bucket will be permanently
622 deleted.
623
624 .. code-block:: python
625
626 # This snippet has been automatically generated and should be regarded as a
627 # code template only.
628 # It will require modifications to work:
629 # - It may require correct/in-range values for request initialization.
630 # - It may require specifying regional endpoints when creating the service
631 # client as shown in:
632 # https://googleapis.dev/python/google-api-core/latest/client_options.html
633 from google.cloud import logging_v2
634
635 async def sample_delete_bucket():
636 # Create a client
637 client = logging_v2.ConfigServiceV2AsyncClient()
638
639 # Initialize request argument(s)
640 request = logging_v2.DeleteBucketRequest(
641 name="name_value",
642 )
643
644 # Make the request
645 await client.delete_bucket(request=request)
646
647 Args:
648 request (Optional[Union[google.cloud.logging_v2.types.DeleteBucketRequest, dict]]):
649 The request object. The parameters to ``DeleteBucket``.
650 retry (google.api_core.retry.Retry): Designation of what errors, if any,
651 should be retried.
652 timeout (float): The timeout for this request.
653 metadata (Sequence[Tuple[str, str]]): Strings which should be
654 sent along with the request as metadata.
655 """
656 # Create or coerce a protobuf request object.
657 request = logging_config.DeleteBucketRequest(request)
658
659 # Wrap the RPC method; this adds retry and timeout information,
660 # and friendly error handling.
661 rpc = gapic_v1.method_async.wrap_method(
662 self._client._transport.delete_bucket,
663 default_timeout=None,
664 client_info=DEFAULT_CLIENT_INFO,
665 )
666
667 # Certain fields should be provided within the metadata header;
668 # add these here.
669 metadata = tuple(metadata) + (
670 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
671 )
672
673 # Send the request.
674 await rpc(
675 request,
676 retry=retry,
677 timeout=timeout,
678 metadata=metadata,
679 )
680
681 async def undelete_bucket(
682 self,
683 request: Optional[Union[logging_config.UndeleteBucketRequest, dict]] = None,
684 *,
685 retry: OptionalRetry = gapic_v1.method.DEFAULT,
686 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
687 metadata: Sequence[Tuple[str, str]] = (),
688 ) -> None:
689 r"""Undeletes a log bucket. A bucket that has been
690 deleted can be undeleted within the grace period of 7
691 days.
692
693 .. code-block:: python
694
695 # This snippet has been automatically generated and should be regarded as a
696 # code template only.
697 # It will require modifications to work:
698 # - It may require correct/in-range values for request initialization.
699 # - It may require specifying regional endpoints when creating the service
700 # client as shown in:
701 # https://googleapis.dev/python/google-api-core/latest/client_options.html
702 from google.cloud import logging_v2
703
704 async def sample_undelete_bucket():
705 # Create a client
706 client = logging_v2.ConfigServiceV2AsyncClient()
707
708 # Initialize request argument(s)
709 request = logging_v2.UndeleteBucketRequest(
710 name="name_value",
711 )
712
713 # Make the request
714 await client.undelete_bucket(request=request)
715
716 Args:
717 request (Optional[Union[google.cloud.logging_v2.types.UndeleteBucketRequest, dict]]):
718 The request object. The parameters to ``UndeleteBucket``.
719 retry (google.api_core.retry.Retry): Designation of what errors, if any,
720 should be retried.
721 timeout (float): The timeout for this request.
722 metadata (Sequence[Tuple[str, str]]): Strings which should be
723 sent along with the request as metadata.
724 """
725 # Create or coerce a protobuf request object.
726 request = logging_config.UndeleteBucketRequest(request)
727
728 # Wrap the RPC method; this adds retry and timeout information,
729 # and friendly error handling.
730 rpc = gapic_v1.method_async.wrap_method(
731 self._client._transport.undelete_bucket,
732 default_timeout=None,
733 client_info=DEFAULT_CLIENT_INFO,
734 )
735
736 # Certain fields should be provided within the metadata header;
737 # add these here.
738 metadata = tuple(metadata) + (
739 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
740 )
741
742 # Send the request.
743 await rpc(
744 request,
745 retry=retry,
746 timeout=timeout,
747 metadata=metadata,
748 )
749
750 async def list_views(
751 self,
752 request: Optional[Union[logging_config.ListViewsRequest, dict]] = None,
753 *,
754 parent: Optional[str] = None,
755 retry: OptionalRetry = gapic_v1.method.DEFAULT,
756 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
757 metadata: Sequence[Tuple[str, str]] = (),
758 ) -> pagers.ListViewsAsyncPager:
759 r"""Lists views on a log bucket.
760
761 .. code-block:: python
762
763 # This snippet has been automatically generated and should be regarded as a
764 # code template only.
765 # It will require modifications to work:
766 # - It may require correct/in-range values for request initialization.
767 # - It may require specifying regional endpoints when creating the service
768 # client as shown in:
769 # https://googleapis.dev/python/google-api-core/latest/client_options.html
770 from google.cloud import logging_v2
771
772 async def sample_list_views():
773 # Create a client
774 client = logging_v2.ConfigServiceV2AsyncClient()
775
776 # Initialize request argument(s)
777 request = logging_v2.ListViewsRequest(
778 parent="parent_value",
779 )
780
781 # Make the request
782 page_result = client.list_views(request=request)
783
784 # Handle the response
785 async for response in page_result:
786 print(response)
787
788 Args:
789 request (Optional[Union[google.cloud.logging_v2.types.ListViewsRequest, dict]]):
790 The request object. The parameters to ``ListViews``.
791 parent (:class:`str`):
792 Required. The bucket whose views are to be listed:
793
794 ::
795
796 "projects/[PROJECT_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]"
797
798 This corresponds to the ``parent`` field
799 on the ``request`` instance; if ``request`` is provided, this
800 should not be set.
801 retry (google.api_core.retry.Retry): Designation of what errors, if any,
802 should be retried.
803 timeout (float): The timeout for this request.
804 metadata (Sequence[Tuple[str, str]]): Strings which should be
805 sent along with the request as metadata.
806
807 Returns:
808 google.cloud.logging_v2.services.config_service_v2.pagers.ListViewsAsyncPager:
809 The response from ListViews.
810 Iterating over this object will yield
811 results and resolve additional pages
812 automatically.
813
814 """
815 # Create or coerce a protobuf request object.
816 # Quick check: If we got a request object, we should *not* have
817 # gotten any keyword arguments that map to the request.
818 has_flattened_params = any([parent])
819 if request is not None and has_flattened_params:
820 raise ValueError(
821 "If the `request` argument is set, then none of "
822 "the individual field arguments should be set."
823 )
824
825 request = logging_config.ListViewsRequest(request)
826
827 # If we have keyword arguments corresponding to fields on the
828 # request, apply these.
829 if parent is not None:
830 request.parent = parent
831
832 # Wrap the RPC method; this adds retry and timeout information,
833 # and friendly error handling.
834 rpc = gapic_v1.method_async.wrap_method(
835 self._client._transport.list_views,
836 default_timeout=None,
837 client_info=DEFAULT_CLIENT_INFO,
838 )
839
840 # Certain fields should be provided within the metadata header;
841 # add these here.
842 metadata = tuple(metadata) + (
843 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
844 )
845
846 # Send the request.
847 response = await rpc(
848 request,
849 retry=retry,
850 timeout=timeout,
851 metadata=metadata,
852 )
853
854 # This method is paged; wrap the response in a pager, which provides
855 # an `__aiter__` convenience method.
856 response = pagers.ListViewsAsyncPager(
857 method=rpc,
858 request=request,
859 response=response,
860 metadata=metadata,
861 )
862
863 # Done; return the response.
864 return response
865
866 async def get_view(
867 self,
868 request: Optional[Union[logging_config.GetViewRequest, dict]] = None,
869 *,
870 retry: OptionalRetry = gapic_v1.method.DEFAULT,
871 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
872 metadata: Sequence[Tuple[str, str]] = (),
873 ) -> logging_config.LogView:
874 r"""Gets a view on a log bucket..
875
876 .. code-block:: python
877
878 # This snippet has been automatically generated and should be regarded as a
879 # code template only.
880 # It will require modifications to work:
881 # - It may require correct/in-range values for request initialization.
882 # - It may require specifying regional endpoints when creating the service
883 # client as shown in:
884 # https://googleapis.dev/python/google-api-core/latest/client_options.html
885 from google.cloud import logging_v2
886
887 async def sample_get_view():
888 # Create a client
889 client = logging_v2.ConfigServiceV2AsyncClient()
890
891 # Initialize request argument(s)
892 request = logging_v2.GetViewRequest(
893 name="name_value",
894 )
895
896 # Make the request
897 response = await client.get_view(request=request)
898
899 # Handle the response
900 print(response)
901
902 Args:
903 request (Optional[Union[google.cloud.logging_v2.types.GetViewRequest, dict]]):
904 The request object. The parameters to ``GetView``.
905 retry (google.api_core.retry.Retry): Designation of what errors, if any,
906 should be retried.
907 timeout (float): The timeout for this request.
908 metadata (Sequence[Tuple[str, str]]): Strings which should be
909 sent along with the request as metadata.
910
911 Returns:
912 google.cloud.logging_v2.types.LogView:
913 Describes a view over log entries in
914 a bucket.
915
916 """
917 # Create or coerce a protobuf request object.
918 request = logging_config.GetViewRequest(request)
919
920 # Wrap the RPC method; this adds retry and timeout information,
921 # and friendly error handling.
922 rpc = gapic_v1.method_async.wrap_method(
923 self._client._transport.get_view,
924 default_timeout=None,
925 client_info=DEFAULT_CLIENT_INFO,
926 )
927
928 # Certain fields should be provided within the metadata header;
929 # add these here.
930 metadata = tuple(metadata) + (
931 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
932 )
933
934 # Send the request.
935 response = await rpc(
936 request,
937 retry=retry,
938 timeout=timeout,
939 metadata=metadata,
940 )
941
942 # Done; return the response.
943 return response
944
945 async def create_view(
946 self,
947 request: Optional[Union[logging_config.CreateViewRequest, dict]] = None,
948 *,
949 retry: OptionalRetry = gapic_v1.method.DEFAULT,
950 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
951 metadata: Sequence[Tuple[str, str]] = (),
952 ) -> logging_config.LogView:
953 r"""Creates a view over log entries in a log bucket. A
954 bucket may contain a maximum of 30 views.
955
956 .. code-block:: python
957
958 # This snippet has been automatically generated and should be regarded as a
959 # code template only.
960 # It will require modifications to work:
961 # - It may require correct/in-range values for request initialization.
962 # - It may require specifying regional endpoints when creating the service
963 # client as shown in:
964 # https://googleapis.dev/python/google-api-core/latest/client_options.html
965 from google.cloud import logging_v2
966
967 async def sample_create_view():
968 # Create a client
969 client = logging_v2.ConfigServiceV2AsyncClient()
970
971 # Initialize request argument(s)
972 request = logging_v2.CreateViewRequest(
973 parent="parent_value",
974 view_id="view_id_value",
975 )
976
977 # Make the request
978 response = await client.create_view(request=request)
979
980 # Handle the response
981 print(response)
982
983 Args:
984 request (Optional[Union[google.cloud.logging_v2.types.CreateViewRequest, dict]]):
985 The request object. The parameters to ``CreateView``.
986 retry (google.api_core.retry.Retry): Designation of what errors, if any,
987 should be retried.
988 timeout (float): The timeout for this request.
989 metadata (Sequence[Tuple[str, str]]): Strings which should be
990 sent along with the request as metadata.
991
992 Returns:
993 google.cloud.logging_v2.types.LogView:
994 Describes a view over log entries in
995 a bucket.
996
997 """
998 # Create or coerce a protobuf request object.
999 request = logging_config.CreateViewRequest(request)
1000
1001 # Wrap the RPC method; this adds retry and timeout information,
1002 # and friendly error handling.
1003 rpc = gapic_v1.method_async.wrap_method(
1004 self._client._transport.create_view,
1005 default_timeout=None,
1006 client_info=DEFAULT_CLIENT_INFO,
1007 )
1008
1009 # Certain fields should be provided within the metadata header;
1010 # add these here.
1011 metadata = tuple(metadata) + (
1012 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
1013 )
1014
1015 # Send the request.
1016 response = await rpc(
1017 request,
1018 retry=retry,
1019 timeout=timeout,
1020 metadata=metadata,
1021 )
1022
1023 # Done; return the response.
1024 return response
1025
1026 async def update_view(
1027 self,
1028 request: Optional[Union[logging_config.UpdateViewRequest, dict]] = None,
1029 *,
1030 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1031 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1032 metadata: Sequence[Tuple[str, str]] = (),
1033 ) -> logging_config.LogView:
1034 r"""Updates a view on a log bucket. This method replaces the
1035 following fields in the existing view with values from the new
1036 view: ``filter``. If an ``UNAVAILABLE`` error is returned, this
1037 indicates that system is not in a state where it can update the
1038 view. If this occurs, please try again in a few minutes.
1039
1040 .. code-block:: python
1041
1042 # This snippet has been automatically generated and should be regarded as a
1043 # code template only.
1044 # It will require modifications to work:
1045 # - It may require correct/in-range values for request initialization.
1046 # - It may require specifying regional endpoints when creating the service
1047 # client as shown in:
1048 # https://googleapis.dev/python/google-api-core/latest/client_options.html
1049 from google.cloud import logging_v2
1050
1051 async def sample_update_view():
1052 # Create a client
1053 client = logging_v2.ConfigServiceV2AsyncClient()
1054
1055 # Initialize request argument(s)
1056 request = logging_v2.UpdateViewRequest(
1057 name="name_value",
1058 )
1059
1060 # Make the request
1061 response = await client.update_view(request=request)
1062
1063 # Handle the response
1064 print(response)
1065
1066 Args:
1067 request (Optional[Union[google.cloud.logging_v2.types.UpdateViewRequest, dict]]):
1068 The request object. The parameters to ``UpdateView``.
1069 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1070 should be retried.
1071 timeout (float): The timeout for this request.
1072 metadata (Sequence[Tuple[str, str]]): Strings which should be
1073 sent along with the request as metadata.
1074
1075 Returns:
1076 google.cloud.logging_v2.types.LogView:
1077 Describes a view over log entries in
1078 a bucket.
1079
1080 """
1081 # Create or coerce a protobuf request object.
1082 request = logging_config.UpdateViewRequest(request)
1083
1084 # Wrap the RPC method; this adds retry and timeout information,
1085 # and friendly error handling.
1086 rpc = gapic_v1.method_async.wrap_method(
1087 self._client._transport.update_view,
1088 default_timeout=None,
1089 client_info=DEFAULT_CLIENT_INFO,
1090 )
1091
1092 # Certain fields should be provided within the metadata header;
1093 # add these here.
1094 metadata = tuple(metadata) + (
1095 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1096 )
1097
1098 # Send the request.
1099 response = await rpc(
1100 request,
1101 retry=retry,
1102 timeout=timeout,
1103 metadata=metadata,
1104 )
1105
1106 # Done; return the response.
1107 return response
1108
1109 async def delete_view(
1110 self,
1111 request: Optional[Union[logging_config.DeleteViewRequest, dict]] = None,
1112 *,
1113 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1114 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1115 metadata: Sequence[Tuple[str, str]] = (),
1116 ) -> None:
1117 r"""Deletes a view on a log bucket. If an ``UNAVAILABLE`` error is
1118 returned, this indicates that system is not in a state where it
1119 can delete the view. If this occurs, please try again in a few
1120 minutes.
1121
1122 .. code-block:: python
1123
1124 # This snippet has been automatically generated and should be regarded as a
1125 # code template only.
1126 # It will require modifications to work:
1127 # - It may require correct/in-range values for request initialization.
1128 # - It may require specifying regional endpoints when creating the service
1129 # client as shown in:
1130 # https://googleapis.dev/python/google-api-core/latest/client_options.html
1131 from google.cloud import logging_v2
1132
1133 async def sample_delete_view():
1134 # Create a client
1135 client = logging_v2.ConfigServiceV2AsyncClient()
1136
1137 # Initialize request argument(s)
1138 request = logging_v2.DeleteViewRequest(
1139 name="name_value",
1140 )
1141
1142 # Make the request
1143 await client.delete_view(request=request)
1144
1145 Args:
1146 request (Optional[Union[google.cloud.logging_v2.types.DeleteViewRequest, dict]]):
1147 The request object. The parameters to ``DeleteView``.
1148 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1149 should be retried.
1150 timeout (float): The timeout for this request.
1151 metadata (Sequence[Tuple[str, str]]): Strings which should be
1152 sent along with the request as metadata.
1153 """
1154 # Create or coerce a protobuf request object.
1155 request = logging_config.DeleteViewRequest(request)
1156
1157 # Wrap the RPC method; this adds retry and timeout information,
1158 # and friendly error handling.
1159 rpc = gapic_v1.method_async.wrap_method(
1160 self._client._transport.delete_view,
1161 default_timeout=None,
1162 client_info=DEFAULT_CLIENT_INFO,
1163 )
1164
1165 # Certain fields should be provided within the metadata header;
1166 # add these here.
1167 metadata = tuple(metadata) + (
1168 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1169 )
1170
1171 # Send the request.
1172 await rpc(
1173 request,
1174 retry=retry,
1175 timeout=timeout,
1176 metadata=metadata,
1177 )
1178
1179 async def list_sinks(
1180 self,
1181 request: Optional[Union[logging_config.ListSinksRequest, dict]] = None,
1182 *,
1183 parent: Optional[str] = None,
1184 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1185 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1186 metadata: Sequence[Tuple[str, str]] = (),
1187 ) -> pagers.ListSinksAsyncPager:
1188 r"""Lists sinks.
1189
1190 .. code-block:: python
1191
1192 # This snippet has been automatically generated and should be regarded as a
1193 # code template only.
1194 # It will require modifications to work:
1195 # - It may require correct/in-range values for request initialization.
1196 # - It may require specifying regional endpoints when creating the service
1197 # client as shown in:
1198 # https://googleapis.dev/python/google-api-core/latest/client_options.html
1199 from google.cloud import logging_v2
1200
1201 async def sample_list_sinks():
1202 # Create a client
1203 client = logging_v2.ConfigServiceV2AsyncClient()
1204
1205 # Initialize request argument(s)
1206 request = logging_v2.ListSinksRequest(
1207 parent="parent_value",
1208 )
1209
1210 # Make the request
1211 page_result = client.list_sinks(request=request)
1212
1213 # Handle the response
1214 async for response in page_result:
1215 print(response)
1216
1217 Args:
1218 request (Optional[Union[google.cloud.logging_v2.types.ListSinksRequest, dict]]):
1219 The request object. The parameters to ``ListSinks``.
1220 parent (:class:`str`):
1221 Required. The parent resource whose sinks are to be
1222 listed:
1223
1224 ::
1225
1226 "projects/[PROJECT_ID]"
1227 "organizations/[ORGANIZATION_ID]"
1228 "billingAccounts/[BILLING_ACCOUNT_ID]"
1229 "folders/[FOLDER_ID]"
1230
1231 This corresponds to the ``parent`` field
1232 on the ``request`` instance; if ``request`` is provided, this
1233 should not be set.
1234 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1235 should be retried.
1236 timeout (float): The timeout for this request.
1237 metadata (Sequence[Tuple[str, str]]): Strings which should be
1238 sent along with the request as metadata.
1239
1240 Returns:
1241 google.cloud.logging_v2.services.config_service_v2.pagers.ListSinksAsyncPager:
1242 Result returned from ListSinks.
1243
1244 Iterating over this object will yield results and
1245 resolve additional pages automatically.
1246
1247 """
1248 # Create or coerce a protobuf request object.
1249 # Quick check: If we got a request object, we should *not* have
1250 # gotten any keyword arguments that map to the request.
1251 has_flattened_params = any([parent])
1252 if request is not None and has_flattened_params:
1253 raise ValueError(
1254 "If the `request` argument is set, then none of "
1255 "the individual field arguments should be set."
1256 )
1257
1258 request = logging_config.ListSinksRequest(request)
1259
1260 # If we have keyword arguments corresponding to fields on the
1261 # request, apply these.
1262 if parent is not None:
1263 request.parent = parent
1264
1265 # Wrap the RPC method; this adds retry and timeout information,
1266 # and friendly error handling.
1267 rpc = gapic_v1.method_async.wrap_method(
1268 self._client._transport.list_sinks,
1269 default_retry=retries.Retry(
1270 initial=0.1,
1271 maximum=60.0,
1272 multiplier=1.3,
1273 predicate=retries.if_exception_type(
1274 core_exceptions.DeadlineExceeded,
1275 core_exceptions.InternalServerError,
1276 core_exceptions.ServiceUnavailable,
1277 ),
1278 deadline=60.0,
1279 ),
1280 default_timeout=60.0,
1281 client_info=DEFAULT_CLIENT_INFO,
1282 )
1283
1284 # Certain fields should be provided within the metadata header;
1285 # add these here.
1286 metadata = tuple(metadata) + (
1287 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
1288 )
1289
1290 # Send the request.
1291 response = await rpc(
1292 request,
1293 retry=retry,
1294 timeout=timeout,
1295 metadata=metadata,
1296 )
1297
1298 # This method is paged; wrap the response in a pager, which provides
1299 # an `__aiter__` convenience method.
1300 response = pagers.ListSinksAsyncPager(
1301 method=rpc,
1302 request=request,
1303 response=response,
1304 metadata=metadata,
1305 )
1306
1307 # Done; return the response.
1308 return response
1309
1310 async def get_sink(
1311 self,
1312 request: Optional[Union[logging_config.GetSinkRequest, dict]] = None,
1313 *,
1314 sink_name: Optional[str] = None,
1315 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1316 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1317 metadata: Sequence[Tuple[str, str]] = (),
1318 ) -> logging_config.LogSink:
1319 r"""Gets a sink.
1320
1321 .. code-block:: python
1322
1323 # This snippet has been automatically generated and should be regarded as a
1324 # code template only.
1325 # It will require modifications to work:
1326 # - It may require correct/in-range values for request initialization.
1327 # - It may require specifying regional endpoints when creating the service
1328 # client as shown in:
1329 # https://googleapis.dev/python/google-api-core/latest/client_options.html
1330 from google.cloud import logging_v2
1331
1332 async def sample_get_sink():
1333 # Create a client
1334 client = logging_v2.ConfigServiceV2AsyncClient()
1335
1336 # Initialize request argument(s)
1337 request = logging_v2.GetSinkRequest(
1338 sink_name="sink_name_value",
1339 )
1340
1341 # Make the request
1342 response = await client.get_sink(request=request)
1343
1344 # Handle the response
1345 print(response)
1346
1347 Args:
1348 request (Optional[Union[google.cloud.logging_v2.types.GetSinkRequest, dict]]):
1349 The request object. The parameters to ``GetSink``.
1350 sink_name (:class:`str`):
1351 Required. The resource name of the sink:
1352
1353 ::
1354
1355 "projects/[PROJECT_ID]/sinks/[SINK_ID]"
1356 "organizations/[ORGANIZATION_ID]/sinks/[SINK_ID]"
1357 "billingAccounts/[BILLING_ACCOUNT_ID]/sinks/[SINK_ID]"
1358 "folders/[FOLDER_ID]/sinks/[SINK_ID]"
1359
1360 For example:
1361
1362 ``"projects/my-project/sinks/my-sink"``
1363
1364 This corresponds to the ``sink_name`` field
1365 on the ``request`` instance; if ``request`` is provided, this
1366 should not be set.
1367 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1368 should be retried.
1369 timeout (float): The timeout for this request.
1370 metadata (Sequence[Tuple[str, str]]): Strings which should be
1371 sent along with the request as metadata.
1372
1373 Returns:
1374 google.cloud.logging_v2.types.LogSink:
1375 Describes a sink used to export log
1376 entries to one of the following
1377 destinations in any project: a Cloud
1378 Storage bucket, a BigQuery dataset, a
1379 Pub/Sub topic or a Cloud Logging log
1380 bucket. A logs filter controls which log
1381 entries are exported. The sink must be
1382 created within a project, organization,
1383 billing account, or folder.
1384
1385 """
1386 # Create or coerce a protobuf request object.
1387 # Quick check: If we got a request object, we should *not* have
1388 # gotten any keyword arguments that map to the request.
1389 has_flattened_params = any([sink_name])
1390 if request is not None and has_flattened_params:
1391 raise ValueError(
1392 "If the `request` argument is set, then none of "
1393 "the individual field arguments should be set."
1394 )
1395
1396 request = logging_config.GetSinkRequest(request)
1397
1398 # If we have keyword arguments corresponding to fields on the
1399 # request, apply these.
1400 if sink_name is not None:
1401 request.sink_name = sink_name
1402
1403 # Wrap the RPC method; this adds retry and timeout information,
1404 # and friendly error handling.
1405 rpc = gapic_v1.method_async.wrap_method(
1406 self._client._transport.get_sink,
1407 default_retry=retries.Retry(
1408 initial=0.1,
1409 maximum=60.0,
1410 multiplier=1.3,
1411 predicate=retries.if_exception_type(
1412 core_exceptions.DeadlineExceeded,
1413 core_exceptions.InternalServerError,
1414 core_exceptions.ServiceUnavailable,
1415 ),
1416 deadline=60.0,
1417 ),
1418 default_timeout=60.0,
1419 client_info=DEFAULT_CLIENT_INFO,
1420 )
1421
1422 # Certain fields should be provided within the metadata header;
1423 # add these here.
1424 metadata = tuple(metadata) + (
1425 gapic_v1.routing_header.to_grpc_metadata(
1426 (("sink_name", request.sink_name),)
1427 ),
1428 )
1429
1430 # Send the request.
1431 response = await rpc(
1432 request,
1433 retry=retry,
1434 timeout=timeout,
1435 metadata=metadata,
1436 )
1437
1438 # Done; return the response.
1439 return response
1440
1441 async def create_sink(
1442 self,
1443 request: Optional[Union[logging_config.CreateSinkRequest, dict]] = None,
1444 *,
1445 parent: Optional[str] = None,
1446 sink: Optional[logging_config.LogSink] = None,
1447 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1448 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1449 metadata: Sequence[Tuple[str, str]] = (),
1450 ) -> logging_config.LogSink:
1451 r"""Creates a sink that exports specified log entries to a
1452 destination. The export of newly-ingested log entries begins
1453 immediately, unless the sink's ``writer_identity`` is not
1454 permitted to write to the destination. A sink can export log
1455 entries only from the resource owning the sink.
1456
1457 .. code-block:: python
1458
1459 # This snippet has been automatically generated and should be regarded as a
1460 # code template only.
1461 # It will require modifications to work:
1462 # - It may require correct/in-range values for request initialization.
1463 # - It may require specifying regional endpoints when creating the service
1464 # client as shown in:
1465 # https://googleapis.dev/python/google-api-core/latest/client_options.html
1466 from google.cloud import logging_v2
1467
1468 async def sample_create_sink():
1469 # Create a client
1470 client = logging_v2.ConfigServiceV2AsyncClient()
1471
1472 # Initialize request argument(s)
1473 sink = logging_v2.LogSink()
1474 sink.name = "name_value"
1475 sink.destination = "destination_value"
1476
1477 request = logging_v2.CreateSinkRequest(
1478 parent="parent_value",
1479 sink=sink,
1480 )
1481
1482 # Make the request
1483 response = await client.create_sink(request=request)
1484
1485 # Handle the response
1486 print(response)
1487
1488 Args:
1489 request (Optional[Union[google.cloud.logging_v2.types.CreateSinkRequest, dict]]):
1490 The request object. The parameters to ``CreateSink``.
1491 parent (:class:`str`):
1492 Required. The resource in which to create the sink:
1493
1494 ::
1495
1496 "projects/[PROJECT_ID]"
1497 "organizations/[ORGANIZATION_ID]"
1498 "billingAccounts/[BILLING_ACCOUNT_ID]"
1499 "folders/[FOLDER_ID]"
1500
1501 For examples:
1502
1503 ``"projects/my-project"`` ``"organizations/123456789"``
1504
1505 This corresponds to the ``parent`` field
1506 on the ``request`` instance; if ``request`` is provided, this
1507 should not be set.
1508 sink (:class:`google.cloud.logging_v2.types.LogSink`):
1509 Required. The new sink, whose ``name`` parameter is a
1510 sink identifier that is not already in use.
1511
1512 This corresponds to the ``sink`` field
1513 on the ``request`` instance; if ``request`` is provided, this
1514 should not be set.
1515 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1516 should be retried.
1517 timeout (float): The timeout for this request.
1518 metadata (Sequence[Tuple[str, str]]): Strings which should be
1519 sent along with the request as metadata.
1520
1521 Returns:
1522 google.cloud.logging_v2.types.LogSink:
1523 Describes a sink used to export log
1524 entries to one of the following
1525 destinations in any project: a Cloud
1526 Storage bucket, a BigQuery dataset, a
1527 Pub/Sub topic or a Cloud Logging log
1528 bucket. A logs filter controls which log
1529 entries are exported. The sink must be
1530 created within a project, organization,
1531 billing account, or folder.
1532
1533 """
1534 # Create or coerce a protobuf request object.
1535 # Quick check: If we got a request object, we should *not* have
1536 # gotten any keyword arguments that map to the request.
1537 has_flattened_params = any([parent, sink])
1538 if request is not None and has_flattened_params:
1539 raise ValueError(
1540 "If the `request` argument is set, then none of "
1541 "the individual field arguments should be set."
1542 )
1543
1544 request = logging_config.CreateSinkRequest(request)
1545
1546 # If we have keyword arguments corresponding to fields on the
1547 # request, apply these.
1548 if parent is not None:
1549 request.parent = parent
1550 if sink is not None:
1551 request.sink = sink
1552
1553 # Wrap the RPC method; this adds retry and timeout information,
1554 # and friendly error handling.
1555 rpc = gapic_v1.method_async.wrap_method(
1556 self._client._transport.create_sink,
1557 default_timeout=120.0,
1558 client_info=DEFAULT_CLIENT_INFO,
1559 )
1560
1561 # Certain fields should be provided within the metadata header;
1562 # add these here.
1563 metadata = tuple(metadata) + (
1564 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
1565 )
1566
1567 # Send the request.
1568 response = await rpc(
1569 request,
1570 retry=retry,
1571 timeout=timeout,
1572 metadata=metadata,
1573 )
1574
1575 # Done; return the response.
1576 return response
1577
1578 async def update_sink(
1579 self,
1580 request: Optional[Union[logging_config.UpdateSinkRequest, dict]] = None,
1581 *,
1582 sink_name: Optional[str] = None,
1583 sink: Optional[logging_config.LogSink] = None,
1584 update_mask: Optional[field_mask_pb2.FieldMask] = None,
1585 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1586 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1587 metadata: Sequence[Tuple[str, str]] = (),
1588 ) -> logging_config.LogSink:
1589 r"""Updates a sink. This method replaces the following fields in the
1590 existing sink with values from the new sink: ``destination``,
1591 and ``filter``.
1592
1593 The updated sink might also have a new ``writer_identity``; see
1594 the ``unique_writer_identity`` field.
1595
1596 .. code-block:: python
1597
1598 # This snippet has been automatically generated and should be regarded as a
1599 # code template only.
1600 # It will require modifications to work:
1601 # - It may require correct/in-range values for request initialization.
1602 # - It may require specifying regional endpoints when creating the service
1603 # client as shown in:
1604 # https://googleapis.dev/python/google-api-core/latest/client_options.html
1605 from google.cloud import logging_v2
1606
1607 async def sample_update_sink():
1608 # Create a client
1609 client = logging_v2.ConfigServiceV2AsyncClient()
1610
1611 # Initialize request argument(s)
1612 sink = logging_v2.LogSink()
1613 sink.name = "name_value"
1614 sink.destination = "destination_value"
1615
1616 request = logging_v2.UpdateSinkRequest(
1617 sink_name="sink_name_value",
1618 sink=sink,
1619 )
1620
1621 # Make the request
1622 response = await client.update_sink(request=request)
1623
1624 # Handle the response
1625 print(response)
1626
1627 Args:
1628 request (Optional[Union[google.cloud.logging_v2.types.UpdateSinkRequest, dict]]):
1629 The request object. The parameters to ``UpdateSink``.
1630 sink_name (:class:`str`):
1631 Required. The full resource name of the sink to update,
1632 including the parent resource and the sink identifier:
1633
1634 ::
1635
1636 "projects/[PROJECT_ID]/sinks/[SINK_ID]"
1637 "organizations/[ORGANIZATION_ID]/sinks/[SINK_ID]"
1638 "billingAccounts/[BILLING_ACCOUNT_ID]/sinks/[SINK_ID]"
1639 "folders/[FOLDER_ID]/sinks/[SINK_ID]"
1640
1641 For example:
1642
1643 ``"projects/my-project/sinks/my-sink"``
1644
1645 This corresponds to the ``sink_name`` field
1646 on the ``request`` instance; if ``request`` is provided, this
1647 should not be set.
1648 sink (:class:`google.cloud.logging_v2.types.LogSink`):
1649 Required. The updated sink, whose name is the same
1650 identifier that appears as part of ``sink_name``.
1651
1652 This corresponds to the ``sink`` field
1653 on the ``request`` instance; if ``request`` is provided, this
1654 should not be set.
1655 update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`):
1656 Optional. Field mask that specifies the fields in
1657 ``sink`` that need an update. A sink field will be
1658 overwritten if, and only if, it is in the update mask.
1659 ``name`` and output only fields cannot be updated.
1660
1661 An empty ``updateMask`` is temporarily treated as using
1662 the following mask for backwards compatibility purposes:
1663
1664 ``destination,filter,includeChildren``
1665
1666 At some point in the future, behavior will be removed
1667 and specifying an empty ``updateMask`` will be an error.
1668
1669 For a detailed ``FieldMask`` definition, see
1670 https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#google.protobuf.FieldMask
1671
1672 For example: ``updateMask=filter``
1673
1674 This corresponds to the ``update_mask`` field
1675 on the ``request`` instance; if ``request`` is provided, this
1676 should not be set.
1677 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1678 should be retried.
1679 timeout (float): The timeout for this request.
1680 metadata (Sequence[Tuple[str, str]]): Strings which should be
1681 sent along with the request as metadata.
1682
1683 Returns:
1684 google.cloud.logging_v2.types.LogSink:
1685 Describes a sink used to export log
1686 entries to one of the following
1687 destinations in any project: a Cloud
1688 Storage bucket, a BigQuery dataset, a
1689 Pub/Sub topic or a Cloud Logging log
1690 bucket. A logs filter controls which log
1691 entries are exported. The sink must be
1692 created within a project, organization,
1693 billing account, or folder.
1694
1695 """
1696 # Create or coerce a protobuf request object.
1697 # Quick check: If we got a request object, we should *not* have
1698 # gotten any keyword arguments that map to the request.
1699 has_flattened_params = any([sink_name, sink, update_mask])
1700 if request is not None and has_flattened_params:
1701 raise ValueError(
1702 "If the `request` argument is set, then none of "
1703 "the individual field arguments should be set."
1704 )
1705
1706 request = logging_config.UpdateSinkRequest(request)
1707
1708 # If we have keyword arguments corresponding to fields on the
1709 # request, apply these.
1710 if sink_name is not None:
1711 request.sink_name = sink_name
1712 if sink is not None:
1713 request.sink = sink
1714 if update_mask is not None:
1715 request.update_mask = update_mask
1716
1717 # Wrap the RPC method; this adds retry and timeout information,
1718 # and friendly error handling.
1719 rpc = gapic_v1.method_async.wrap_method(
1720 self._client._transport.update_sink,
1721 default_retry=retries.Retry(
1722 initial=0.1,
1723 maximum=60.0,
1724 multiplier=1.3,
1725 predicate=retries.if_exception_type(
1726 core_exceptions.DeadlineExceeded,
1727 core_exceptions.InternalServerError,
1728 core_exceptions.ServiceUnavailable,
1729 ),
1730 deadline=60.0,
1731 ),
1732 default_timeout=60.0,
1733 client_info=DEFAULT_CLIENT_INFO,
1734 )
1735
1736 # Certain fields should be provided within the metadata header;
1737 # add these here.
1738 metadata = tuple(metadata) + (
1739 gapic_v1.routing_header.to_grpc_metadata(
1740 (("sink_name", request.sink_name),)
1741 ),
1742 )
1743
1744 # Send the request.
1745 response = await rpc(
1746 request,
1747 retry=retry,
1748 timeout=timeout,
1749 metadata=metadata,
1750 )
1751
1752 # Done; return the response.
1753 return response
1754
1755 async def delete_sink(
1756 self,
1757 request: Optional[Union[logging_config.DeleteSinkRequest, dict]] = None,
1758 *,
1759 sink_name: Optional[str] = None,
1760 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1761 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1762 metadata: Sequence[Tuple[str, str]] = (),
1763 ) -> None:
1764 r"""Deletes a sink. If the sink has a unique ``writer_identity``,
1765 then that service account is also deleted.
1766
1767 .. code-block:: python
1768
1769 # This snippet has been automatically generated and should be regarded as a
1770 # code template only.
1771 # It will require modifications to work:
1772 # - It may require correct/in-range values for request initialization.
1773 # - It may require specifying regional endpoints when creating the service
1774 # client as shown in:
1775 # https://googleapis.dev/python/google-api-core/latest/client_options.html
1776 from google.cloud import logging_v2
1777
1778 async def sample_delete_sink():
1779 # Create a client
1780 client = logging_v2.ConfigServiceV2AsyncClient()
1781
1782 # Initialize request argument(s)
1783 request = logging_v2.DeleteSinkRequest(
1784 sink_name="sink_name_value",
1785 )
1786
1787 # Make the request
1788 await client.delete_sink(request=request)
1789
1790 Args:
1791 request (Optional[Union[google.cloud.logging_v2.types.DeleteSinkRequest, dict]]):
1792 The request object. The parameters to ``DeleteSink``.
1793 sink_name (:class:`str`):
1794 Required. The full resource name of the sink to delete,
1795 including the parent resource and the sink identifier:
1796
1797 ::
1798
1799 "projects/[PROJECT_ID]/sinks/[SINK_ID]"
1800 "organizations/[ORGANIZATION_ID]/sinks/[SINK_ID]"
1801 "billingAccounts/[BILLING_ACCOUNT_ID]/sinks/[SINK_ID]"
1802 "folders/[FOLDER_ID]/sinks/[SINK_ID]"
1803
1804 For example:
1805
1806 ``"projects/my-project/sinks/my-sink"``
1807
1808 This corresponds to the ``sink_name`` field
1809 on the ``request`` instance; if ``request`` is provided, this
1810 should not be set.
1811 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1812 should be retried.
1813 timeout (float): The timeout for this request.
1814 metadata (Sequence[Tuple[str, str]]): Strings which should be
1815 sent along with the request as metadata.
1816 """
1817 # Create or coerce a protobuf request object.
1818 # Quick check: If we got a request object, we should *not* have
1819 # gotten any keyword arguments that map to the request.
1820 has_flattened_params = any([sink_name])
1821 if request is not None and has_flattened_params:
1822 raise ValueError(
1823 "If the `request` argument is set, then none of "
1824 "the individual field arguments should be set."
1825 )
1826
1827 request = logging_config.DeleteSinkRequest(request)
1828
1829 # If we have keyword arguments corresponding to fields on the
1830 # request, apply these.
1831 if sink_name is not None:
1832 request.sink_name = sink_name
1833
1834 # Wrap the RPC method; this adds retry and timeout information,
1835 # and friendly error handling.
1836 rpc = gapic_v1.method_async.wrap_method(
1837 self._client._transport.delete_sink,
1838 default_retry=retries.Retry(
1839 initial=0.1,
1840 maximum=60.0,
1841 multiplier=1.3,
1842 predicate=retries.if_exception_type(
1843 core_exceptions.DeadlineExceeded,
1844 core_exceptions.InternalServerError,
1845 core_exceptions.ServiceUnavailable,
1846 ),
1847 deadline=60.0,
1848 ),
1849 default_timeout=60.0,
1850 client_info=DEFAULT_CLIENT_INFO,
1851 )
1852
1853 # Certain fields should be provided within the metadata header;
1854 # add these here.
1855 metadata = tuple(metadata) + (
1856 gapic_v1.routing_header.to_grpc_metadata(
1857 (("sink_name", request.sink_name),)
1858 ),
1859 )
1860
1861 # Send the request.
1862 await rpc(
1863 request,
1864 retry=retry,
1865 timeout=timeout,
1866 metadata=metadata,
1867 )
1868
1869 async def list_exclusions(
1870 self,
1871 request: Optional[Union[logging_config.ListExclusionsRequest, dict]] = None,
1872 *,
1873 parent: Optional[str] = None,
1874 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1875 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1876 metadata: Sequence[Tuple[str, str]] = (),
1877 ) -> pagers.ListExclusionsAsyncPager:
1878 r"""Lists all the exclusions on the \_Default sink in a parent
1879 resource.
1880
1881 .. code-block:: python
1882
1883 # This snippet has been automatically generated and should be regarded as a
1884 # code template only.
1885 # It will require modifications to work:
1886 # - It may require correct/in-range values for request initialization.
1887 # - It may require specifying regional endpoints when creating the service
1888 # client as shown in:
1889 # https://googleapis.dev/python/google-api-core/latest/client_options.html
1890 from google.cloud import logging_v2
1891
1892 async def sample_list_exclusions():
1893 # Create a client
1894 client = logging_v2.ConfigServiceV2AsyncClient()
1895
1896 # Initialize request argument(s)
1897 request = logging_v2.ListExclusionsRequest(
1898 parent="parent_value",
1899 )
1900
1901 # Make the request
1902 page_result = client.list_exclusions(request=request)
1903
1904 # Handle the response
1905 async for response in page_result:
1906 print(response)
1907
1908 Args:
1909 request (Optional[Union[google.cloud.logging_v2.types.ListExclusionsRequest, dict]]):
1910 The request object. The parameters to ``ListExclusions``.
1911 parent (:class:`str`):
1912 Required. The parent resource whose exclusions are to be
1913 listed.
1914
1915 ::
1916
1917 "projects/[PROJECT_ID]"
1918 "organizations/[ORGANIZATION_ID]"
1919 "billingAccounts/[BILLING_ACCOUNT_ID]"
1920 "folders/[FOLDER_ID]"
1921
1922 This corresponds to the ``parent`` field
1923 on the ``request`` instance; if ``request`` is provided, this
1924 should not be set.
1925 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1926 should be retried.
1927 timeout (float): The timeout for this request.
1928 metadata (Sequence[Tuple[str, str]]): Strings which should be
1929 sent along with the request as metadata.
1930
1931 Returns:
1932 google.cloud.logging_v2.services.config_service_v2.pagers.ListExclusionsAsyncPager:
1933 Result returned from ListExclusions.
1934
1935 Iterating over this object will yield results and
1936 resolve additional pages automatically.
1937
1938 """
1939 # Create or coerce a protobuf request object.
1940 # Quick check: If we got a request object, we should *not* have
1941 # gotten any keyword arguments that map to the request.
1942 has_flattened_params = any([parent])
1943 if request is not None and has_flattened_params:
1944 raise ValueError(
1945 "If the `request` argument is set, then none of "
1946 "the individual field arguments should be set."
1947 )
1948
1949 request = logging_config.ListExclusionsRequest(request)
1950
1951 # If we have keyword arguments corresponding to fields on the
1952 # request, apply these.
1953 if parent is not None:
1954 request.parent = parent
1955
1956 # Wrap the RPC method; this adds retry and timeout information,
1957 # and friendly error handling.
1958 rpc = gapic_v1.method_async.wrap_method(
1959 self._client._transport.list_exclusions,
1960 default_retry=retries.Retry(
1961 initial=0.1,
1962 maximum=60.0,
1963 multiplier=1.3,
1964 predicate=retries.if_exception_type(
1965 core_exceptions.DeadlineExceeded,
1966 core_exceptions.InternalServerError,
1967 core_exceptions.ServiceUnavailable,
1968 ),
1969 deadline=60.0,
1970 ),
1971 default_timeout=60.0,
1972 client_info=DEFAULT_CLIENT_INFO,
1973 )
1974
1975 # Certain fields should be provided within the metadata header;
1976 # add these here.
1977 metadata = tuple(metadata) + (
1978 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
1979 )
1980
1981 # Send the request.
1982 response = await rpc(
1983 request,
1984 retry=retry,
1985 timeout=timeout,
1986 metadata=metadata,
1987 )
1988
1989 # This method is paged; wrap the response in a pager, which provides
1990 # an `__aiter__` convenience method.
1991 response = pagers.ListExclusionsAsyncPager(
1992 method=rpc,
1993 request=request,
1994 response=response,
1995 metadata=metadata,
1996 )
1997
1998 # Done; return the response.
1999 return response
2000
2001 async def get_exclusion(
2002 self,
2003 request: Optional[Union[logging_config.GetExclusionRequest, dict]] = None,
2004 *,
2005 name: Optional[str] = None,
2006 retry: OptionalRetry = gapic_v1.method.DEFAULT,
2007 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
2008 metadata: Sequence[Tuple[str, str]] = (),
2009 ) -> logging_config.LogExclusion:
2010 r"""Gets the description of an exclusion in the \_Default sink.
2011
2012 .. code-block:: python
2013
2014 # This snippet has been automatically generated and should be regarded as a
2015 # code template only.
2016 # It will require modifications to work:
2017 # - It may require correct/in-range values for request initialization.
2018 # - It may require specifying regional endpoints when creating the service
2019 # client as shown in:
2020 # https://googleapis.dev/python/google-api-core/latest/client_options.html
2021 from google.cloud import logging_v2
2022
2023 async def sample_get_exclusion():
2024 # Create a client
2025 client = logging_v2.ConfigServiceV2AsyncClient()
2026
2027 # Initialize request argument(s)
2028 request = logging_v2.GetExclusionRequest(
2029 name="name_value",
2030 )
2031
2032 # Make the request
2033 response = await client.get_exclusion(request=request)
2034
2035 # Handle the response
2036 print(response)
2037
2038 Args:
2039 request (Optional[Union[google.cloud.logging_v2.types.GetExclusionRequest, dict]]):
2040 The request object. The parameters to ``GetExclusion``.
2041 name (:class:`str`):
2042 Required. The resource name of an existing exclusion:
2043
2044 ::
2045
2046 "projects/[PROJECT_ID]/exclusions/[EXCLUSION_ID]"
2047 "organizations/[ORGANIZATION_ID]/exclusions/[EXCLUSION_ID]"
2048 "billingAccounts/[BILLING_ACCOUNT_ID]/exclusions/[EXCLUSION_ID]"
2049 "folders/[FOLDER_ID]/exclusions/[EXCLUSION_ID]"
2050
2051 For example:
2052
2053 ``"projects/my-project/exclusions/my-exclusion"``
2054
2055 This corresponds to the ``name`` field
2056 on the ``request`` instance; if ``request`` is provided, this
2057 should not be set.
2058 retry (google.api_core.retry.Retry): Designation of what errors, if any,
2059 should be retried.
2060 timeout (float): The timeout for this request.
2061 metadata (Sequence[Tuple[str, str]]): Strings which should be
2062 sent along with the request as metadata.
2063
2064 Returns:
2065 google.cloud.logging_v2.types.LogExclusion:
2066 Specifies a set of log entries that are filtered out by a sink. If
2067 your Google Cloud resource receives a large volume of
2068 log entries, you can use exclusions to reduce your
2069 chargeable logs. Note that exclusions on
2070 organization-level and folder-level sinks don't apply
2071 to child resources. Note also that you cannot modify
2072 the \_Required sink or exclude logs from it.
2073
2074 """
2075 # Create or coerce a protobuf request object.
2076 # Quick check: If we got a request object, we should *not* have
2077 # gotten any keyword arguments that map to the request.
2078 has_flattened_params = any([name])
2079 if request is not None and has_flattened_params:
2080 raise ValueError(
2081 "If the `request` argument is set, then none of "
2082 "the individual field arguments should be set."
2083 )
2084
2085 request = logging_config.GetExclusionRequest(request)
2086
2087 # If we have keyword arguments corresponding to fields on the
2088 # request, apply these.
2089 if name is not None:
2090 request.name = name
2091
2092 # Wrap the RPC method; this adds retry and timeout information,
2093 # and friendly error handling.
2094 rpc = gapic_v1.method_async.wrap_method(
2095 self._client._transport.get_exclusion,
2096 default_retry=retries.Retry(
2097 initial=0.1,
2098 maximum=60.0,
2099 multiplier=1.3,
2100 predicate=retries.if_exception_type(
2101 core_exceptions.DeadlineExceeded,
2102 core_exceptions.InternalServerError,
2103 core_exceptions.ServiceUnavailable,
2104 ),
2105 deadline=60.0,
2106 ),
2107 default_timeout=60.0,
2108 client_info=DEFAULT_CLIENT_INFO,
2109 )
2110
2111 # Certain fields should be provided within the metadata header;
2112 # add these here.
2113 metadata = tuple(metadata) + (
2114 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
2115 )
2116
2117 # Send the request.
2118 response = await rpc(
2119 request,
2120 retry=retry,
2121 timeout=timeout,
2122 metadata=metadata,
2123 )
2124
2125 # Done; return the response.
2126 return response
2127
2128 async def create_exclusion(
2129 self,
2130 request: Optional[Union[logging_config.CreateExclusionRequest, dict]] = None,
2131 *,
2132 parent: Optional[str] = None,
2133 exclusion: Optional[logging_config.LogExclusion] = None,
2134 retry: OptionalRetry = gapic_v1.method.DEFAULT,
2135 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
2136 metadata: Sequence[Tuple[str, str]] = (),
2137 ) -> logging_config.LogExclusion:
2138 r"""Creates a new exclusion in the \_Default sink in a specified
2139 parent resource. Only log entries belonging to that resource can
2140 be excluded. You can have up to 10 exclusions in a resource.
2141
2142 .. code-block:: python
2143
2144 # This snippet has been automatically generated and should be regarded as a
2145 # code template only.
2146 # It will require modifications to work:
2147 # - It may require correct/in-range values for request initialization.
2148 # - It may require specifying regional endpoints when creating the service
2149 # client as shown in:
2150 # https://googleapis.dev/python/google-api-core/latest/client_options.html
2151 from google.cloud import logging_v2
2152
2153 async def sample_create_exclusion():
2154 # Create a client
2155 client = logging_v2.ConfigServiceV2AsyncClient()
2156
2157 # Initialize request argument(s)
2158 exclusion = logging_v2.LogExclusion()
2159 exclusion.name = "name_value"
2160 exclusion.filter = "filter_value"
2161
2162 request = logging_v2.CreateExclusionRequest(
2163 parent="parent_value",
2164 exclusion=exclusion,
2165 )
2166
2167 # Make the request
2168 response = await client.create_exclusion(request=request)
2169
2170 # Handle the response
2171 print(response)
2172
2173 Args:
2174 request (Optional[Union[google.cloud.logging_v2.types.CreateExclusionRequest, dict]]):
2175 The request object. The parameters to ``CreateExclusion``.
2176 parent (:class:`str`):
2177 Required. The parent resource in which to create the
2178 exclusion:
2179
2180 ::
2181
2182 "projects/[PROJECT_ID]"
2183 "organizations/[ORGANIZATION_ID]"
2184 "billingAccounts/[BILLING_ACCOUNT_ID]"
2185 "folders/[FOLDER_ID]"
2186
2187 For examples:
2188
2189 ``"projects/my-logging-project"``
2190 ``"organizations/123456789"``
2191
2192 This corresponds to the ``parent`` field
2193 on the ``request`` instance; if ``request`` is provided, this
2194 should not be set.
2195 exclusion (:class:`google.cloud.logging_v2.types.LogExclusion`):
2196 Required. The new exclusion, whose ``name`` parameter is
2197 an exclusion name that is not already used in the parent
2198 resource.
2199
2200 This corresponds to the ``exclusion`` field
2201 on the ``request`` instance; if ``request`` is provided, this
2202 should not be set.
2203 retry (google.api_core.retry.Retry): Designation of what errors, if any,
2204 should be retried.
2205 timeout (float): The timeout for this request.
2206 metadata (Sequence[Tuple[str, str]]): Strings which should be
2207 sent along with the request as metadata.
2208
2209 Returns:
2210 google.cloud.logging_v2.types.LogExclusion:
2211 Specifies a set of log entries that are filtered out by a sink. If
2212 your Google Cloud resource receives a large volume of
2213 log entries, you can use exclusions to reduce your
2214 chargeable logs. Note that exclusions on
2215 organization-level and folder-level sinks don't apply
2216 to child resources. Note also that you cannot modify
2217 the \_Required sink or exclude logs from it.
2218
2219 """
2220 # Create or coerce a protobuf request object.
2221 # Quick check: If we got a request object, we should *not* have
2222 # gotten any keyword arguments that map to the request.
2223 has_flattened_params = any([parent, exclusion])
2224 if request is not None and has_flattened_params:
2225 raise ValueError(
2226 "If the `request` argument is set, then none of "
2227 "the individual field arguments should be set."
2228 )
2229
2230 request = logging_config.CreateExclusionRequest(request)
2231
2232 # If we have keyword arguments corresponding to fields on the
2233 # request, apply these.
2234 if parent is not None:
2235 request.parent = parent
2236 if exclusion is not None:
2237 request.exclusion = exclusion
2238
2239 # Wrap the RPC method; this adds retry and timeout information,
2240 # and friendly error handling.
2241 rpc = gapic_v1.method_async.wrap_method(
2242 self._client._transport.create_exclusion,
2243 default_timeout=120.0,
2244 client_info=DEFAULT_CLIENT_INFO,
2245 )
2246
2247 # Certain fields should be provided within the metadata header;
2248 # add these here.
2249 metadata = tuple(metadata) + (
2250 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
2251 )
2252
2253 # Send the request.
2254 response = await rpc(
2255 request,
2256 retry=retry,
2257 timeout=timeout,
2258 metadata=metadata,
2259 )
2260
2261 # Done; return the response.
2262 return response
2263
2264 async def update_exclusion(
2265 self,
2266 request: Optional[Union[logging_config.UpdateExclusionRequest, dict]] = None,
2267 *,
2268 name: Optional[str] = None,
2269 exclusion: Optional[logging_config.LogExclusion] = None,
2270 update_mask: Optional[field_mask_pb2.FieldMask] = None,
2271 retry: OptionalRetry = gapic_v1.method.DEFAULT,
2272 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
2273 metadata: Sequence[Tuple[str, str]] = (),
2274 ) -> logging_config.LogExclusion:
2275 r"""Changes one or more properties of an existing exclusion in the
2276 \_Default sink.
2277
2278 .. code-block:: python
2279
2280 # This snippet has been automatically generated and should be regarded as a
2281 # code template only.
2282 # It will require modifications to work:
2283 # - It may require correct/in-range values for request initialization.
2284 # - It may require specifying regional endpoints when creating the service
2285 # client as shown in:
2286 # https://googleapis.dev/python/google-api-core/latest/client_options.html
2287 from google.cloud import logging_v2
2288
2289 async def sample_update_exclusion():
2290 # Create a client
2291 client = logging_v2.ConfigServiceV2AsyncClient()
2292
2293 # Initialize request argument(s)
2294 exclusion = logging_v2.LogExclusion()
2295 exclusion.name = "name_value"
2296 exclusion.filter = "filter_value"
2297
2298 request = logging_v2.UpdateExclusionRequest(
2299 name="name_value",
2300 exclusion=exclusion,
2301 )
2302
2303 # Make the request
2304 response = await client.update_exclusion(request=request)
2305
2306 # Handle the response
2307 print(response)
2308
2309 Args:
2310 request (Optional[Union[google.cloud.logging_v2.types.UpdateExclusionRequest, dict]]):
2311 The request object. The parameters to ``UpdateExclusion``.
2312 name (:class:`str`):
2313 Required. The resource name of the exclusion to update:
2314
2315 ::
2316
2317 "projects/[PROJECT_ID]/exclusions/[EXCLUSION_ID]"
2318 "organizations/[ORGANIZATION_ID]/exclusions/[EXCLUSION_ID]"
2319 "billingAccounts/[BILLING_ACCOUNT_ID]/exclusions/[EXCLUSION_ID]"
2320 "folders/[FOLDER_ID]/exclusions/[EXCLUSION_ID]"
2321
2322 For example:
2323
2324 ``"projects/my-project/exclusions/my-exclusion"``
2325
2326 This corresponds to the ``name`` field
2327 on the ``request`` instance; if ``request`` is provided, this
2328 should not be set.
2329 exclusion (:class:`google.cloud.logging_v2.types.LogExclusion`):
2330 Required. New values for the existing exclusion. Only
2331 the fields specified in ``update_mask`` are relevant.
2332
2333 This corresponds to the ``exclusion`` field
2334 on the ``request`` instance; if ``request`` is provided, this
2335 should not be set.
2336 update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`):
2337 Required. A non-empty list of fields to change in the
2338 existing exclusion. New values for the fields are taken
2339 from the corresponding fields in the
2340 [LogExclusion][google.logging.v2.LogExclusion] included
2341 in this request. Fields not mentioned in ``update_mask``
2342 are not changed and are ignored in the request.
2343
2344 For example, to change the filter and description of an
2345 exclusion, specify an ``update_mask`` of
2346 ``"filter,description"``.
2347
2348 This corresponds to the ``update_mask`` field
2349 on the ``request`` instance; if ``request`` is provided, this
2350 should not be set.
2351 retry (google.api_core.retry.Retry): Designation of what errors, if any,
2352 should be retried.
2353 timeout (float): The timeout for this request.
2354 metadata (Sequence[Tuple[str, str]]): Strings which should be
2355 sent along with the request as metadata.
2356
2357 Returns:
2358 google.cloud.logging_v2.types.LogExclusion:
2359 Specifies a set of log entries that are filtered out by a sink. If
2360 your Google Cloud resource receives a large volume of
2361 log entries, you can use exclusions to reduce your
2362 chargeable logs. Note that exclusions on
2363 organization-level and folder-level sinks don't apply
2364 to child resources. Note also that you cannot modify
2365 the \_Required sink or exclude logs from it.
2366
2367 """
2368 # Create or coerce a protobuf request object.
2369 # Quick check: If we got a request object, we should *not* have
2370 # gotten any keyword arguments that map to the request.
2371 has_flattened_params = any([name, exclusion, update_mask])
2372 if request is not None and has_flattened_params:
2373 raise ValueError(
2374 "If the `request` argument is set, then none of "
2375 "the individual field arguments should be set."
2376 )
2377
2378 request = logging_config.UpdateExclusionRequest(request)
2379
2380 # If we have keyword arguments corresponding to fields on the
2381 # request, apply these.
2382 if name is not None:
2383 request.name = name
2384 if exclusion is not None:
2385 request.exclusion = exclusion
2386 if update_mask is not None:
2387 request.update_mask = update_mask
2388
2389 # Wrap the RPC method; this adds retry and timeout information,
2390 # and friendly error handling.
2391 rpc = gapic_v1.method_async.wrap_method(
2392 self._client._transport.update_exclusion,
2393 default_timeout=120.0,
2394 client_info=DEFAULT_CLIENT_INFO,
2395 )
2396
2397 # Certain fields should be provided within the metadata header;
2398 # add these here.
2399 metadata = tuple(metadata) + (
2400 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
2401 )
2402
2403 # Send the request.
2404 response = await rpc(
2405 request,
2406 retry=retry,
2407 timeout=timeout,
2408 metadata=metadata,
2409 )
2410
2411 # Done; return the response.
2412 return response
2413
2414 async def delete_exclusion(
2415 self,
2416 request: Optional[Union[logging_config.DeleteExclusionRequest, dict]] = None,
2417 *,
2418 name: Optional[str] = None,
2419 retry: OptionalRetry = gapic_v1.method.DEFAULT,
2420 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
2421 metadata: Sequence[Tuple[str, str]] = (),
2422 ) -> None:
2423 r"""Deletes an exclusion in the \_Default sink.
2424
2425 .. code-block:: python
2426
2427 # This snippet has been automatically generated and should be regarded as a
2428 # code template only.
2429 # It will require modifications to work:
2430 # - It may require correct/in-range values for request initialization.
2431 # - It may require specifying regional endpoints when creating the service
2432 # client as shown in:
2433 # https://googleapis.dev/python/google-api-core/latest/client_options.html
2434 from google.cloud import logging_v2
2435
2436 async def sample_delete_exclusion():
2437 # Create a client
2438 client = logging_v2.ConfigServiceV2AsyncClient()
2439
2440 # Initialize request argument(s)
2441 request = logging_v2.DeleteExclusionRequest(
2442 name="name_value",
2443 )
2444
2445 # Make the request
2446 await client.delete_exclusion(request=request)
2447
2448 Args:
2449 request (Optional[Union[google.cloud.logging_v2.types.DeleteExclusionRequest, dict]]):
2450 The request object. The parameters to ``DeleteExclusion``.
2451 name (:class:`str`):
2452 Required. The resource name of an existing exclusion to
2453 delete:
2454
2455 ::
2456
2457 "projects/[PROJECT_ID]/exclusions/[EXCLUSION_ID]"
2458 "organizations/[ORGANIZATION_ID]/exclusions/[EXCLUSION_ID]"
2459 "billingAccounts/[BILLING_ACCOUNT_ID]/exclusions/[EXCLUSION_ID]"
2460 "folders/[FOLDER_ID]/exclusions/[EXCLUSION_ID]"
2461
2462 For example:
2463
2464 ``"projects/my-project/exclusions/my-exclusion"``
2465
2466 This corresponds to the ``name`` field
2467 on the ``request`` instance; if ``request`` is provided, this
2468 should not be set.
2469 retry (google.api_core.retry.Retry): Designation of what errors, if any,
2470 should be retried.
2471 timeout (float): The timeout for this request.
2472 metadata (Sequence[Tuple[str, str]]): Strings which should be
2473 sent along with the request as metadata.
2474 """
2475 # Create or coerce a protobuf request object.
2476 # Quick check: If we got a request object, we should *not* have
2477 # gotten any keyword arguments that map to the request.
2478 has_flattened_params = any([name])
2479 if request is not None and has_flattened_params:
2480 raise ValueError(
2481 "If the `request` argument is set, then none of "
2482 "the individual field arguments should be set."
2483 )
2484
2485 request = logging_config.DeleteExclusionRequest(request)
2486
2487 # If we have keyword arguments corresponding to fields on the
2488 # request, apply these.
2489 if name is not None:
2490 request.name = name
2491
2492 # Wrap the RPC method; this adds retry and timeout information,
2493 # and friendly error handling.
2494 rpc = gapic_v1.method_async.wrap_method(
2495 self._client._transport.delete_exclusion,
2496 default_retry=retries.Retry(
2497 initial=0.1,
2498 maximum=60.0,
2499 multiplier=1.3,
2500 predicate=retries.if_exception_type(
2501 core_exceptions.DeadlineExceeded,
2502 core_exceptions.InternalServerError,
2503 core_exceptions.ServiceUnavailable,
2504 ),
2505 deadline=60.0,
2506 ),
2507 default_timeout=60.0,
2508 client_info=DEFAULT_CLIENT_INFO,
2509 )
2510
2511 # Certain fields should be provided within the metadata header;
2512 # add these here.
2513 metadata = tuple(metadata) + (
2514 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
2515 )
2516
2517 # Send the request.
2518 await rpc(
2519 request,
2520 retry=retry,
2521 timeout=timeout,
2522 metadata=metadata,
2523 )
2524
2525 async def get_cmek_settings(
2526 self,
2527 request: Optional[Union[logging_config.GetCmekSettingsRequest, dict]] = None,
2528 *,
2529 retry: OptionalRetry = gapic_v1.method.DEFAULT,
2530 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
2531 metadata: Sequence[Tuple[str, str]] = (),
2532 ) -> logging_config.CmekSettings:
2533 r"""Gets the Logging CMEK settings for the given resource.
2534
2535 Note: CMEK for the Log Router can be configured for Google Cloud
2536 projects, folders, organizations and billing accounts. Once
2537 configured for an organization, it applies to all projects and
2538 folders in the Google Cloud organization.
2539
2540 See `Enabling CMEK for Log
2541 Router <https://cloud.google.com/logging/docs/routing/managed-encryption>`__
2542 for more information.
2543
2544 .. code-block:: python
2545
2546 # This snippet has been automatically generated and should be regarded as a
2547 # code template only.
2548 # It will require modifications to work:
2549 # - It may require correct/in-range values for request initialization.
2550 # - It may require specifying regional endpoints when creating the service
2551 # client as shown in:
2552 # https://googleapis.dev/python/google-api-core/latest/client_options.html
2553 from google.cloud import logging_v2
2554
2555 async def sample_get_cmek_settings():
2556 # Create a client
2557 client = logging_v2.ConfigServiceV2AsyncClient()
2558
2559 # Initialize request argument(s)
2560 request = logging_v2.GetCmekSettingsRequest(
2561 name="name_value",
2562 )
2563
2564 # Make the request
2565 response = await client.get_cmek_settings(request=request)
2566
2567 # Handle the response
2568 print(response)
2569
2570 Args:
2571 request (Optional[Union[google.cloud.logging_v2.types.GetCmekSettingsRequest, dict]]):
2572 The request object. The parameters to
2573 [GetCmekSettings][google.logging.v2.ConfigServiceV2.GetCmekSettings].
2574
2575 See `Enabling CMEK for Log
2576 Router <https://cloud.google.com/logging/docs/routing/managed-encryption>`__
2577 for more information.
2578 retry (google.api_core.retry.Retry): Designation of what errors, if any,
2579 should be retried.
2580 timeout (float): The timeout for this request.
2581 metadata (Sequence[Tuple[str, str]]): Strings which should be
2582 sent along with the request as metadata.
2583
2584 Returns:
2585 google.cloud.logging_v2.types.CmekSettings:
2586 Describes the customer-managed encryption key (CMEK) settings associated with
2587 a project, folder, organization, billing account, or
2588 flexible resource.
2589
2590 Note: CMEK for the Log Router can currently only be
2591 configured for Google Cloud organizations. Once
2592 configured, it applies to all projects and folders in
2593 the Google Cloud organization.
2594
2595 See [Enabling CMEK for Log
2596 Router](\ https://cloud.google.com/logging/docs/routing/managed-encryption)
2597 for more information.
2598
2599 """
2600 # Create or coerce a protobuf request object.
2601 request = logging_config.GetCmekSettingsRequest(request)
2602
2603 # Wrap the RPC method; this adds retry and timeout information,
2604 # and friendly error handling.
2605 rpc = gapic_v1.method_async.wrap_method(
2606 self._client._transport.get_cmek_settings,
2607 default_timeout=None,
2608 client_info=DEFAULT_CLIENT_INFO,
2609 )
2610
2611 # Certain fields should be provided within the metadata header;
2612 # add these here.
2613 metadata = tuple(metadata) + (
2614 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
2615 )
2616
2617 # Send the request.
2618 response = await rpc(
2619 request,
2620 retry=retry,
2621 timeout=timeout,
2622 metadata=metadata,
2623 )
2624
2625 # Done; return the response.
2626 return response
2627
2628 async def update_cmek_settings(
2629 self,
2630 request: Optional[Union[logging_config.UpdateCmekSettingsRequest, dict]] = None,
2631 *,
2632 retry: OptionalRetry = gapic_v1.method.DEFAULT,
2633 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
2634 metadata: Sequence[Tuple[str, str]] = (),
2635 ) -> logging_config.CmekSettings:
2636 r"""Updates the Log Router CMEK settings for the given resource.
2637
2638 Note: CMEK for the Log Router can currently only be configured
2639 for Google Cloud organizations. Once configured, it applies to
2640 all projects and folders in the Google Cloud organization.
2641
2642 [UpdateCmekSettings][google.logging.v2.ConfigServiceV2.UpdateCmekSettings]
2643 will fail if 1) ``kms_key_name`` is invalid, or 2) the
2644 associated service account does not have the required
2645 ``roles/cloudkms.cryptoKeyEncrypterDecrypter`` role assigned for
2646 the key, or 3) access to the key is disabled.
2647
2648 See `Enabling CMEK for Log
2649 Router <https://cloud.google.com/logging/docs/routing/managed-encryption>`__
2650 for more information.
2651
2652 .. code-block:: python
2653
2654 # This snippet has been automatically generated and should be regarded as a
2655 # code template only.
2656 # It will require modifications to work:
2657 # - It may require correct/in-range values for request initialization.
2658 # - It may require specifying regional endpoints when creating the service
2659 # client as shown in:
2660 # https://googleapis.dev/python/google-api-core/latest/client_options.html
2661 from google.cloud import logging_v2
2662
2663 async def sample_update_cmek_settings():
2664 # Create a client
2665 client = logging_v2.ConfigServiceV2AsyncClient()
2666
2667 # Initialize request argument(s)
2668 request = logging_v2.UpdateCmekSettingsRequest(
2669 name="name_value",
2670 )
2671
2672 # Make the request
2673 response = await client.update_cmek_settings(request=request)
2674
2675 # Handle the response
2676 print(response)
2677
2678 Args:
2679 request (Optional[Union[google.cloud.logging_v2.types.UpdateCmekSettingsRequest, dict]]):
2680 The request object. The parameters to
2681 [UpdateCmekSettings][google.logging.v2.ConfigServiceV2.UpdateCmekSettings].
2682
2683 See `Enabling CMEK for Log
2684 Router <https://cloud.google.com/logging/docs/routing/managed-encryption>`__
2685 for more information.
2686 retry (google.api_core.retry.Retry): Designation of what errors, if any,
2687 should be retried.
2688 timeout (float): The timeout for this request.
2689 metadata (Sequence[Tuple[str, str]]): Strings which should be
2690 sent along with the request as metadata.
2691
2692 Returns:
2693 google.cloud.logging_v2.types.CmekSettings:
2694 Describes the customer-managed encryption key (CMEK) settings associated with
2695 a project, folder, organization, billing account, or
2696 flexible resource.
2697
2698 Note: CMEK for the Log Router can currently only be
2699 configured for Google Cloud organizations. Once
2700 configured, it applies to all projects and folders in
2701 the Google Cloud organization.
2702
2703 See [Enabling CMEK for Log
2704 Router](\ https://cloud.google.com/logging/docs/routing/managed-encryption)
2705 for more information.
2706
2707 """
2708 # Create or coerce a protobuf request object.
2709 request = logging_config.UpdateCmekSettingsRequest(request)
2710
2711 # Wrap the RPC method; this adds retry and timeout information,
2712 # and friendly error handling.
2713 rpc = gapic_v1.method_async.wrap_method(
2714 self._client._transport.update_cmek_settings,
2715 default_timeout=None,
2716 client_info=DEFAULT_CLIENT_INFO,
2717 )
2718
2719 # Certain fields should be provided within the metadata header;
2720 # add these here.
2721 metadata = tuple(metadata) + (
2722 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
2723 )
2724
2725 # Send the request.
2726 response = await rpc(
2727 request,
2728 retry=retry,
2729 timeout=timeout,
2730 metadata=metadata,
2731 )
2732
2733 # Done; return the response.
2734 return response
2735
2736 async def get_settings(
2737 self,
2738 request: Optional[Union[logging_config.GetSettingsRequest, dict]] = None,
2739 *,
2740 name: Optional[str] = None,
2741 retry: OptionalRetry = gapic_v1.method.DEFAULT,
2742 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
2743 metadata: Sequence[Tuple[str, str]] = (),
2744 ) -> logging_config.Settings:
2745 r"""Gets the Log Router settings for the given resource.
2746
2747 Note: Settings for the Log Router can be get for Google Cloud
2748 projects, folders, organizations and billing accounts. Currently
2749 it can only be configured for organizations. Once configured for
2750 an organization, it applies to all projects and folders in the
2751 Google Cloud organization.
2752
2753 See `Enabling CMEK for Log
2754 Router <https://cloud.google.com/logging/docs/routing/managed-encryption>`__
2755 for more information.
2756
2757 .. code-block:: python
2758
2759 # This snippet has been automatically generated and should be regarded as a
2760 # code template only.
2761 # It will require modifications to work:
2762 # - It may require correct/in-range values for request initialization.
2763 # - It may require specifying regional endpoints when creating the service
2764 # client as shown in:
2765 # https://googleapis.dev/python/google-api-core/latest/client_options.html
2766 from google.cloud import logging_v2
2767
2768 async def sample_get_settings():
2769 # Create a client
2770 client = logging_v2.ConfigServiceV2AsyncClient()
2771
2772 # Initialize request argument(s)
2773 request = logging_v2.GetSettingsRequest(
2774 name="name_value",
2775 )
2776
2777 # Make the request
2778 response = await client.get_settings(request=request)
2779
2780 # Handle the response
2781 print(response)
2782
2783 Args:
2784 request (Optional[Union[google.cloud.logging_v2.types.GetSettingsRequest, dict]]):
2785 The request object. The parameters to
2786 [GetSettings][google.logging.v2.ConfigServiceV2.GetSettings].
2787
2788 See `Enabling CMEK for Log
2789 Router <https://cloud.google.com/logging/docs/routing/managed-encryption>`__
2790 for more information.
2791 name (:class:`str`):
2792 Required. The resource for which to retrieve settings.
2793
2794 ::
2795
2796 "projects/[PROJECT_ID]/settings"
2797 "organizations/[ORGANIZATION_ID]/settings"
2798 "billingAccounts/[BILLING_ACCOUNT_ID]/settings"
2799 "folders/[FOLDER_ID]/settings"
2800
2801 For example:
2802
2803 ``"organizations/12345/settings"``
2804
2805 Note: Settings for the Log Router can be get for Google
2806 Cloud projects, folders, organizations and billing
2807 accounts. Currently it can only be configured for
2808 organizations. Once configured for an organization, it
2809 applies to all projects and folders in the Google Cloud
2810 organization.
2811
2812 This corresponds to the ``name`` field
2813 on the ``request`` instance; if ``request`` is provided, this
2814 should not be set.
2815 retry (google.api_core.retry.Retry): Designation of what errors, if any,
2816 should be retried.
2817 timeout (float): The timeout for this request.
2818 metadata (Sequence[Tuple[str, str]]): Strings which should be
2819 sent along with the request as metadata.
2820
2821 Returns:
2822 google.cloud.logging_v2.types.Settings:
2823 Describes the settings associated
2824 with a project, folder, organization,
2825 billing account, or flexible resource.
2826
2827 """
2828 # Create or coerce a protobuf request object.
2829 # Quick check: If we got a request object, we should *not* have
2830 # gotten any keyword arguments that map to the request.
2831 has_flattened_params = any([name])
2832 if request is not None and has_flattened_params:
2833 raise ValueError(
2834 "If the `request` argument is set, then none of "
2835 "the individual field arguments should be set."
2836 )
2837
2838 request = logging_config.GetSettingsRequest(request)
2839
2840 # If we have keyword arguments corresponding to fields on the
2841 # request, apply these.
2842 if name is not None:
2843 request.name = name
2844
2845 # Wrap the RPC method; this adds retry and timeout information,
2846 # and friendly error handling.
2847 rpc = gapic_v1.method_async.wrap_method(
2848 self._client._transport.get_settings,
2849 default_timeout=None,
2850 client_info=DEFAULT_CLIENT_INFO,
2851 )
2852
2853 # Certain fields should be provided within the metadata header;
2854 # add these here.
2855 metadata = tuple(metadata) + (
2856 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
2857 )
2858
2859 # Send the request.
2860 response = await rpc(
2861 request,
2862 retry=retry,
2863 timeout=timeout,
2864 metadata=metadata,
2865 )
2866
2867 # Done; return the response.
2868 return response
2869
2870 async def update_settings(
2871 self,
2872 request: Optional[Union[logging_config.UpdateSettingsRequest, dict]] = None,
2873 *,
2874 settings: Optional[logging_config.Settings] = None,
2875 update_mask: Optional[field_mask_pb2.FieldMask] = None,
2876 retry: OptionalRetry = gapic_v1.method.DEFAULT,
2877 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
2878 metadata: Sequence[Tuple[str, str]] = (),
2879 ) -> logging_config.Settings:
2880 r"""Updates the Log Router settings for the given resource.
2881
2882 Note: Settings for the Log Router can currently only be
2883 configured for Google Cloud organizations. Once configured, it
2884 applies to all projects and folders in the Google Cloud
2885 organization.
2886
2887 [UpdateSettings][google.logging.v2.ConfigServiceV2.UpdateSettings]
2888 will fail if 1) ``kms_key_name`` is invalid, or 2) the
2889 associated service account does not have the required
2890 ``roles/cloudkms.cryptoKeyEncrypterDecrypter`` role assigned for
2891 the key, or 3) access to the key is disabled. 4) ``location_id``
2892 is not supported by Logging. 5) ``location_id`` violate
2893 OrgPolicy.
2894
2895 See `Enabling CMEK for Log
2896 Router <https://cloud.google.com/logging/docs/routing/managed-encryption>`__
2897 for more information.
2898
2899 .. code-block:: python
2900
2901 # This snippet has been automatically generated and should be regarded as a
2902 # code template only.
2903 # It will require modifications to work:
2904 # - It may require correct/in-range values for request initialization.
2905 # - It may require specifying regional endpoints when creating the service
2906 # client as shown in:
2907 # https://googleapis.dev/python/google-api-core/latest/client_options.html
2908 from google.cloud import logging_v2
2909
2910 async def sample_update_settings():
2911 # Create a client
2912 client = logging_v2.ConfigServiceV2AsyncClient()
2913
2914 # Initialize request argument(s)
2915 request = logging_v2.UpdateSettingsRequest(
2916 name="name_value",
2917 )
2918
2919 # Make the request
2920 response = await client.update_settings(request=request)
2921
2922 # Handle the response
2923 print(response)
2924
2925 Args:
2926 request (Optional[Union[google.cloud.logging_v2.types.UpdateSettingsRequest, dict]]):
2927 The request object. The parameters to
2928 [UpdateSettings][google.logging.v2.ConfigServiceV2.UpdateSettings].
2929
2930 See `Enabling CMEK for Log
2931 Router <https://cloud.google.com/logging/docs/routing/managed-encryption>`__
2932 for more information.
2933 settings (:class:`google.cloud.logging_v2.types.Settings`):
2934 Required. The settings to update.
2935
2936 See `Enabling CMEK for Log
2937 Router <https://cloud.google.com/logging/docs/routing/managed-encryption>`__
2938 for more information.
2939
2940 This corresponds to the ``settings`` field
2941 on the ``request`` instance; if ``request`` is provided, this
2942 should not be set.
2943 update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`):
2944 Optional. Field mask identifying which fields from
2945 ``settings`` should be updated. A field will be
2946 overwritten if and only if it is in the update mask.
2947 Output only fields cannot be updated.
2948
2949 See [FieldMask][google.protobuf.FieldMask] for more
2950 information.
2951
2952 For example: ``"updateMask=kmsKeyName"``
2953
2954 This corresponds to the ``update_mask`` field
2955 on the ``request`` instance; if ``request`` is provided, this
2956 should not be set.
2957 retry (google.api_core.retry.Retry): Designation of what errors, if any,
2958 should be retried.
2959 timeout (float): The timeout for this request.
2960 metadata (Sequence[Tuple[str, str]]): Strings which should be
2961 sent along with the request as metadata.
2962
2963 Returns:
2964 google.cloud.logging_v2.types.Settings:
2965 Describes the settings associated
2966 with a project, folder, organization,
2967 billing account, or flexible resource.
2968
2969 """
2970 # Create or coerce a protobuf request object.
2971 # Quick check: If we got a request object, we should *not* have
2972 # gotten any keyword arguments that map to the request.
2973 has_flattened_params = any([settings, update_mask])
2974 if request is not None and has_flattened_params:
2975 raise ValueError(
2976 "If the `request` argument is set, then none of "
2977 "the individual field arguments should be set."
2978 )
2979
2980 request = logging_config.UpdateSettingsRequest(request)
2981
2982 # If we have keyword arguments corresponding to fields on the
2983 # request, apply these.
2984 if settings is not None:
2985 request.settings = settings
2986 if update_mask is not None:
2987 request.update_mask = update_mask
2988
2989 # Wrap the RPC method; this adds retry and timeout information,
2990 # and friendly error handling.
2991 rpc = gapic_v1.method_async.wrap_method(
2992 self._client._transport.update_settings,
2993 default_timeout=None,
2994 client_info=DEFAULT_CLIENT_INFO,
2995 )
2996
2997 # Certain fields should be provided within the metadata header;
2998 # add these here.
2999 metadata = tuple(metadata) + (
3000 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
3001 )
3002
3003 # Send the request.
3004 response = await rpc(
3005 request,
3006 retry=retry,
3007 timeout=timeout,
3008 metadata=metadata,
3009 )
3010
3011 # Done; return the response.
3012 return response
3013
3014 async def copy_log_entries(
3015 self,
3016 request: Optional[Union[logging_config.CopyLogEntriesRequest, dict]] = None,
3017 *,
3018 retry: OptionalRetry = gapic_v1.method.DEFAULT,
3019 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
3020 metadata: Sequence[Tuple[str, str]] = (),
3021 ) -> operation_async.AsyncOperation:
3022 r"""Copies a set of log entries from a log bucket to a
3023 Cloud Storage bucket.
3024
3025 .. code-block:: python
3026
3027 # This snippet has been automatically generated and should be regarded as a
3028 # code template only.
3029 # It will require modifications to work:
3030 # - It may require correct/in-range values for request initialization.
3031 # - It may require specifying regional endpoints when creating the service
3032 # client as shown in:
3033 # https://googleapis.dev/python/google-api-core/latest/client_options.html
3034 from google.cloud import logging_v2
3035
3036 async def sample_copy_log_entries():
3037 # Create a client
3038 client = logging_v2.ConfigServiceV2AsyncClient()
3039
3040 # Initialize request argument(s)
3041 request = logging_v2.CopyLogEntriesRequest(
3042 name="name_value",
3043 destination="destination_value",
3044 )
3045
3046 # Make the request
3047 operation = client.copy_log_entries(request=request)
3048
3049 print("Waiting for operation to complete...")
3050
3051 response = (await operation).result()
3052
3053 # Handle the response
3054 print(response)
3055
3056 Args:
3057 request (Optional[Union[google.cloud.logging_v2.types.CopyLogEntriesRequest, dict]]):
3058 The request object. The parameters to CopyLogEntries.
3059 retry (google.api_core.retry.Retry): Designation of what errors, if any,
3060 should be retried.
3061 timeout (float): The timeout for this request.
3062 metadata (Sequence[Tuple[str, str]]): Strings which should be
3063 sent along with the request as metadata.
3064
3065 Returns:
3066 google.api_core.operation_async.AsyncOperation:
3067 An object representing a long-running operation.
3068
3069 The result type for the operation will be
3070 :class:`google.cloud.logging_v2.types.CopyLogEntriesResponse`
3071 Response type for CopyLogEntries long running
3072 operations.
3073
3074 """
3075 # Create or coerce a protobuf request object.
3076 request = logging_config.CopyLogEntriesRequest(request)
3077
3078 # Wrap the RPC method; this adds retry and timeout information,
3079 # and friendly error handling.
3080 rpc = gapic_v1.method_async.wrap_method(
3081 self._client._transport.copy_log_entries,
3082 default_timeout=None,
3083 client_info=DEFAULT_CLIENT_INFO,
3084 )
3085
3086 # Send the request.
3087 response = await rpc(
3088 request,
3089 retry=retry,
3090 timeout=timeout,
3091 metadata=metadata,
3092 )
3093
3094 # Wrap the response in an operation future.
3095 response = operation_async.from_gapic(
3096 response,
3097 self._client._transport.operations_client,
3098 logging_config.CopyLogEntriesResponse,
3099 metadata_type=logging_config.CopyLogEntriesMetadata,
3100 )
3101
3102 # Done; return the response.
3103 return response
3104
3105 async def __aenter__(self):
3106 return self
3107
3108 async def __aexit__(self, exc_type, exc, tb):
3109 await self.transport.close()
3110
3111
3112DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
3113 gapic_version=package_version.__version__
3114)
3115
3116
3117__all__ = ("ConfigServiceV2AsyncClient",)