Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/google/cloud/logging_v2/services/config_service_v2/client.py: 28%
453 statements
« prev ^ index » next coverage.py v7.2.2, created at 2023-03-26 07:30 +0000
« prev ^ index » next coverage.py v7.2.2, created at 2023-03-26 07:30 +0000
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 os
18import re
19from typing import (
20 Dict,
21 Mapping,
22 MutableMapping,
23 MutableSequence,
24 Optional,
25 Sequence,
26 Tuple,
27 Type,
28 Union,
29 cast,
30)
32from google.cloud.logging_v2 import gapic_version as package_version
34from google.api_core import client_options as client_options_lib
35from google.api_core import exceptions as core_exceptions
36from google.api_core import gapic_v1
37from google.api_core import retry as retries
38from google.auth import credentials as ga_credentials # type: ignore
39from google.auth.transport import mtls # type: ignore
40from google.auth.transport.grpc import SslCredentials # type: ignore
41from google.auth.exceptions import MutualTLSChannelError # type: ignore
42from google.oauth2 import service_account # type: ignore
44try:
45 OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault]
46except AttributeError: # pragma: NO COVER
47 OptionalRetry = Union[retries.Retry, object] # type: ignore
49from google.api_core import operation # type: ignore
50from google.api_core import operation_async # type: ignore
51from google.cloud.logging_v2.services.config_service_v2 import pagers
52from google.cloud.logging_v2.types import logging_config
53from google.protobuf import field_mask_pb2 # type: ignore
54from google.protobuf import timestamp_pb2 # type: ignore
55from .transports.base import ConfigServiceV2Transport, DEFAULT_CLIENT_INFO
56from .transports.grpc import ConfigServiceV2GrpcTransport
57from .transports.grpc_asyncio import ConfigServiceV2GrpcAsyncIOTransport
60class ConfigServiceV2ClientMeta(type):
61 """Metaclass for the ConfigServiceV2 client.
63 This provides class-level methods for building and retrieving
64 support objects (e.g. transport) without polluting the client instance
65 objects.
66 """
68 _transport_registry = (
69 OrderedDict()
70 ) # type: Dict[str, Type[ConfigServiceV2Transport]]
71 _transport_registry["grpc"] = ConfigServiceV2GrpcTransport
72 _transport_registry["grpc_asyncio"] = ConfigServiceV2GrpcAsyncIOTransport
74 def get_transport_class(
75 cls,
76 label: Optional[str] = None,
77 ) -> Type[ConfigServiceV2Transport]:
78 """Returns an appropriate transport class.
80 Args:
81 label: The name of the desired transport. If none is
82 provided, then the first transport in the registry is used.
84 Returns:
85 The transport class to use.
86 """
87 # If a specific transport is requested, return that one.
88 if label:
89 return cls._transport_registry[label]
91 # No transport is requested; return the default (that is, the first one
92 # in the dictionary).
93 return next(iter(cls._transport_registry.values()))
96class ConfigServiceV2Client(metaclass=ConfigServiceV2ClientMeta):
97 """Service for configuring sinks used to route log entries."""
99 @staticmethod
100 def _get_default_mtls_endpoint(api_endpoint):
101 """Converts api endpoint to mTLS endpoint.
103 Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to
104 "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively.
105 Args:
106 api_endpoint (Optional[str]): the api endpoint to convert.
107 Returns:
108 str: converted mTLS api endpoint.
109 """
110 if not api_endpoint:
111 return api_endpoint
113 mtls_endpoint_re = re.compile(
114 r"(?P<name>[^.]+)(?P<mtls>\.mtls)?(?P<sandbox>\.sandbox)?(?P<googledomain>\.googleapis\.com)?"
115 )
117 m = mtls_endpoint_re.match(api_endpoint)
118 name, mtls, sandbox, googledomain = m.groups()
119 if mtls or not googledomain:
120 return api_endpoint
122 if sandbox:
123 return api_endpoint.replace(
124 "sandbox.googleapis.com", "mtls.sandbox.googleapis.com"
125 )
127 return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com")
129 DEFAULT_ENDPOINT = "logging.googleapis.com"
130 DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore
131 DEFAULT_ENDPOINT
132 )
134 @classmethod
135 def from_service_account_info(cls, info: dict, *args, **kwargs):
136 """Creates an instance of this client using the provided credentials
137 info.
139 Args:
140 info (dict): The service account private key info.
141 args: Additional arguments to pass to the constructor.
142 kwargs: Additional arguments to pass to the constructor.
144 Returns:
145 ConfigServiceV2Client: The constructed client.
146 """
147 credentials = service_account.Credentials.from_service_account_info(info)
148 kwargs["credentials"] = credentials
149 return cls(*args, **kwargs)
151 @classmethod
152 def from_service_account_file(cls, filename: str, *args, **kwargs):
153 """Creates an instance of this client using the provided credentials
154 file.
156 Args:
157 filename (str): The path to the service account private key json
158 file.
159 args: Additional arguments to pass to the constructor.
160 kwargs: Additional arguments to pass to the constructor.
162 Returns:
163 ConfigServiceV2Client: The constructed client.
164 """
165 credentials = service_account.Credentials.from_service_account_file(filename)
166 kwargs["credentials"] = credentials
167 return cls(*args, **kwargs)
169 from_service_account_json = from_service_account_file
171 @property
172 def transport(self) -> ConfigServiceV2Transport:
173 """Returns the transport used by the client instance.
175 Returns:
176 ConfigServiceV2Transport: The transport used by the client
177 instance.
178 """
179 return self._transport
181 @staticmethod
182 def cmek_settings_path(
183 project: str,
184 ) -> str:
185 """Returns a fully-qualified cmek_settings string."""
186 return "projects/{project}/cmekSettings".format(
187 project=project,
188 )
190 @staticmethod
191 def parse_cmek_settings_path(path: str) -> Dict[str, str]:
192 """Parses a cmek_settings path into its component segments."""
193 m = re.match(r"^projects/(?P<project>.+?)/cmekSettings$", path)
194 return m.groupdict() if m else {}
196 @staticmethod
197 def log_bucket_path(
198 project: str,
199 location: str,
200 bucket: str,
201 ) -> str:
202 """Returns a fully-qualified log_bucket string."""
203 return "projects/{project}/locations/{location}/buckets/{bucket}".format(
204 project=project,
205 location=location,
206 bucket=bucket,
207 )
209 @staticmethod
210 def parse_log_bucket_path(path: str) -> Dict[str, str]:
211 """Parses a log_bucket path into its component segments."""
212 m = re.match(
213 r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)/buckets/(?P<bucket>.+?)$",
214 path,
215 )
216 return m.groupdict() if m else {}
218 @staticmethod
219 def log_exclusion_path(
220 project: str,
221 exclusion: str,
222 ) -> str:
223 """Returns a fully-qualified log_exclusion string."""
224 return "projects/{project}/exclusions/{exclusion}".format(
225 project=project,
226 exclusion=exclusion,
227 )
229 @staticmethod
230 def parse_log_exclusion_path(path: str) -> Dict[str, str]:
231 """Parses a log_exclusion path into its component segments."""
232 m = re.match(r"^projects/(?P<project>.+?)/exclusions/(?P<exclusion>.+?)$", path)
233 return m.groupdict() if m else {}
235 @staticmethod
236 def log_sink_path(
237 project: str,
238 sink: str,
239 ) -> str:
240 """Returns a fully-qualified log_sink string."""
241 return "projects/{project}/sinks/{sink}".format(
242 project=project,
243 sink=sink,
244 )
246 @staticmethod
247 def parse_log_sink_path(path: str) -> Dict[str, str]:
248 """Parses a log_sink path into its component segments."""
249 m = re.match(r"^projects/(?P<project>.+?)/sinks/(?P<sink>.+?)$", path)
250 return m.groupdict() if m else {}
252 @staticmethod
253 def log_view_path(
254 project: str,
255 location: str,
256 bucket: str,
257 view: str,
258 ) -> str:
259 """Returns a fully-qualified log_view string."""
260 return "projects/{project}/locations/{location}/buckets/{bucket}/views/{view}".format(
261 project=project,
262 location=location,
263 bucket=bucket,
264 view=view,
265 )
267 @staticmethod
268 def parse_log_view_path(path: str) -> Dict[str, str]:
269 """Parses a log_view path into its component segments."""
270 m = re.match(
271 r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)/buckets/(?P<bucket>.+?)/views/(?P<view>.+?)$",
272 path,
273 )
274 return m.groupdict() if m else {}
276 @staticmethod
277 def settings_path(
278 project: str,
279 ) -> str:
280 """Returns a fully-qualified settings string."""
281 return "projects/{project}/settings".format(
282 project=project,
283 )
285 @staticmethod
286 def parse_settings_path(path: str) -> Dict[str, str]:
287 """Parses a settings path into its component segments."""
288 m = re.match(r"^projects/(?P<project>.+?)/settings$", path)
289 return m.groupdict() if m else {}
291 @staticmethod
292 def common_billing_account_path(
293 billing_account: str,
294 ) -> str:
295 """Returns a fully-qualified billing_account string."""
296 return "billingAccounts/{billing_account}".format(
297 billing_account=billing_account,
298 )
300 @staticmethod
301 def parse_common_billing_account_path(path: str) -> Dict[str, str]:
302 """Parse a billing_account path into its component segments."""
303 m = re.match(r"^billingAccounts/(?P<billing_account>.+?)$", path)
304 return m.groupdict() if m else {}
306 @staticmethod
307 def common_folder_path(
308 folder: str,
309 ) -> str:
310 """Returns a fully-qualified folder string."""
311 return "folders/{folder}".format(
312 folder=folder,
313 )
315 @staticmethod
316 def parse_common_folder_path(path: str) -> Dict[str, str]:
317 """Parse a folder path into its component segments."""
318 m = re.match(r"^folders/(?P<folder>.+?)$", path)
319 return m.groupdict() if m else {}
321 @staticmethod
322 def common_organization_path(
323 organization: str,
324 ) -> str:
325 """Returns a fully-qualified organization string."""
326 return "organizations/{organization}".format(
327 organization=organization,
328 )
330 @staticmethod
331 def parse_common_organization_path(path: str) -> Dict[str, str]:
332 """Parse a organization path into its component segments."""
333 m = re.match(r"^organizations/(?P<organization>.+?)$", path)
334 return m.groupdict() if m else {}
336 @staticmethod
337 def common_project_path(
338 project: str,
339 ) -> str:
340 """Returns a fully-qualified project string."""
341 return "projects/{project}".format(
342 project=project,
343 )
345 @staticmethod
346 def parse_common_project_path(path: str) -> Dict[str, str]:
347 """Parse a project path into its component segments."""
348 m = re.match(r"^projects/(?P<project>.+?)$", path)
349 return m.groupdict() if m else {}
351 @staticmethod
352 def common_location_path(
353 project: str,
354 location: str,
355 ) -> str:
356 """Returns a fully-qualified location string."""
357 return "projects/{project}/locations/{location}".format(
358 project=project,
359 location=location,
360 )
362 @staticmethod
363 def parse_common_location_path(path: str) -> Dict[str, str]:
364 """Parse a location path into its component segments."""
365 m = re.match(r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)$", path)
366 return m.groupdict() if m else {}
368 @classmethod
369 def get_mtls_endpoint_and_cert_source(
370 cls, client_options: Optional[client_options_lib.ClientOptions] = None
371 ):
372 """Return the API endpoint and client cert source for mutual TLS.
374 The client cert source is determined in the following order:
375 (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the
376 client cert source is None.
377 (2) if `client_options.client_cert_source` is provided, use the provided one; if the
378 default client cert source exists, use the default one; otherwise the client cert
379 source is None.
381 The API endpoint is determined in the following order:
382 (1) if `client_options.api_endpoint` if provided, use the provided one.
383 (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the
384 default mTLS endpoint; if the environment variable is "never", use the default API
385 endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise
386 use the default API endpoint.
388 More details can be found at https://google.aip.dev/auth/4114.
390 Args:
391 client_options (google.api_core.client_options.ClientOptions): Custom options for the
392 client. Only the `api_endpoint` and `client_cert_source` properties may be used
393 in this method.
395 Returns:
396 Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the
397 client cert source to use.
399 Raises:
400 google.auth.exceptions.MutualTLSChannelError: If any errors happen.
401 """
402 if client_options is None:
403 client_options = client_options_lib.ClientOptions()
404 use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")
405 use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto")
406 if use_client_cert not in ("true", "false"):
407 raise ValueError(
408 "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
409 )
410 if use_mtls_endpoint not in ("auto", "never", "always"):
411 raise MutualTLSChannelError(
412 "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
413 )
415 # Figure out the client cert source to use.
416 client_cert_source = None
417 if use_client_cert == "true":
418 if client_options.client_cert_source:
419 client_cert_source = client_options.client_cert_source
420 elif mtls.has_default_client_cert_source():
421 client_cert_source = mtls.default_client_cert_source()
423 # Figure out which api endpoint to use.
424 if client_options.api_endpoint is not None:
425 api_endpoint = client_options.api_endpoint
426 elif use_mtls_endpoint == "always" or (
427 use_mtls_endpoint == "auto" and client_cert_source
428 ):
429 api_endpoint = cls.DEFAULT_MTLS_ENDPOINT
430 else:
431 api_endpoint = cls.DEFAULT_ENDPOINT
433 return api_endpoint, client_cert_source
435 def __init__(
436 self,
437 *,
438 credentials: Optional[ga_credentials.Credentials] = None,
439 transport: Optional[Union[str, ConfigServiceV2Transport]] = None,
440 client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None,
441 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
442 ) -> None:
443 """Instantiates the config service v2 client.
445 Args:
446 credentials (Optional[google.auth.credentials.Credentials]): The
447 authorization credentials to attach to requests. These
448 credentials identify the application to the service; if none
449 are specified, the client will attempt to ascertain the
450 credentials from the environment.
451 transport (Union[str, ConfigServiceV2Transport]): The
452 transport to use. If set to None, a transport is chosen
453 automatically.
454 client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]): Custom options for the
455 client. It won't take effect if a ``transport`` instance is provided.
456 (1) The ``api_endpoint`` property can be used to override the
457 default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT
458 environment variable can also be used to override the endpoint:
459 "always" (always use the default mTLS endpoint), "never" (always
460 use the default regular endpoint) and "auto" (auto switch to the
461 default mTLS endpoint if client certificate is present, this is
462 the default value). However, the ``api_endpoint`` property takes
463 precedence if provided.
464 (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable
465 is "true", then the ``client_cert_source`` property can be used
466 to provide client certificate for mutual TLS transport. If
467 not provided, the default SSL client certificate will be used if
468 present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not
469 set, no client certificate will be used.
470 client_info (google.api_core.gapic_v1.client_info.ClientInfo):
471 The client info used to send a user-agent string along with
472 API requests. If ``None``, then default info will be used.
473 Generally, you only need to set this if you're developing
474 your own client library.
476 Raises:
477 google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
478 creation failed for any reason.
479 """
480 if isinstance(client_options, dict):
481 client_options = client_options_lib.from_dict(client_options)
482 if client_options is None:
483 client_options = client_options_lib.ClientOptions()
484 client_options = cast(client_options_lib.ClientOptions, client_options)
486 api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source(
487 client_options
488 )
490 api_key_value = getattr(client_options, "api_key", None)
491 if api_key_value and credentials:
492 raise ValueError(
493 "client_options.api_key and credentials are mutually exclusive"
494 )
496 # Save or instantiate the transport.
497 # Ordinarily, we provide the transport, but allowing a custom transport
498 # instance provides an extensibility point for unusual situations.
499 if isinstance(transport, ConfigServiceV2Transport):
500 # transport is a ConfigServiceV2Transport instance.
501 if credentials or client_options.credentials_file or api_key_value:
502 raise ValueError(
503 "When providing a transport instance, "
504 "provide its credentials directly."
505 )
506 if client_options.scopes:
507 raise ValueError(
508 "When providing a transport instance, provide its scopes "
509 "directly."
510 )
511 self._transport = transport
512 else:
513 import google.auth._default # type: ignore
515 if api_key_value and hasattr(
516 google.auth._default, "get_api_key_credentials"
517 ):
518 credentials = google.auth._default.get_api_key_credentials(
519 api_key_value
520 )
522 Transport = type(self).get_transport_class(transport)
523 self._transport = Transport(
524 credentials=credentials,
525 credentials_file=client_options.credentials_file,
526 host=api_endpoint,
527 scopes=client_options.scopes,
528 client_cert_source_for_mtls=client_cert_source_func,
529 quota_project_id=client_options.quota_project_id,
530 client_info=client_info,
531 always_use_jwt_access=True,
532 api_audience=client_options.api_audience,
533 )
535 def list_buckets(
536 self,
537 request: Optional[Union[logging_config.ListBucketsRequest, dict]] = None,
538 *,
539 parent: Optional[str] = None,
540 retry: OptionalRetry = gapic_v1.method.DEFAULT,
541 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
542 metadata: Sequence[Tuple[str, str]] = (),
543 ) -> pagers.ListBucketsPager:
544 r"""Lists log buckets.
546 .. code-block:: python
548 # This snippet has been automatically generated and should be regarded as a
549 # code template only.
550 # It will require modifications to work:
551 # - It may require correct/in-range values for request initialization.
552 # - It may require specifying regional endpoints when creating the service
553 # client as shown in:
554 # https://googleapis.dev/python/google-api-core/latest/client_options.html
555 from google.cloud import logging_v2
557 def sample_list_buckets():
558 # Create a client
559 client = logging_v2.ConfigServiceV2Client()
561 # Initialize request argument(s)
562 request = logging_v2.ListBucketsRequest(
563 parent="parent_value",
564 )
566 # Make the request
567 page_result = client.list_buckets(request=request)
569 # Handle the response
570 for response in page_result:
571 print(response)
573 Args:
574 request (Union[google.cloud.logging_v2.types.ListBucketsRequest, dict]):
575 The request object. The parameters to `ListBuckets`.
576 parent (str):
577 Required. The parent resource whose buckets are to be
578 listed:
580 ::
582 "projects/[PROJECT_ID]/locations/[LOCATION_ID]"
583 "organizations/[ORGANIZATION_ID]/locations/[LOCATION_ID]"
584 "billingAccounts/[BILLING_ACCOUNT_ID]/locations/[LOCATION_ID]"
585 "folders/[FOLDER_ID]/locations/[LOCATION_ID]"
587 Note: The locations portion of the resource must be
588 specified, but supplying the character ``-`` in place of
589 [LOCATION_ID] will return all buckets.
591 This corresponds to the ``parent`` field
592 on the ``request`` instance; if ``request`` is provided, this
593 should not be set.
594 retry (google.api_core.retry.Retry): Designation of what errors, if any,
595 should be retried.
596 timeout (float): The timeout for this request.
597 metadata (Sequence[Tuple[str, str]]): Strings which should be
598 sent along with the request as metadata.
600 Returns:
601 google.cloud.logging_v2.services.config_service_v2.pagers.ListBucketsPager:
602 The response from ListBuckets.
603 Iterating over this object will yield
604 results and resolve additional pages
605 automatically.
607 """
608 # Create or coerce a protobuf request object.
609 # Quick check: If we got a request object, we should *not* have
610 # gotten any keyword arguments that map to the request.
611 has_flattened_params = any([parent])
612 if request is not None and has_flattened_params:
613 raise ValueError(
614 "If the `request` argument is set, then none of "
615 "the individual field arguments should be set."
616 )
618 # Minor optimization to avoid making a copy if the user passes
619 # in a logging_config.ListBucketsRequest.
620 # There's no risk of modifying the input as we've already verified
621 # there are no flattened fields.
622 if not isinstance(request, logging_config.ListBucketsRequest):
623 request = logging_config.ListBucketsRequest(request)
624 # If we have keyword arguments corresponding to fields on the
625 # request, apply these.
626 if parent is not None:
627 request.parent = parent
629 # Wrap the RPC method; this adds retry and timeout information,
630 # and friendly error handling.
631 rpc = self._transport._wrapped_methods[self._transport.list_buckets]
633 # Certain fields should be provided within the metadata header;
634 # add these here.
635 metadata = tuple(metadata) + (
636 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
637 )
639 # Send the request.
640 response = rpc(
641 request,
642 retry=retry,
643 timeout=timeout,
644 metadata=metadata,
645 )
647 # This method is paged; wrap the response in a pager, which provides
648 # an `__iter__` convenience method.
649 response = pagers.ListBucketsPager(
650 method=rpc,
651 request=request,
652 response=response,
653 metadata=metadata,
654 )
656 # Done; return the response.
657 return response
659 def get_bucket(
660 self,
661 request: Optional[Union[logging_config.GetBucketRequest, dict]] = None,
662 *,
663 retry: OptionalRetry = gapic_v1.method.DEFAULT,
664 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
665 metadata: Sequence[Tuple[str, str]] = (),
666 ) -> logging_config.LogBucket:
667 r"""Gets a log bucket.
669 .. code-block:: python
671 # This snippet has been automatically generated and should be regarded as a
672 # code template only.
673 # It will require modifications to work:
674 # - It may require correct/in-range values for request initialization.
675 # - It may require specifying regional endpoints when creating the service
676 # client as shown in:
677 # https://googleapis.dev/python/google-api-core/latest/client_options.html
678 from google.cloud import logging_v2
680 def sample_get_bucket():
681 # Create a client
682 client = logging_v2.ConfigServiceV2Client()
684 # Initialize request argument(s)
685 request = logging_v2.GetBucketRequest(
686 name="name_value",
687 )
689 # Make the request
690 response = client.get_bucket(request=request)
692 # Handle the response
693 print(response)
695 Args:
696 request (Union[google.cloud.logging_v2.types.GetBucketRequest, dict]):
697 The request object. The parameters to `GetBucket`.
698 retry (google.api_core.retry.Retry): Designation of what errors, if any,
699 should be retried.
700 timeout (float): The timeout for this request.
701 metadata (Sequence[Tuple[str, str]]): Strings which should be
702 sent along with the request as metadata.
704 Returns:
705 google.cloud.logging_v2.types.LogBucket:
706 Describes a repository in which log
707 entries are stored.
709 """
710 # Create or coerce a protobuf request object.
711 # Minor optimization to avoid making a copy if the user passes
712 # in a logging_config.GetBucketRequest.
713 # There's no risk of modifying the input as we've already verified
714 # there are no flattened fields.
715 if not isinstance(request, logging_config.GetBucketRequest):
716 request = logging_config.GetBucketRequest(request)
718 # Wrap the RPC method; this adds retry and timeout information,
719 # and friendly error handling.
720 rpc = self._transport._wrapped_methods[self._transport.get_bucket]
722 # Certain fields should be provided within the metadata header;
723 # add these here.
724 metadata = tuple(metadata) + (
725 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
726 )
728 # Send the request.
729 response = rpc(
730 request,
731 retry=retry,
732 timeout=timeout,
733 metadata=metadata,
734 )
736 # Done; return the response.
737 return response
739 def create_bucket(
740 self,
741 request: Optional[Union[logging_config.CreateBucketRequest, dict]] = None,
742 *,
743 retry: OptionalRetry = gapic_v1.method.DEFAULT,
744 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
745 metadata: Sequence[Tuple[str, str]] = (),
746 ) -> logging_config.LogBucket:
747 r"""Creates a log bucket that can be used to store log
748 entries. After a bucket has been created, the bucket's
749 location cannot be changed.
751 .. code-block:: python
753 # This snippet has been automatically generated and should be regarded as a
754 # code template only.
755 # It will require modifications to work:
756 # - It may require correct/in-range values for request initialization.
757 # - It may require specifying regional endpoints when creating the service
758 # client as shown in:
759 # https://googleapis.dev/python/google-api-core/latest/client_options.html
760 from google.cloud import logging_v2
762 def sample_create_bucket():
763 # Create a client
764 client = logging_v2.ConfigServiceV2Client()
766 # Initialize request argument(s)
767 request = logging_v2.CreateBucketRequest(
768 parent="parent_value",
769 bucket_id="bucket_id_value",
770 )
772 # Make the request
773 response = client.create_bucket(request=request)
775 # Handle the response
776 print(response)
778 Args:
779 request (Union[google.cloud.logging_v2.types.CreateBucketRequest, dict]):
780 The request object. The parameters to `CreateBucket`.
781 retry (google.api_core.retry.Retry): Designation of what errors, if any,
782 should be retried.
783 timeout (float): The timeout for this request.
784 metadata (Sequence[Tuple[str, str]]): Strings which should be
785 sent along with the request as metadata.
787 Returns:
788 google.cloud.logging_v2.types.LogBucket:
789 Describes a repository in which log
790 entries are stored.
792 """
793 # Create or coerce a protobuf request object.
794 # Minor optimization to avoid making a copy if the user passes
795 # in a logging_config.CreateBucketRequest.
796 # There's no risk of modifying the input as we've already verified
797 # there are no flattened fields.
798 if not isinstance(request, logging_config.CreateBucketRequest):
799 request = logging_config.CreateBucketRequest(request)
801 # Wrap the RPC method; this adds retry and timeout information,
802 # and friendly error handling.
803 rpc = self._transport._wrapped_methods[self._transport.create_bucket]
805 # Certain fields should be provided within the metadata header;
806 # add these here.
807 metadata = tuple(metadata) + (
808 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
809 )
811 # Send the request.
812 response = rpc(
813 request,
814 retry=retry,
815 timeout=timeout,
816 metadata=metadata,
817 )
819 # Done; return the response.
820 return response
822 def update_bucket(
823 self,
824 request: Optional[Union[logging_config.UpdateBucketRequest, dict]] = None,
825 *,
826 retry: OptionalRetry = gapic_v1.method.DEFAULT,
827 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
828 metadata: Sequence[Tuple[str, str]] = (),
829 ) -> logging_config.LogBucket:
830 r"""Updates a log bucket. This method replaces the following fields
831 in the existing bucket with values from the new bucket:
832 ``retention_period``
834 If the retention period is decreased and the bucket is locked,
835 ``FAILED_PRECONDITION`` will be returned.
837 If the bucket has a ``lifecycle_state`` of ``DELETE_REQUESTED``,
838 then ``FAILED_PRECONDITION`` will be returned.
840 After a bucket has been created, the bucket's location cannot be
841 changed.
843 .. code-block:: python
845 # This snippet has been automatically generated and should be regarded as a
846 # code template only.
847 # It will require modifications to work:
848 # - It may require correct/in-range values for request initialization.
849 # - It may require specifying regional endpoints when creating the service
850 # client as shown in:
851 # https://googleapis.dev/python/google-api-core/latest/client_options.html
852 from google.cloud import logging_v2
854 def sample_update_bucket():
855 # Create a client
856 client = logging_v2.ConfigServiceV2Client()
858 # Initialize request argument(s)
859 request = logging_v2.UpdateBucketRequest(
860 name="name_value",
861 )
863 # Make the request
864 response = client.update_bucket(request=request)
866 # Handle the response
867 print(response)
869 Args:
870 request (Union[google.cloud.logging_v2.types.UpdateBucketRequest, dict]):
871 The request object. The parameters to `UpdateBucket`.
872 retry (google.api_core.retry.Retry): Designation of what errors, if any,
873 should be retried.
874 timeout (float): The timeout for this request.
875 metadata (Sequence[Tuple[str, str]]): Strings which should be
876 sent along with the request as metadata.
878 Returns:
879 google.cloud.logging_v2.types.LogBucket:
880 Describes a repository in which log
881 entries are stored.
883 """
884 # Create or coerce a protobuf request object.
885 # Minor optimization to avoid making a copy if the user passes
886 # in a logging_config.UpdateBucketRequest.
887 # There's no risk of modifying the input as we've already verified
888 # there are no flattened fields.
889 if not isinstance(request, logging_config.UpdateBucketRequest):
890 request = logging_config.UpdateBucketRequest(request)
892 # Wrap the RPC method; this adds retry and timeout information,
893 # and friendly error handling.
894 rpc = self._transport._wrapped_methods[self._transport.update_bucket]
896 # Certain fields should be provided within the metadata header;
897 # add these here.
898 metadata = tuple(metadata) + (
899 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
900 )
902 # Send the request.
903 response = rpc(
904 request,
905 retry=retry,
906 timeout=timeout,
907 metadata=metadata,
908 )
910 # Done; return the response.
911 return response
913 def delete_bucket(
914 self,
915 request: Optional[Union[logging_config.DeleteBucketRequest, dict]] = None,
916 *,
917 retry: OptionalRetry = gapic_v1.method.DEFAULT,
918 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
919 metadata: Sequence[Tuple[str, str]] = (),
920 ) -> None:
921 r"""Deletes a log bucket.
923 Changes the bucket's ``lifecycle_state`` to the
924 ``DELETE_REQUESTED`` state. After 7 days, the bucket will be
925 purged and all log entries in the bucket will be permanently
926 deleted.
928 .. code-block:: python
930 # This snippet has been automatically generated and should be regarded as a
931 # code template only.
932 # It will require modifications to work:
933 # - It may require correct/in-range values for request initialization.
934 # - It may require specifying regional endpoints when creating the service
935 # client as shown in:
936 # https://googleapis.dev/python/google-api-core/latest/client_options.html
937 from google.cloud import logging_v2
939 def sample_delete_bucket():
940 # Create a client
941 client = logging_v2.ConfigServiceV2Client()
943 # Initialize request argument(s)
944 request = logging_v2.DeleteBucketRequest(
945 name="name_value",
946 )
948 # Make the request
949 client.delete_bucket(request=request)
951 Args:
952 request (Union[google.cloud.logging_v2.types.DeleteBucketRequest, dict]):
953 The request object. The parameters to `DeleteBucket`.
954 retry (google.api_core.retry.Retry): Designation of what errors, if any,
955 should be retried.
956 timeout (float): The timeout for this request.
957 metadata (Sequence[Tuple[str, str]]): Strings which should be
958 sent along with the request as metadata.
959 """
960 # Create or coerce a protobuf request object.
961 # Minor optimization to avoid making a copy if the user passes
962 # in a logging_config.DeleteBucketRequest.
963 # There's no risk of modifying the input as we've already verified
964 # there are no flattened fields.
965 if not isinstance(request, logging_config.DeleteBucketRequest):
966 request = logging_config.DeleteBucketRequest(request)
968 # Wrap the RPC method; this adds retry and timeout information,
969 # and friendly error handling.
970 rpc = self._transport._wrapped_methods[self._transport.delete_bucket]
972 # Certain fields should be provided within the metadata header;
973 # add these here.
974 metadata = tuple(metadata) + (
975 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
976 )
978 # Send the request.
979 rpc(
980 request,
981 retry=retry,
982 timeout=timeout,
983 metadata=metadata,
984 )
986 def undelete_bucket(
987 self,
988 request: Optional[Union[logging_config.UndeleteBucketRequest, dict]] = None,
989 *,
990 retry: OptionalRetry = gapic_v1.method.DEFAULT,
991 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
992 metadata: Sequence[Tuple[str, str]] = (),
993 ) -> None:
994 r"""Undeletes a log bucket. A bucket that has been
995 deleted can be undeleted within the grace period of 7
996 days.
998 .. code-block:: python
1000 # This snippet has been automatically generated and should be regarded as a
1001 # code template only.
1002 # It will require modifications to work:
1003 # - It may require correct/in-range values for request initialization.
1004 # - It may require specifying regional endpoints when creating the service
1005 # client as shown in:
1006 # https://googleapis.dev/python/google-api-core/latest/client_options.html
1007 from google.cloud import logging_v2
1009 def sample_undelete_bucket():
1010 # Create a client
1011 client = logging_v2.ConfigServiceV2Client()
1013 # Initialize request argument(s)
1014 request = logging_v2.UndeleteBucketRequest(
1015 name="name_value",
1016 )
1018 # Make the request
1019 client.undelete_bucket(request=request)
1021 Args:
1022 request (Union[google.cloud.logging_v2.types.UndeleteBucketRequest, dict]):
1023 The request object. The parameters to `UndeleteBucket`.
1024 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1025 should be retried.
1026 timeout (float): The timeout for this request.
1027 metadata (Sequence[Tuple[str, str]]): Strings which should be
1028 sent along with the request as metadata.
1029 """
1030 # Create or coerce a protobuf request object.
1031 # Minor optimization to avoid making a copy if the user passes
1032 # in a logging_config.UndeleteBucketRequest.
1033 # There's no risk of modifying the input as we've already verified
1034 # there are no flattened fields.
1035 if not isinstance(request, logging_config.UndeleteBucketRequest):
1036 request = logging_config.UndeleteBucketRequest(request)
1038 # Wrap the RPC method; this adds retry and timeout information,
1039 # and friendly error handling.
1040 rpc = self._transport._wrapped_methods[self._transport.undelete_bucket]
1042 # Certain fields should be provided within the metadata header;
1043 # add these here.
1044 metadata = tuple(metadata) + (
1045 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1046 )
1048 # Send the request.
1049 rpc(
1050 request,
1051 retry=retry,
1052 timeout=timeout,
1053 metadata=metadata,
1054 )
1056 def list_views(
1057 self,
1058 request: Optional[Union[logging_config.ListViewsRequest, dict]] = None,
1059 *,
1060 parent: Optional[str] = None,
1061 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1062 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1063 metadata: Sequence[Tuple[str, str]] = (),
1064 ) -> pagers.ListViewsPager:
1065 r"""Lists views on a log bucket.
1067 .. code-block:: python
1069 # This snippet has been automatically generated and should be regarded as a
1070 # code template only.
1071 # It will require modifications to work:
1072 # - It may require correct/in-range values for request initialization.
1073 # - It may require specifying regional endpoints when creating the service
1074 # client as shown in:
1075 # https://googleapis.dev/python/google-api-core/latest/client_options.html
1076 from google.cloud import logging_v2
1078 def sample_list_views():
1079 # Create a client
1080 client = logging_v2.ConfigServiceV2Client()
1082 # Initialize request argument(s)
1083 request = logging_v2.ListViewsRequest(
1084 parent="parent_value",
1085 )
1087 # Make the request
1088 page_result = client.list_views(request=request)
1090 # Handle the response
1091 for response in page_result:
1092 print(response)
1094 Args:
1095 request (Union[google.cloud.logging_v2.types.ListViewsRequest, dict]):
1096 The request object. The parameters to `ListViews`.
1097 parent (str):
1098 Required. The bucket whose views are to be listed:
1100 ::
1102 "projects/[PROJECT_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]"
1104 This corresponds to the ``parent`` field
1105 on the ``request`` instance; if ``request`` is provided, this
1106 should not be set.
1107 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1108 should be retried.
1109 timeout (float): The timeout for this request.
1110 metadata (Sequence[Tuple[str, str]]): Strings which should be
1111 sent along with the request as metadata.
1113 Returns:
1114 google.cloud.logging_v2.services.config_service_v2.pagers.ListViewsPager:
1115 The response from ListViews.
1116 Iterating over this object will yield
1117 results and resolve additional pages
1118 automatically.
1120 """
1121 # Create or coerce a protobuf request object.
1122 # Quick check: If we got a request object, we should *not* have
1123 # gotten any keyword arguments that map to the request.
1124 has_flattened_params = any([parent])
1125 if request is not None and has_flattened_params:
1126 raise ValueError(
1127 "If the `request` argument is set, then none of "
1128 "the individual field arguments should be set."
1129 )
1131 # Minor optimization to avoid making a copy if the user passes
1132 # in a logging_config.ListViewsRequest.
1133 # There's no risk of modifying the input as we've already verified
1134 # there are no flattened fields.
1135 if not isinstance(request, logging_config.ListViewsRequest):
1136 request = logging_config.ListViewsRequest(request)
1137 # If we have keyword arguments corresponding to fields on the
1138 # request, apply these.
1139 if parent is not None:
1140 request.parent = parent
1142 # Wrap the RPC method; this adds retry and timeout information,
1143 # and friendly error handling.
1144 rpc = self._transport._wrapped_methods[self._transport.list_views]
1146 # Certain fields should be provided within the metadata header;
1147 # add these here.
1148 metadata = tuple(metadata) + (
1149 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
1150 )
1152 # Send the request.
1153 response = rpc(
1154 request,
1155 retry=retry,
1156 timeout=timeout,
1157 metadata=metadata,
1158 )
1160 # This method is paged; wrap the response in a pager, which provides
1161 # an `__iter__` convenience method.
1162 response = pagers.ListViewsPager(
1163 method=rpc,
1164 request=request,
1165 response=response,
1166 metadata=metadata,
1167 )
1169 # Done; return the response.
1170 return response
1172 def get_view(
1173 self,
1174 request: Optional[Union[logging_config.GetViewRequest, dict]] = None,
1175 *,
1176 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1177 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1178 metadata: Sequence[Tuple[str, str]] = (),
1179 ) -> logging_config.LogView:
1180 r"""Gets a view on a log bucket..
1182 .. code-block:: python
1184 # This snippet has been automatically generated and should be regarded as a
1185 # code template only.
1186 # It will require modifications to work:
1187 # - It may require correct/in-range values for request initialization.
1188 # - It may require specifying regional endpoints when creating the service
1189 # client as shown in:
1190 # https://googleapis.dev/python/google-api-core/latest/client_options.html
1191 from google.cloud import logging_v2
1193 def sample_get_view():
1194 # Create a client
1195 client = logging_v2.ConfigServiceV2Client()
1197 # Initialize request argument(s)
1198 request = logging_v2.GetViewRequest(
1199 name="name_value",
1200 )
1202 # Make the request
1203 response = client.get_view(request=request)
1205 # Handle the response
1206 print(response)
1208 Args:
1209 request (Union[google.cloud.logging_v2.types.GetViewRequest, dict]):
1210 The request object. The parameters to `GetView`.
1211 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1212 should be retried.
1213 timeout (float): The timeout for this request.
1214 metadata (Sequence[Tuple[str, str]]): Strings which should be
1215 sent along with the request as metadata.
1217 Returns:
1218 google.cloud.logging_v2.types.LogView:
1219 Describes a view over log entries in
1220 a bucket.
1222 """
1223 # Create or coerce a protobuf request object.
1224 # Minor optimization to avoid making a copy if the user passes
1225 # in a logging_config.GetViewRequest.
1226 # There's no risk of modifying the input as we've already verified
1227 # there are no flattened fields.
1228 if not isinstance(request, logging_config.GetViewRequest):
1229 request = logging_config.GetViewRequest(request)
1231 # Wrap the RPC method; this adds retry and timeout information,
1232 # and friendly error handling.
1233 rpc = self._transport._wrapped_methods[self._transport.get_view]
1235 # Certain fields should be provided within the metadata header;
1236 # add these here.
1237 metadata = tuple(metadata) + (
1238 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1239 )
1241 # Send the request.
1242 response = rpc(
1243 request,
1244 retry=retry,
1245 timeout=timeout,
1246 metadata=metadata,
1247 )
1249 # Done; return the response.
1250 return response
1252 def create_view(
1253 self,
1254 request: Optional[Union[logging_config.CreateViewRequest, dict]] = None,
1255 *,
1256 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1257 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1258 metadata: Sequence[Tuple[str, str]] = (),
1259 ) -> logging_config.LogView:
1260 r"""Creates a view over log entries in a log bucket. A
1261 bucket may contain a maximum of 30 views.
1263 .. code-block:: python
1265 # This snippet has been automatically generated and should be regarded as a
1266 # code template only.
1267 # It will require modifications to work:
1268 # - It may require correct/in-range values for request initialization.
1269 # - It may require specifying regional endpoints when creating the service
1270 # client as shown in:
1271 # https://googleapis.dev/python/google-api-core/latest/client_options.html
1272 from google.cloud import logging_v2
1274 def sample_create_view():
1275 # Create a client
1276 client = logging_v2.ConfigServiceV2Client()
1278 # Initialize request argument(s)
1279 request = logging_v2.CreateViewRequest(
1280 parent="parent_value",
1281 view_id="view_id_value",
1282 )
1284 # Make the request
1285 response = client.create_view(request=request)
1287 # Handle the response
1288 print(response)
1290 Args:
1291 request (Union[google.cloud.logging_v2.types.CreateViewRequest, dict]):
1292 The request object. The parameters to `CreateView`.
1293 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1294 should be retried.
1295 timeout (float): The timeout for this request.
1296 metadata (Sequence[Tuple[str, str]]): Strings which should be
1297 sent along with the request as metadata.
1299 Returns:
1300 google.cloud.logging_v2.types.LogView:
1301 Describes a view over log entries in
1302 a bucket.
1304 """
1305 # Create or coerce a protobuf request object.
1306 # Minor optimization to avoid making a copy if the user passes
1307 # in a logging_config.CreateViewRequest.
1308 # There's no risk of modifying the input as we've already verified
1309 # there are no flattened fields.
1310 if not isinstance(request, logging_config.CreateViewRequest):
1311 request = logging_config.CreateViewRequest(request)
1313 # Wrap the RPC method; this adds retry and timeout information,
1314 # and friendly error handling.
1315 rpc = self._transport._wrapped_methods[self._transport.create_view]
1317 # Certain fields should be provided within the metadata header;
1318 # add these here.
1319 metadata = tuple(metadata) + (
1320 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
1321 )
1323 # Send the request.
1324 response = rpc(
1325 request,
1326 retry=retry,
1327 timeout=timeout,
1328 metadata=metadata,
1329 )
1331 # Done; return the response.
1332 return response
1334 def update_view(
1335 self,
1336 request: Optional[Union[logging_config.UpdateViewRequest, dict]] = None,
1337 *,
1338 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1339 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1340 metadata: Sequence[Tuple[str, str]] = (),
1341 ) -> logging_config.LogView:
1342 r"""Updates a view on a log bucket. This method replaces the
1343 following fields in the existing view with values from the new
1344 view: ``filter``. If an ``UNAVAILABLE`` error is returned, this
1345 indicates that system is not in a state where it can update the
1346 view. If this occurs, please try again in a few minutes.
1348 .. code-block:: python
1350 # This snippet has been automatically generated and should be regarded as a
1351 # code template only.
1352 # It will require modifications to work:
1353 # - It may require correct/in-range values for request initialization.
1354 # - It may require specifying regional endpoints when creating the service
1355 # client as shown in:
1356 # https://googleapis.dev/python/google-api-core/latest/client_options.html
1357 from google.cloud import logging_v2
1359 def sample_update_view():
1360 # Create a client
1361 client = logging_v2.ConfigServiceV2Client()
1363 # Initialize request argument(s)
1364 request = logging_v2.UpdateViewRequest(
1365 name="name_value",
1366 )
1368 # Make the request
1369 response = client.update_view(request=request)
1371 # Handle the response
1372 print(response)
1374 Args:
1375 request (Union[google.cloud.logging_v2.types.UpdateViewRequest, dict]):
1376 The request object. The parameters to `UpdateView`.
1377 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1378 should be retried.
1379 timeout (float): The timeout for this request.
1380 metadata (Sequence[Tuple[str, str]]): Strings which should be
1381 sent along with the request as metadata.
1383 Returns:
1384 google.cloud.logging_v2.types.LogView:
1385 Describes a view over log entries in
1386 a bucket.
1388 """
1389 # Create or coerce a protobuf request object.
1390 # Minor optimization to avoid making a copy if the user passes
1391 # in a logging_config.UpdateViewRequest.
1392 # There's no risk of modifying the input as we've already verified
1393 # there are no flattened fields.
1394 if not isinstance(request, logging_config.UpdateViewRequest):
1395 request = logging_config.UpdateViewRequest(request)
1397 # Wrap the RPC method; this adds retry and timeout information,
1398 # and friendly error handling.
1399 rpc = self._transport._wrapped_methods[self._transport.update_view]
1401 # Certain fields should be provided within the metadata header;
1402 # add these here.
1403 metadata = tuple(metadata) + (
1404 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1405 )
1407 # Send the request.
1408 response = rpc(
1409 request,
1410 retry=retry,
1411 timeout=timeout,
1412 metadata=metadata,
1413 )
1415 # Done; return the response.
1416 return response
1418 def delete_view(
1419 self,
1420 request: Optional[Union[logging_config.DeleteViewRequest, dict]] = None,
1421 *,
1422 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1423 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1424 metadata: Sequence[Tuple[str, str]] = (),
1425 ) -> None:
1426 r"""Deletes a view on a log bucket. If an ``UNAVAILABLE`` error is
1427 returned, this indicates that system is not in a state where it
1428 can delete the view. If this occurs, please try again in a few
1429 minutes.
1431 .. code-block:: python
1433 # This snippet has been automatically generated and should be regarded as a
1434 # code template only.
1435 # It will require modifications to work:
1436 # - It may require correct/in-range values for request initialization.
1437 # - It may require specifying regional endpoints when creating the service
1438 # client as shown in:
1439 # https://googleapis.dev/python/google-api-core/latest/client_options.html
1440 from google.cloud import logging_v2
1442 def sample_delete_view():
1443 # Create a client
1444 client = logging_v2.ConfigServiceV2Client()
1446 # Initialize request argument(s)
1447 request = logging_v2.DeleteViewRequest(
1448 name="name_value",
1449 )
1451 # Make the request
1452 client.delete_view(request=request)
1454 Args:
1455 request (Union[google.cloud.logging_v2.types.DeleteViewRequest, dict]):
1456 The request object. The parameters to `DeleteView`.
1457 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1458 should be retried.
1459 timeout (float): The timeout for this request.
1460 metadata (Sequence[Tuple[str, str]]): Strings which should be
1461 sent along with the request as metadata.
1462 """
1463 # Create or coerce a protobuf request object.
1464 # Minor optimization to avoid making a copy if the user passes
1465 # in a logging_config.DeleteViewRequest.
1466 # There's no risk of modifying the input as we've already verified
1467 # there are no flattened fields.
1468 if not isinstance(request, logging_config.DeleteViewRequest):
1469 request = logging_config.DeleteViewRequest(request)
1471 # Wrap the RPC method; this adds retry and timeout information,
1472 # and friendly error handling.
1473 rpc = self._transport._wrapped_methods[self._transport.delete_view]
1475 # Certain fields should be provided within the metadata header;
1476 # add these here.
1477 metadata = tuple(metadata) + (
1478 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1479 )
1481 # Send the request.
1482 rpc(
1483 request,
1484 retry=retry,
1485 timeout=timeout,
1486 metadata=metadata,
1487 )
1489 def list_sinks(
1490 self,
1491 request: Optional[Union[logging_config.ListSinksRequest, dict]] = None,
1492 *,
1493 parent: Optional[str] = None,
1494 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1495 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1496 metadata: Sequence[Tuple[str, str]] = (),
1497 ) -> pagers.ListSinksPager:
1498 r"""Lists sinks.
1500 .. code-block:: python
1502 # This snippet has been automatically generated and should be regarded as a
1503 # code template only.
1504 # It will require modifications to work:
1505 # - It may require correct/in-range values for request initialization.
1506 # - It may require specifying regional endpoints when creating the service
1507 # client as shown in:
1508 # https://googleapis.dev/python/google-api-core/latest/client_options.html
1509 from google.cloud import logging_v2
1511 def sample_list_sinks():
1512 # Create a client
1513 client = logging_v2.ConfigServiceV2Client()
1515 # Initialize request argument(s)
1516 request = logging_v2.ListSinksRequest(
1517 parent="parent_value",
1518 )
1520 # Make the request
1521 page_result = client.list_sinks(request=request)
1523 # Handle the response
1524 for response in page_result:
1525 print(response)
1527 Args:
1528 request (Union[google.cloud.logging_v2.types.ListSinksRequest, dict]):
1529 The request object. The parameters to `ListSinks`.
1530 parent (str):
1531 Required. The parent resource whose sinks are to be
1532 listed:
1534 ::
1536 "projects/[PROJECT_ID]"
1537 "organizations/[ORGANIZATION_ID]"
1538 "billingAccounts/[BILLING_ACCOUNT_ID]"
1539 "folders/[FOLDER_ID]"
1541 This corresponds to the ``parent`` field
1542 on the ``request`` instance; if ``request`` is provided, this
1543 should not be set.
1544 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1545 should be retried.
1546 timeout (float): The timeout for this request.
1547 metadata (Sequence[Tuple[str, str]]): Strings which should be
1548 sent along with the request as metadata.
1550 Returns:
1551 google.cloud.logging_v2.services.config_service_v2.pagers.ListSinksPager:
1552 Result returned from ListSinks.
1554 Iterating over this object will yield results and
1555 resolve additional pages automatically.
1557 """
1558 # Create or coerce a protobuf request object.
1559 # Quick check: If we got a request object, we should *not* have
1560 # gotten any keyword arguments that map to the request.
1561 has_flattened_params = any([parent])
1562 if request is not None and has_flattened_params:
1563 raise ValueError(
1564 "If the `request` argument is set, then none of "
1565 "the individual field arguments should be set."
1566 )
1568 # Minor optimization to avoid making a copy if the user passes
1569 # in a logging_config.ListSinksRequest.
1570 # There's no risk of modifying the input as we've already verified
1571 # there are no flattened fields.
1572 if not isinstance(request, logging_config.ListSinksRequest):
1573 request = logging_config.ListSinksRequest(request)
1574 # If we have keyword arguments corresponding to fields on the
1575 # request, apply these.
1576 if parent is not None:
1577 request.parent = parent
1579 # Wrap the RPC method; this adds retry and timeout information,
1580 # and friendly error handling.
1581 rpc = self._transport._wrapped_methods[self._transport.list_sinks]
1583 # Certain fields should be provided within the metadata header;
1584 # add these here.
1585 metadata = tuple(metadata) + (
1586 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
1587 )
1589 # Send the request.
1590 response = rpc(
1591 request,
1592 retry=retry,
1593 timeout=timeout,
1594 metadata=metadata,
1595 )
1597 # This method is paged; wrap the response in a pager, which provides
1598 # an `__iter__` convenience method.
1599 response = pagers.ListSinksPager(
1600 method=rpc,
1601 request=request,
1602 response=response,
1603 metadata=metadata,
1604 )
1606 # Done; return the response.
1607 return response
1609 def get_sink(
1610 self,
1611 request: Optional[Union[logging_config.GetSinkRequest, dict]] = None,
1612 *,
1613 sink_name: Optional[str] = None,
1614 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1615 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1616 metadata: Sequence[Tuple[str, str]] = (),
1617 ) -> logging_config.LogSink:
1618 r"""Gets a sink.
1620 .. code-block:: python
1622 # This snippet has been automatically generated and should be regarded as a
1623 # code template only.
1624 # It will require modifications to work:
1625 # - It may require correct/in-range values for request initialization.
1626 # - It may require specifying regional endpoints when creating the service
1627 # client as shown in:
1628 # https://googleapis.dev/python/google-api-core/latest/client_options.html
1629 from google.cloud import logging_v2
1631 def sample_get_sink():
1632 # Create a client
1633 client = logging_v2.ConfigServiceV2Client()
1635 # Initialize request argument(s)
1636 request = logging_v2.GetSinkRequest(
1637 sink_name="sink_name_value",
1638 )
1640 # Make the request
1641 response = client.get_sink(request=request)
1643 # Handle the response
1644 print(response)
1646 Args:
1647 request (Union[google.cloud.logging_v2.types.GetSinkRequest, dict]):
1648 The request object. The parameters to `GetSink`.
1649 sink_name (str):
1650 Required. The resource name of the sink:
1652 ::
1654 "projects/[PROJECT_ID]/sinks/[SINK_ID]"
1655 "organizations/[ORGANIZATION_ID]/sinks/[SINK_ID]"
1656 "billingAccounts/[BILLING_ACCOUNT_ID]/sinks/[SINK_ID]"
1657 "folders/[FOLDER_ID]/sinks/[SINK_ID]"
1659 For example:
1661 ``"projects/my-project/sinks/my-sink"``
1663 This corresponds to the ``sink_name`` field
1664 on the ``request`` instance; if ``request`` is provided, this
1665 should not be set.
1666 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1667 should be retried.
1668 timeout (float): The timeout for this request.
1669 metadata (Sequence[Tuple[str, str]]): Strings which should be
1670 sent along with the request as metadata.
1672 Returns:
1673 google.cloud.logging_v2.types.LogSink:
1674 Describes a sink used to export log
1675 entries to one of the following
1676 destinations in any project: a Cloud
1677 Storage bucket, a BigQuery dataset, a
1678 Pub/Sub topic or a Cloud Logging log
1679 bucket. A logs filter controls which log
1680 entries are exported. The sink must be
1681 created within a project, organization,
1682 billing account, or folder.
1684 """
1685 # Create or coerce a protobuf request object.
1686 # Quick check: If we got a request object, we should *not* have
1687 # gotten any keyword arguments that map to the request.
1688 has_flattened_params = any([sink_name])
1689 if request is not None and has_flattened_params:
1690 raise ValueError(
1691 "If the `request` argument is set, then none of "
1692 "the individual field arguments should be set."
1693 )
1695 # Minor optimization to avoid making a copy if the user passes
1696 # in a logging_config.GetSinkRequest.
1697 # There's no risk of modifying the input as we've already verified
1698 # there are no flattened fields.
1699 if not isinstance(request, logging_config.GetSinkRequest):
1700 request = logging_config.GetSinkRequest(request)
1701 # If we have keyword arguments corresponding to fields on the
1702 # request, apply these.
1703 if sink_name is not None:
1704 request.sink_name = sink_name
1706 # Wrap the RPC method; this adds retry and timeout information,
1707 # and friendly error handling.
1708 rpc = self._transport._wrapped_methods[self._transport.get_sink]
1710 # Certain fields should be provided within the metadata header;
1711 # add these here.
1712 metadata = tuple(metadata) + (
1713 gapic_v1.routing_header.to_grpc_metadata(
1714 (("sink_name", request.sink_name),)
1715 ),
1716 )
1718 # Send the request.
1719 response = rpc(
1720 request,
1721 retry=retry,
1722 timeout=timeout,
1723 metadata=metadata,
1724 )
1726 # Done; return the response.
1727 return response
1729 def create_sink(
1730 self,
1731 request: Optional[Union[logging_config.CreateSinkRequest, dict]] = None,
1732 *,
1733 parent: Optional[str] = None,
1734 sink: Optional[logging_config.LogSink] = None,
1735 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1736 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1737 metadata: Sequence[Tuple[str, str]] = (),
1738 ) -> logging_config.LogSink:
1739 r"""Creates a sink that exports specified log entries to a
1740 destination. The export of newly-ingested log entries begins
1741 immediately, unless the sink's ``writer_identity`` is not
1742 permitted to write to the destination. A sink can export log
1743 entries only from the resource owning the sink.
1745 .. code-block:: python
1747 # This snippet has been automatically generated and should be regarded as a
1748 # code template only.
1749 # It will require modifications to work:
1750 # - It may require correct/in-range values for request initialization.
1751 # - It may require specifying regional endpoints when creating the service
1752 # client as shown in:
1753 # https://googleapis.dev/python/google-api-core/latest/client_options.html
1754 from google.cloud import logging_v2
1756 def sample_create_sink():
1757 # Create a client
1758 client = logging_v2.ConfigServiceV2Client()
1760 # Initialize request argument(s)
1761 sink = logging_v2.LogSink()
1762 sink.name = "name_value"
1763 sink.destination = "destination_value"
1765 request = logging_v2.CreateSinkRequest(
1766 parent="parent_value",
1767 sink=sink,
1768 )
1770 # Make the request
1771 response = client.create_sink(request=request)
1773 # Handle the response
1774 print(response)
1776 Args:
1777 request (Union[google.cloud.logging_v2.types.CreateSinkRequest, dict]):
1778 The request object. The parameters to `CreateSink`.
1779 parent (str):
1780 Required. The resource in which to create the sink:
1782 ::
1784 "projects/[PROJECT_ID]"
1785 "organizations/[ORGANIZATION_ID]"
1786 "billingAccounts/[BILLING_ACCOUNT_ID]"
1787 "folders/[FOLDER_ID]"
1789 For examples:
1791 ``"projects/my-project"`` ``"organizations/123456789"``
1793 This corresponds to the ``parent`` field
1794 on the ``request`` instance; if ``request`` is provided, this
1795 should not be set.
1796 sink (google.cloud.logging_v2.types.LogSink):
1797 Required. The new sink, whose ``name`` parameter is a
1798 sink identifier that is not already in use.
1800 This corresponds to the ``sink`` field
1801 on the ``request`` instance; if ``request`` is provided, this
1802 should not be set.
1803 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1804 should be retried.
1805 timeout (float): The timeout for this request.
1806 metadata (Sequence[Tuple[str, str]]): Strings which should be
1807 sent along with the request as metadata.
1809 Returns:
1810 google.cloud.logging_v2.types.LogSink:
1811 Describes a sink used to export log
1812 entries to one of the following
1813 destinations in any project: a Cloud
1814 Storage bucket, a BigQuery dataset, a
1815 Pub/Sub topic or a Cloud Logging log
1816 bucket. A logs filter controls which log
1817 entries are exported. The sink must be
1818 created within a project, organization,
1819 billing account, or folder.
1821 """
1822 # Create or coerce a protobuf request object.
1823 # Quick check: If we got a request object, we should *not* have
1824 # gotten any keyword arguments that map to the request.
1825 has_flattened_params = any([parent, sink])
1826 if request is not None and has_flattened_params:
1827 raise ValueError(
1828 "If the `request` argument is set, then none of "
1829 "the individual field arguments should be set."
1830 )
1832 # Minor optimization to avoid making a copy if the user passes
1833 # in a logging_config.CreateSinkRequest.
1834 # There's no risk of modifying the input as we've already verified
1835 # there are no flattened fields.
1836 if not isinstance(request, logging_config.CreateSinkRequest):
1837 request = logging_config.CreateSinkRequest(request)
1838 # If we have keyword arguments corresponding to fields on the
1839 # request, apply these.
1840 if parent is not None:
1841 request.parent = parent
1842 if sink is not None:
1843 request.sink = sink
1845 # Wrap the RPC method; this adds retry and timeout information,
1846 # and friendly error handling.
1847 rpc = self._transport._wrapped_methods[self._transport.create_sink]
1849 # Certain fields should be provided within the metadata header;
1850 # add these here.
1851 metadata = tuple(metadata) + (
1852 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
1853 )
1855 # Send the request.
1856 response = rpc(
1857 request,
1858 retry=retry,
1859 timeout=timeout,
1860 metadata=metadata,
1861 )
1863 # Done; return the response.
1864 return response
1866 def update_sink(
1867 self,
1868 request: Optional[Union[logging_config.UpdateSinkRequest, dict]] = None,
1869 *,
1870 sink_name: Optional[str] = None,
1871 sink: Optional[logging_config.LogSink] = None,
1872 update_mask: Optional[field_mask_pb2.FieldMask] = None,
1873 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1874 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1875 metadata: Sequence[Tuple[str, str]] = (),
1876 ) -> logging_config.LogSink:
1877 r"""Updates a sink. This method replaces the following fields in the
1878 existing sink with values from the new sink: ``destination``,
1879 and ``filter``.
1881 The updated sink might also have a new ``writer_identity``; see
1882 the ``unique_writer_identity`` field.
1884 .. code-block:: python
1886 # This snippet has been automatically generated and should be regarded as a
1887 # code template only.
1888 # It will require modifications to work:
1889 # - It may require correct/in-range values for request initialization.
1890 # - It may require specifying regional endpoints when creating the service
1891 # client as shown in:
1892 # https://googleapis.dev/python/google-api-core/latest/client_options.html
1893 from google.cloud import logging_v2
1895 def sample_update_sink():
1896 # Create a client
1897 client = logging_v2.ConfigServiceV2Client()
1899 # Initialize request argument(s)
1900 sink = logging_v2.LogSink()
1901 sink.name = "name_value"
1902 sink.destination = "destination_value"
1904 request = logging_v2.UpdateSinkRequest(
1905 sink_name="sink_name_value",
1906 sink=sink,
1907 )
1909 # Make the request
1910 response = client.update_sink(request=request)
1912 # Handle the response
1913 print(response)
1915 Args:
1916 request (Union[google.cloud.logging_v2.types.UpdateSinkRequest, dict]):
1917 The request object. The parameters to `UpdateSink`.
1918 sink_name (str):
1919 Required. The full resource name of the sink to update,
1920 including the parent resource and the sink identifier:
1922 ::
1924 "projects/[PROJECT_ID]/sinks/[SINK_ID]"
1925 "organizations/[ORGANIZATION_ID]/sinks/[SINK_ID]"
1926 "billingAccounts/[BILLING_ACCOUNT_ID]/sinks/[SINK_ID]"
1927 "folders/[FOLDER_ID]/sinks/[SINK_ID]"
1929 For example:
1931 ``"projects/my-project/sinks/my-sink"``
1933 This corresponds to the ``sink_name`` field
1934 on the ``request`` instance; if ``request`` is provided, this
1935 should not be set.
1936 sink (google.cloud.logging_v2.types.LogSink):
1937 Required. The updated sink, whose name is the same
1938 identifier that appears as part of ``sink_name``.
1940 This corresponds to the ``sink`` field
1941 on the ``request`` instance; if ``request`` is provided, this
1942 should not be set.
1943 update_mask (google.protobuf.field_mask_pb2.FieldMask):
1944 Optional. Field mask that specifies the fields in
1945 ``sink`` that need an update. A sink field will be
1946 overwritten if, and only if, it is in the update mask.
1947 ``name`` and output only fields cannot be updated.
1949 An empty ``updateMask`` is temporarily treated as using
1950 the following mask for backwards compatibility purposes:
1952 ``destination,filter,includeChildren``
1954 At some point in the future, behavior will be removed
1955 and specifying an empty ``updateMask`` will be an error.
1957 For a detailed ``FieldMask`` definition, see
1958 https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#google.protobuf.FieldMask
1960 For example: ``updateMask=filter``
1962 This corresponds to the ``update_mask`` field
1963 on the ``request`` instance; if ``request`` is provided, this
1964 should not be set.
1965 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1966 should be retried.
1967 timeout (float): The timeout for this request.
1968 metadata (Sequence[Tuple[str, str]]): Strings which should be
1969 sent along with the request as metadata.
1971 Returns:
1972 google.cloud.logging_v2.types.LogSink:
1973 Describes a sink used to export log
1974 entries to one of the following
1975 destinations in any project: a Cloud
1976 Storage bucket, a BigQuery dataset, a
1977 Pub/Sub topic or a Cloud Logging log
1978 bucket. A logs filter controls which log
1979 entries are exported. The sink must be
1980 created within a project, organization,
1981 billing account, or folder.
1983 """
1984 # Create or coerce a protobuf request object.
1985 # Quick check: If we got a request object, we should *not* have
1986 # gotten any keyword arguments that map to the request.
1987 has_flattened_params = any([sink_name, sink, update_mask])
1988 if request is not None and has_flattened_params:
1989 raise ValueError(
1990 "If the `request` argument is set, then none of "
1991 "the individual field arguments should be set."
1992 )
1994 # Minor optimization to avoid making a copy if the user passes
1995 # in a logging_config.UpdateSinkRequest.
1996 # There's no risk of modifying the input as we've already verified
1997 # there are no flattened fields.
1998 if not isinstance(request, logging_config.UpdateSinkRequest):
1999 request = logging_config.UpdateSinkRequest(request)
2000 # If we have keyword arguments corresponding to fields on the
2001 # request, apply these.
2002 if sink_name is not None:
2003 request.sink_name = sink_name
2004 if sink is not None:
2005 request.sink = sink
2006 if update_mask is not None:
2007 request.update_mask = update_mask
2009 # Wrap the RPC method; this adds retry and timeout information,
2010 # and friendly error handling.
2011 rpc = self._transport._wrapped_methods[self._transport.update_sink]
2013 # Certain fields should be provided within the metadata header;
2014 # add these here.
2015 metadata = tuple(metadata) + (
2016 gapic_v1.routing_header.to_grpc_metadata(
2017 (("sink_name", request.sink_name),)
2018 ),
2019 )
2021 # Send the request.
2022 response = rpc(
2023 request,
2024 retry=retry,
2025 timeout=timeout,
2026 metadata=metadata,
2027 )
2029 # Done; return the response.
2030 return response
2032 def delete_sink(
2033 self,
2034 request: Optional[Union[logging_config.DeleteSinkRequest, dict]] = None,
2035 *,
2036 sink_name: Optional[str] = None,
2037 retry: OptionalRetry = gapic_v1.method.DEFAULT,
2038 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
2039 metadata: Sequence[Tuple[str, str]] = (),
2040 ) -> None:
2041 r"""Deletes a sink. If the sink has a unique ``writer_identity``,
2042 then that service account is also deleted.
2044 .. code-block:: python
2046 # This snippet has been automatically generated and should be regarded as a
2047 # code template only.
2048 # It will require modifications to work:
2049 # - It may require correct/in-range values for request initialization.
2050 # - It may require specifying regional endpoints when creating the service
2051 # client as shown in:
2052 # https://googleapis.dev/python/google-api-core/latest/client_options.html
2053 from google.cloud import logging_v2
2055 def sample_delete_sink():
2056 # Create a client
2057 client = logging_v2.ConfigServiceV2Client()
2059 # Initialize request argument(s)
2060 request = logging_v2.DeleteSinkRequest(
2061 sink_name="sink_name_value",
2062 )
2064 # Make the request
2065 client.delete_sink(request=request)
2067 Args:
2068 request (Union[google.cloud.logging_v2.types.DeleteSinkRequest, dict]):
2069 The request object. The parameters to `DeleteSink`.
2070 sink_name (str):
2071 Required. The full resource name of the sink to delete,
2072 including the parent resource and the sink identifier:
2074 ::
2076 "projects/[PROJECT_ID]/sinks/[SINK_ID]"
2077 "organizations/[ORGANIZATION_ID]/sinks/[SINK_ID]"
2078 "billingAccounts/[BILLING_ACCOUNT_ID]/sinks/[SINK_ID]"
2079 "folders/[FOLDER_ID]/sinks/[SINK_ID]"
2081 For example:
2083 ``"projects/my-project/sinks/my-sink"``
2085 This corresponds to the ``sink_name`` field
2086 on the ``request`` instance; if ``request`` is provided, this
2087 should not be set.
2088 retry (google.api_core.retry.Retry): Designation of what errors, if any,
2089 should be retried.
2090 timeout (float): The timeout for this request.
2091 metadata (Sequence[Tuple[str, str]]): Strings which should be
2092 sent along with the request as metadata.
2093 """
2094 # Create or coerce a protobuf request object.
2095 # Quick check: If we got a request object, we should *not* have
2096 # gotten any keyword arguments that map to the request.
2097 has_flattened_params = any([sink_name])
2098 if request is not None and has_flattened_params:
2099 raise ValueError(
2100 "If the `request` argument is set, then none of "
2101 "the individual field arguments should be set."
2102 )
2104 # Minor optimization to avoid making a copy if the user passes
2105 # in a logging_config.DeleteSinkRequest.
2106 # There's no risk of modifying the input as we've already verified
2107 # there are no flattened fields.
2108 if not isinstance(request, logging_config.DeleteSinkRequest):
2109 request = logging_config.DeleteSinkRequest(request)
2110 # If we have keyword arguments corresponding to fields on the
2111 # request, apply these.
2112 if sink_name is not None:
2113 request.sink_name = sink_name
2115 # Wrap the RPC method; this adds retry and timeout information,
2116 # and friendly error handling.
2117 rpc = self._transport._wrapped_methods[self._transport.delete_sink]
2119 # Certain fields should be provided within the metadata header;
2120 # add these here.
2121 metadata = tuple(metadata) + (
2122 gapic_v1.routing_header.to_grpc_metadata(
2123 (("sink_name", request.sink_name),)
2124 ),
2125 )
2127 # Send the request.
2128 rpc(
2129 request,
2130 retry=retry,
2131 timeout=timeout,
2132 metadata=metadata,
2133 )
2135 def list_exclusions(
2136 self,
2137 request: Optional[Union[logging_config.ListExclusionsRequest, dict]] = None,
2138 *,
2139 parent: Optional[str] = None,
2140 retry: OptionalRetry = gapic_v1.method.DEFAULT,
2141 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
2142 metadata: Sequence[Tuple[str, str]] = (),
2143 ) -> pagers.ListExclusionsPager:
2144 r"""Lists all the exclusions on the \_Default sink in a parent
2145 resource.
2147 .. code-block:: python
2149 # This snippet has been automatically generated and should be regarded as a
2150 # code template only.
2151 # It will require modifications to work:
2152 # - It may require correct/in-range values for request initialization.
2153 # - It may require specifying regional endpoints when creating the service
2154 # client as shown in:
2155 # https://googleapis.dev/python/google-api-core/latest/client_options.html
2156 from google.cloud import logging_v2
2158 def sample_list_exclusions():
2159 # Create a client
2160 client = logging_v2.ConfigServiceV2Client()
2162 # Initialize request argument(s)
2163 request = logging_v2.ListExclusionsRequest(
2164 parent="parent_value",
2165 )
2167 # Make the request
2168 page_result = client.list_exclusions(request=request)
2170 # Handle the response
2171 for response in page_result:
2172 print(response)
2174 Args:
2175 request (Union[google.cloud.logging_v2.types.ListExclusionsRequest, dict]):
2176 The request object. The parameters to `ListExclusions`.
2177 parent (str):
2178 Required. The parent resource whose exclusions are to be
2179 listed.
2181 ::
2183 "projects/[PROJECT_ID]"
2184 "organizations/[ORGANIZATION_ID]"
2185 "billingAccounts/[BILLING_ACCOUNT_ID]"
2186 "folders/[FOLDER_ID]"
2188 This corresponds to the ``parent`` field
2189 on the ``request`` instance; if ``request`` is provided, this
2190 should not be set.
2191 retry (google.api_core.retry.Retry): Designation of what errors, if any,
2192 should be retried.
2193 timeout (float): The timeout for this request.
2194 metadata (Sequence[Tuple[str, str]]): Strings which should be
2195 sent along with the request as metadata.
2197 Returns:
2198 google.cloud.logging_v2.services.config_service_v2.pagers.ListExclusionsPager:
2199 Result returned from ListExclusions.
2201 Iterating over this object will yield results and
2202 resolve additional pages automatically.
2204 """
2205 # Create or coerce a protobuf request object.
2206 # Quick check: If we got a request object, we should *not* have
2207 # gotten any keyword arguments that map to the request.
2208 has_flattened_params = any([parent])
2209 if request is not None and has_flattened_params:
2210 raise ValueError(
2211 "If the `request` argument is set, then none of "
2212 "the individual field arguments should be set."
2213 )
2215 # Minor optimization to avoid making a copy if the user passes
2216 # in a logging_config.ListExclusionsRequest.
2217 # There's no risk of modifying the input as we've already verified
2218 # there are no flattened fields.
2219 if not isinstance(request, logging_config.ListExclusionsRequest):
2220 request = logging_config.ListExclusionsRequest(request)
2221 # If we have keyword arguments corresponding to fields on the
2222 # request, apply these.
2223 if parent is not None:
2224 request.parent = parent
2226 # Wrap the RPC method; this adds retry and timeout information,
2227 # and friendly error handling.
2228 rpc = self._transport._wrapped_methods[self._transport.list_exclusions]
2230 # Certain fields should be provided within the metadata header;
2231 # add these here.
2232 metadata = tuple(metadata) + (
2233 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
2234 )
2236 # Send the request.
2237 response = rpc(
2238 request,
2239 retry=retry,
2240 timeout=timeout,
2241 metadata=metadata,
2242 )
2244 # This method is paged; wrap the response in a pager, which provides
2245 # an `__iter__` convenience method.
2246 response = pagers.ListExclusionsPager(
2247 method=rpc,
2248 request=request,
2249 response=response,
2250 metadata=metadata,
2251 )
2253 # Done; return the response.
2254 return response
2256 def get_exclusion(
2257 self,
2258 request: Optional[Union[logging_config.GetExclusionRequest, dict]] = None,
2259 *,
2260 name: Optional[str] = None,
2261 retry: OptionalRetry = gapic_v1.method.DEFAULT,
2262 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
2263 metadata: Sequence[Tuple[str, str]] = (),
2264 ) -> logging_config.LogExclusion:
2265 r"""Gets the description of an exclusion in the \_Default sink.
2267 .. code-block:: python
2269 # This snippet has been automatically generated and should be regarded as a
2270 # code template only.
2271 # It will require modifications to work:
2272 # - It may require correct/in-range values for request initialization.
2273 # - It may require specifying regional endpoints when creating the service
2274 # client as shown in:
2275 # https://googleapis.dev/python/google-api-core/latest/client_options.html
2276 from google.cloud import logging_v2
2278 def sample_get_exclusion():
2279 # Create a client
2280 client = logging_v2.ConfigServiceV2Client()
2282 # Initialize request argument(s)
2283 request = logging_v2.GetExclusionRequest(
2284 name="name_value",
2285 )
2287 # Make the request
2288 response = client.get_exclusion(request=request)
2290 # Handle the response
2291 print(response)
2293 Args:
2294 request (Union[google.cloud.logging_v2.types.GetExclusionRequest, dict]):
2295 The request object. The parameters to `GetExclusion`.
2296 name (str):
2297 Required. The resource name of an existing exclusion:
2299 ::
2301 "projects/[PROJECT_ID]/exclusions/[EXCLUSION_ID]"
2302 "organizations/[ORGANIZATION_ID]/exclusions/[EXCLUSION_ID]"
2303 "billingAccounts/[BILLING_ACCOUNT_ID]/exclusions/[EXCLUSION_ID]"
2304 "folders/[FOLDER_ID]/exclusions/[EXCLUSION_ID]"
2306 For example:
2308 ``"projects/my-project/exclusions/my-exclusion"``
2310 This corresponds to the ``name`` field
2311 on the ``request`` instance; if ``request`` is provided, this
2312 should not be set.
2313 retry (google.api_core.retry.Retry): Designation of what errors, if any,
2314 should be retried.
2315 timeout (float): The timeout for this request.
2316 metadata (Sequence[Tuple[str, str]]): Strings which should be
2317 sent along with the request as metadata.
2319 Returns:
2320 google.cloud.logging_v2.types.LogExclusion:
2321 Specifies a set of log entries that are filtered out by a sink. If
2322 your Google Cloud resource receives a large volume of
2323 log entries, you can use exclusions to reduce your
2324 chargeable logs. Note that exclusions on
2325 organization-level and folder-level sinks don't apply
2326 to child resources. Note also that you cannot modify
2327 the \_Required sink or exclude logs from it.
2329 """
2330 # Create or coerce a protobuf request object.
2331 # Quick check: If we got a request object, we should *not* have
2332 # gotten any keyword arguments that map to the request.
2333 has_flattened_params = any([name])
2334 if request is not None and has_flattened_params:
2335 raise ValueError(
2336 "If the `request` argument is set, then none of "
2337 "the individual field arguments should be set."
2338 )
2340 # Minor optimization to avoid making a copy if the user passes
2341 # in a logging_config.GetExclusionRequest.
2342 # There's no risk of modifying the input as we've already verified
2343 # there are no flattened fields.
2344 if not isinstance(request, logging_config.GetExclusionRequest):
2345 request = logging_config.GetExclusionRequest(request)
2346 # If we have keyword arguments corresponding to fields on the
2347 # request, apply these.
2348 if name is not None:
2349 request.name = name
2351 # Wrap the RPC method; this adds retry and timeout information,
2352 # and friendly error handling.
2353 rpc = self._transport._wrapped_methods[self._transport.get_exclusion]
2355 # Certain fields should be provided within the metadata header;
2356 # add these here.
2357 metadata = tuple(metadata) + (
2358 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
2359 )
2361 # Send the request.
2362 response = rpc(
2363 request,
2364 retry=retry,
2365 timeout=timeout,
2366 metadata=metadata,
2367 )
2369 # Done; return the response.
2370 return response
2372 def create_exclusion(
2373 self,
2374 request: Optional[Union[logging_config.CreateExclusionRequest, dict]] = None,
2375 *,
2376 parent: Optional[str] = None,
2377 exclusion: Optional[logging_config.LogExclusion] = None,
2378 retry: OptionalRetry = gapic_v1.method.DEFAULT,
2379 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
2380 metadata: Sequence[Tuple[str, str]] = (),
2381 ) -> logging_config.LogExclusion:
2382 r"""Creates a new exclusion in the \_Default sink in a specified
2383 parent resource. Only log entries belonging to that resource can
2384 be excluded. You can have up to 10 exclusions in a resource.
2386 .. code-block:: python
2388 # This snippet has been automatically generated and should be regarded as a
2389 # code template only.
2390 # It will require modifications to work:
2391 # - It may require correct/in-range values for request initialization.
2392 # - It may require specifying regional endpoints when creating the service
2393 # client as shown in:
2394 # https://googleapis.dev/python/google-api-core/latest/client_options.html
2395 from google.cloud import logging_v2
2397 def sample_create_exclusion():
2398 # Create a client
2399 client = logging_v2.ConfigServiceV2Client()
2401 # Initialize request argument(s)
2402 exclusion = logging_v2.LogExclusion()
2403 exclusion.name = "name_value"
2404 exclusion.filter = "filter_value"
2406 request = logging_v2.CreateExclusionRequest(
2407 parent="parent_value",
2408 exclusion=exclusion,
2409 )
2411 # Make the request
2412 response = client.create_exclusion(request=request)
2414 # Handle the response
2415 print(response)
2417 Args:
2418 request (Union[google.cloud.logging_v2.types.CreateExclusionRequest, dict]):
2419 The request object. The parameters to `CreateExclusion`.
2420 parent (str):
2421 Required. The parent resource in which to create the
2422 exclusion:
2424 ::
2426 "projects/[PROJECT_ID]"
2427 "organizations/[ORGANIZATION_ID]"
2428 "billingAccounts/[BILLING_ACCOUNT_ID]"
2429 "folders/[FOLDER_ID]"
2431 For examples:
2433 ``"projects/my-logging-project"``
2434 ``"organizations/123456789"``
2436 This corresponds to the ``parent`` field
2437 on the ``request`` instance; if ``request`` is provided, this
2438 should not be set.
2439 exclusion (google.cloud.logging_v2.types.LogExclusion):
2440 Required. The new exclusion, whose ``name`` parameter is
2441 an exclusion name that is not already used in the parent
2442 resource.
2444 This corresponds to the ``exclusion`` field
2445 on the ``request`` instance; if ``request`` is provided, this
2446 should not be set.
2447 retry (google.api_core.retry.Retry): Designation of what errors, if any,
2448 should be retried.
2449 timeout (float): The timeout for this request.
2450 metadata (Sequence[Tuple[str, str]]): Strings which should be
2451 sent along with the request as metadata.
2453 Returns:
2454 google.cloud.logging_v2.types.LogExclusion:
2455 Specifies a set of log entries that are filtered out by a sink. If
2456 your Google Cloud resource receives a large volume of
2457 log entries, you can use exclusions to reduce your
2458 chargeable logs. Note that exclusions on
2459 organization-level and folder-level sinks don't apply
2460 to child resources. Note also that you cannot modify
2461 the \_Required sink or exclude logs from it.
2463 """
2464 # Create or coerce a protobuf request object.
2465 # Quick check: If we got a request object, we should *not* have
2466 # gotten any keyword arguments that map to the request.
2467 has_flattened_params = any([parent, exclusion])
2468 if request is not None and has_flattened_params:
2469 raise ValueError(
2470 "If the `request` argument is set, then none of "
2471 "the individual field arguments should be set."
2472 )
2474 # Minor optimization to avoid making a copy if the user passes
2475 # in a logging_config.CreateExclusionRequest.
2476 # There's no risk of modifying the input as we've already verified
2477 # there are no flattened fields.
2478 if not isinstance(request, logging_config.CreateExclusionRequest):
2479 request = logging_config.CreateExclusionRequest(request)
2480 # If we have keyword arguments corresponding to fields on the
2481 # request, apply these.
2482 if parent is not None:
2483 request.parent = parent
2484 if exclusion is not None:
2485 request.exclusion = exclusion
2487 # Wrap the RPC method; this adds retry and timeout information,
2488 # and friendly error handling.
2489 rpc = self._transport._wrapped_methods[self._transport.create_exclusion]
2491 # Certain fields should be provided within the metadata header;
2492 # add these here.
2493 metadata = tuple(metadata) + (
2494 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
2495 )
2497 # Send the request.
2498 response = rpc(
2499 request,
2500 retry=retry,
2501 timeout=timeout,
2502 metadata=metadata,
2503 )
2505 # Done; return the response.
2506 return response
2508 def update_exclusion(
2509 self,
2510 request: Optional[Union[logging_config.UpdateExclusionRequest, dict]] = None,
2511 *,
2512 name: Optional[str] = None,
2513 exclusion: Optional[logging_config.LogExclusion] = None,
2514 update_mask: Optional[field_mask_pb2.FieldMask] = None,
2515 retry: OptionalRetry = gapic_v1.method.DEFAULT,
2516 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
2517 metadata: Sequence[Tuple[str, str]] = (),
2518 ) -> logging_config.LogExclusion:
2519 r"""Changes one or more properties of an existing exclusion in the
2520 \_Default sink.
2522 .. code-block:: python
2524 # This snippet has been automatically generated and should be regarded as a
2525 # code template only.
2526 # It will require modifications to work:
2527 # - It may require correct/in-range values for request initialization.
2528 # - It may require specifying regional endpoints when creating the service
2529 # client as shown in:
2530 # https://googleapis.dev/python/google-api-core/latest/client_options.html
2531 from google.cloud import logging_v2
2533 def sample_update_exclusion():
2534 # Create a client
2535 client = logging_v2.ConfigServiceV2Client()
2537 # Initialize request argument(s)
2538 exclusion = logging_v2.LogExclusion()
2539 exclusion.name = "name_value"
2540 exclusion.filter = "filter_value"
2542 request = logging_v2.UpdateExclusionRequest(
2543 name="name_value",
2544 exclusion=exclusion,
2545 )
2547 # Make the request
2548 response = client.update_exclusion(request=request)
2550 # Handle the response
2551 print(response)
2553 Args:
2554 request (Union[google.cloud.logging_v2.types.UpdateExclusionRequest, dict]):
2555 The request object. The parameters to `UpdateExclusion`.
2556 name (str):
2557 Required. The resource name of the exclusion to update:
2559 ::
2561 "projects/[PROJECT_ID]/exclusions/[EXCLUSION_ID]"
2562 "organizations/[ORGANIZATION_ID]/exclusions/[EXCLUSION_ID]"
2563 "billingAccounts/[BILLING_ACCOUNT_ID]/exclusions/[EXCLUSION_ID]"
2564 "folders/[FOLDER_ID]/exclusions/[EXCLUSION_ID]"
2566 For example:
2568 ``"projects/my-project/exclusions/my-exclusion"``
2570 This corresponds to the ``name`` field
2571 on the ``request`` instance; if ``request`` is provided, this
2572 should not be set.
2573 exclusion (google.cloud.logging_v2.types.LogExclusion):
2574 Required. New values for the existing exclusion. Only
2575 the fields specified in ``update_mask`` are relevant.
2577 This corresponds to the ``exclusion`` field
2578 on the ``request`` instance; if ``request`` is provided, this
2579 should not be set.
2580 update_mask (google.protobuf.field_mask_pb2.FieldMask):
2581 Required. A non-empty list of fields to change in the
2582 existing exclusion. New values for the fields are taken
2583 from the corresponding fields in the
2584 [LogExclusion][google.logging.v2.LogExclusion] included
2585 in this request. Fields not mentioned in ``update_mask``
2586 are not changed and are ignored in the request.
2588 For example, to change the filter and description of an
2589 exclusion, specify an ``update_mask`` of
2590 ``"filter,description"``.
2592 This corresponds to the ``update_mask`` field
2593 on the ``request`` instance; if ``request`` is provided, this
2594 should not be set.
2595 retry (google.api_core.retry.Retry): Designation of what errors, if any,
2596 should be retried.
2597 timeout (float): The timeout for this request.
2598 metadata (Sequence[Tuple[str, str]]): Strings which should be
2599 sent along with the request as metadata.
2601 Returns:
2602 google.cloud.logging_v2.types.LogExclusion:
2603 Specifies a set of log entries that are filtered out by a sink. If
2604 your Google Cloud resource receives a large volume of
2605 log entries, you can use exclusions to reduce your
2606 chargeable logs. Note that exclusions on
2607 organization-level and folder-level sinks don't apply
2608 to child resources. Note also that you cannot modify
2609 the \_Required sink or exclude logs from it.
2611 """
2612 # Create or coerce a protobuf request object.
2613 # Quick check: If we got a request object, we should *not* have
2614 # gotten any keyword arguments that map to the request.
2615 has_flattened_params = any([name, exclusion, update_mask])
2616 if request is not None and has_flattened_params:
2617 raise ValueError(
2618 "If the `request` argument is set, then none of "
2619 "the individual field arguments should be set."
2620 )
2622 # Minor optimization to avoid making a copy if the user passes
2623 # in a logging_config.UpdateExclusionRequest.
2624 # There's no risk of modifying the input as we've already verified
2625 # there are no flattened fields.
2626 if not isinstance(request, logging_config.UpdateExclusionRequest):
2627 request = logging_config.UpdateExclusionRequest(request)
2628 # If we have keyword arguments corresponding to fields on the
2629 # request, apply these.
2630 if name is not None:
2631 request.name = name
2632 if exclusion is not None:
2633 request.exclusion = exclusion
2634 if update_mask is not None:
2635 request.update_mask = update_mask
2637 # Wrap the RPC method; this adds retry and timeout information,
2638 # and friendly error handling.
2639 rpc = self._transport._wrapped_methods[self._transport.update_exclusion]
2641 # Certain fields should be provided within the metadata header;
2642 # add these here.
2643 metadata = tuple(metadata) + (
2644 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
2645 )
2647 # Send the request.
2648 response = rpc(
2649 request,
2650 retry=retry,
2651 timeout=timeout,
2652 metadata=metadata,
2653 )
2655 # Done; return the response.
2656 return response
2658 def delete_exclusion(
2659 self,
2660 request: Optional[Union[logging_config.DeleteExclusionRequest, dict]] = None,
2661 *,
2662 name: Optional[str] = None,
2663 retry: OptionalRetry = gapic_v1.method.DEFAULT,
2664 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
2665 metadata: Sequence[Tuple[str, str]] = (),
2666 ) -> None:
2667 r"""Deletes an exclusion in the \_Default sink.
2669 .. code-block:: python
2671 # This snippet has been automatically generated and should be regarded as a
2672 # code template only.
2673 # It will require modifications to work:
2674 # - It may require correct/in-range values for request initialization.
2675 # - It may require specifying regional endpoints when creating the service
2676 # client as shown in:
2677 # https://googleapis.dev/python/google-api-core/latest/client_options.html
2678 from google.cloud import logging_v2
2680 def sample_delete_exclusion():
2681 # Create a client
2682 client = logging_v2.ConfigServiceV2Client()
2684 # Initialize request argument(s)
2685 request = logging_v2.DeleteExclusionRequest(
2686 name="name_value",
2687 )
2689 # Make the request
2690 client.delete_exclusion(request=request)
2692 Args:
2693 request (Union[google.cloud.logging_v2.types.DeleteExclusionRequest, dict]):
2694 The request object. The parameters to `DeleteExclusion`.
2695 name (str):
2696 Required. The resource name of an existing exclusion to
2697 delete:
2699 ::
2701 "projects/[PROJECT_ID]/exclusions/[EXCLUSION_ID]"
2702 "organizations/[ORGANIZATION_ID]/exclusions/[EXCLUSION_ID]"
2703 "billingAccounts/[BILLING_ACCOUNT_ID]/exclusions/[EXCLUSION_ID]"
2704 "folders/[FOLDER_ID]/exclusions/[EXCLUSION_ID]"
2706 For example:
2708 ``"projects/my-project/exclusions/my-exclusion"``
2710 This corresponds to the ``name`` field
2711 on the ``request`` instance; if ``request`` is provided, this
2712 should not be set.
2713 retry (google.api_core.retry.Retry): Designation of what errors, if any,
2714 should be retried.
2715 timeout (float): The timeout for this request.
2716 metadata (Sequence[Tuple[str, str]]): Strings which should be
2717 sent along with the request as metadata.
2718 """
2719 # Create or coerce a protobuf request object.
2720 # Quick check: If we got a request object, we should *not* have
2721 # gotten any keyword arguments that map to the request.
2722 has_flattened_params = any([name])
2723 if request is not None and has_flattened_params:
2724 raise ValueError(
2725 "If the `request` argument is set, then none of "
2726 "the individual field arguments should be set."
2727 )
2729 # Minor optimization to avoid making a copy if the user passes
2730 # in a logging_config.DeleteExclusionRequest.
2731 # There's no risk of modifying the input as we've already verified
2732 # there are no flattened fields.
2733 if not isinstance(request, logging_config.DeleteExclusionRequest):
2734 request = logging_config.DeleteExclusionRequest(request)
2735 # If we have keyword arguments corresponding to fields on the
2736 # request, apply these.
2737 if name is not None:
2738 request.name = name
2740 # Wrap the RPC method; this adds retry and timeout information,
2741 # and friendly error handling.
2742 rpc = self._transport._wrapped_methods[self._transport.delete_exclusion]
2744 # Certain fields should be provided within the metadata header;
2745 # add these here.
2746 metadata = tuple(metadata) + (
2747 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
2748 )
2750 # Send the request.
2751 rpc(
2752 request,
2753 retry=retry,
2754 timeout=timeout,
2755 metadata=metadata,
2756 )
2758 def get_cmek_settings(
2759 self,
2760 request: Optional[Union[logging_config.GetCmekSettingsRequest, dict]] = None,
2761 *,
2762 retry: OptionalRetry = gapic_v1.method.DEFAULT,
2763 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
2764 metadata: Sequence[Tuple[str, str]] = (),
2765 ) -> logging_config.CmekSettings:
2766 r"""Gets the Logging CMEK settings for the given resource.
2768 Note: CMEK for the Log Router can be configured for Google Cloud
2769 projects, folders, organizations and billing accounts. Once
2770 configured for an organization, it applies to all projects and
2771 folders in the Google Cloud organization.
2773 See `Enabling CMEK for Log
2774 Router <https://cloud.google.com/logging/docs/routing/managed-encryption>`__
2775 for more information.
2777 .. code-block:: python
2779 # This snippet has been automatically generated and should be regarded as a
2780 # code template only.
2781 # It will require modifications to work:
2782 # - It may require correct/in-range values for request initialization.
2783 # - It may require specifying regional endpoints when creating the service
2784 # client as shown in:
2785 # https://googleapis.dev/python/google-api-core/latest/client_options.html
2786 from google.cloud import logging_v2
2788 def sample_get_cmek_settings():
2789 # Create a client
2790 client = logging_v2.ConfigServiceV2Client()
2792 # Initialize request argument(s)
2793 request = logging_v2.GetCmekSettingsRequest(
2794 name="name_value",
2795 )
2797 # Make the request
2798 response = client.get_cmek_settings(request=request)
2800 # Handle the response
2801 print(response)
2803 Args:
2804 request (Union[google.cloud.logging_v2.types.GetCmekSettingsRequest, dict]):
2805 The request object. The parameters to
2806 [GetCmekSettings][google.logging.v2.ConfigServiceV2.GetCmekSettings].
2807 See [Enabling CMEK for Log
2808 Router](https://cloud.google.com/logging/docs/routing/managed-encryption)
2809 for more information.
2810 retry (google.api_core.retry.Retry): Designation of what errors, if any,
2811 should be retried.
2812 timeout (float): The timeout for this request.
2813 metadata (Sequence[Tuple[str, str]]): Strings which should be
2814 sent along with the request as metadata.
2816 Returns:
2817 google.cloud.logging_v2.types.CmekSettings:
2818 Describes the customer-managed encryption key (CMEK) settings associated with
2819 a project, folder, organization, billing account, or
2820 flexible resource.
2822 Note: CMEK for the Log Router can currently only be
2823 configured for Google Cloud organizations. Once
2824 configured, it applies to all projects and folders in
2825 the Google Cloud organization.
2827 See [Enabling CMEK for Log
2828 Router](\ https://cloud.google.com/logging/docs/routing/managed-encryption)
2829 for more information.
2831 """
2832 # Create or coerce a protobuf request object.
2833 # Minor optimization to avoid making a copy if the user passes
2834 # in a logging_config.GetCmekSettingsRequest.
2835 # There's no risk of modifying the input as we've already verified
2836 # there are no flattened fields.
2837 if not isinstance(request, logging_config.GetCmekSettingsRequest):
2838 request = logging_config.GetCmekSettingsRequest(request)
2840 # Wrap the RPC method; this adds retry and timeout information,
2841 # and friendly error handling.
2842 rpc = self._transport._wrapped_methods[self._transport.get_cmek_settings]
2844 # Certain fields should be provided within the metadata header;
2845 # add these here.
2846 metadata = tuple(metadata) + (
2847 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
2848 )
2850 # Send the request.
2851 response = rpc(
2852 request,
2853 retry=retry,
2854 timeout=timeout,
2855 metadata=metadata,
2856 )
2858 # Done; return the response.
2859 return response
2861 def update_cmek_settings(
2862 self,
2863 request: Optional[Union[logging_config.UpdateCmekSettingsRequest, dict]] = None,
2864 *,
2865 retry: OptionalRetry = gapic_v1.method.DEFAULT,
2866 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
2867 metadata: Sequence[Tuple[str, str]] = (),
2868 ) -> logging_config.CmekSettings:
2869 r"""Updates the Log Router CMEK settings for the given resource.
2871 Note: CMEK for the Log Router can currently only be configured
2872 for Google Cloud organizations. Once configured, it applies to
2873 all projects and folders in the Google Cloud organization.
2875 [UpdateCmekSettings][google.logging.v2.ConfigServiceV2.UpdateCmekSettings]
2876 will fail if 1) ``kms_key_name`` is invalid, or 2) the
2877 associated service account does not have the required
2878 ``roles/cloudkms.cryptoKeyEncrypterDecrypter`` role assigned for
2879 the key, or 3) access to the key is disabled.
2881 See `Enabling CMEK for Log
2882 Router <https://cloud.google.com/logging/docs/routing/managed-encryption>`__
2883 for more information.
2885 .. code-block:: python
2887 # This snippet has been automatically generated and should be regarded as a
2888 # code template only.
2889 # It will require modifications to work:
2890 # - It may require correct/in-range values for request initialization.
2891 # - It may require specifying regional endpoints when creating the service
2892 # client as shown in:
2893 # https://googleapis.dev/python/google-api-core/latest/client_options.html
2894 from google.cloud import logging_v2
2896 def sample_update_cmek_settings():
2897 # Create a client
2898 client = logging_v2.ConfigServiceV2Client()
2900 # Initialize request argument(s)
2901 request = logging_v2.UpdateCmekSettingsRequest(
2902 name="name_value",
2903 )
2905 # Make the request
2906 response = client.update_cmek_settings(request=request)
2908 # Handle the response
2909 print(response)
2911 Args:
2912 request (Union[google.cloud.logging_v2.types.UpdateCmekSettingsRequest, dict]):
2913 The request object. The parameters to
2914 [UpdateCmekSettings][google.logging.v2.ConfigServiceV2.UpdateCmekSettings].
2915 See [Enabling CMEK for Log
2916 Router](https://cloud.google.com/logging/docs/routing/managed-encryption)
2917 for more information.
2918 retry (google.api_core.retry.Retry): Designation of what errors, if any,
2919 should be retried.
2920 timeout (float): The timeout for this request.
2921 metadata (Sequence[Tuple[str, str]]): Strings which should be
2922 sent along with the request as metadata.
2924 Returns:
2925 google.cloud.logging_v2.types.CmekSettings:
2926 Describes the customer-managed encryption key (CMEK) settings associated with
2927 a project, folder, organization, billing account, or
2928 flexible resource.
2930 Note: CMEK for the Log Router can currently only be
2931 configured for Google Cloud organizations. Once
2932 configured, it applies to all projects and folders in
2933 the Google Cloud organization.
2935 See [Enabling CMEK for Log
2936 Router](\ https://cloud.google.com/logging/docs/routing/managed-encryption)
2937 for more information.
2939 """
2940 # Create or coerce a protobuf request object.
2941 # Minor optimization to avoid making a copy if the user passes
2942 # in a logging_config.UpdateCmekSettingsRequest.
2943 # There's no risk of modifying the input as we've already verified
2944 # there are no flattened fields.
2945 if not isinstance(request, logging_config.UpdateCmekSettingsRequest):
2946 request = logging_config.UpdateCmekSettingsRequest(request)
2948 # Wrap the RPC method; this adds retry and timeout information,
2949 # and friendly error handling.
2950 rpc = self._transport._wrapped_methods[self._transport.update_cmek_settings]
2952 # Certain fields should be provided within the metadata header;
2953 # add these here.
2954 metadata = tuple(metadata) + (
2955 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
2956 )
2958 # Send the request.
2959 response = rpc(
2960 request,
2961 retry=retry,
2962 timeout=timeout,
2963 metadata=metadata,
2964 )
2966 # Done; return the response.
2967 return response
2969 def get_settings(
2970 self,
2971 request: Optional[Union[logging_config.GetSettingsRequest, dict]] = None,
2972 *,
2973 name: Optional[str] = None,
2974 retry: OptionalRetry = gapic_v1.method.DEFAULT,
2975 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
2976 metadata: Sequence[Tuple[str, str]] = (),
2977 ) -> logging_config.Settings:
2978 r"""Gets the Log Router settings for the given resource.
2980 Note: Settings for the Log Router can be get for Google Cloud
2981 projects, folders, organizations and billing accounts. Currently
2982 it can only be configured for organizations. Once configured for
2983 an organization, it applies to all projects and folders in the
2984 Google Cloud organization.
2986 See `Enabling CMEK for Log
2987 Router <https://cloud.google.com/logging/docs/routing/managed-encryption>`__
2988 for more information.
2990 .. code-block:: python
2992 # This snippet has been automatically generated and should be regarded as a
2993 # code template only.
2994 # It will require modifications to work:
2995 # - It may require correct/in-range values for request initialization.
2996 # - It may require specifying regional endpoints when creating the service
2997 # client as shown in:
2998 # https://googleapis.dev/python/google-api-core/latest/client_options.html
2999 from google.cloud import logging_v2
3001 def sample_get_settings():
3002 # Create a client
3003 client = logging_v2.ConfigServiceV2Client()
3005 # Initialize request argument(s)
3006 request = logging_v2.GetSettingsRequest(
3007 name="name_value",
3008 )
3010 # Make the request
3011 response = client.get_settings(request=request)
3013 # Handle the response
3014 print(response)
3016 Args:
3017 request (Union[google.cloud.logging_v2.types.GetSettingsRequest, dict]):
3018 The request object. The parameters to
3019 [GetSettings][google.logging.v2.ConfigServiceV2.GetSettings].
3020 See [Enabling CMEK for Log
3021 Router](https://cloud.google.com/logging/docs/routing/managed-encryption)
3022 for more information.
3023 name (str):
3024 Required. The resource for which to retrieve settings.
3026 ::
3028 "projects/[PROJECT_ID]/settings"
3029 "organizations/[ORGANIZATION_ID]/settings"
3030 "billingAccounts/[BILLING_ACCOUNT_ID]/settings"
3031 "folders/[FOLDER_ID]/settings"
3033 For example:
3035 ``"organizations/12345/settings"``
3037 Note: Settings for the Log Router can be get for Google
3038 Cloud projects, folders, organizations and billing
3039 accounts. Currently it can only be configured for
3040 organizations. Once configured for an organization, it
3041 applies to all projects and folders in the Google Cloud
3042 organization.
3044 This corresponds to the ``name`` field
3045 on the ``request`` instance; if ``request`` is provided, this
3046 should not be set.
3047 retry (google.api_core.retry.Retry): Designation of what errors, if any,
3048 should be retried.
3049 timeout (float): The timeout for this request.
3050 metadata (Sequence[Tuple[str, str]]): Strings which should be
3051 sent along with the request as metadata.
3053 Returns:
3054 google.cloud.logging_v2.types.Settings:
3055 Describes the settings associated
3056 with a project, folder, organization,
3057 billing account, or flexible resource.
3059 """
3060 # Create or coerce a protobuf request object.
3061 # Quick check: If we got a request object, we should *not* have
3062 # gotten any keyword arguments that map to the request.
3063 has_flattened_params = any([name])
3064 if request is not None and has_flattened_params:
3065 raise ValueError(
3066 "If the `request` argument is set, then none of "
3067 "the individual field arguments should be set."
3068 )
3070 # Minor optimization to avoid making a copy if the user passes
3071 # in a logging_config.GetSettingsRequest.
3072 # There's no risk of modifying the input as we've already verified
3073 # there are no flattened fields.
3074 if not isinstance(request, logging_config.GetSettingsRequest):
3075 request = logging_config.GetSettingsRequest(request)
3076 # If we have keyword arguments corresponding to fields on the
3077 # request, apply these.
3078 if name is not None:
3079 request.name = name
3081 # Wrap the RPC method; this adds retry and timeout information,
3082 # and friendly error handling.
3083 rpc = self._transport._wrapped_methods[self._transport.get_settings]
3085 # Certain fields should be provided within the metadata header;
3086 # add these here.
3087 metadata = tuple(metadata) + (
3088 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
3089 )
3091 # Send the request.
3092 response = rpc(
3093 request,
3094 retry=retry,
3095 timeout=timeout,
3096 metadata=metadata,
3097 )
3099 # Done; return the response.
3100 return response
3102 def update_settings(
3103 self,
3104 request: Optional[Union[logging_config.UpdateSettingsRequest, dict]] = None,
3105 *,
3106 settings: Optional[logging_config.Settings] = None,
3107 update_mask: Optional[field_mask_pb2.FieldMask] = None,
3108 retry: OptionalRetry = gapic_v1.method.DEFAULT,
3109 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
3110 metadata: Sequence[Tuple[str, str]] = (),
3111 ) -> logging_config.Settings:
3112 r"""Updates the Log Router settings for the given resource.
3114 Note: Settings for the Log Router can currently only be
3115 configured for Google Cloud organizations. Once configured, it
3116 applies to all projects and folders in the Google Cloud
3117 organization.
3119 [UpdateSettings][google.logging.v2.ConfigServiceV2.UpdateSettings]
3120 will fail if 1) ``kms_key_name`` is invalid, or 2) the
3121 associated service account does not have the required
3122 ``roles/cloudkms.cryptoKeyEncrypterDecrypter`` role assigned for
3123 the key, or 3) access to the key is disabled. 4) ``location_id``
3124 is not supported by Logging. 5) ``location_id`` violate
3125 OrgPolicy.
3127 See `Enabling CMEK for Log
3128 Router <https://cloud.google.com/logging/docs/routing/managed-encryption>`__
3129 for more information.
3131 .. code-block:: python
3133 # This snippet has been automatically generated and should be regarded as a
3134 # code template only.
3135 # It will require modifications to work:
3136 # - It may require correct/in-range values for request initialization.
3137 # - It may require specifying regional endpoints when creating the service
3138 # client as shown in:
3139 # https://googleapis.dev/python/google-api-core/latest/client_options.html
3140 from google.cloud import logging_v2
3142 def sample_update_settings():
3143 # Create a client
3144 client = logging_v2.ConfigServiceV2Client()
3146 # Initialize request argument(s)
3147 request = logging_v2.UpdateSettingsRequest(
3148 name="name_value",
3149 )
3151 # Make the request
3152 response = client.update_settings(request=request)
3154 # Handle the response
3155 print(response)
3157 Args:
3158 request (Union[google.cloud.logging_v2.types.UpdateSettingsRequest, dict]):
3159 The request object. The parameters to
3160 [UpdateSettings][google.logging.v2.ConfigServiceV2.UpdateSettings].
3161 See [Enabling CMEK for Log
3162 Router](https://cloud.google.com/logging/docs/routing/managed-encryption)
3163 for more information.
3164 settings (google.cloud.logging_v2.types.Settings):
3165 Required. The settings to update.
3167 See `Enabling CMEK for Log
3168 Router <https://cloud.google.com/logging/docs/routing/managed-encryption>`__
3169 for more information.
3171 This corresponds to the ``settings`` field
3172 on the ``request`` instance; if ``request`` is provided, this
3173 should not be set.
3174 update_mask (google.protobuf.field_mask_pb2.FieldMask):
3175 Optional. Field mask identifying which fields from
3176 ``settings`` should be updated. A field will be
3177 overwritten if and only if it is in the update mask.
3178 Output only fields cannot be updated.
3180 See [FieldMask][google.protobuf.FieldMask] for more
3181 information.
3183 For example: ``"updateMask=kmsKeyName"``
3185 This corresponds to the ``update_mask`` field
3186 on the ``request`` instance; if ``request`` is provided, this
3187 should not be set.
3188 retry (google.api_core.retry.Retry): Designation of what errors, if any,
3189 should be retried.
3190 timeout (float): The timeout for this request.
3191 metadata (Sequence[Tuple[str, str]]): Strings which should be
3192 sent along with the request as metadata.
3194 Returns:
3195 google.cloud.logging_v2.types.Settings:
3196 Describes the settings associated
3197 with a project, folder, organization,
3198 billing account, or flexible resource.
3200 """
3201 # Create or coerce a protobuf request object.
3202 # Quick check: If we got a request object, we should *not* have
3203 # gotten any keyword arguments that map to the request.
3204 has_flattened_params = any([settings, update_mask])
3205 if request is not None and has_flattened_params:
3206 raise ValueError(
3207 "If the `request` argument is set, then none of "
3208 "the individual field arguments should be set."
3209 )
3211 # Minor optimization to avoid making a copy if the user passes
3212 # in a logging_config.UpdateSettingsRequest.
3213 # There's no risk of modifying the input as we've already verified
3214 # there are no flattened fields.
3215 if not isinstance(request, logging_config.UpdateSettingsRequest):
3216 request = logging_config.UpdateSettingsRequest(request)
3217 # If we have keyword arguments corresponding to fields on the
3218 # request, apply these.
3219 if settings is not None:
3220 request.settings = settings
3221 if update_mask is not None:
3222 request.update_mask = update_mask
3224 # Wrap the RPC method; this adds retry and timeout information,
3225 # and friendly error handling.
3226 rpc = self._transport._wrapped_methods[self._transport.update_settings]
3228 # Certain fields should be provided within the metadata header;
3229 # add these here.
3230 metadata = tuple(metadata) + (
3231 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
3232 )
3234 # Send the request.
3235 response = rpc(
3236 request,
3237 retry=retry,
3238 timeout=timeout,
3239 metadata=metadata,
3240 )
3242 # Done; return the response.
3243 return response
3245 def copy_log_entries(
3246 self,
3247 request: Optional[Union[logging_config.CopyLogEntriesRequest, dict]] = None,
3248 *,
3249 retry: OptionalRetry = gapic_v1.method.DEFAULT,
3250 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
3251 metadata: Sequence[Tuple[str, str]] = (),
3252 ) -> operation.Operation:
3253 r"""Copies a set of log entries from a log bucket to a
3254 Cloud Storage bucket.
3256 .. code-block:: python
3258 # This snippet has been automatically generated and should be regarded as a
3259 # code template only.
3260 # It will require modifications to work:
3261 # - It may require correct/in-range values for request initialization.
3262 # - It may require specifying regional endpoints when creating the service
3263 # client as shown in:
3264 # https://googleapis.dev/python/google-api-core/latest/client_options.html
3265 from google.cloud import logging_v2
3267 def sample_copy_log_entries():
3268 # Create a client
3269 client = logging_v2.ConfigServiceV2Client()
3271 # Initialize request argument(s)
3272 request = logging_v2.CopyLogEntriesRequest(
3273 name="name_value",
3274 destination="destination_value",
3275 )
3277 # Make the request
3278 operation = client.copy_log_entries(request=request)
3280 print("Waiting for operation to complete...")
3282 response = operation.result()
3284 # Handle the response
3285 print(response)
3287 Args:
3288 request (Union[google.cloud.logging_v2.types.CopyLogEntriesRequest, dict]):
3289 The request object. The parameters to CopyLogEntries.
3290 retry (google.api_core.retry.Retry): Designation of what errors, if any,
3291 should be retried.
3292 timeout (float): The timeout for this request.
3293 metadata (Sequence[Tuple[str, str]]): Strings which should be
3294 sent along with the request as metadata.
3296 Returns:
3297 google.api_core.operation.Operation:
3298 An object representing a long-running operation.
3300 The result type for the operation will be
3301 :class:`google.cloud.logging_v2.types.CopyLogEntriesResponse`
3302 Response type for CopyLogEntries long running
3303 operations.
3305 """
3306 # Create or coerce a protobuf request object.
3307 # Minor optimization to avoid making a copy if the user passes
3308 # in a logging_config.CopyLogEntriesRequest.
3309 # There's no risk of modifying the input as we've already verified
3310 # there are no flattened fields.
3311 if not isinstance(request, logging_config.CopyLogEntriesRequest):
3312 request = logging_config.CopyLogEntriesRequest(request)
3314 # Wrap the RPC method; this adds retry and timeout information,
3315 # and friendly error handling.
3316 rpc = self._transport._wrapped_methods[self._transport.copy_log_entries]
3318 # Send the request.
3319 response = rpc(
3320 request,
3321 retry=retry,
3322 timeout=timeout,
3323 metadata=metadata,
3324 )
3326 # Wrap the response in an operation future.
3327 response = operation.from_gapic(
3328 response,
3329 self._transport.operations_client,
3330 logging_config.CopyLogEntriesResponse,
3331 metadata_type=logging_config.CopyLogEntriesMetadata,
3332 )
3334 # Done; return the response.
3335 return response
3337 def __enter__(self) -> "ConfigServiceV2Client":
3338 return self
3340 def __exit__(self, type, value, traceback):
3341 """Releases underlying transport's resources.
3343 .. warning::
3344 ONLY use as a context manager if the transport is NOT shared
3345 with other clients! Exiting the with block will CLOSE the transport
3346 and may cause errors in other clients!
3347 """
3348 self.transport.close()
3351DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
3352 gapic_version=package_version.__version__
3353)
3356__all__ = ("ConfigServiceV2Client",)