1# -*- coding: utf-8 -*-
2# Copyright 2025 Google LLC
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16from collections import OrderedDict
17from http import HTTPStatus
18import json
19import logging as std_logging
20import os
21import re
22from typing import (
23 Dict,
24 Callable,
25 Mapping,
26 MutableMapping,
27 MutableSequence,
28 Optional,
29 Sequence,
30 Tuple,
31 Type,
32 Union,
33 cast,
34)
35import warnings
36
37from google.cloud.logging_v2 import gapic_version as package_version
38
39from google.api_core import client_options as client_options_lib
40from google.api_core import exceptions as core_exceptions
41from google.api_core import gapic_v1
42from google.api_core import retry as retries
43from google.auth import credentials as ga_credentials # type: ignore
44from google.auth.transport import mtls # type: ignore
45from google.auth.transport.grpc import SslCredentials # type: ignore
46from google.auth.exceptions import MutualTLSChannelError # type: ignore
47from google.oauth2 import service_account # type: ignore
48
49try:
50 OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None]
51except AttributeError: # pragma: NO COVER
52 OptionalRetry = Union[retries.Retry, object, None] # type: ignore
53
54try:
55 from google.api_core import client_logging # type: ignore
56
57 CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER
58except ImportError: # pragma: NO COVER
59 CLIENT_LOGGING_SUPPORTED = False
60
61_LOGGER = std_logging.getLogger(__name__)
62
63from google.api_core import operation # type: ignore
64from google.api_core import operation_async # type: ignore
65from google.cloud.logging_v2.services.config_service_v2 import pagers
66from google.cloud.logging_v2.types import logging_config
67from google.longrunning import operations_pb2 # type: ignore
68from google.protobuf import empty_pb2 # type: ignore
69from google.protobuf import field_mask_pb2 # type: ignore
70from google.protobuf import timestamp_pb2 # type: ignore
71from .transports.base import ConfigServiceV2Transport, DEFAULT_CLIENT_INFO
72from .transports.grpc import ConfigServiceV2GrpcTransport
73from .transports.grpc_asyncio import ConfigServiceV2GrpcAsyncIOTransport
74
75
76class ConfigServiceV2ClientMeta(type):
77 """Metaclass for the ConfigServiceV2 client.
78
79 This provides class-level methods for building and retrieving
80 support objects (e.g. transport) without polluting the client instance
81 objects.
82 """
83
84 _transport_registry = (
85 OrderedDict()
86 ) # type: Dict[str, Type[ConfigServiceV2Transport]]
87 _transport_registry["grpc"] = ConfigServiceV2GrpcTransport
88 _transport_registry["grpc_asyncio"] = ConfigServiceV2GrpcAsyncIOTransport
89
90 def get_transport_class(
91 cls,
92 label: Optional[str] = None,
93 ) -> Type[ConfigServiceV2Transport]:
94 """Returns an appropriate transport class.
95
96 Args:
97 label: The name of the desired transport. If none is
98 provided, then the first transport in the registry is used.
99
100 Returns:
101 The transport class to use.
102 """
103 # If a specific transport is requested, return that one.
104 if label:
105 return cls._transport_registry[label]
106
107 # No transport is requested; return the default (that is, the first one
108 # in the dictionary).
109 return next(iter(cls._transport_registry.values()))
110
111
112class ConfigServiceV2Client(metaclass=ConfigServiceV2ClientMeta):
113 """Service for configuring sinks used to route log entries."""
114
115 @staticmethod
116 def _get_default_mtls_endpoint(api_endpoint):
117 """Converts api endpoint to mTLS endpoint.
118
119 Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to
120 "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively.
121 Args:
122 api_endpoint (Optional[str]): the api endpoint to convert.
123 Returns:
124 str: converted mTLS api endpoint.
125 """
126 if not api_endpoint:
127 return api_endpoint
128
129 mtls_endpoint_re = re.compile(
130 r"(?P<name>[^.]+)(?P<mtls>\.mtls)?(?P<sandbox>\.sandbox)?(?P<googledomain>\.googleapis\.com)?"
131 )
132
133 m = mtls_endpoint_re.match(api_endpoint)
134 name, mtls, sandbox, googledomain = m.groups()
135 if mtls or not googledomain:
136 return api_endpoint
137
138 if sandbox:
139 return api_endpoint.replace(
140 "sandbox.googleapis.com", "mtls.sandbox.googleapis.com"
141 )
142
143 return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com")
144
145 # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead.
146 DEFAULT_ENDPOINT = "logging.googleapis.com"
147 DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore
148 DEFAULT_ENDPOINT
149 )
150
151 _DEFAULT_ENDPOINT_TEMPLATE = "logging.{UNIVERSE_DOMAIN}"
152 _DEFAULT_UNIVERSE = "googleapis.com"
153
154 @classmethod
155 def from_service_account_info(cls, info: dict, *args, **kwargs):
156 """Creates an instance of this client using the provided credentials
157 info.
158
159 Args:
160 info (dict): The service account private key info.
161 args: Additional arguments to pass to the constructor.
162 kwargs: Additional arguments to pass to the constructor.
163
164 Returns:
165 ConfigServiceV2Client: The constructed client.
166 """
167 credentials = service_account.Credentials.from_service_account_info(info)
168 kwargs["credentials"] = credentials
169 return cls(*args, **kwargs)
170
171 @classmethod
172 def from_service_account_file(cls, filename: str, *args, **kwargs):
173 """Creates an instance of this client using the provided credentials
174 file.
175
176 Args:
177 filename (str): The path to the service account private key json
178 file.
179 args: Additional arguments to pass to the constructor.
180 kwargs: Additional arguments to pass to the constructor.
181
182 Returns:
183 ConfigServiceV2Client: The constructed client.
184 """
185 credentials = service_account.Credentials.from_service_account_file(filename)
186 kwargs["credentials"] = credentials
187 return cls(*args, **kwargs)
188
189 from_service_account_json = from_service_account_file
190
191 @property
192 def transport(self) -> ConfigServiceV2Transport:
193 """Returns the transport used by the client instance.
194
195 Returns:
196 ConfigServiceV2Transport: The transport used by the client
197 instance.
198 """
199 return self._transport
200
201 @staticmethod
202 def cmek_settings_path(
203 project: str,
204 ) -> str:
205 """Returns a fully-qualified cmek_settings string."""
206 return "projects/{project}/cmekSettings".format(
207 project=project,
208 )
209
210 @staticmethod
211 def parse_cmek_settings_path(path: str) -> Dict[str, str]:
212 """Parses a cmek_settings path into its component segments."""
213 m = re.match(r"^projects/(?P<project>.+?)/cmekSettings$", path)
214 return m.groupdict() if m else {}
215
216 @staticmethod
217 def link_path(
218 project: str,
219 location: str,
220 bucket: str,
221 link: str,
222 ) -> str:
223 """Returns a fully-qualified link string."""
224 return "projects/{project}/locations/{location}/buckets/{bucket}/links/{link}".format(
225 project=project,
226 location=location,
227 bucket=bucket,
228 link=link,
229 )
230
231 @staticmethod
232 def parse_link_path(path: str) -> Dict[str, str]:
233 """Parses a link path into its component segments."""
234 m = re.match(
235 r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)/buckets/(?P<bucket>.+?)/links/(?P<link>.+?)$",
236 path,
237 )
238 return m.groupdict() if m else {}
239
240 @staticmethod
241 def log_bucket_path(
242 project: str,
243 location: str,
244 bucket: str,
245 ) -> str:
246 """Returns a fully-qualified log_bucket string."""
247 return "projects/{project}/locations/{location}/buckets/{bucket}".format(
248 project=project,
249 location=location,
250 bucket=bucket,
251 )
252
253 @staticmethod
254 def parse_log_bucket_path(path: str) -> Dict[str, str]:
255 """Parses a log_bucket path into its component segments."""
256 m = re.match(
257 r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)/buckets/(?P<bucket>.+?)$",
258 path,
259 )
260 return m.groupdict() if m else {}
261
262 @staticmethod
263 def log_exclusion_path(
264 project: str,
265 exclusion: str,
266 ) -> str:
267 """Returns a fully-qualified log_exclusion string."""
268 return "projects/{project}/exclusions/{exclusion}".format(
269 project=project,
270 exclusion=exclusion,
271 )
272
273 @staticmethod
274 def parse_log_exclusion_path(path: str) -> Dict[str, str]:
275 """Parses a log_exclusion path into its component segments."""
276 m = re.match(r"^projects/(?P<project>.+?)/exclusions/(?P<exclusion>.+?)$", path)
277 return m.groupdict() if m else {}
278
279 @staticmethod
280 def log_sink_path(
281 project: str,
282 sink: str,
283 ) -> str:
284 """Returns a fully-qualified log_sink string."""
285 return "projects/{project}/sinks/{sink}".format(
286 project=project,
287 sink=sink,
288 )
289
290 @staticmethod
291 def parse_log_sink_path(path: str) -> Dict[str, str]:
292 """Parses a log_sink path into its component segments."""
293 m = re.match(r"^projects/(?P<project>.+?)/sinks/(?P<sink>.+?)$", path)
294 return m.groupdict() if m else {}
295
296 @staticmethod
297 def log_view_path(
298 project: str,
299 location: str,
300 bucket: str,
301 view: str,
302 ) -> str:
303 """Returns a fully-qualified log_view string."""
304 return "projects/{project}/locations/{location}/buckets/{bucket}/views/{view}".format(
305 project=project,
306 location=location,
307 bucket=bucket,
308 view=view,
309 )
310
311 @staticmethod
312 def parse_log_view_path(path: str) -> Dict[str, str]:
313 """Parses a log_view path into its component segments."""
314 m = re.match(
315 r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)/buckets/(?P<bucket>.+?)/views/(?P<view>.+?)$",
316 path,
317 )
318 return m.groupdict() if m else {}
319
320 @staticmethod
321 def settings_path(
322 project: str,
323 ) -> str:
324 """Returns a fully-qualified settings string."""
325 return "projects/{project}/settings".format(
326 project=project,
327 )
328
329 @staticmethod
330 def parse_settings_path(path: str) -> Dict[str, str]:
331 """Parses a settings path into its component segments."""
332 m = re.match(r"^projects/(?P<project>.+?)/settings$", path)
333 return m.groupdict() if m else {}
334
335 @staticmethod
336 def common_billing_account_path(
337 billing_account: str,
338 ) -> str:
339 """Returns a fully-qualified billing_account string."""
340 return "billingAccounts/{billing_account}".format(
341 billing_account=billing_account,
342 )
343
344 @staticmethod
345 def parse_common_billing_account_path(path: str) -> Dict[str, str]:
346 """Parse a billing_account path into its component segments."""
347 m = re.match(r"^billingAccounts/(?P<billing_account>.+?)$", path)
348 return m.groupdict() if m else {}
349
350 @staticmethod
351 def common_folder_path(
352 folder: str,
353 ) -> str:
354 """Returns a fully-qualified folder string."""
355 return "folders/{folder}".format(
356 folder=folder,
357 )
358
359 @staticmethod
360 def parse_common_folder_path(path: str) -> Dict[str, str]:
361 """Parse a folder path into its component segments."""
362 m = re.match(r"^folders/(?P<folder>.+?)$", path)
363 return m.groupdict() if m else {}
364
365 @staticmethod
366 def common_organization_path(
367 organization: str,
368 ) -> str:
369 """Returns a fully-qualified organization string."""
370 return "organizations/{organization}".format(
371 organization=organization,
372 )
373
374 @staticmethod
375 def parse_common_organization_path(path: str) -> Dict[str, str]:
376 """Parse a organization path into its component segments."""
377 m = re.match(r"^organizations/(?P<organization>.+?)$", path)
378 return m.groupdict() if m else {}
379
380 @staticmethod
381 def common_project_path(
382 project: str,
383 ) -> str:
384 """Returns a fully-qualified project string."""
385 return "projects/{project}".format(
386 project=project,
387 )
388
389 @staticmethod
390 def parse_common_project_path(path: str) -> Dict[str, str]:
391 """Parse a project path into its component segments."""
392 m = re.match(r"^projects/(?P<project>.+?)$", path)
393 return m.groupdict() if m else {}
394
395 @staticmethod
396 def common_location_path(
397 project: str,
398 location: str,
399 ) -> str:
400 """Returns a fully-qualified location string."""
401 return "projects/{project}/locations/{location}".format(
402 project=project,
403 location=location,
404 )
405
406 @staticmethod
407 def parse_common_location_path(path: str) -> Dict[str, str]:
408 """Parse a location path into its component segments."""
409 m = re.match(r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)$", path)
410 return m.groupdict() if m else {}
411
412 @classmethod
413 def get_mtls_endpoint_and_cert_source(
414 cls, client_options: Optional[client_options_lib.ClientOptions] = None
415 ):
416 """Deprecated. Return the API endpoint and client cert source for mutual TLS.
417
418 The client cert source is determined in the following order:
419 (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the
420 client cert source is None.
421 (2) if `client_options.client_cert_source` is provided, use the provided one; if the
422 default client cert source exists, use the default one; otherwise the client cert
423 source is None.
424
425 The API endpoint is determined in the following order:
426 (1) if `client_options.api_endpoint` if provided, use the provided one.
427 (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the
428 default mTLS endpoint; if the environment variable is "never", use the default API
429 endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise
430 use the default API endpoint.
431
432 More details can be found at https://google.aip.dev/auth/4114.
433
434 Args:
435 client_options (google.api_core.client_options.ClientOptions): Custom options for the
436 client. Only the `api_endpoint` and `client_cert_source` properties may be used
437 in this method.
438
439 Returns:
440 Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the
441 client cert source to use.
442
443 Raises:
444 google.auth.exceptions.MutualTLSChannelError: If any errors happen.
445 """
446
447 warnings.warn(
448 "get_mtls_endpoint_and_cert_source is deprecated. Use the api_endpoint property instead.",
449 DeprecationWarning,
450 )
451 if client_options is None:
452 client_options = client_options_lib.ClientOptions()
453 use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")
454 use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto")
455 if use_client_cert not in ("true", "false"):
456 raise ValueError(
457 "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
458 )
459 if use_mtls_endpoint not in ("auto", "never", "always"):
460 raise MutualTLSChannelError(
461 "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
462 )
463
464 # Figure out the client cert source to use.
465 client_cert_source = None
466 if use_client_cert == "true":
467 if client_options.client_cert_source:
468 client_cert_source = client_options.client_cert_source
469 elif mtls.has_default_client_cert_source():
470 client_cert_source = mtls.default_client_cert_source()
471
472 # Figure out which api endpoint to use.
473 if client_options.api_endpoint is not None:
474 api_endpoint = client_options.api_endpoint
475 elif use_mtls_endpoint == "always" or (
476 use_mtls_endpoint == "auto" and client_cert_source
477 ):
478 api_endpoint = cls.DEFAULT_MTLS_ENDPOINT
479 else:
480 api_endpoint = cls.DEFAULT_ENDPOINT
481
482 return api_endpoint, client_cert_source
483
484 @staticmethod
485 def _read_environment_variables():
486 """Returns the environment variables used by the client.
487
488 Returns:
489 Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE,
490 GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables.
491
492 Raises:
493 ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not
494 any of ["true", "false"].
495 google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT
496 is not any of ["auto", "never", "always"].
497 """
498 use_client_cert = os.getenv(
499 "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"
500 ).lower()
501 use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower()
502 universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN")
503 if use_client_cert not in ("true", "false"):
504 raise ValueError(
505 "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
506 )
507 if use_mtls_endpoint not in ("auto", "never", "always"):
508 raise MutualTLSChannelError(
509 "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
510 )
511 return use_client_cert == "true", use_mtls_endpoint, universe_domain_env
512
513 @staticmethod
514 def _get_client_cert_source(provided_cert_source, use_cert_flag):
515 """Return the client cert source to be used by the client.
516
517 Args:
518 provided_cert_source (bytes): The client certificate source provided.
519 use_cert_flag (bool): A flag indicating whether to use the client certificate.
520
521 Returns:
522 bytes or None: The client cert source to be used by the client.
523 """
524 client_cert_source = None
525 if use_cert_flag:
526 if provided_cert_source:
527 client_cert_source = provided_cert_source
528 elif mtls.has_default_client_cert_source():
529 client_cert_source = mtls.default_client_cert_source()
530 return client_cert_source
531
532 @staticmethod
533 def _get_api_endpoint(
534 api_override, client_cert_source, universe_domain, use_mtls_endpoint
535 ):
536 """Return the API endpoint used by the client.
537
538 Args:
539 api_override (str): The API endpoint override. If specified, this is always
540 the return value of this function and the other arguments are not used.
541 client_cert_source (bytes): The client certificate source used by the client.
542 universe_domain (str): The universe domain used by the client.
543 use_mtls_endpoint (str): How to use the mTLS endpoint, which depends also on the other parameters.
544 Possible values are "always", "auto", or "never".
545
546 Returns:
547 str: The API endpoint to be used by the client.
548 """
549 if api_override is not None:
550 api_endpoint = api_override
551 elif use_mtls_endpoint == "always" or (
552 use_mtls_endpoint == "auto" and client_cert_source
553 ):
554 _default_universe = ConfigServiceV2Client._DEFAULT_UNIVERSE
555 if universe_domain != _default_universe:
556 raise MutualTLSChannelError(
557 f"mTLS is not supported in any universe other than {_default_universe}."
558 )
559 api_endpoint = ConfigServiceV2Client.DEFAULT_MTLS_ENDPOINT
560 else:
561 api_endpoint = ConfigServiceV2Client._DEFAULT_ENDPOINT_TEMPLATE.format(
562 UNIVERSE_DOMAIN=universe_domain
563 )
564 return api_endpoint
565
566 @staticmethod
567 def _get_universe_domain(
568 client_universe_domain: Optional[str], universe_domain_env: Optional[str]
569 ) -> str:
570 """Return the universe domain used by the client.
571
572 Args:
573 client_universe_domain (Optional[str]): The universe domain configured via the client options.
574 universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable.
575
576 Returns:
577 str: The universe domain to be used by the client.
578
579 Raises:
580 ValueError: If the universe domain is an empty string.
581 """
582 universe_domain = ConfigServiceV2Client._DEFAULT_UNIVERSE
583 if client_universe_domain is not None:
584 universe_domain = client_universe_domain
585 elif universe_domain_env is not None:
586 universe_domain = universe_domain_env
587 if len(universe_domain.strip()) == 0:
588 raise ValueError("Universe Domain cannot be an empty string.")
589 return universe_domain
590
591 def _validate_universe_domain(self):
592 """Validates client's and credentials' universe domains are consistent.
593
594 Returns:
595 bool: True iff the configured universe domain is valid.
596
597 Raises:
598 ValueError: If the configured universe domain is not valid.
599 """
600
601 # NOTE (b/349488459): universe validation is disabled until further notice.
602 return True
603
604 def _add_cred_info_for_auth_errors(
605 self, error: core_exceptions.GoogleAPICallError
606 ) -> None:
607 """Adds credential info string to error details for 401/403/404 errors.
608
609 Args:
610 error (google.api_core.exceptions.GoogleAPICallError): The error to add the cred info.
611 """
612 if error.code not in [
613 HTTPStatus.UNAUTHORIZED,
614 HTTPStatus.FORBIDDEN,
615 HTTPStatus.NOT_FOUND,
616 ]:
617 return
618
619 cred = self._transport._credentials
620
621 # get_cred_info is only available in google-auth>=2.35.0
622 if not hasattr(cred, "get_cred_info"):
623 return
624
625 # ignore the type check since pypy test fails when get_cred_info
626 # is not available
627 cred_info = cred.get_cred_info() # type: ignore
628 if cred_info and hasattr(error._details, "append"):
629 error._details.append(json.dumps(cred_info))
630
631 @property
632 def api_endpoint(self):
633 """Return the API endpoint used by the client instance.
634
635 Returns:
636 str: The API endpoint used by the client instance.
637 """
638 return self._api_endpoint
639
640 @property
641 def universe_domain(self) -> str:
642 """Return the universe domain used by the client instance.
643
644 Returns:
645 str: The universe domain used by the client instance.
646 """
647 return self._universe_domain
648
649 def __init__(
650 self,
651 *,
652 credentials: Optional[ga_credentials.Credentials] = None,
653 transport: Optional[
654 Union[
655 str, ConfigServiceV2Transport, Callable[..., ConfigServiceV2Transport]
656 ]
657 ] = None,
658 client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None,
659 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
660 ) -> None:
661 """Instantiates the config service v2 client.
662
663 Args:
664 credentials (Optional[google.auth.credentials.Credentials]): The
665 authorization credentials to attach to requests. These
666 credentials identify the application to the service; if none
667 are specified, the client will attempt to ascertain the
668 credentials from the environment.
669 transport (Optional[Union[str,ConfigServiceV2Transport,Callable[..., ConfigServiceV2Transport]]]):
670 The transport to use, or a Callable that constructs and returns a new transport.
671 If a Callable is given, it will be called with the same set of initialization
672 arguments as used in the ConfigServiceV2Transport constructor.
673 If set to None, a transport is chosen automatically.
674 client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]):
675 Custom options for the client.
676
677 1. The ``api_endpoint`` property can be used to override the
678 default endpoint provided by the client when ``transport`` is
679 not explicitly provided. Only if this property is not set and
680 ``transport`` was not explicitly provided, the endpoint is
681 determined by the GOOGLE_API_USE_MTLS_ENDPOINT environment
682 variable, which have one of the following values:
683 "always" (always use the default mTLS endpoint), "never" (always
684 use the default regular endpoint) and "auto" (auto-switch to the
685 default mTLS endpoint if client certificate is present; this is
686 the default value).
687
688 2. If the GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable
689 is "true", then the ``client_cert_source`` property can be used
690 to provide a client certificate for mTLS transport. If
691 not provided, the default SSL client certificate will be used if
692 present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not
693 set, no client certificate will be used.
694
695 3. The ``universe_domain`` property can be used to override the
696 default "googleapis.com" universe. Note that the ``api_endpoint``
697 property still takes precedence; and ``universe_domain`` is
698 currently not supported for mTLS.
699
700 client_info (google.api_core.gapic_v1.client_info.ClientInfo):
701 The client info used to send a user-agent string along with
702 API requests. If ``None``, then default info will be used.
703 Generally, you only need to set this if you're developing
704 your own client library.
705
706 Raises:
707 google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
708 creation failed for any reason.
709 """
710 self._client_options = client_options
711 if isinstance(self._client_options, dict):
712 self._client_options = client_options_lib.from_dict(self._client_options)
713 if self._client_options is None:
714 self._client_options = client_options_lib.ClientOptions()
715 self._client_options = cast(
716 client_options_lib.ClientOptions, self._client_options
717 )
718
719 universe_domain_opt = getattr(self._client_options, "universe_domain", None)
720
721 (
722 self._use_client_cert,
723 self._use_mtls_endpoint,
724 self._universe_domain_env,
725 ) = ConfigServiceV2Client._read_environment_variables()
726 self._client_cert_source = ConfigServiceV2Client._get_client_cert_source(
727 self._client_options.client_cert_source, self._use_client_cert
728 )
729 self._universe_domain = ConfigServiceV2Client._get_universe_domain(
730 universe_domain_opt, self._universe_domain_env
731 )
732 self._api_endpoint = None # updated below, depending on `transport`
733
734 # Initialize the universe domain validation.
735 self._is_universe_domain_valid = False
736
737 if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER
738 # Setup logging.
739 client_logging.initialize_logging()
740
741 api_key_value = getattr(self._client_options, "api_key", None)
742 if api_key_value and credentials:
743 raise ValueError(
744 "client_options.api_key and credentials are mutually exclusive"
745 )
746
747 # Save or instantiate the transport.
748 # Ordinarily, we provide the transport, but allowing a custom transport
749 # instance provides an extensibility point for unusual situations.
750 transport_provided = isinstance(transport, ConfigServiceV2Transport)
751 if transport_provided:
752 # transport is a ConfigServiceV2Transport instance.
753 if credentials or self._client_options.credentials_file or api_key_value:
754 raise ValueError(
755 "When providing a transport instance, "
756 "provide its credentials directly."
757 )
758 if self._client_options.scopes:
759 raise ValueError(
760 "When providing a transport instance, provide its scopes "
761 "directly."
762 )
763 self._transport = cast(ConfigServiceV2Transport, transport)
764 self._api_endpoint = self._transport.host
765
766 self._api_endpoint = (
767 self._api_endpoint
768 or ConfigServiceV2Client._get_api_endpoint(
769 self._client_options.api_endpoint,
770 self._client_cert_source,
771 self._universe_domain,
772 self._use_mtls_endpoint,
773 )
774 )
775
776 if not transport_provided:
777 import google.auth._default # type: ignore
778
779 if api_key_value and hasattr(
780 google.auth._default, "get_api_key_credentials"
781 ):
782 credentials = google.auth._default.get_api_key_credentials(
783 api_key_value
784 )
785
786 transport_init: Union[
787 Type[ConfigServiceV2Transport], Callable[..., ConfigServiceV2Transport]
788 ] = (
789 ConfigServiceV2Client.get_transport_class(transport)
790 if isinstance(transport, str) or transport is None
791 else cast(Callable[..., ConfigServiceV2Transport], transport)
792 )
793 # initialize with the provided callable or the passed in class
794 self._transport = transport_init(
795 credentials=credentials,
796 credentials_file=self._client_options.credentials_file,
797 host=self._api_endpoint,
798 scopes=self._client_options.scopes,
799 client_cert_source_for_mtls=self._client_cert_source,
800 quota_project_id=self._client_options.quota_project_id,
801 client_info=client_info,
802 always_use_jwt_access=True,
803 api_audience=self._client_options.api_audience,
804 )
805
806 if "async" not in str(self._transport):
807 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
808 std_logging.DEBUG
809 ): # pragma: NO COVER
810 _LOGGER.debug(
811 "Created client `google.logging_v2.ConfigServiceV2Client`.",
812 extra={
813 "serviceName": "google.logging.v2.ConfigServiceV2",
814 "universeDomain": getattr(
815 self._transport._credentials, "universe_domain", ""
816 ),
817 "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}",
818 "credentialsInfo": getattr(
819 self.transport._credentials, "get_cred_info", lambda: None
820 )(),
821 }
822 if hasattr(self._transport, "_credentials")
823 else {
824 "serviceName": "google.logging.v2.ConfigServiceV2",
825 "credentialsType": None,
826 },
827 )
828
829 def list_buckets(
830 self,
831 request: Optional[Union[logging_config.ListBucketsRequest, dict]] = None,
832 *,
833 parent: Optional[str] = None,
834 retry: OptionalRetry = gapic_v1.method.DEFAULT,
835 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
836 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
837 ) -> pagers.ListBucketsPager:
838 r"""Lists log buckets.
839
840 .. code-block:: python
841
842 # This snippet has been automatically generated and should be regarded as a
843 # code template only.
844 # It will require modifications to work:
845 # - It may require correct/in-range values for request initialization.
846 # - It may require specifying regional endpoints when creating the service
847 # client as shown in:
848 # https://googleapis.dev/python/google-api-core/latest/client_options.html
849 from google.cloud import logging_v2
850
851 def sample_list_buckets():
852 # Create a client
853 client = logging_v2.ConfigServiceV2Client()
854
855 # Initialize request argument(s)
856 request = logging_v2.ListBucketsRequest(
857 parent="parent_value",
858 )
859
860 # Make the request
861 page_result = client.list_buckets(request=request)
862
863 # Handle the response
864 for response in page_result:
865 print(response)
866
867 Args:
868 request (Union[google.cloud.logging_v2.types.ListBucketsRequest, dict]):
869 The request object. The parameters to ``ListBuckets``.
870 parent (str):
871 Required. The parent resource whose buckets are to be
872 listed:
873
874 ::
875
876 "projects/[PROJECT_ID]/locations/[LOCATION_ID]"
877 "organizations/[ORGANIZATION_ID]/locations/[LOCATION_ID]"
878 "billingAccounts/[BILLING_ACCOUNT_ID]/locations/[LOCATION_ID]"
879 "folders/[FOLDER_ID]/locations/[LOCATION_ID]"
880
881 Note: The locations portion of the resource must be
882 specified, but supplying the character ``-`` in place of
883 [LOCATION_ID] will return all buckets.
884
885 This corresponds to the ``parent`` field
886 on the ``request`` instance; if ``request`` is provided, this
887 should not be set.
888 retry (google.api_core.retry.Retry): Designation of what errors, if any,
889 should be retried.
890 timeout (float): The timeout for this request.
891 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
892 sent along with the request as metadata. Normally, each value must be of type `str`,
893 but for metadata keys ending with the suffix `-bin`, the corresponding values must
894 be of type `bytes`.
895
896 Returns:
897 google.cloud.logging_v2.services.config_service_v2.pagers.ListBucketsPager:
898 The response from ListBuckets.
899
900 Iterating over this object will yield
901 results and resolve additional pages
902 automatically.
903
904 """
905 # Create or coerce a protobuf request object.
906 # - Quick check: If we got a request object, we should *not* have
907 # gotten any keyword arguments that map to the request.
908 flattened_params = [parent]
909 has_flattened_params = (
910 len([param for param in flattened_params if param is not None]) > 0
911 )
912 if request is not None and has_flattened_params:
913 raise ValueError(
914 "If the `request` argument is set, then none of "
915 "the individual field arguments should be set."
916 )
917
918 # - Use the request object if provided (there's no risk of modifying the input as
919 # there are no flattened fields), or create one.
920 if not isinstance(request, logging_config.ListBucketsRequest):
921 request = logging_config.ListBucketsRequest(request)
922 # If we have keyword arguments corresponding to fields on the
923 # request, apply these.
924 if parent is not None:
925 request.parent = parent
926
927 # Wrap the RPC method; this adds retry and timeout information,
928 # and friendly error handling.
929 rpc = self._transport._wrapped_methods[self._transport.list_buckets]
930
931 # Certain fields should be provided within the metadata header;
932 # add these here.
933 metadata = tuple(metadata) + (
934 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
935 )
936
937 # Validate the universe domain.
938 self._validate_universe_domain()
939
940 # Send the request.
941 response = rpc(
942 request,
943 retry=retry,
944 timeout=timeout,
945 metadata=metadata,
946 )
947
948 # This method is paged; wrap the response in a pager, which provides
949 # an `__iter__` convenience method.
950 response = pagers.ListBucketsPager(
951 method=rpc,
952 request=request,
953 response=response,
954 retry=retry,
955 timeout=timeout,
956 metadata=metadata,
957 )
958
959 # Done; return the response.
960 return response
961
962 def get_bucket(
963 self,
964 request: Optional[Union[logging_config.GetBucketRequest, dict]] = None,
965 *,
966 retry: OptionalRetry = gapic_v1.method.DEFAULT,
967 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
968 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
969 ) -> logging_config.LogBucket:
970 r"""Gets a log bucket.
971
972 .. code-block:: python
973
974 # This snippet has been automatically generated and should be regarded as a
975 # code template only.
976 # It will require modifications to work:
977 # - It may require correct/in-range values for request initialization.
978 # - It may require specifying regional endpoints when creating the service
979 # client as shown in:
980 # https://googleapis.dev/python/google-api-core/latest/client_options.html
981 from google.cloud import logging_v2
982
983 def sample_get_bucket():
984 # Create a client
985 client = logging_v2.ConfigServiceV2Client()
986
987 # Initialize request argument(s)
988 request = logging_v2.GetBucketRequest(
989 name="name_value",
990 )
991
992 # Make the request
993 response = client.get_bucket(request=request)
994
995 # Handle the response
996 print(response)
997
998 Args:
999 request (Union[google.cloud.logging_v2.types.GetBucketRequest, dict]):
1000 The request object. The parameters to ``GetBucket``.
1001 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1002 should be retried.
1003 timeout (float): The timeout for this request.
1004 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1005 sent along with the request as metadata. Normally, each value must be of type `str`,
1006 but for metadata keys ending with the suffix `-bin`, the corresponding values must
1007 be of type `bytes`.
1008
1009 Returns:
1010 google.cloud.logging_v2.types.LogBucket:
1011 Describes a repository in which log
1012 entries are stored.
1013
1014 """
1015 # Create or coerce a protobuf request object.
1016 # - Use the request object if provided (there's no risk of modifying the input as
1017 # there are no flattened fields), or create one.
1018 if not isinstance(request, logging_config.GetBucketRequest):
1019 request = logging_config.GetBucketRequest(request)
1020
1021 # Wrap the RPC method; this adds retry and timeout information,
1022 # and friendly error handling.
1023 rpc = self._transport._wrapped_methods[self._transport.get_bucket]
1024
1025 # Certain fields should be provided within the metadata header;
1026 # add these here.
1027 metadata = tuple(metadata) + (
1028 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1029 )
1030
1031 # Validate the universe domain.
1032 self._validate_universe_domain()
1033
1034 # Send the request.
1035 response = rpc(
1036 request,
1037 retry=retry,
1038 timeout=timeout,
1039 metadata=metadata,
1040 )
1041
1042 # Done; return the response.
1043 return response
1044
1045 def create_bucket_async(
1046 self,
1047 request: Optional[Union[logging_config.CreateBucketRequest, dict]] = None,
1048 *,
1049 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1050 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1051 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1052 ) -> operation.Operation:
1053 r"""Creates a log bucket asynchronously that can be used
1054 to store log entries.
1055 After a bucket has been created, the bucket's location
1056 cannot be changed.
1057
1058 .. code-block:: python
1059
1060 # This snippet has been automatically generated and should be regarded as a
1061 # code template only.
1062 # It will require modifications to work:
1063 # - It may require correct/in-range values for request initialization.
1064 # - It may require specifying regional endpoints when creating the service
1065 # client as shown in:
1066 # https://googleapis.dev/python/google-api-core/latest/client_options.html
1067 from google.cloud import logging_v2
1068
1069 def sample_create_bucket_async():
1070 # Create a client
1071 client = logging_v2.ConfigServiceV2Client()
1072
1073 # Initialize request argument(s)
1074 request = logging_v2.CreateBucketRequest(
1075 parent="parent_value",
1076 bucket_id="bucket_id_value",
1077 )
1078
1079 # Make the request
1080 operation = client.create_bucket_async(request=request)
1081
1082 print("Waiting for operation to complete...")
1083
1084 response = operation.result()
1085
1086 # Handle the response
1087 print(response)
1088
1089 Args:
1090 request (Union[google.cloud.logging_v2.types.CreateBucketRequest, dict]):
1091 The request object. The parameters to ``CreateBucket``.
1092 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1093 should be retried.
1094 timeout (float): The timeout for this request.
1095 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1096 sent along with the request as metadata. Normally, each value must be of type `str`,
1097 but for metadata keys ending with the suffix `-bin`, the corresponding values must
1098 be of type `bytes`.
1099
1100 Returns:
1101 google.api_core.operation.Operation:
1102 An object representing a long-running operation.
1103
1104 The result type for the operation will be
1105 :class:`google.cloud.logging_v2.types.LogBucket`
1106 Describes a repository in which log entries are stored.
1107
1108 """
1109 # Create or coerce a protobuf request object.
1110 # - Use the request object if provided (there's no risk of modifying the input as
1111 # there are no flattened fields), or create one.
1112 if not isinstance(request, logging_config.CreateBucketRequest):
1113 request = logging_config.CreateBucketRequest(request)
1114
1115 # Wrap the RPC method; this adds retry and timeout information,
1116 # and friendly error handling.
1117 rpc = self._transport._wrapped_methods[self._transport.create_bucket_async]
1118
1119 # Certain fields should be provided within the metadata header;
1120 # add these here.
1121 metadata = tuple(metadata) + (
1122 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
1123 )
1124
1125 # Validate the universe domain.
1126 self._validate_universe_domain()
1127
1128 # Send the request.
1129 response = rpc(
1130 request,
1131 retry=retry,
1132 timeout=timeout,
1133 metadata=metadata,
1134 )
1135
1136 # Wrap the response in an operation future.
1137 response = operation.from_gapic(
1138 response,
1139 self._transport.operations_client,
1140 logging_config.LogBucket,
1141 metadata_type=logging_config.BucketMetadata,
1142 )
1143
1144 # Done; return the response.
1145 return response
1146
1147 def update_bucket_async(
1148 self,
1149 request: Optional[Union[logging_config.UpdateBucketRequest, dict]] = None,
1150 *,
1151 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1152 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1153 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1154 ) -> operation.Operation:
1155 r"""Updates a log bucket asynchronously.
1156
1157 If the bucket has a ``lifecycle_state`` of ``DELETE_REQUESTED``,
1158 then ``FAILED_PRECONDITION`` will be returned.
1159
1160 After a bucket has been created, the bucket's location cannot be
1161 changed.
1162
1163 .. code-block:: python
1164
1165 # This snippet has been automatically generated and should be regarded as a
1166 # code template only.
1167 # It will require modifications to work:
1168 # - It may require correct/in-range values for request initialization.
1169 # - It may require specifying regional endpoints when creating the service
1170 # client as shown in:
1171 # https://googleapis.dev/python/google-api-core/latest/client_options.html
1172 from google.cloud import logging_v2
1173
1174 def sample_update_bucket_async():
1175 # Create a client
1176 client = logging_v2.ConfigServiceV2Client()
1177
1178 # Initialize request argument(s)
1179 request = logging_v2.UpdateBucketRequest(
1180 name="name_value",
1181 )
1182
1183 # Make the request
1184 operation = client.update_bucket_async(request=request)
1185
1186 print("Waiting for operation to complete...")
1187
1188 response = operation.result()
1189
1190 # Handle the response
1191 print(response)
1192
1193 Args:
1194 request (Union[google.cloud.logging_v2.types.UpdateBucketRequest, dict]):
1195 The request object. The parameters to ``UpdateBucket``.
1196 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1197 should be retried.
1198 timeout (float): The timeout for this request.
1199 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1200 sent along with the request as metadata. Normally, each value must be of type `str`,
1201 but for metadata keys ending with the suffix `-bin`, the corresponding values must
1202 be of type `bytes`.
1203
1204 Returns:
1205 google.api_core.operation.Operation:
1206 An object representing a long-running operation.
1207
1208 The result type for the operation will be
1209 :class:`google.cloud.logging_v2.types.LogBucket`
1210 Describes a repository in which log entries are stored.
1211
1212 """
1213 # Create or coerce a protobuf request object.
1214 # - Use the request object if provided (there's no risk of modifying the input as
1215 # there are no flattened fields), or create one.
1216 if not isinstance(request, logging_config.UpdateBucketRequest):
1217 request = logging_config.UpdateBucketRequest(request)
1218
1219 # Wrap the RPC method; this adds retry and timeout information,
1220 # and friendly error handling.
1221 rpc = self._transport._wrapped_methods[self._transport.update_bucket_async]
1222
1223 # Certain fields should be provided within the metadata header;
1224 # add these here.
1225 metadata = tuple(metadata) + (
1226 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1227 )
1228
1229 # Validate the universe domain.
1230 self._validate_universe_domain()
1231
1232 # Send the request.
1233 response = rpc(
1234 request,
1235 retry=retry,
1236 timeout=timeout,
1237 metadata=metadata,
1238 )
1239
1240 # Wrap the response in an operation future.
1241 response = operation.from_gapic(
1242 response,
1243 self._transport.operations_client,
1244 logging_config.LogBucket,
1245 metadata_type=logging_config.BucketMetadata,
1246 )
1247
1248 # Done; return the response.
1249 return response
1250
1251 def create_bucket(
1252 self,
1253 request: Optional[Union[logging_config.CreateBucketRequest, dict]] = None,
1254 *,
1255 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1256 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1257 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1258 ) -> logging_config.LogBucket:
1259 r"""Creates a log bucket that can be used to store log
1260 entries. After a bucket has been created, the bucket's
1261 location cannot be changed.
1262
1263 .. code-block:: python
1264
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
1273
1274 def sample_create_bucket():
1275 # Create a client
1276 client = logging_v2.ConfigServiceV2Client()
1277
1278 # Initialize request argument(s)
1279 request = logging_v2.CreateBucketRequest(
1280 parent="parent_value",
1281 bucket_id="bucket_id_value",
1282 )
1283
1284 # Make the request
1285 response = client.create_bucket(request=request)
1286
1287 # Handle the response
1288 print(response)
1289
1290 Args:
1291 request (Union[google.cloud.logging_v2.types.CreateBucketRequest, dict]):
1292 The request object. The parameters to ``CreateBucket``.
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, Union[str, bytes]]]): Key/value pairs which should be
1297 sent along with the request as metadata. Normally, each value must be of type `str`,
1298 but for metadata keys ending with the suffix `-bin`, the corresponding values must
1299 be of type `bytes`.
1300
1301 Returns:
1302 google.cloud.logging_v2.types.LogBucket:
1303 Describes a repository in which log
1304 entries are stored.
1305
1306 """
1307 # Create or coerce a protobuf request object.
1308 # - Use the request object if provided (there's no risk of modifying the input as
1309 # there are no flattened fields), or create one.
1310 if not isinstance(request, logging_config.CreateBucketRequest):
1311 request = logging_config.CreateBucketRequest(request)
1312
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_bucket]
1316
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 )
1322
1323 # Validate the universe domain.
1324 self._validate_universe_domain()
1325
1326 # Send the request.
1327 response = rpc(
1328 request,
1329 retry=retry,
1330 timeout=timeout,
1331 metadata=metadata,
1332 )
1333
1334 # Done; return the response.
1335 return response
1336
1337 def update_bucket(
1338 self,
1339 request: Optional[Union[logging_config.UpdateBucketRequest, dict]] = None,
1340 *,
1341 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1342 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1343 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1344 ) -> logging_config.LogBucket:
1345 r"""Updates a log bucket.
1346
1347 If the bucket has a ``lifecycle_state`` of ``DELETE_REQUESTED``,
1348 then ``FAILED_PRECONDITION`` will be returned.
1349
1350 After a bucket has been created, the bucket's location cannot be
1351 changed.
1352
1353 .. code-block:: python
1354
1355 # This snippet has been automatically generated and should be regarded as a
1356 # code template only.
1357 # It will require modifications to work:
1358 # - It may require correct/in-range values for request initialization.
1359 # - It may require specifying regional endpoints when creating the service
1360 # client as shown in:
1361 # https://googleapis.dev/python/google-api-core/latest/client_options.html
1362 from google.cloud import logging_v2
1363
1364 def sample_update_bucket():
1365 # Create a client
1366 client = logging_v2.ConfigServiceV2Client()
1367
1368 # Initialize request argument(s)
1369 request = logging_v2.UpdateBucketRequest(
1370 name="name_value",
1371 )
1372
1373 # Make the request
1374 response = client.update_bucket(request=request)
1375
1376 # Handle the response
1377 print(response)
1378
1379 Args:
1380 request (Union[google.cloud.logging_v2.types.UpdateBucketRequest, dict]):
1381 The request object. The parameters to ``UpdateBucket``.
1382 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1383 should be retried.
1384 timeout (float): The timeout for this request.
1385 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1386 sent along with the request as metadata. Normally, each value must be of type `str`,
1387 but for metadata keys ending with the suffix `-bin`, the corresponding values must
1388 be of type `bytes`.
1389
1390 Returns:
1391 google.cloud.logging_v2.types.LogBucket:
1392 Describes a repository in which log
1393 entries are stored.
1394
1395 """
1396 # Create or coerce a protobuf request object.
1397 # - Use the request object if provided (there's no risk of modifying the input as
1398 # there are no flattened fields), or create one.
1399 if not isinstance(request, logging_config.UpdateBucketRequest):
1400 request = logging_config.UpdateBucketRequest(request)
1401
1402 # Wrap the RPC method; this adds retry and timeout information,
1403 # and friendly error handling.
1404 rpc = self._transport._wrapped_methods[self._transport.update_bucket]
1405
1406 # Certain fields should be provided within the metadata header;
1407 # add these here.
1408 metadata = tuple(metadata) + (
1409 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1410 )
1411
1412 # Validate the universe domain.
1413 self._validate_universe_domain()
1414
1415 # Send the request.
1416 response = rpc(
1417 request,
1418 retry=retry,
1419 timeout=timeout,
1420 metadata=metadata,
1421 )
1422
1423 # Done; return the response.
1424 return response
1425
1426 def delete_bucket(
1427 self,
1428 request: Optional[Union[logging_config.DeleteBucketRequest, dict]] = None,
1429 *,
1430 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1431 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1432 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1433 ) -> None:
1434 r"""Deletes a log bucket.
1435
1436 Changes the bucket's ``lifecycle_state`` to the
1437 ``DELETE_REQUESTED`` state. After 7 days, the bucket will be
1438 purged and all log entries in the bucket will be permanently
1439 deleted.
1440
1441 .. code-block:: python
1442
1443 # This snippet has been automatically generated and should be regarded as a
1444 # code template only.
1445 # It will require modifications to work:
1446 # - It may require correct/in-range values for request initialization.
1447 # - It may require specifying regional endpoints when creating the service
1448 # client as shown in:
1449 # https://googleapis.dev/python/google-api-core/latest/client_options.html
1450 from google.cloud import logging_v2
1451
1452 def sample_delete_bucket():
1453 # Create a client
1454 client = logging_v2.ConfigServiceV2Client()
1455
1456 # Initialize request argument(s)
1457 request = logging_v2.DeleteBucketRequest(
1458 name="name_value",
1459 )
1460
1461 # Make the request
1462 client.delete_bucket(request=request)
1463
1464 Args:
1465 request (Union[google.cloud.logging_v2.types.DeleteBucketRequest, dict]):
1466 The request object. The parameters to ``DeleteBucket``.
1467 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1468 should be retried.
1469 timeout (float): The timeout for this request.
1470 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1471 sent along with the request as metadata. Normally, each value must be of type `str`,
1472 but for metadata keys ending with the suffix `-bin`, the corresponding values must
1473 be of type `bytes`.
1474 """
1475 # Create or coerce a protobuf request object.
1476 # - Use the request object if provided (there's no risk of modifying the input as
1477 # there are no flattened fields), or create one.
1478 if not isinstance(request, logging_config.DeleteBucketRequest):
1479 request = logging_config.DeleteBucketRequest(request)
1480
1481 # Wrap the RPC method; this adds retry and timeout information,
1482 # and friendly error handling.
1483 rpc = self._transport._wrapped_methods[self._transport.delete_bucket]
1484
1485 # Certain fields should be provided within the metadata header;
1486 # add these here.
1487 metadata = tuple(metadata) + (
1488 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1489 )
1490
1491 # Validate the universe domain.
1492 self._validate_universe_domain()
1493
1494 # Send the request.
1495 rpc(
1496 request,
1497 retry=retry,
1498 timeout=timeout,
1499 metadata=metadata,
1500 )
1501
1502 def undelete_bucket(
1503 self,
1504 request: Optional[Union[logging_config.UndeleteBucketRequest, dict]] = None,
1505 *,
1506 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1507 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1508 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1509 ) -> None:
1510 r"""Undeletes a log bucket. A bucket that has been
1511 deleted can be undeleted within the grace period of 7
1512 days.
1513
1514 .. code-block:: python
1515
1516 # This snippet has been automatically generated and should be regarded as a
1517 # code template only.
1518 # It will require modifications to work:
1519 # - It may require correct/in-range values for request initialization.
1520 # - It may require specifying regional endpoints when creating the service
1521 # client as shown in:
1522 # https://googleapis.dev/python/google-api-core/latest/client_options.html
1523 from google.cloud import logging_v2
1524
1525 def sample_undelete_bucket():
1526 # Create a client
1527 client = logging_v2.ConfigServiceV2Client()
1528
1529 # Initialize request argument(s)
1530 request = logging_v2.UndeleteBucketRequest(
1531 name="name_value",
1532 )
1533
1534 # Make the request
1535 client.undelete_bucket(request=request)
1536
1537 Args:
1538 request (Union[google.cloud.logging_v2.types.UndeleteBucketRequest, dict]):
1539 The request object. The parameters to ``UndeleteBucket``.
1540 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1541 should be retried.
1542 timeout (float): The timeout for this request.
1543 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1544 sent along with the request as metadata. Normally, each value must be of type `str`,
1545 but for metadata keys ending with the suffix `-bin`, the corresponding values must
1546 be of type `bytes`.
1547 """
1548 # Create or coerce a protobuf request object.
1549 # - Use the request object if provided (there's no risk of modifying the input as
1550 # there are no flattened fields), or create one.
1551 if not isinstance(request, logging_config.UndeleteBucketRequest):
1552 request = logging_config.UndeleteBucketRequest(request)
1553
1554 # Wrap the RPC method; this adds retry and timeout information,
1555 # and friendly error handling.
1556 rpc = self._transport._wrapped_methods[self._transport.undelete_bucket]
1557
1558 # Certain fields should be provided within the metadata header;
1559 # add these here.
1560 metadata = tuple(metadata) + (
1561 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1562 )
1563
1564 # Validate the universe domain.
1565 self._validate_universe_domain()
1566
1567 # Send the request.
1568 rpc(
1569 request,
1570 retry=retry,
1571 timeout=timeout,
1572 metadata=metadata,
1573 )
1574
1575 def list_views(
1576 self,
1577 request: Optional[Union[logging_config.ListViewsRequest, dict]] = None,
1578 *,
1579 parent: Optional[str] = None,
1580 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1581 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1582 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1583 ) -> pagers.ListViewsPager:
1584 r"""Lists views on a log bucket.
1585
1586 .. code-block:: python
1587
1588 # This snippet has been automatically generated and should be regarded as a
1589 # code template only.
1590 # It will require modifications to work:
1591 # - It may require correct/in-range values for request initialization.
1592 # - It may require specifying regional endpoints when creating the service
1593 # client as shown in:
1594 # https://googleapis.dev/python/google-api-core/latest/client_options.html
1595 from google.cloud import logging_v2
1596
1597 def sample_list_views():
1598 # Create a client
1599 client = logging_v2.ConfigServiceV2Client()
1600
1601 # Initialize request argument(s)
1602 request = logging_v2.ListViewsRequest(
1603 parent="parent_value",
1604 )
1605
1606 # Make the request
1607 page_result = client.list_views(request=request)
1608
1609 # Handle the response
1610 for response in page_result:
1611 print(response)
1612
1613 Args:
1614 request (Union[google.cloud.logging_v2.types.ListViewsRequest, dict]):
1615 The request object. The parameters to ``ListViews``.
1616 parent (str):
1617 Required. The bucket whose views are to be listed:
1618
1619 ::
1620
1621 "projects/[PROJECT_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]"
1622
1623 This corresponds to the ``parent`` field
1624 on the ``request`` instance; if ``request`` is provided, this
1625 should not be set.
1626 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1627 should be retried.
1628 timeout (float): The timeout for this request.
1629 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1630 sent along with the request as metadata. Normally, each value must be of type `str`,
1631 but for metadata keys ending with the suffix `-bin`, the corresponding values must
1632 be of type `bytes`.
1633
1634 Returns:
1635 google.cloud.logging_v2.services.config_service_v2.pagers.ListViewsPager:
1636 The response from ListViews.
1637
1638 Iterating over this object will yield
1639 results and resolve additional pages
1640 automatically.
1641
1642 """
1643 # Create or coerce a protobuf request object.
1644 # - Quick check: If we got a request object, we should *not* have
1645 # gotten any keyword arguments that map to the request.
1646 flattened_params = [parent]
1647 has_flattened_params = (
1648 len([param for param in flattened_params if param is not None]) > 0
1649 )
1650 if request is not None and has_flattened_params:
1651 raise ValueError(
1652 "If the `request` argument is set, then none of "
1653 "the individual field arguments should be set."
1654 )
1655
1656 # - Use the request object if provided (there's no risk of modifying the input as
1657 # there are no flattened fields), or create one.
1658 if not isinstance(request, logging_config.ListViewsRequest):
1659 request = logging_config.ListViewsRequest(request)
1660 # If we have keyword arguments corresponding to fields on the
1661 # request, apply these.
1662 if parent is not None:
1663 request.parent = parent
1664
1665 # Wrap the RPC method; this adds retry and timeout information,
1666 # and friendly error handling.
1667 rpc = self._transport._wrapped_methods[self._transport.list_views]
1668
1669 # Certain fields should be provided within the metadata header;
1670 # add these here.
1671 metadata = tuple(metadata) + (
1672 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
1673 )
1674
1675 # Validate the universe domain.
1676 self._validate_universe_domain()
1677
1678 # Send the request.
1679 response = rpc(
1680 request,
1681 retry=retry,
1682 timeout=timeout,
1683 metadata=metadata,
1684 )
1685
1686 # This method is paged; wrap the response in a pager, which provides
1687 # an `__iter__` convenience method.
1688 response = pagers.ListViewsPager(
1689 method=rpc,
1690 request=request,
1691 response=response,
1692 retry=retry,
1693 timeout=timeout,
1694 metadata=metadata,
1695 )
1696
1697 # Done; return the response.
1698 return response
1699
1700 def get_view(
1701 self,
1702 request: Optional[Union[logging_config.GetViewRequest, dict]] = None,
1703 *,
1704 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1705 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1706 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1707 ) -> logging_config.LogView:
1708 r"""Gets a view on a log bucket..
1709
1710 .. code-block:: python
1711
1712 # This snippet has been automatically generated and should be regarded as a
1713 # code template only.
1714 # It will require modifications to work:
1715 # - It may require correct/in-range values for request initialization.
1716 # - It may require specifying regional endpoints when creating the service
1717 # client as shown in:
1718 # https://googleapis.dev/python/google-api-core/latest/client_options.html
1719 from google.cloud import logging_v2
1720
1721 def sample_get_view():
1722 # Create a client
1723 client = logging_v2.ConfigServiceV2Client()
1724
1725 # Initialize request argument(s)
1726 request = logging_v2.GetViewRequest(
1727 name="name_value",
1728 )
1729
1730 # Make the request
1731 response = client.get_view(request=request)
1732
1733 # Handle the response
1734 print(response)
1735
1736 Args:
1737 request (Union[google.cloud.logging_v2.types.GetViewRequest, dict]):
1738 The request object. The parameters to ``GetView``.
1739 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1740 should be retried.
1741 timeout (float): The timeout for this request.
1742 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1743 sent along with the request as metadata. Normally, each value must be of type `str`,
1744 but for metadata keys ending with the suffix `-bin`, the corresponding values must
1745 be of type `bytes`.
1746
1747 Returns:
1748 google.cloud.logging_v2.types.LogView:
1749 Describes a view over log entries in
1750 a bucket.
1751
1752 """
1753 # Create or coerce a protobuf request object.
1754 # - Use the request object if provided (there's no risk of modifying the input as
1755 # there are no flattened fields), or create one.
1756 if not isinstance(request, logging_config.GetViewRequest):
1757 request = logging_config.GetViewRequest(request)
1758
1759 # Wrap the RPC method; this adds retry and timeout information,
1760 # and friendly error handling.
1761 rpc = self._transport._wrapped_methods[self._transport.get_view]
1762
1763 # Certain fields should be provided within the metadata header;
1764 # add these here.
1765 metadata = tuple(metadata) + (
1766 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1767 )
1768
1769 # Validate the universe domain.
1770 self._validate_universe_domain()
1771
1772 # Send the request.
1773 response = rpc(
1774 request,
1775 retry=retry,
1776 timeout=timeout,
1777 metadata=metadata,
1778 )
1779
1780 # Done; return the response.
1781 return response
1782
1783 def create_view(
1784 self,
1785 request: Optional[Union[logging_config.CreateViewRequest, dict]] = None,
1786 *,
1787 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1788 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1789 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1790 ) -> logging_config.LogView:
1791 r"""Creates a view over log entries in a log bucket. A
1792 bucket may contain a maximum of 30 views.
1793
1794 .. code-block:: python
1795
1796 # This snippet has been automatically generated and should be regarded as a
1797 # code template only.
1798 # It will require modifications to work:
1799 # - It may require correct/in-range values for request initialization.
1800 # - It may require specifying regional endpoints when creating the service
1801 # client as shown in:
1802 # https://googleapis.dev/python/google-api-core/latest/client_options.html
1803 from google.cloud import logging_v2
1804
1805 def sample_create_view():
1806 # Create a client
1807 client = logging_v2.ConfigServiceV2Client()
1808
1809 # Initialize request argument(s)
1810 request = logging_v2.CreateViewRequest(
1811 parent="parent_value",
1812 view_id="view_id_value",
1813 )
1814
1815 # Make the request
1816 response = client.create_view(request=request)
1817
1818 # Handle the response
1819 print(response)
1820
1821 Args:
1822 request (Union[google.cloud.logging_v2.types.CreateViewRequest, dict]):
1823 The request object. The parameters to ``CreateView``.
1824 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1825 should be retried.
1826 timeout (float): The timeout for this request.
1827 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1828 sent along with the request as metadata. Normally, each value must be of type `str`,
1829 but for metadata keys ending with the suffix `-bin`, the corresponding values must
1830 be of type `bytes`.
1831
1832 Returns:
1833 google.cloud.logging_v2.types.LogView:
1834 Describes a view over log entries in
1835 a bucket.
1836
1837 """
1838 # Create or coerce a protobuf request object.
1839 # - Use the request object if provided (there's no risk of modifying the input as
1840 # there are no flattened fields), or create one.
1841 if not isinstance(request, logging_config.CreateViewRequest):
1842 request = logging_config.CreateViewRequest(request)
1843
1844 # Wrap the RPC method; this adds retry and timeout information,
1845 # and friendly error handling.
1846 rpc = self._transport._wrapped_methods[self._transport.create_view]
1847
1848 # Certain fields should be provided within the metadata header;
1849 # add these here.
1850 metadata = tuple(metadata) + (
1851 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
1852 )
1853
1854 # Validate the universe domain.
1855 self._validate_universe_domain()
1856
1857 # Send the request.
1858 response = rpc(
1859 request,
1860 retry=retry,
1861 timeout=timeout,
1862 metadata=metadata,
1863 )
1864
1865 # Done; return the response.
1866 return response
1867
1868 def update_view(
1869 self,
1870 request: Optional[Union[logging_config.UpdateViewRequest, dict]] = None,
1871 *,
1872 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1873 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1874 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1875 ) -> logging_config.LogView:
1876 r"""Updates a view on a log bucket. This method replaces the
1877 following fields in the existing view with values from the new
1878 view: ``filter``. If an ``UNAVAILABLE`` error is returned, this
1879 indicates that system is not in a state where it can update the
1880 view. If this occurs, please try again in a few minutes.
1881
1882 .. code-block:: python
1883
1884 # This snippet has been automatically generated and should be regarded as a
1885 # code template only.
1886 # It will require modifications to work:
1887 # - It may require correct/in-range values for request initialization.
1888 # - It may require specifying regional endpoints when creating the service
1889 # client as shown in:
1890 # https://googleapis.dev/python/google-api-core/latest/client_options.html
1891 from google.cloud import logging_v2
1892
1893 def sample_update_view():
1894 # Create a client
1895 client = logging_v2.ConfigServiceV2Client()
1896
1897 # Initialize request argument(s)
1898 request = logging_v2.UpdateViewRequest(
1899 name="name_value",
1900 )
1901
1902 # Make the request
1903 response = client.update_view(request=request)
1904
1905 # Handle the response
1906 print(response)
1907
1908 Args:
1909 request (Union[google.cloud.logging_v2.types.UpdateViewRequest, dict]):
1910 The request object. The parameters to ``UpdateView``.
1911 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1912 should be retried.
1913 timeout (float): The timeout for this request.
1914 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1915 sent along with the request as metadata. Normally, each value must be of type `str`,
1916 but for metadata keys ending with the suffix `-bin`, the corresponding values must
1917 be of type `bytes`.
1918
1919 Returns:
1920 google.cloud.logging_v2.types.LogView:
1921 Describes a view over log entries in
1922 a bucket.
1923
1924 """
1925 # Create or coerce a protobuf request object.
1926 # - Use the request object if provided (there's no risk of modifying the input as
1927 # there are no flattened fields), or create one.
1928 if not isinstance(request, logging_config.UpdateViewRequest):
1929 request = logging_config.UpdateViewRequest(request)
1930
1931 # Wrap the RPC method; this adds retry and timeout information,
1932 # and friendly error handling.
1933 rpc = self._transport._wrapped_methods[self._transport.update_view]
1934
1935 # Certain fields should be provided within the metadata header;
1936 # add these here.
1937 metadata = tuple(metadata) + (
1938 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1939 )
1940
1941 # Validate the universe domain.
1942 self._validate_universe_domain()
1943
1944 # Send the request.
1945 response = rpc(
1946 request,
1947 retry=retry,
1948 timeout=timeout,
1949 metadata=metadata,
1950 )
1951
1952 # Done; return the response.
1953 return response
1954
1955 def delete_view(
1956 self,
1957 request: Optional[Union[logging_config.DeleteViewRequest, dict]] = None,
1958 *,
1959 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1960 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1961 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1962 ) -> None:
1963 r"""Deletes a view on a log bucket. If an ``UNAVAILABLE`` error is
1964 returned, this indicates that system is not in a state where it
1965 can delete the view. If this occurs, please try again in a few
1966 minutes.
1967
1968 .. code-block:: python
1969
1970 # This snippet has been automatically generated and should be regarded as a
1971 # code template only.
1972 # It will require modifications to work:
1973 # - It may require correct/in-range values for request initialization.
1974 # - It may require specifying regional endpoints when creating the service
1975 # client as shown in:
1976 # https://googleapis.dev/python/google-api-core/latest/client_options.html
1977 from google.cloud import logging_v2
1978
1979 def sample_delete_view():
1980 # Create a client
1981 client = logging_v2.ConfigServiceV2Client()
1982
1983 # Initialize request argument(s)
1984 request = logging_v2.DeleteViewRequest(
1985 name="name_value",
1986 )
1987
1988 # Make the request
1989 client.delete_view(request=request)
1990
1991 Args:
1992 request (Union[google.cloud.logging_v2.types.DeleteViewRequest, dict]):
1993 The request object. The parameters to ``DeleteView``.
1994 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1995 should be retried.
1996 timeout (float): The timeout for this request.
1997 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1998 sent along with the request as metadata. Normally, each value must be of type `str`,
1999 but for metadata keys ending with the suffix `-bin`, the corresponding values must
2000 be of type `bytes`.
2001 """
2002 # Create or coerce a protobuf request object.
2003 # - Use the request object if provided (there's no risk of modifying the input as
2004 # there are no flattened fields), or create one.
2005 if not isinstance(request, logging_config.DeleteViewRequest):
2006 request = logging_config.DeleteViewRequest(request)
2007
2008 # Wrap the RPC method; this adds retry and timeout information,
2009 # and friendly error handling.
2010 rpc = self._transport._wrapped_methods[self._transport.delete_view]
2011
2012 # Certain fields should be provided within the metadata header;
2013 # add these here.
2014 metadata = tuple(metadata) + (
2015 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
2016 )
2017
2018 # Validate the universe domain.
2019 self._validate_universe_domain()
2020
2021 # Send the request.
2022 rpc(
2023 request,
2024 retry=retry,
2025 timeout=timeout,
2026 metadata=metadata,
2027 )
2028
2029 def list_sinks(
2030 self,
2031 request: Optional[Union[logging_config.ListSinksRequest, dict]] = None,
2032 *,
2033 parent: Optional[str] = None,
2034 retry: OptionalRetry = gapic_v1.method.DEFAULT,
2035 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
2036 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
2037 ) -> pagers.ListSinksPager:
2038 r"""Lists sinks.
2039
2040 .. code-block:: python
2041
2042 # This snippet has been automatically generated and should be regarded as a
2043 # code template only.
2044 # It will require modifications to work:
2045 # - It may require correct/in-range values for request initialization.
2046 # - It may require specifying regional endpoints when creating the service
2047 # client as shown in:
2048 # https://googleapis.dev/python/google-api-core/latest/client_options.html
2049 from google.cloud import logging_v2
2050
2051 def sample_list_sinks():
2052 # Create a client
2053 client = logging_v2.ConfigServiceV2Client()
2054
2055 # Initialize request argument(s)
2056 request = logging_v2.ListSinksRequest(
2057 parent="parent_value",
2058 )
2059
2060 # Make the request
2061 page_result = client.list_sinks(request=request)
2062
2063 # Handle the response
2064 for response in page_result:
2065 print(response)
2066
2067 Args:
2068 request (Union[google.cloud.logging_v2.types.ListSinksRequest, dict]):
2069 The request object. The parameters to ``ListSinks``.
2070 parent (str):
2071 Required. The parent resource whose sinks are to be
2072 listed:
2073
2074 ::
2075
2076 "projects/[PROJECT_ID]"
2077 "organizations/[ORGANIZATION_ID]"
2078 "billingAccounts/[BILLING_ACCOUNT_ID]"
2079 "folders/[FOLDER_ID]"
2080
2081 This corresponds to the ``parent`` field
2082 on the ``request`` instance; if ``request`` is provided, this
2083 should not be set.
2084 retry (google.api_core.retry.Retry): Designation of what errors, if any,
2085 should be retried.
2086 timeout (float): The timeout for this request.
2087 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
2088 sent along with the request as metadata. Normally, each value must be of type `str`,
2089 but for metadata keys ending with the suffix `-bin`, the corresponding values must
2090 be of type `bytes`.
2091
2092 Returns:
2093 google.cloud.logging_v2.services.config_service_v2.pagers.ListSinksPager:
2094 Result returned from ListSinks.
2095
2096 Iterating over this object will yield results and
2097 resolve additional pages automatically.
2098
2099 """
2100 # Create or coerce a protobuf request object.
2101 # - Quick check: If we got a request object, we should *not* have
2102 # gotten any keyword arguments that map to the request.
2103 flattened_params = [parent]
2104 has_flattened_params = (
2105 len([param for param in flattened_params if param is not None]) > 0
2106 )
2107 if request is not None and has_flattened_params:
2108 raise ValueError(
2109 "If the `request` argument is set, then none of "
2110 "the individual field arguments should be set."
2111 )
2112
2113 # - Use the request object if provided (there's no risk of modifying the input as
2114 # there are no flattened fields), or create one.
2115 if not isinstance(request, logging_config.ListSinksRequest):
2116 request = logging_config.ListSinksRequest(request)
2117 # If we have keyword arguments corresponding to fields on the
2118 # request, apply these.
2119 if parent is not None:
2120 request.parent = parent
2121
2122 # Wrap the RPC method; this adds retry and timeout information,
2123 # and friendly error handling.
2124 rpc = self._transport._wrapped_methods[self._transport.list_sinks]
2125
2126 # Certain fields should be provided within the metadata header;
2127 # add these here.
2128 metadata = tuple(metadata) + (
2129 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
2130 )
2131
2132 # Validate the universe domain.
2133 self._validate_universe_domain()
2134
2135 # Send the request.
2136 response = rpc(
2137 request,
2138 retry=retry,
2139 timeout=timeout,
2140 metadata=metadata,
2141 )
2142
2143 # This method is paged; wrap the response in a pager, which provides
2144 # an `__iter__` convenience method.
2145 response = pagers.ListSinksPager(
2146 method=rpc,
2147 request=request,
2148 response=response,
2149 retry=retry,
2150 timeout=timeout,
2151 metadata=metadata,
2152 )
2153
2154 # Done; return the response.
2155 return response
2156
2157 def get_sink(
2158 self,
2159 request: Optional[Union[logging_config.GetSinkRequest, dict]] = None,
2160 *,
2161 sink_name: Optional[str] = None,
2162 retry: OptionalRetry = gapic_v1.method.DEFAULT,
2163 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
2164 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
2165 ) -> logging_config.LogSink:
2166 r"""Gets a sink.
2167
2168 .. code-block:: python
2169
2170 # This snippet has been automatically generated and should be regarded as a
2171 # code template only.
2172 # It will require modifications to work:
2173 # - It may require correct/in-range values for request initialization.
2174 # - It may require specifying regional endpoints when creating the service
2175 # client as shown in:
2176 # https://googleapis.dev/python/google-api-core/latest/client_options.html
2177 from google.cloud import logging_v2
2178
2179 def sample_get_sink():
2180 # Create a client
2181 client = logging_v2.ConfigServiceV2Client()
2182
2183 # Initialize request argument(s)
2184 request = logging_v2.GetSinkRequest(
2185 sink_name="sink_name_value",
2186 )
2187
2188 # Make the request
2189 response = client.get_sink(request=request)
2190
2191 # Handle the response
2192 print(response)
2193
2194 Args:
2195 request (Union[google.cloud.logging_v2.types.GetSinkRequest, dict]):
2196 The request object. The parameters to ``GetSink``.
2197 sink_name (str):
2198 Required. The resource name of the sink:
2199
2200 ::
2201
2202 "projects/[PROJECT_ID]/sinks/[SINK_ID]"
2203 "organizations/[ORGANIZATION_ID]/sinks/[SINK_ID]"
2204 "billingAccounts/[BILLING_ACCOUNT_ID]/sinks/[SINK_ID]"
2205 "folders/[FOLDER_ID]/sinks/[SINK_ID]"
2206
2207 For example:
2208
2209 ``"projects/my-project/sinks/my-sink"``
2210
2211 This corresponds to the ``sink_name`` field
2212 on the ``request`` instance; if ``request`` is provided, this
2213 should not be set.
2214 retry (google.api_core.retry.Retry): Designation of what errors, if any,
2215 should be retried.
2216 timeout (float): The timeout for this request.
2217 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
2218 sent along with the request as metadata. Normally, each value must be of type `str`,
2219 but for metadata keys ending with the suffix `-bin`, the corresponding values must
2220 be of type `bytes`.
2221
2222 Returns:
2223 google.cloud.logging_v2.types.LogSink:
2224 Describes a sink used to export log
2225 entries to one of the following
2226 destinations in any project: a Cloud
2227 Storage bucket, a BigQuery dataset, a
2228 Pub/Sub topic or a Cloud Logging log
2229 bucket. A logs filter controls which log
2230 entries are exported. The sink must be
2231 created within a project, organization,
2232 billing account, or folder.
2233
2234 """
2235 # Create or coerce a protobuf request object.
2236 # - Quick check: If we got a request object, we should *not* have
2237 # gotten any keyword arguments that map to the request.
2238 flattened_params = [sink_name]
2239 has_flattened_params = (
2240 len([param for param in flattened_params if param is not None]) > 0
2241 )
2242 if request is not None and has_flattened_params:
2243 raise ValueError(
2244 "If the `request` argument is set, then none of "
2245 "the individual field arguments should be set."
2246 )
2247
2248 # - Use the request object if provided (there's no risk of modifying the input as
2249 # there are no flattened fields), or create one.
2250 if not isinstance(request, logging_config.GetSinkRequest):
2251 request = logging_config.GetSinkRequest(request)
2252 # If we have keyword arguments corresponding to fields on the
2253 # request, apply these.
2254 if sink_name is not None:
2255 request.sink_name = sink_name
2256
2257 # Wrap the RPC method; this adds retry and timeout information,
2258 # and friendly error handling.
2259 rpc = self._transport._wrapped_methods[self._transport.get_sink]
2260
2261 # Certain fields should be provided within the metadata header;
2262 # add these here.
2263 metadata = tuple(metadata) + (
2264 gapic_v1.routing_header.to_grpc_metadata(
2265 (("sink_name", request.sink_name),)
2266 ),
2267 )
2268
2269 # Validate the universe domain.
2270 self._validate_universe_domain()
2271
2272 # Send the request.
2273 response = rpc(
2274 request,
2275 retry=retry,
2276 timeout=timeout,
2277 metadata=metadata,
2278 )
2279
2280 # Done; return the response.
2281 return response
2282
2283 def create_sink(
2284 self,
2285 request: Optional[Union[logging_config.CreateSinkRequest, dict]] = None,
2286 *,
2287 parent: Optional[str] = None,
2288 sink: Optional[logging_config.LogSink] = None,
2289 retry: OptionalRetry = gapic_v1.method.DEFAULT,
2290 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
2291 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
2292 ) -> logging_config.LogSink:
2293 r"""Creates a sink that exports specified log entries to a
2294 destination. The export of newly-ingested log entries begins
2295 immediately, unless the sink's ``writer_identity`` is not
2296 permitted to write to the destination. A sink can export log
2297 entries only from the resource owning the sink.
2298
2299 .. code-block:: python
2300
2301 # This snippet has been automatically generated and should be regarded as a
2302 # code template only.
2303 # It will require modifications to work:
2304 # - It may require correct/in-range values for request initialization.
2305 # - It may require specifying regional endpoints when creating the service
2306 # client as shown in:
2307 # https://googleapis.dev/python/google-api-core/latest/client_options.html
2308 from google.cloud import logging_v2
2309
2310 def sample_create_sink():
2311 # Create a client
2312 client = logging_v2.ConfigServiceV2Client()
2313
2314 # Initialize request argument(s)
2315 sink = logging_v2.LogSink()
2316 sink.name = "name_value"
2317 sink.destination = "destination_value"
2318
2319 request = logging_v2.CreateSinkRequest(
2320 parent="parent_value",
2321 sink=sink,
2322 )
2323
2324 # Make the request
2325 response = client.create_sink(request=request)
2326
2327 # Handle the response
2328 print(response)
2329
2330 Args:
2331 request (Union[google.cloud.logging_v2.types.CreateSinkRequest, dict]):
2332 The request object. The parameters to ``CreateSink``.
2333 parent (str):
2334 Required. The resource in which to create the sink:
2335
2336 ::
2337
2338 "projects/[PROJECT_ID]"
2339 "organizations/[ORGANIZATION_ID]"
2340 "billingAccounts/[BILLING_ACCOUNT_ID]"
2341 "folders/[FOLDER_ID]"
2342
2343 For examples:
2344
2345 ``"projects/my-project"`` ``"organizations/123456789"``
2346
2347 This corresponds to the ``parent`` field
2348 on the ``request`` instance; if ``request`` is provided, this
2349 should not be set.
2350 sink (google.cloud.logging_v2.types.LogSink):
2351 Required. The new sink, whose ``name`` parameter is a
2352 sink identifier that is not already in use.
2353
2354 This corresponds to the ``sink`` field
2355 on the ``request`` instance; if ``request`` is provided, this
2356 should not be set.
2357 retry (google.api_core.retry.Retry): Designation of what errors, if any,
2358 should be retried.
2359 timeout (float): The timeout for this request.
2360 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
2361 sent along with the request as metadata. Normally, each value must be of type `str`,
2362 but for metadata keys ending with the suffix `-bin`, the corresponding values must
2363 be of type `bytes`.
2364
2365 Returns:
2366 google.cloud.logging_v2.types.LogSink:
2367 Describes a sink used to export log
2368 entries to one of the following
2369 destinations in any project: a Cloud
2370 Storage bucket, a BigQuery dataset, a
2371 Pub/Sub topic or a Cloud Logging log
2372 bucket. A logs filter controls which log
2373 entries are exported. The sink must be
2374 created within a project, organization,
2375 billing account, or folder.
2376
2377 """
2378 # Create or coerce a protobuf request object.
2379 # - Quick check: If we got a request object, we should *not* have
2380 # gotten any keyword arguments that map to the request.
2381 flattened_params = [parent, sink]
2382 has_flattened_params = (
2383 len([param for param in flattened_params if param is not None]) > 0
2384 )
2385 if request is not None and has_flattened_params:
2386 raise ValueError(
2387 "If the `request` argument is set, then none of "
2388 "the individual field arguments should be set."
2389 )
2390
2391 # - Use the request object if provided (there's no risk of modifying the input as
2392 # there are no flattened fields), or create one.
2393 if not isinstance(request, logging_config.CreateSinkRequest):
2394 request = logging_config.CreateSinkRequest(request)
2395 # If we have keyword arguments corresponding to fields on the
2396 # request, apply these.
2397 if parent is not None:
2398 request.parent = parent
2399 if sink is not None:
2400 request.sink = sink
2401
2402 # Wrap the RPC method; this adds retry and timeout information,
2403 # and friendly error handling.
2404 rpc = self._transport._wrapped_methods[self._transport.create_sink]
2405
2406 # Certain fields should be provided within the metadata header;
2407 # add these here.
2408 metadata = tuple(metadata) + (
2409 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
2410 )
2411
2412 # Validate the universe domain.
2413 self._validate_universe_domain()
2414
2415 # Send the request.
2416 response = rpc(
2417 request,
2418 retry=retry,
2419 timeout=timeout,
2420 metadata=metadata,
2421 )
2422
2423 # Done; return the response.
2424 return response
2425
2426 def update_sink(
2427 self,
2428 request: Optional[Union[logging_config.UpdateSinkRequest, dict]] = None,
2429 *,
2430 sink_name: Optional[str] = None,
2431 sink: Optional[logging_config.LogSink] = None,
2432 update_mask: Optional[field_mask_pb2.FieldMask] = None,
2433 retry: OptionalRetry = gapic_v1.method.DEFAULT,
2434 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
2435 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
2436 ) -> logging_config.LogSink:
2437 r"""Updates a sink. This method replaces the following fields in the
2438 existing sink with values from the new sink: ``destination``,
2439 and ``filter``.
2440
2441 The updated sink might also have a new ``writer_identity``; see
2442 the ``unique_writer_identity`` field.
2443
2444 .. code-block:: python
2445
2446 # This snippet has been automatically generated and should be regarded as a
2447 # code template only.
2448 # It will require modifications to work:
2449 # - It may require correct/in-range values for request initialization.
2450 # - It may require specifying regional endpoints when creating the service
2451 # client as shown in:
2452 # https://googleapis.dev/python/google-api-core/latest/client_options.html
2453 from google.cloud import logging_v2
2454
2455 def sample_update_sink():
2456 # Create a client
2457 client = logging_v2.ConfigServiceV2Client()
2458
2459 # Initialize request argument(s)
2460 sink = logging_v2.LogSink()
2461 sink.name = "name_value"
2462 sink.destination = "destination_value"
2463
2464 request = logging_v2.UpdateSinkRequest(
2465 sink_name="sink_name_value",
2466 sink=sink,
2467 )
2468
2469 # Make the request
2470 response = client.update_sink(request=request)
2471
2472 # Handle the response
2473 print(response)
2474
2475 Args:
2476 request (Union[google.cloud.logging_v2.types.UpdateSinkRequest, dict]):
2477 The request object. The parameters to ``UpdateSink``.
2478 sink_name (str):
2479 Required. The full resource name of the sink to update,
2480 including the parent resource and the sink identifier:
2481
2482 ::
2483
2484 "projects/[PROJECT_ID]/sinks/[SINK_ID]"
2485 "organizations/[ORGANIZATION_ID]/sinks/[SINK_ID]"
2486 "billingAccounts/[BILLING_ACCOUNT_ID]/sinks/[SINK_ID]"
2487 "folders/[FOLDER_ID]/sinks/[SINK_ID]"
2488
2489 For example:
2490
2491 ``"projects/my-project/sinks/my-sink"``
2492
2493 This corresponds to the ``sink_name`` field
2494 on the ``request`` instance; if ``request`` is provided, this
2495 should not be set.
2496 sink (google.cloud.logging_v2.types.LogSink):
2497 Required. The updated sink, whose name is the same
2498 identifier that appears as part of ``sink_name``.
2499
2500 This corresponds to the ``sink`` field
2501 on the ``request`` instance; if ``request`` is provided, this
2502 should not be set.
2503 update_mask (google.protobuf.field_mask_pb2.FieldMask):
2504 Optional. Field mask that specifies the fields in
2505 ``sink`` that need an update. A sink field will be
2506 overwritten if, and only if, it is in the update mask.
2507 ``name`` and output only fields cannot be updated.
2508
2509 An empty ``updateMask`` is temporarily treated as using
2510 the following mask for backwards compatibility purposes:
2511
2512 ``destination,filter,includeChildren``
2513
2514 At some point in the future, behavior will be removed
2515 and specifying an empty ``updateMask`` will be an error.
2516
2517 For a detailed ``FieldMask`` definition, see
2518 https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#google.protobuf.FieldMask
2519
2520 For example: ``updateMask=filter``
2521
2522 This corresponds to the ``update_mask`` field
2523 on the ``request`` instance; if ``request`` is provided, this
2524 should not be set.
2525 retry (google.api_core.retry.Retry): Designation of what errors, if any,
2526 should be retried.
2527 timeout (float): The timeout for this request.
2528 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
2529 sent along with the request as metadata. Normally, each value must be of type `str`,
2530 but for metadata keys ending with the suffix `-bin`, the corresponding values must
2531 be of type `bytes`.
2532
2533 Returns:
2534 google.cloud.logging_v2.types.LogSink:
2535 Describes a sink used to export log
2536 entries to one of the following
2537 destinations in any project: a Cloud
2538 Storage bucket, a BigQuery dataset, a
2539 Pub/Sub topic or a Cloud Logging log
2540 bucket. A logs filter controls which log
2541 entries are exported. The sink must be
2542 created within a project, organization,
2543 billing account, or folder.
2544
2545 """
2546 # Create or coerce a protobuf request object.
2547 # - Quick check: If we got a request object, we should *not* have
2548 # gotten any keyword arguments that map to the request.
2549 flattened_params = [sink_name, sink, update_mask]
2550 has_flattened_params = (
2551 len([param for param in flattened_params if param is not None]) > 0
2552 )
2553 if request is not None and has_flattened_params:
2554 raise ValueError(
2555 "If the `request` argument is set, then none of "
2556 "the individual field arguments should be set."
2557 )
2558
2559 # - Use the request object if provided (there's no risk of modifying the input as
2560 # there are no flattened fields), or create one.
2561 if not isinstance(request, logging_config.UpdateSinkRequest):
2562 request = logging_config.UpdateSinkRequest(request)
2563 # If we have keyword arguments corresponding to fields on the
2564 # request, apply these.
2565 if sink_name is not None:
2566 request.sink_name = sink_name
2567 if sink is not None:
2568 request.sink = sink
2569 if update_mask is not None:
2570 request.update_mask = update_mask
2571
2572 # Wrap the RPC method; this adds retry and timeout information,
2573 # and friendly error handling.
2574 rpc = self._transport._wrapped_methods[self._transport.update_sink]
2575
2576 # Certain fields should be provided within the metadata header;
2577 # add these here.
2578 metadata = tuple(metadata) + (
2579 gapic_v1.routing_header.to_grpc_metadata(
2580 (("sink_name", request.sink_name),)
2581 ),
2582 )
2583
2584 # Validate the universe domain.
2585 self._validate_universe_domain()
2586
2587 # Send the request.
2588 response = rpc(
2589 request,
2590 retry=retry,
2591 timeout=timeout,
2592 metadata=metadata,
2593 )
2594
2595 # Done; return the response.
2596 return response
2597
2598 def delete_sink(
2599 self,
2600 request: Optional[Union[logging_config.DeleteSinkRequest, dict]] = None,
2601 *,
2602 sink_name: Optional[str] = None,
2603 retry: OptionalRetry = gapic_v1.method.DEFAULT,
2604 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
2605 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
2606 ) -> None:
2607 r"""Deletes a sink. If the sink has a unique ``writer_identity``,
2608 then that service account is also deleted.
2609
2610 .. code-block:: python
2611
2612 # This snippet has been automatically generated and should be regarded as a
2613 # code template only.
2614 # It will require modifications to work:
2615 # - It may require correct/in-range values for request initialization.
2616 # - It may require specifying regional endpoints when creating the service
2617 # client as shown in:
2618 # https://googleapis.dev/python/google-api-core/latest/client_options.html
2619 from google.cloud import logging_v2
2620
2621 def sample_delete_sink():
2622 # Create a client
2623 client = logging_v2.ConfigServiceV2Client()
2624
2625 # Initialize request argument(s)
2626 request = logging_v2.DeleteSinkRequest(
2627 sink_name="sink_name_value",
2628 )
2629
2630 # Make the request
2631 client.delete_sink(request=request)
2632
2633 Args:
2634 request (Union[google.cloud.logging_v2.types.DeleteSinkRequest, dict]):
2635 The request object. The parameters to ``DeleteSink``.
2636 sink_name (str):
2637 Required. The full resource name of the sink to delete,
2638 including the parent resource and the sink identifier:
2639
2640 ::
2641
2642 "projects/[PROJECT_ID]/sinks/[SINK_ID]"
2643 "organizations/[ORGANIZATION_ID]/sinks/[SINK_ID]"
2644 "billingAccounts/[BILLING_ACCOUNT_ID]/sinks/[SINK_ID]"
2645 "folders/[FOLDER_ID]/sinks/[SINK_ID]"
2646
2647 For example:
2648
2649 ``"projects/my-project/sinks/my-sink"``
2650
2651 This corresponds to the ``sink_name`` field
2652 on the ``request`` instance; if ``request`` is provided, this
2653 should not be set.
2654 retry (google.api_core.retry.Retry): Designation of what errors, if any,
2655 should be retried.
2656 timeout (float): The timeout for this request.
2657 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
2658 sent along with the request as metadata. Normally, each value must be of type `str`,
2659 but for metadata keys ending with the suffix `-bin`, the corresponding values must
2660 be of type `bytes`.
2661 """
2662 # Create or coerce a protobuf request object.
2663 # - Quick check: If we got a request object, we should *not* have
2664 # gotten any keyword arguments that map to the request.
2665 flattened_params = [sink_name]
2666 has_flattened_params = (
2667 len([param for param in flattened_params if param is not None]) > 0
2668 )
2669 if request is not None and has_flattened_params:
2670 raise ValueError(
2671 "If the `request` argument is set, then none of "
2672 "the individual field arguments should be set."
2673 )
2674
2675 # - Use the request object if provided (there's no risk of modifying the input as
2676 # there are no flattened fields), or create one.
2677 if not isinstance(request, logging_config.DeleteSinkRequest):
2678 request = logging_config.DeleteSinkRequest(request)
2679 # If we have keyword arguments corresponding to fields on the
2680 # request, apply these.
2681 if sink_name is not None:
2682 request.sink_name = sink_name
2683
2684 # Wrap the RPC method; this adds retry and timeout information,
2685 # and friendly error handling.
2686 rpc = self._transport._wrapped_methods[self._transport.delete_sink]
2687
2688 # Certain fields should be provided within the metadata header;
2689 # add these here.
2690 metadata = tuple(metadata) + (
2691 gapic_v1.routing_header.to_grpc_metadata(
2692 (("sink_name", request.sink_name),)
2693 ),
2694 )
2695
2696 # Validate the universe domain.
2697 self._validate_universe_domain()
2698
2699 # Send the request.
2700 rpc(
2701 request,
2702 retry=retry,
2703 timeout=timeout,
2704 metadata=metadata,
2705 )
2706
2707 def create_link(
2708 self,
2709 request: Optional[Union[logging_config.CreateLinkRequest, dict]] = None,
2710 *,
2711 parent: Optional[str] = None,
2712 link: Optional[logging_config.Link] = None,
2713 link_id: Optional[str] = None,
2714 retry: OptionalRetry = gapic_v1.method.DEFAULT,
2715 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
2716 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
2717 ) -> operation.Operation:
2718 r"""Asynchronously creates a linked dataset in BigQuery
2719 which makes it possible to use BigQuery to read the logs
2720 stored in the log bucket. A log bucket may currently
2721 only contain one link.
2722
2723 .. code-block:: python
2724
2725 # This snippet has been automatically generated and should be regarded as a
2726 # code template only.
2727 # It will require modifications to work:
2728 # - It may require correct/in-range values for request initialization.
2729 # - It may require specifying regional endpoints when creating the service
2730 # client as shown in:
2731 # https://googleapis.dev/python/google-api-core/latest/client_options.html
2732 from google.cloud import logging_v2
2733
2734 def sample_create_link():
2735 # Create a client
2736 client = logging_v2.ConfigServiceV2Client()
2737
2738 # Initialize request argument(s)
2739 request = logging_v2.CreateLinkRequest(
2740 parent="parent_value",
2741 link_id="link_id_value",
2742 )
2743
2744 # Make the request
2745 operation = client.create_link(request=request)
2746
2747 print("Waiting for operation to complete...")
2748
2749 response = operation.result()
2750
2751 # Handle the response
2752 print(response)
2753
2754 Args:
2755 request (Union[google.cloud.logging_v2.types.CreateLinkRequest, dict]):
2756 The request object. The parameters to CreateLink.
2757 parent (str):
2758 Required. The full resource name of the bucket to create
2759 a link for.
2760
2761 ::
2762
2763 "projects/[PROJECT_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]"
2764 "organizations/[ORGANIZATION_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]"
2765 "billingAccounts/[BILLING_ACCOUNT_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]"
2766 "folders/[FOLDER_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]"
2767
2768 This corresponds to the ``parent`` field
2769 on the ``request`` instance; if ``request`` is provided, this
2770 should not be set.
2771 link (google.cloud.logging_v2.types.Link):
2772 Required. The new link.
2773 This corresponds to the ``link`` field
2774 on the ``request`` instance; if ``request`` is provided, this
2775 should not be set.
2776 link_id (str):
2777 Required. The ID to use for the link. The link_id can
2778 have up to 100 characters. A valid link_id must only
2779 have alphanumeric characters and underscores within it.
2780
2781 This corresponds to the ``link_id`` field
2782 on the ``request`` instance; if ``request`` is provided, this
2783 should not be set.
2784 retry (google.api_core.retry.Retry): Designation of what errors, if any,
2785 should be retried.
2786 timeout (float): The timeout for this request.
2787 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
2788 sent along with the request as metadata. Normally, each value must be of type `str`,
2789 but for metadata keys ending with the suffix `-bin`, the corresponding values must
2790 be of type `bytes`.
2791
2792 Returns:
2793 google.api_core.operation.Operation:
2794 An object representing a long-running operation.
2795
2796 The result type for the operation will be
2797 :class:`google.cloud.logging_v2.types.Link` Describes a
2798 link connected to an analytics enabled bucket.
2799
2800 """
2801 # Create or coerce a protobuf request object.
2802 # - Quick check: If we got a request object, we should *not* have
2803 # gotten any keyword arguments that map to the request.
2804 flattened_params = [parent, link, link_id]
2805 has_flattened_params = (
2806 len([param for param in flattened_params if param is not None]) > 0
2807 )
2808 if request is not None and has_flattened_params:
2809 raise ValueError(
2810 "If the `request` argument is set, then none of "
2811 "the individual field arguments should be set."
2812 )
2813
2814 # - Use the request object if provided (there's no risk of modifying the input as
2815 # there are no flattened fields), or create one.
2816 if not isinstance(request, logging_config.CreateLinkRequest):
2817 request = logging_config.CreateLinkRequest(request)
2818 # If we have keyword arguments corresponding to fields on the
2819 # request, apply these.
2820 if parent is not None:
2821 request.parent = parent
2822 if link is not None:
2823 request.link = link
2824 if link_id is not None:
2825 request.link_id = link_id
2826
2827 # Wrap the RPC method; this adds retry and timeout information,
2828 # and friendly error handling.
2829 rpc = self._transport._wrapped_methods[self._transport.create_link]
2830
2831 # Certain fields should be provided within the metadata header;
2832 # add these here.
2833 metadata = tuple(metadata) + (
2834 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
2835 )
2836
2837 # Validate the universe domain.
2838 self._validate_universe_domain()
2839
2840 # Send the request.
2841 response = rpc(
2842 request,
2843 retry=retry,
2844 timeout=timeout,
2845 metadata=metadata,
2846 )
2847
2848 # Wrap the response in an operation future.
2849 response = operation.from_gapic(
2850 response,
2851 self._transport.operations_client,
2852 logging_config.Link,
2853 metadata_type=logging_config.LinkMetadata,
2854 )
2855
2856 # Done; return the response.
2857 return response
2858
2859 def delete_link(
2860 self,
2861 request: Optional[Union[logging_config.DeleteLinkRequest, dict]] = None,
2862 *,
2863 name: Optional[str] = None,
2864 retry: OptionalRetry = gapic_v1.method.DEFAULT,
2865 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
2866 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
2867 ) -> operation.Operation:
2868 r"""Deletes a link. This will also delete the
2869 corresponding BigQuery linked dataset.
2870
2871 .. code-block:: python
2872
2873 # This snippet has been automatically generated and should be regarded as a
2874 # code template only.
2875 # It will require modifications to work:
2876 # - It may require correct/in-range values for request initialization.
2877 # - It may require specifying regional endpoints when creating the service
2878 # client as shown in:
2879 # https://googleapis.dev/python/google-api-core/latest/client_options.html
2880 from google.cloud import logging_v2
2881
2882 def sample_delete_link():
2883 # Create a client
2884 client = logging_v2.ConfigServiceV2Client()
2885
2886 # Initialize request argument(s)
2887 request = logging_v2.DeleteLinkRequest(
2888 name="name_value",
2889 )
2890
2891 # Make the request
2892 operation = client.delete_link(request=request)
2893
2894 print("Waiting for operation to complete...")
2895
2896 response = operation.result()
2897
2898 # Handle the response
2899 print(response)
2900
2901 Args:
2902 request (Union[google.cloud.logging_v2.types.DeleteLinkRequest, dict]):
2903 The request object. The parameters to DeleteLink.
2904 name (str):
2905 Required. The full resource name of the link to delete.
2906
2907 "projects/[PROJECT_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]/links/[LINK_ID]"
2908 "organizations/[ORGANIZATION_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]/links/[LINK_ID]"
2909 "billingAccounts/[BILLING_ACCOUNT_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]/links/[LINK_ID]"
2910 "folders/[FOLDER_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]/links/[LINK_ID]"
2911
2912 This corresponds to the ``name`` field
2913 on the ``request`` instance; if ``request`` is provided, this
2914 should not be set.
2915 retry (google.api_core.retry.Retry): Designation of what errors, if any,
2916 should be retried.
2917 timeout (float): The timeout for this request.
2918 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
2919 sent along with the request as metadata. Normally, each value must be of type `str`,
2920 but for metadata keys ending with the suffix `-bin`, the corresponding values must
2921 be of type `bytes`.
2922
2923 Returns:
2924 google.api_core.operation.Operation:
2925 An object representing a long-running operation.
2926
2927 The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated
2928 empty messages in your APIs. A typical example is to
2929 use it as the request or the response type of an API
2930 method. For instance:
2931
2932 service Foo {
2933 rpc Bar(google.protobuf.Empty) returns
2934 (google.protobuf.Empty);
2935
2936 }
2937
2938 """
2939 # Create or coerce a protobuf request object.
2940 # - Quick check: If we got a request object, we should *not* have
2941 # gotten any keyword arguments that map to the request.
2942 flattened_params = [name]
2943 has_flattened_params = (
2944 len([param for param in flattened_params if param is not None]) > 0
2945 )
2946 if request is not None and has_flattened_params:
2947 raise ValueError(
2948 "If the `request` argument is set, then none of "
2949 "the individual field arguments should be set."
2950 )
2951
2952 # - Use the request object if provided (there's no risk of modifying the input as
2953 # there are no flattened fields), or create one.
2954 if not isinstance(request, logging_config.DeleteLinkRequest):
2955 request = logging_config.DeleteLinkRequest(request)
2956 # If we have keyword arguments corresponding to fields on the
2957 # request, apply these.
2958 if name is not None:
2959 request.name = name
2960
2961 # Wrap the RPC method; this adds retry and timeout information,
2962 # and friendly error handling.
2963 rpc = self._transport._wrapped_methods[self._transport.delete_link]
2964
2965 # Certain fields should be provided within the metadata header;
2966 # add these here.
2967 metadata = tuple(metadata) + (
2968 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
2969 )
2970
2971 # Validate the universe domain.
2972 self._validate_universe_domain()
2973
2974 # Send the request.
2975 response = rpc(
2976 request,
2977 retry=retry,
2978 timeout=timeout,
2979 metadata=metadata,
2980 )
2981
2982 # Wrap the response in an operation future.
2983 response = operation.from_gapic(
2984 response,
2985 self._transport.operations_client,
2986 empty_pb2.Empty,
2987 metadata_type=logging_config.LinkMetadata,
2988 )
2989
2990 # Done; return the response.
2991 return response
2992
2993 def list_links(
2994 self,
2995 request: Optional[Union[logging_config.ListLinksRequest, dict]] = None,
2996 *,
2997 parent: Optional[str] = None,
2998 retry: OptionalRetry = gapic_v1.method.DEFAULT,
2999 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
3000 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
3001 ) -> pagers.ListLinksPager:
3002 r"""Lists links.
3003
3004 .. code-block:: python
3005
3006 # This snippet has been automatically generated and should be regarded as a
3007 # code template only.
3008 # It will require modifications to work:
3009 # - It may require correct/in-range values for request initialization.
3010 # - It may require specifying regional endpoints when creating the service
3011 # client as shown in:
3012 # https://googleapis.dev/python/google-api-core/latest/client_options.html
3013 from google.cloud import logging_v2
3014
3015 def sample_list_links():
3016 # Create a client
3017 client = logging_v2.ConfigServiceV2Client()
3018
3019 # Initialize request argument(s)
3020 request = logging_v2.ListLinksRequest(
3021 parent="parent_value",
3022 )
3023
3024 # Make the request
3025 page_result = client.list_links(request=request)
3026
3027 # Handle the response
3028 for response in page_result:
3029 print(response)
3030
3031 Args:
3032 request (Union[google.cloud.logging_v2.types.ListLinksRequest, dict]):
3033 The request object. The parameters to ListLinks.
3034 parent (str):
3035 Required. The parent resource whose links are to be
3036 listed:
3037
3038 "projects/[PROJECT_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]/links/"
3039 "organizations/[ORGANIZATION_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]/"
3040 "billingAccounts/[BILLING_ACCOUNT_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]/"
3041 "folders/[FOLDER_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]/
3042
3043 This corresponds to the ``parent`` field
3044 on the ``request`` instance; if ``request`` is provided, this
3045 should not be set.
3046 retry (google.api_core.retry.Retry): Designation of what errors, if any,
3047 should be retried.
3048 timeout (float): The timeout for this request.
3049 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
3050 sent along with the request as metadata. Normally, each value must be of type `str`,
3051 but for metadata keys ending with the suffix `-bin`, the corresponding values must
3052 be of type `bytes`.
3053
3054 Returns:
3055 google.cloud.logging_v2.services.config_service_v2.pagers.ListLinksPager:
3056 The response from ListLinks.
3057
3058 Iterating over this object will yield
3059 results and resolve additional pages
3060 automatically.
3061
3062 """
3063 # Create or coerce a protobuf request object.
3064 # - Quick check: If we got a request object, we should *not* have
3065 # gotten any keyword arguments that map to the request.
3066 flattened_params = [parent]
3067 has_flattened_params = (
3068 len([param for param in flattened_params if param is not None]) > 0
3069 )
3070 if request is not None and has_flattened_params:
3071 raise ValueError(
3072 "If the `request` argument is set, then none of "
3073 "the individual field arguments should be set."
3074 )
3075
3076 # - Use the request object if provided (there's no risk of modifying the input as
3077 # there are no flattened fields), or create one.
3078 if not isinstance(request, logging_config.ListLinksRequest):
3079 request = logging_config.ListLinksRequest(request)
3080 # If we have keyword arguments corresponding to fields on the
3081 # request, apply these.
3082 if parent is not None:
3083 request.parent = parent
3084
3085 # Wrap the RPC method; this adds retry and timeout information,
3086 # and friendly error handling.
3087 rpc = self._transport._wrapped_methods[self._transport.list_links]
3088
3089 # Certain fields should be provided within the metadata header;
3090 # add these here.
3091 metadata = tuple(metadata) + (
3092 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
3093 )
3094
3095 # Validate the universe domain.
3096 self._validate_universe_domain()
3097
3098 # Send the request.
3099 response = rpc(
3100 request,
3101 retry=retry,
3102 timeout=timeout,
3103 metadata=metadata,
3104 )
3105
3106 # This method is paged; wrap the response in a pager, which provides
3107 # an `__iter__` convenience method.
3108 response = pagers.ListLinksPager(
3109 method=rpc,
3110 request=request,
3111 response=response,
3112 retry=retry,
3113 timeout=timeout,
3114 metadata=metadata,
3115 )
3116
3117 # Done; return the response.
3118 return response
3119
3120 def get_link(
3121 self,
3122 request: Optional[Union[logging_config.GetLinkRequest, dict]] = None,
3123 *,
3124 name: Optional[str] = None,
3125 retry: OptionalRetry = gapic_v1.method.DEFAULT,
3126 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
3127 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
3128 ) -> logging_config.Link:
3129 r"""Gets a link.
3130
3131 .. code-block:: python
3132
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
3141
3142 def sample_get_link():
3143 # Create a client
3144 client = logging_v2.ConfigServiceV2Client()
3145
3146 # Initialize request argument(s)
3147 request = logging_v2.GetLinkRequest(
3148 name="name_value",
3149 )
3150
3151 # Make the request
3152 response = client.get_link(request=request)
3153
3154 # Handle the response
3155 print(response)
3156
3157 Args:
3158 request (Union[google.cloud.logging_v2.types.GetLinkRequest, dict]):
3159 The request object. The parameters to GetLink.
3160 name (str):
3161 Required. The resource name of the link:
3162
3163 "projects/[PROJECT_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]/links/[LINK_ID]"
3164 "organizations/[ORGANIZATION_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]/links/[LINK_ID]"
3165 "billingAccounts/[BILLING_ACCOUNT_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]/links/[LINK_ID]"
3166 "folders/[FOLDER_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]/links/[LINK_ID]
3167
3168 This corresponds to the ``name`` field
3169 on the ``request`` instance; if ``request`` is provided, this
3170 should not be set.
3171 retry (google.api_core.retry.Retry): Designation of what errors, if any,
3172 should be retried.
3173 timeout (float): The timeout for this request.
3174 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
3175 sent along with the request as metadata. Normally, each value must be of type `str`,
3176 but for metadata keys ending with the suffix `-bin`, the corresponding values must
3177 be of type `bytes`.
3178
3179 Returns:
3180 google.cloud.logging_v2.types.Link:
3181 Describes a link connected to an
3182 analytics enabled bucket.
3183
3184 """
3185 # Create or coerce a protobuf request object.
3186 # - Quick check: If we got a request object, we should *not* have
3187 # gotten any keyword arguments that map to the request.
3188 flattened_params = [name]
3189 has_flattened_params = (
3190 len([param for param in flattened_params if param is not None]) > 0
3191 )
3192 if request is not None and has_flattened_params:
3193 raise ValueError(
3194 "If the `request` argument is set, then none of "
3195 "the individual field arguments should be set."
3196 )
3197
3198 # - Use the request object if provided (there's no risk of modifying the input as
3199 # there are no flattened fields), or create one.
3200 if not isinstance(request, logging_config.GetLinkRequest):
3201 request = logging_config.GetLinkRequest(request)
3202 # If we have keyword arguments corresponding to fields on the
3203 # request, apply these.
3204 if name is not None:
3205 request.name = name
3206
3207 # Wrap the RPC method; this adds retry and timeout information,
3208 # and friendly error handling.
3209 rpc = self._transport._wrapped_methods[self._transport.get_link]
3210
3211 # Certain fields should be provided within the metadata header;
3212 # add these here.
3213 metadata = tuple(metadata) + (
3214 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
3215 )
3216
3217 # Validate the universe domain.
3218 self._validate_universe_domain()
3219
3220 # Send the request.
3221 response = rpc(
3222 request,
3223 retry=retry,
3224 timeout=timeout,
3225 metadata=metadata,
3226 )
3227
3228 # Done; return the response.
3229 return response
3230
3231 def list_exclusions(
3232 self,
3233 request: Optional[Union[logging_config.ListExclusionsRequest, dict]] = None,
3234 *,
3235 parent: Optional[str] = None,
3236 retry: OptionalRetry = gapic_v1.method.DEFAULT,
3237 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
3238 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
3239 ) -> pagers.ListExclusionsPager:
3240 r"""Lists all the exclusions on the \_Default sink in a parent
3241 resource.
3242
3243 .. code-block:: python
3244
3245 # This snippet has been automatically generated and should be regarded as a
3246 # code template only.
3247 # It will require modifications to work:
3248 # - It may require correct/in-range values for request initialization.
3249 # - It may require specifying regional endpoints when creating the service
3250 # client as shown in:
3251 # https://googleapis.dev/python/google-api-core/latest/client_options.html
3252 from google.cloud import logging_v2
3253
3254 def sample_list_exclusions():
3255 # Create a client
3256 client = logging_v2.ConfigServiceV2Client()
3257
3258 # Initialize request argument(s)
3259 request = logging_v2.ListExclusionsRequest(
3260 parent="parent_value",
3261 )
3262
3263 # Make the request
3264 page_result = client.list_exclusions(request=request)
3265
3266 # Handle the response
3267 for response in page_result:
3268 print(response)
3269
3270 Args:
3271 request (Union[google.cloud.logging_v2.types.ListExclusionsRequest, dict]):
3272 The request object. The parameters to ``ListExclusions``.
3273 parent (str):
3274 Required. The parent resource whose exclusions are to be
3275 listed.
3276
3277 ::
3278
3279 "projects/[PROJECT_ID]"
3280 "organizations/[ORGANIZATION_ID]"
3281 "billingAccounts/[BILLING_ACCOUNT_ID]"
3282 "folders/[FOLDER_ID]"
3283
3284 This corresponds to the ``parent`` field
3285 on the ``request`` instance; if ``request`` is provided, this
3286 should not be set.
3287 retry (google.api_core.retry.Retry): Designation of what errors, if any,
3288 should be retried.
3289 timeout (float): The timeout for this request.
3290 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
3291 sent along with the request as metadata. Normally, each value must be of type `str`,
3292 but for metadata keys ending with the suffix `-bin`, the corresponding values must
3293 be of type `bytes`.
3294
3295 Returns:
3296 google.cloud.logging_v2.services.config_service_v2.pagers.ListExclusionsPager:
3297 Result returned from ListExclusions.
3298
3299 Iterating over this object will yield results and
3300 resolve additional pages automatically.
3301
3302 """
3303 # Create or coerce a protobuf request object.
3304 # - Quick check: If we got a request object, we should *not* have
3305 # gotten any keyword arguments that map to the request.
3306 flattened_params = [parent]
3307 has_flattened_params = (
3308 len([param for param in flattened_params if param is not None]) > 0
3309 )
3310 if request is not None and has_flattened_params:
3311 raise ValueError(
3312 "If the `request` argument is set, then none of "
3313 "the individual field arguments should be set."
3314 )
3315
3316 # - Use the request object if provided (there's no risk of modifying the input as
3317 # there are no flattened fields), or create one.
3318 if not isinstance(request, logging_config.ListExclusionsRequest):
3319 request = logging_config.ListExclusionsRequest(request)
3320 # If we have keyword arguments corresponding to fields on the
3321 # request, apply these.
3322 if parent is not None:
3323 request.parent = parent
3324
3325 # Wrap the RPC method; this adds retry and timeout information,
3326 # and friendly error handling.
3327 rpc = self._transport._wrapped_methods[self._transport.list_exclusions]
3328
3329 # Certain fields should be provided within the metadata header;
3330 # add these here.
3331 metadata = tuple(metadata) + (
3332 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
3333 )
3334
3335 # Validate the universe domain.
3336 self._validate_universe_domain()
3337
3338 # Send the request.
3339 response = rpc(
3340 request,
3341 retry=retry,
3342 timeout=timeout,
3343 metadata=metadata,
3344 )
3345
3346 # This method is paged; wrap the response in a pager, which provides
3347 # an `__iter__` convenience method.
3348 response = pagers.ListExclusionsPager(
3349 method=rpc,
3350 request=request,
3351 response=response,
3352 retry=retry,
3353 timeout=timeout,
3354 metadata=metadata,
3355 )
3356
3357 # Done; return the response.
3358 return response
3359
3360 def get_exclusion(
3361 self,
3362 request: Optional[Union[logging_config.GetExclusionRequest, dict]] = None,
3363 *,
3364 name: Optional[str] = None,
3365 retry: OptionalRetry = gapic_v1.method.DEFAULT,
3366 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
3367 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
3368 ) -> logging_config.LogExclusion:
3369 r"""Gets the description of an exclusion in the \_Default sink.
3370
3371 .. code-block:: python
3372
3373 # This snippet has been automatically generated and should be regarded as a
3374 # code template only.
3375 # It will require modifications to work:
3376 # - It may require correct/in-range values for request initialization.
3377 # - It may require specifying regional endpoints when creating the service
3378 # client as shown in:
3379 # https://googleapis.dev/python/google-api-core/latest/client_options.html
3380 from google.cloud import logging_v2
3381
3382 def sample_get_exclusion():
3383 # Create a client
3384 client = logging_v2.ConfigServiceV2Client()
3385
3386 # Initialize request argument(s)
3387 request = logging_v2.GetExclusionRequest(
3388 name="name_value",
3389 )
3390
3391 # Make the request
3392 response = client.get_exclusion(request=request)
3393
3394 # Handle the response
3395 print(response)
3396
3397 Args:
3398 request (Union[google.cloud.logging_v2.types.GetExclusionRequest, dict]):
3399 The request object. The parameters to ``GetExclusion``.
3400 name (str):
3401 Required. The resource name of an existing exclusion:
3402
3403 ::
3404
3405 "projects/[PROJECT_ID]/exclusions/[EXCLUSION_ID]"
3406 "organizations/[ORGANIZATION_ID]/exclusions/[EXCLUSION_ID]"
3407 "billingAccounts/[BILLING_ACCOUNT_ID]/exclusions/[EXCLUSION_ID]"
3408 "folders/[FOLDER_ID]/exclusions/[EXCLUSION_ID]"
3409
3410 For example:
3411
3412 ``"projects/my-project/exclusions/my-exclusion"``
3413
3414 This corresponds to the ``name`` field
3415 on the ``request`` instance; if ``request`` is provided, this
3416 should not be set.
3417 retry (google.api_core.retry.Retry): Designation of what errors, if any,
3418 should be retried.
3419 timeout (float): The timeout for this request.
3420 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
3421 sent along with the request as metadata. Normally, each value must be of type `str`,
3422 but for metadata keys ending with the suffix `-bin`, the corresponding values must
3423 be of type `bytes`.
3424
3425 Returns:
3426 google.cloud.logging_v2.types.LogExclusion:
3427 Specifies a set of log entries that are filtered out by a sink. If
3428 your Google Cloud resource receives a large volume of
3429 log entries, you can use exclusions to reduce your
3430 chargeable logs. Note that exclusions on
3431 organization-level and folder-level sinks don't apply
3432 to child resources. Note also that you cannot modify
3433 the \_Required sink or exclude logs from it.
3434
3435 """
3436 # Create or coerce a protobuf request object.
3437 # - Quick check: If we got a request object, we should *not* have
3438 # gotten any keyword arguments that map to the request.
3439 flattened_params = [name]
3440 has_flattened_params = (
3441 len([param for param in flattened_params if param is not None]) > 0
3442 )
3443 if request is not None and has_flattened_params:
3444 raise ValueError(
3445 "If the `request` argument is set, then none of "
3446 "the individual field arguments should be set."
3447 )
3448
3449 # - Use the request object if provided (there's no risk of modifying the input as
3450 # there are no flattened fields), or create one.
3451 if not isinstance(request, logging_config.GetExclusionRequest):
3452 request = logging_config.GetExclusionRequest(request)
3453 # If we have keyword arguments corresponding to fields on the
3454 # request, apply these.
3455 if name is not None:
3456 request.name = name
3457
3458 # Wrap the RPC method; this adds retry and timeout information,
3459 # and friendly error handling.
3460 rpc = self._transport._wrapped_methods[self._transport.get_exclusion]
3461
3462 # Certain fields should be provided within the metadata header;
3463 # add these here.
3464 metadata = tuple(metadata) + (
3465 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
3466 )
3467
3468 # Validate the universe domain.
3469 self._validate_universe_domain()
3470
3471 # Send the request.
3472 response = rpc(
3473 request,
3474 retry=retry,
3475 timeout=timeout,
3476 metadata=metadata,
3477 )
3478
3479 # Done; return the response.
3480 return response
3481
3482 def create_exclusion(
3483 self,
3484 request: Optional[Union[logging_config.CreateExclusionRequest, dict]] = None,
3485 *,
3486 parent: Optional[str] = None,
3487 exclusion: Optional[logging_config.LogExclusion] = None,
3488 retry: OptionalRetry = gapic_v1.method.DEFAULT,
3489 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
3490 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
3491 ) -> logging_config.LogExclusion:
3492 r"""Creates a new exclusion in the \_Default sink in a specified
3493 parent resource. Only log entries belonging to that resource can
3494 be excluded. You can have up to 10 exclusions in a resource.
3495
3496 .. code-block:: python
3497
3498 # This snippet has been automatically generated and should be regarded as a
3499 # code template only.
3500 # It will require modifications to work:
3501 # - It may require correct/in-range values for request initialization.
3502 # - It may require specifying regional endpoints when creating the service
3503 # client as shown in:
3504 # https://googleapis.dev/python/google-api-core/latest/client_options.html
3505 from google.cloud import logging_v2
3506
3507 def sample_create_exclusion():
3508 # Create a client
3509 client = logging_v2.ConfigServiceV2Client()
3510
3511 # Initialize request argument(s)
3512 exclusion = logging_v2.LogExclusion()
3513 exclusion.name = "name_value"
3514 exclusion.filter = "filter_value"
3515
3516 request = logging_v2.CreateExclusionRequest(
3517 parent="parent_value",
3518 exclusion=exclusion,
3519 )
3520
3521 # Make the request
3522 response = client.create_exclusion(request=request)
3523
3524 # Handle the response
3525 print(response)
3526
3527 Args:
3528 request (Union[google.cloud.logging_v2.types.CreateExclusionRequest, dict]):
3529 The request object. The parameters to ``CreateExclusion``.
3530 parent (str):
3531 Required. The parent resource in which to create the
3532 exclusion:
3533
3534 ::
3535
3536 "projects/[PROJECT_ID]"
3537 "organizations/[ORGANIZATION_ID]"
3538 "billingAccounts/[BILLING_ACCOUNT_ID]"
3539 "folders/[FOLDER_ID]"
3540
3541 For examples:
3542
3543 ``"projects/my-logging-project"``
3544 ``"organizations/123456789"``
3545
3546 This corresponds to the ``parent`` field
3547 on the ``request`` instance; if ``request`` is provided, this
3548 should not be set.
3549 exclusion (google.cloud.logging_v2.types.LogExclusion):
3550 Required. The new exclusion, whose ``name`` parameter is
3551 an exclusion name that is not already used in the parent
3552 resource.
3553
3554 This corresponds to the ``exclusion`` field
3555 on the ``request`` instance; if ``request`` is provided, this
3556 should not be set.
3557 retry (google.api_core.retry.Retry): Designation of what errors, if any,
3558 should be retried.
3559 timeout (float): The timeout for this request.
3560 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
3561 sent along with the request as metadata. Normally, each value must be of type `str`,
3562 but for metadata keys ending with the suffix `-bin`, the corresponding values must
3563 be of type `bytes`.
3564
3565 Returns:
3566 google.cloud.logging_v2.types.LogExclusion:
3567 Specifies a set of log entries that are filtered out by a sink. If
3568 your Google Cloud resource receives a large volume of
3569 log entries, you can use exclusions to reduce your
3570 chargeable logs. Note that exclusions on
3571 organization-level and folder-level sinks don't apply
3572 to child resources. Note also that you cannot modify
3573 the \_Required sink or exclude logs from it.
3574
3575 """
3576 # Create or coerce a protobuf request object.
3577 # - Quick check: If we got a request object, we should *not* have
3578 # gotten any keyword arguments that map to the request.
3579 flattened_params = [parent, exclusion]
3580 has_flattened_params = (
3581 len([param for param in flattened_params if param is not None]) > 0
3582 )
3583 if request is not None and has_flattened_params:
3584 raise ValueError(
3585 "If the `request` argument is set, then none of "
3586 "the individual field arguments should be set."
3587 )
3588
3589 # - Use the request object if provided (there's no risk of modifying the input as
3590 # there are no flattened fields), or create one.
3591 if not isinstance(request, logging_config.CreateExclusionRequest):
3592 request = logging_config.CreateExclusionRequest(request)
3593 # If we have keyword arguments corresponding to fields on the
3594 # request, apply these.
3595 if parent is not None:
3596 request.parent = parent
3597 if exclusion is not None:
3598 request.exclusion = exclusion
3599
3600 # Wrap the RPC method; this adds retry and timeout information,
3601 # and friendly error handling.
3602 rpc = self._transport._wrapped_methods[self._transport.create_exclusion]
3603
3604 # Certain fields should be provided within the metadata header;
3605 # add these here.
3606 metadata = tuple(metadata) + (
3607 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
3608 )
3609
3610 # Validate the universe domain.
3611 self._validate_universe_domain()
3612
3613 # Send the request.
3614 response = rpc(
3615 request,
3616 retry=retry,
3617 timeout=timeout,
3618 metadata=metadata,
3619 )
3620
3621 # Done; return the response.
3622 return response
3623
3624 def update_exclusion(
3625 self,
3626 request: Optional[Union[logging_config.UpdateExclusionRequest, dict]] = None,
3627 *,
3628 name: Optional[str] = None,
3629 exclusion: Optional[logging_config.LogExclusion] = None,
3630 update_mask: Optional[field_mask_pb2.FieldMask] = None,
3631 retry: OptionalRetry = gapic_v1.method.DEFAULT,
3632 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
3633 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
3634 ) -> logging_config.LogExclusion:
3635 r"""Changes one or more properties of an existing exclusion in the
3636 \_Default sink.
3637
3638 .. code-block:: python
3639
3640 # This snippet has been automatically generated and should be regarded as a
3641 # code template only.
3642 # It will require modifications to work:
3643 # - It may require correct/in-range values for request initialization.
3644 # - It may require specifying regional endpoints when creating the service
3645 # client as shown in:
3646 # https://googleapis.dev/python/google-api-core/latest/client_options.html
3647 from google.cloud import logging_v2
3648
3649 def sample_update_exclusion():
3650 # Create a client
3651 client = logging_v2.ConfigServiceV2Client()
3652
3653 # Initialize request argument(s)
3654 exclusion = logging_v2.LogExclusion()
3655 exclusion.name = "name_value"
3656 exclusion.filter = "filter_value"
3657
3658 request = logging_v2.UpdateExclusionRequest(
3659 name="name_value",
3660 exclusion=exclusion,
3661 )
3662
3663 # Make the request
3664 response = client.update_exclusion(request=request)
3665
3666 # Handle the response
3667 print(response)
3668
3669 Args:
3670 request (Union[google.cloud.logging_v2.types.UpdateExclusionRequest, dict]):
3671 The request object. The parameters to ``UpdateExclusion``.
3672 name (str):
3673 Required. The resource name of the exclusion to update:
3674
3675 ::
3676
3677 "projects/[PROJECT_ID]/exclusions/[EXCLUSION_ID]"
3678 "organizations/[ORGANIZATION_ID]/exclusions/[EXCLUSION_ID]"
3679 "billingAccounts/[BILLING_ACCOUNT_ID]/exclusions/[EXCLUSION_ID]"
3680 "folders/[FOLDER_ID]/exclusions/[EXCLUSION_ID]"
3681
3682 For example:
3683
3684 ``"projects/my-project/exclusions/my-exclusion"``
3685
3686 This corresponds to the ``name`` field
3687 on the ``request`` instance; if ``request`` is provided, this
3688 should not be set.
3689 exclusion (google.cloud.logging_v2.types.LogExclusion):
3690 Required. New values for the existing exclusion. Only
3691 the fields specified in ``update_mask`` are relevant.
3692
3693 This corresponds to the ``exclusion`` field
3694 on the ``request`` instance; if ``request`` is provided, this
3695 should not be set.
3696 update_mask (google.protobuf.field_mask_pb2.FieldMask):
3697 Required. A non-empty list of fields to change in the
3698 existing exclusion. New values for the fields are taken
3699 from the corresponding fields in the
3700 [LogExclusion][google.logging.v2.LogExclusion] included
3701 in this request. Fields not mentioned in ``update_mask``
3702 are not changed and are ignored in the request.
3703
3704 For example, to change the filter and description of an
3705 exclusion, specify an ``update_mask`` of
3706 ``"filter,description"``.
3707
3708 This corresponds to the ``update_mask`` field
3709 on the ``request`` instance; if ``request`` is provided, this
3710 should not be set.
3711 retry (google.api_core.retry.Retry): Designation of what errors, if any,
3712 should be retried.
3713 timeout (float): The timeout for this request.
3714 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
3715 sent along with the request as metadata. Normally, each value must be of type `str`,
3716 but for metadata keys ending with the suffix `-bin`, the corresponding values must
3717 be of type `bytes`.
3718
3719 Returns:
3720 google.cloud.logging_v2.types.LogExclusion:
3721 Specifies a set of log entries that are filtered out by a sink. If
3722 your Google Cloud resource receives a large volume of
3723 log entries, you can use exclusions to reduce your
3724 chargeable logs. Note that exclusions on
3725 organization-level and folder-level sinks don't apply
3726 to child resources. Note also that you cannot modify
3727 the \_Required sink or exclude logs from it.
3728
3729 """
3730 # Create or coerce a protobuf request object.
3731 # - Quick check: If we got a request object, we should *not* have
3732 # gotten any keyword arguments that map to the request.
3733 flattened_params = [name, exclusion, update_mask]
3734 has_flattened_params = (
3735 len([param for param in flattened_params if param is not None]) > 0
3736 )
3737 if request is not None and has_flattened_params:
3738 raise ValueError(
3739 "If the `request` argument is set, then none of "
3740 "the individual field arguments should be set."
3741 )
3742
3743 # - Use the request object if provided (there's no risk of modifying the input as
3744 # there are no flattened fields), or create one.
3745 if not isinstance(request, logging_config.UpdateExclusionRequest):
3746 request = logging_config.UpdateExclusionRequest(request)
3747 # If we have keyword arguments corresponding to fields on the
3748 # request, apply these.
3749 if name is not None:
3750 request.name = name
3751 if exclusion is not None:
3752 request.exclusion = exclusion
3753 if update_mask is not None:
3754 request.update_mask = update_mask
3755
3756 # Wrap the RPC method; this adds retry and timeout information,
3757 # and friendly error handling.
3758 rpc = self._transport._wrapped_methods[self._transport.update_exclusion]
3759
3760 # Certain fields should be provided within the metadata header;
3761 # add these here.
3762 metadata = tuple(metadata) + (
3763 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
3764 )
3765
3766 # Validate the universe domain.
3767 self._validate_universe_domain()
3768
3769 # Send the request.
3770 response = rpc(
3771 request,
3772 retry=retry,
3773 timeout=timeout,
3774 metadata=metadata,
3775 )
3776
3777 # Done; return the response.
3778 return response
3779
3780 def delete_exclusion(
3781 self,
3782 request: Optional[Union[logging_config.DeleteExclusionRequest, dict]] = None,
3783 *,
3784 name: Optional[str] = None,
3785 retry: OptionalRetry = gapic_v1.method.DEFAULT,
3786 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
3787 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
3788 ) -> None:
3789 r"""Deletes an exclusion in the \_Default sink.
3790
3791 .. code-block:: python
3792
3793 # This snippet has been automatically generated and should be regarded as a
3794 # code template only.
3795 # It will require modifications to work:
3796 # - It may require correct/in-range values for request initialization.
3797 # - It may require specifying regional endpoints when creating the service
3798 # client as shown in:
3799 # https://googleapis.dev/python/google-api-core/latest/client_options.html
3800 from google.cloud import logging_v2
3801
3802 def sample_delete_exclusion():
3803 # Create a client
3804 client = logging_v2.ConfigServiceV2Client()
3805
3806 # Initialize request argument(s)
3807 request = logging_v2.DeleteExclusionRequest(
3808 name="name_value",
3809 )
3810
3811 # Make the request
3812 client.delete_exclusion(request=request)
3813
3814 Args:
3815 request (Union[google.cloud.logging_v2.types.DeleteExclusionRequest, dict]):
3816 The request object. The parameters to ``DeleteExclusion``.
3817 name (str):
3818 Required. The resource name of an existing exclusion to
3819 delete:
3820
3821 ::
3822
3823 "projects/[PROJECT_ID]/exclusions/[EXCLUSION_ID]"
3824 "organizations/[ORGANIZATION_ID]/exclusions/[EXCLUSION_ID]"
3825 "billingAccounts/[BILLING_ACCOUNT_ID]/exclusions/[EXCLUSION_ID]"
3826 "folders/[FOLDER_ID]/exclusions/[EXCLUSION_ID]"
3827
3828 For example:
3829
3830 ``"projects/my-project/exclusions/my-exclusion"``
3831
3832 This corresponds to the ``name`` field
3833 on the ``request`` instance; if ``request`` is provided, this
3834 should not be set.
3835 retry (google.api_core.retry.Retry): Designation of what errors, if any,
3836 should be retried.
3837 timeout (float): The timeout for this request.
3838 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
3839 sent along with the request as metadata. Normally, each value must be of type `str`,
3840 but for metadata keys ending with the suffix `-bin`, the corresponding values must
3841 be of type `bytes`.
3842 """
3843 # Create or coerce a protobuf request object.
3844 # - Quick check: If we got a request object, we should *not* have
3845 # gotten any keyword arguments that map to the request.
3846 flattened_params = [name]
3847 has_flattened_params = (
3848 len([param for param in flattened_params if param is not None]) > 0
3849 )
3850 if request is not None and has_flattened_params:
3851 raise ValueError(
3852 "If the `request` argument is set, then none of "
3853 "the individual field arguments should be set."
3854 )
3855
3856 # - Use the request object if provided (there's no risk of modifying the input as
3857 # there are no flattened fields), or create one.
3858 if not isinstance(request, logging_config.DeleteExclusionRequest):
3859 request = logging_config.DeleteExclusionRequest(request)
3860 # If we have keyword arguments corresponding to fields on the
3861 # request, apply these.
3862 if name is not None:
3863 request.name = name
3864
3865 # Wrap the RPC method; this adds retry and timeout information,
3866 # and friendly error handling.
3867 rpc = self._transport._wrapped_methods[self._transport.delete_exclusion]
3868
3869 # Certain fields should be provided within the metadata header;
3870 # add these here.
3871 metadata = tuple(metadata) + (
3872 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
3873 )
3874
3875 # Validate the universe domain.
3876 self._validate_universe_domain()
3877
3878 # Send the request.
3879 rpc(
3880 request,
3881 retry=retry,
3882 timeout=timeout,
3883 metadata=metadata,
3884 )
3885
3886 def get_cmek_settings(
3887 self,
3888 request: Optional[Union[logging_config.GetCmekSettingsRequest, dict]] = None,
3889 *,
3890 retry: OptionalRetry = gapic_v1.method.DEFAULT,
3891 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
3892 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
3893 ) -> logging_config.CmekSettings:
3894 r"""Gets the Logging CMEK settings for the given resource.
3895
3896 Note: CMEK for the Log Router can be configured for Google Cloud
3897 projects, folders, organizations and billing accounts. Once
3898 configured for an organization, it applies to all projects and
3899 folders in the Google Cloud organization.
3900
3901 See `Enabling CMEK for Log
3902 Router <https://cloud.google.com/logging/docs/routing/managed-encryption>`__
3903 for more information.
3904
3905 .. code-block:: python
3906
3907 # This snippet has been automatically generated and should be regarded as a
3908 # code template only.
3909 # It will require modifications to work:
3910 # - It may require correct/in-range values for request initialization.
3911 # - It may require specifying regional endpoints when creating the service
3912 # client as shown in:
3913 # https://googleapis.dev/python/google-api-core/latest/client_options.html
3914 from google.cloud import logging_v2
3915
3916 def sample_get_cmek_settings():
3917 # Create a client
3918 client = logging_v2.ConfigServiceV2Client()
3919
3920 # Initialize request argument(s)
3921 request = logging_v2.GetCmekSettingsRequest(
3922 name="name_value",
3923 )
3924
3925 # Make the request
3926 response = client.get_cmek_settings(request=request)
3927
3928 # Handle the response
3929 print(response)
3930
3931 Args:
3932 request (Union[google.cloud.logging_v2.types.GetCmekSettingsRequest, dict]):
3933 The request object. The parameters to
3934 [GetCmekSettings][google.logging.v2.ConfigServiceV2.GetCmekSettings].
3935
3936 See `Enabling CMEK for Log
3937 Router <https://cloud.google.com/logging/docs/routing/managed-encryption>`__
3938 for more information.
3939 retry (google.api_core.retry.Retry): Designation of what errors, if any,
3940 should be retried.
3941 timeout (float): The timeout for this request.
3942 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
3943 sent along with the request as metadata. Normally, each value must be of type `str`,
3944 but for metadata keys ending with the suffix `-bin`, the corresponding values must
3945 be of type `bytes`.
3946
3947 Returns:
3948 google.cloud.logging_v2.types.CmekSettings:
3949 Describes the customer-managed encryption key (CMEK) settings associated with
3950 a project, folder, organization, billing account, or
3951 flexible resource.
3952
3953 Note: CMEK for the Log Router can currently only be
3954 configured for Google Cloud organizations. Once
3955 configured, it applies to all projects and folders in
3956 the Google Cloud organization.
3957
3958 See [Enabling CMEK for Log
3959 Router](\ https://cloud.google.com/logging/docs/routing/managed-encryption)
3960 for more information.
3961
3962 """
3963 # Create or coerce a protobuf request object.
3964 # - Use the request object if provided (there's no risk of modifying the input as
3965 # there are no flattened fields), or create one.
3966 if not isinstance(request, logging_config.GetCmekSettingsRequest):
3967 request = logging_config.GetCmekSettingsRequest(request)
3968
3969 # Wrap the RPC method; this adds retry and timeout information,
3970 # and friendly error handling.
3971 rpc = self._transport._wrapped_methods[self._transport.get_cmek_settings]
3972
3973 # Certain fields should be provided within the metadata header;
3974 # add these here.
3975 metadata = tuple(metadata) + (
3976 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
3977 )
3978
3979 # Validate the universe domain.
3980 self._validate_universe_domain()
3981
3982 # Send the request.
3983 response = rpc(
3984 request,
3985 retry=retry,
3986 timeout=timeout,
3987 metadata=metadata,
3988 )
3989
3990 # Done; return the response.
3991 return response
3992
3993 def update_cmek_settings(
3994 self,
3995 request: Optional[Union[logging_config.UpdateCmekSettingsRequest, dict]] = None,
3996 *,
3997 retry: OptionalRetry = gapic_v1.method.DEFAULT,
3998 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
3999 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
4000 ) -> logging_config.CmekSettings:
4001 r"""Updates the Log Router CMEK settings for the given resource.
4002
4003 Note: CMEK for the Log Router can currently only be configured
4004 for Google Cloud organizations. Once configured, it applies to
4005 all projects and folders in the Google Cloud organization.
4006
4007 [UpdateCmekSettings][google.logging.v2.ConfigServiceV2.UpdateCmekSettings]
4008 will fail if 1) ``kms_key_name`` is invalid, or 2) the
4009 associated service account does not have the required
4010 ``roles/cloudkms.cryptoKeyEncrypterDecrypter`` role assigned for
4011 the key, or 3) access to the key is disabled.
4012
4013 See `Enabling CMEK for Log
4014 Router <https://cloud.google.com/logging/docs/routing/managed-encryption>`__
4015 for more information.
4016
4017 .. code-block:: python
4018
4019 # This snippet has been automatically generated and should be regarded as a
4020 # code template only.
4021 # It will require modifications to work:
4022 # - It may require correct/in-range values for request initialization.
4023 # - It may require specifying regional endpoints when creating the service
4024 # client as shown in:
4025 # https://googleapis.dev/python/google-api-core/latest/client_options.html
4026 from google.cloud import logging_v2
4027
4028 def sample_update_cmek_settings():
4029 # Create a client
4030 client = logging_v2.ConfigServiceV2Client()
4031
4032 # Initialize request argument(s)
4033 request = logging_v2.UpdateCmekSettingsRequest(
4034 name="name_value",
4035 )
4036
4037 # Make the request
4038 response = client.update_cmek_settings(request=request)
4039
4040 # Handle the response
4041 print(response)
4042
4043 Args:
4044 request (Union[google.cloud.logging_v2.types.UpdateCmekSettingsRequest, dict]):
4045 The request object. The parameters to
4046 [UpdateCmekSettings][google.logging.v2.ConfigServiceV2.UpdateCmekSettings].
4047
4048 See `Enabling CMEK for Log
4049 Router <https://cloud.google.com/logging/docs/routing/managed-encryption>`__
4050 for more information.
4051 retry (google.api_core.retry.Retry): Designation of what errors, if any,
4052 should be retried.
4053 timeout (float): The timeout for this request.
4054 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
4055 sent along with the request as metadata. Normally, each value must be of type `str`,
4056 but for metadata keys ending with the suffix `-bin`, the corresponding values must
4057 be of type `bytes`.
4058
4059 Returns:
4060 google.cloud.logging_v2.types.CmekSettings:
4061 Describes the customer-managed encryption key (CMEK) settings associated with
4062 a project, folder, organization, billing account, or
4063 flexible resource.
4064
4065 Note: CMEK for the Log Router can currently only be
4066 configured for Google Cloud organizations. Once
4067 configured, it applies to all projects and folders in
4068 the Google Cloud organization.
4069
4070 See [Enabling CMEK for Log
4071 Router](\ https://cloud.google.com/logging/docs/routing/managed-encryption)
4072 for more information.
4073
4074 """
4075 # Create or coerce a protobuf request object.
4076 # - Use the request object if provided (there's no risk of modifying the input as
4077 # there are no flattened fields), or create one.
4078 if not isinstance(request, logging_config.UpdateCmekSettingsRequest):
4079 request = logging_config.UpdateCmekSettingsRequest(request)
4080
4081 # Wrap the RPC method; this adds retry and timeout information,
4082 # and friendly error handling.
4083 rpc = self._transport._wrapped_methods[self._transport.update_cmek_settings]
4084
4085 # Certain fields should be provided within the metadata header;
4086 # add these here.
4087 metadata = tuple(metadata) + (
4088 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
4089 )
4090
4091 # Validate the universe domain.
4092 self._validate_universe_domain()
4093
4094 # Send the request.
4095 response = rpc(
4096 request,
4097 retry=retry,
4098 timeout=timeout,
4099 metadata=metadata,
4100 )
4101
4102 # Done; return the response.
4103 return response
4104
4105 def get_settings(
4106 self,
4107 request: Optional[Union[logging_config.GetSettingsRequest, dict]] = None,
4108 *,
4109 name: Optional[str] = None,
4110 retry: OptionalRetry = gapic_v1.method.DEFAULT,
4111 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
4112 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
4113 ) -> logging_config.Settings:
4114 r"""Gets the Log Router settings for the given resource.
4115
4116 Note: Settings for the Log Router can be get for Google Cloud
4117 projects, folders, organizations and billing accounts. Currently
4118 it can only be configured for organizations. Once configured for
4119 an organization, it applies to all projects and folders in the
4120 Google Cloud organization.
4121
4122 See `Enabling CMEK for Log
4123 Router <https://cloud.google.com/logging/docs/routing/managed-encryption>`__
4124 for more information.
4125
4126 .. code-block:: python
4127
4128 # This snippet has been automatically generated and should be regarded as a
4129 # code template only.
4130 # It will require modifications to work:
4131 # - It may require correct/in-range values for request initialization.
4132 # - It may require specifying regional endpoints when creating the service
4133 # client as shown in:
4134 # https://googleapis.dev/python/google-api-core/latest/client_options.html
4135 from google.cloud import logging_v2
4136
4137 def sample_get_settings():
4138 # Create a client
4139 client = logging_v2.ConfigServiceV2Client()
4140
4141 # Initialize request argument(s)
4142 request = logging_v2.GetSettingsRequest(
4143 name="name_value",
4144 )
4145
4146 # Make the request
4147 response = client.get_settings(request=request)
4148
4149 # Handle the response
4150 print(response)
4151
4152 Args:
4153 request (Union[google.cloud.logging_v2.types.GetSettingsRequest, dict]):
4154 The request object. The parameters to
4155 [GetSettings][google.logging.v2.ConfigServiceV2.GetSettings].
4156
4157 See `Enabling CMEK for Log
4158 Router <https://cloud.google.com/logging/docs/routing/managed-encryption>`__
4159 for more information.
4160 name (str):
4161 Required. The resource for which to retrieve settings.
4162
4163 ::
4164
4165 "projects/[PROJECT_ID]/settings"
4166 "organizations/[ORGANIZATION_ID]/settings"
4167 "billingAccounts/[BILLING_ACCOUNT_ID]/settings"
4168 "folders/[FOLDER_ID]/settings"
4169
4170 For example:
4171
4172 ``"organizations/12345/settings"``
4173
4174 Note: Settings for the Log Router can be get for Google
4175 Cloud projects, folders, organizations and billing
4176 accounts. Currently it can only be configured for
4177 organizations. Once configured for an organization, it
4178 applies to all projects and folders in the Google Cloud
4179 organization.
4180
4181 This corresponds to the ``name`` field
4182 on the ``request`` instance; if ``request`` is provided, this
4183 should not be set.
4184 retry (google.api_core.retry.Retry): Designation of what errors, if any,
4185 should be retried.
4186 timeout (float): The timeout for this request.
4187 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
4188 sent along with the request as metadata. Normally, each value must be of type `str`,
4189 but for metadata keys ending with the suffix `-bin`, the corresponding values must
4190 be of type `bytes`.
4191
4192 Returns:
4193 google.cloud.logging_v2.types.Settings:
4194 Describes the settings associated
4195 with a project, folder, organization,
4196 billing account, or flexible resource.
4197
4198 """
4199 # Create or coerce a protobuf request object.
4200 # - Quick check: If we got a request object, we should *not* have
4201 # gotten any keyword arguments that map to the request.
4202 flattened_params = [name]
4203 has_flattened_params = (
4204 len([param for param in flattened_params if param is not None]) > 0
4205 )
4206 if request is not None and has_flattened_params:
4207 raise ValueError(
4208 "If the `request` argument is set, then none of "
4209 "the individual field arguments should be set."
4210 )
4211
4212 # - Use the request object if provided (there's no risk of modifying the input as
4213 # there are no flattened fields), or create one.
4214 if not isinstance(request, logging_config.GetSettingsRequest):
4215 request = logging_config.GetSettingsRequest(request)
4216 # If we have keyword arguments corresponding to fields on the
4217 # request, apply these.
4218 if name is not None:
4219 request.name = name
4220
4221 # Wrap the RPC method; this adds retry and timeout information,
4222 # and friendly error handling.
4223 rpc = self._transport._wrapped_methods[self._transport.get_settings]
4224
4225 # Certain fields should be provided within the metadata header;
4226 # add these here.
4227 metadata = tuple(metadata) + (
4228 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
4229 )
4230
4231 # Validate the universe domain.
4232 self._validate_universe_domain()
4233
4234 # Send the request.
4235 response = rpc(
4236 request,
4237 retry=retry,
4238 timeout=timeout,
4239 metadata=metadata,
4240 )
4241
4242 # Done; return the response.
4243 return response
4244
4245 def update_settings(
4246 self,
4247 request: Optional[Union[logging_config.UpdateSettingsRequest, dict]] = None,
4248 *,
4249 settings: Optional[logging_config.Settings] = None,
4250 update_mask: Optional[field_mask_pb2.FieldMask] = None,
4251 retry: OptionalRetry = gapic_v1.method.DEFAULT,
4252 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
4253 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
4254 ) -> logging_config.Settings:
4255 r"""Updates the Log Router settings for the given resource.
4256
4257 Note: Settings for the Log Router can currently only be
4258 configured for Google Cloud organizations. Once configured, it
4259 applies to all projects and folders in the Google Cloud
4260 organization.
4261
4262 [UpdateSettings][google.logging.v2.ConfigServiceV2.UpdateSettings]
4263 will fail if 1) ``kms_key_name`` is invalid, or 2) the
4264 associated service account does not have the required
4265 ``roles/cloudkms.cryptoKeyEncrypterDecrypter`` role assigned for
4266 the key, or 3) access to the key is disabled. 4) ``location_id``
4267 is not supported by Logging. 5) ``location_id`` violate
4268 OrgPolicy.
4269
4270 See `Enabling CMEK for Log
4271 Router <https://cloud.google.com/logging/docs/routing/managed-encryption>`__
4272 for more information.
4273
4274 .. code-block:: python
4275
4276 # This snippet has been automatically generated and should be regarded as a
4277 # code template only.
4278 # It will require modifications to work:
4279 # - It may require correct/in-range values for request initialization.
4280 # - It may require specifying regional endpoints when creating the service
4281 # client as shown in:
4282 # https://googleapis.dev/python/google-api-core/latest/client_options.html
4283 from google.cloud import logging_v2
4284
4285 def sample_update_settings():
4286 # Create a client
4287 client = logging_v2.ConfigServiceV2Client()
4288
4289 # Initialize request argument(s)
4290 request = logging_v2.UpdateSettingsRequest(
4291 name="name_value",
4292 )
4293
4294 # Make the request
4295 response = client.update_settings(request=request)
4296
4297 # Handle the response
4298 print(response)
4299
4300 Args:
4301 request (Union[google.cloud.logging_v2.types.UpdateSettingsRequest, dict]):
4302 The request object. The parameters to
4303 [UpdateSettings][google.logging.v2.ConfigServiceV2.UpdateSettings].
4304
4305 See `Enabling CMEK for Log
4306 Router <https://cloud.google.com/logging/docs/routing/managed-encryption>`__
4307 for more information.
4308 settings (google.cloud.logging_v2.types.Settings):
4309 Required. The settings to update.
4310
4311 See `Enabling CMEK for Log
4312 Router <https://cloud.google.com/logging/docs/routing/managed-encryption>`__
4313 for more information.
4314
4315 This corresponds to the ``settings`` field
4316 on the ``request`` instance; if ``request`` is provided, this
4317 should not be set.
4318 update_mask (google.protobuf.field_mask_pb2.FieldMask):
4319 Optional. Field mask identifying which fields from
4320 ``settings`` should be updated. A field will be
4321 overwritten if and only if it is in the update mask.
4322 Output only fields cannot be updated.
4323
4324 See [FieldMask][google.protobuf.FieldMask] for more
4325 information.
4326
4327 For example: ``"updateMask=kmsKeyName"``
4328
4329 This corresponds to the ``update_mask`` field
4330 on the ``request`` instance; if ``request`` is provided, this
4331 should not be set.
4332 retry (google.api_core.retry.Retry): Designation of what errors, if any,
4333 should be retried.
4334 timeout (float): The timeout for this request.
4335 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
4336 sent along with the request as metadata. Normally, each value must be of type `str`,
4337 but for metadata keys ending with the suffix `-bin`, the corresponding values must
4338 be of type `bytes`.
4339
4340 Returns:
4341 google.cloud.logging_v2.types.Settings:
4342 Describes the settings associated
4343 with a project, folder, organization,
4344 billing account, or flexible resource.
4345
4346 """
4347 # Create or coerce a protobuf request object.
4348 # - Quick check: If we got a request object, we should *not* have
4349 # gotten any keyword arguments that map to the request.
4350 flattened_params = [settings, update_mask]
4351 has_flattened_params = (
4352 len([param for param in flattened_params if param is not None]) > 0
4353 )
4354 if request is not None and has_flattened_params:
4355 raise ValueError(
4356 "If the `request` argument is set, then none of "
4357 "the individual field arguments should be set."
4358 )
4359
4360 # - Use the request object if provided (there's no risk of modifying the input as
4361 # there are no flattened fields), or create one.
4362 if not isinstance(request, logging_config.UpdateSettingsRequest):
4363 request = logging_config.UpdateSettingsRequest(request)
4364 # If we have keyword arguments corresponding to fields on the
4365 # request, apply these.
4366 if settings is not None:
4367 request.settings = settings
4368 if update_mask is not None:
4369 request.update_mask = update_mask
4370
4371 # Wrap the RPC method; this adds retry and timeout information,
4372 # and friendly error handling.
4373 rpc = self._transport._wrapped_methods[self._transport.update_settings]
4374
4375 # Certain fields should be provided within the metadata header;
4376 # add these here.
4377 metadata = tuple(metadata) + (
4378 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
4379 )
4380
4381 # Validate the universe domain.
4382 self._validate_universe_domain()
4383
4384 # Send the request.
4385 response = rpc(
4386 request,
4387 retry=retry,
4388 timeout=timeout,
4389 metadata=metadata,
4390 )
4391
4392 # Done; return the response.
4393 return response
4394
4395 def copy_log_entries(
4396 self,
4397 request: Optional[Union[logging_config.CopyLogEntriesRequest, dict]] = None,
4398 *,
4399 retry: OptionalRetry = gapic_v1.method.DEFAULT,
4400 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
4401 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
4402 ) -> operation.Operation:
4403 r"""Copies a set of log entries from a log bucket to a
4404 Cloud Storage bucket.
4405
4406 .. code-block:: python
4407
4408 # This snippet has been automatically generated and should be regarded as a
4409 # code template only.
4410 # It will require modifications to work:
4411 # - It may require correct/in-range values for request initialization.
4412 # - It may require specifying regional endpoints when creating the service
4413 # client as shown in:
4414 # https://googleapis.dev/python/google-api-core/latest/client_options.html
4415 from google.cloud import logging_v2
4416
4417 def sample_copy_log_entries():
4418 # Create a client
4419 client = logging_v2.ConfigServiceV2Client()
4420
4421 # Initialize request argument(s)
4422 request = logging_v2.CopyLogEntriesRequest(
4423 name="name_value",
4424 destination="destination_value",
4425 )
4426
4427 # Make the request
4428 operation = client.copy_log_entries(request=request)
4429
4430 print("Waiting for operation to complete...")
4431
4432 response = operation.result()
4433
4434 # Handle the response
4435 print(response)
4436
4437 Args:
4438 request (Union[google.cloud.logging_v2.types.CopyLogEntriesRequest, dict]):
4439 The request object. The parameters to CopyLogEntries.
4440 retry (google.api_core.retry.Retry): Designation of what errors, if any,
4441 should be retried.
4442 timeout (float): The timeout for this request.
4443 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
4444 sent along with the request as metadata. Normally, each value must be of type `str`,
4445 but for metadata keys ending with the suffix `-bin`, the corresponding values must
4446 be of type `bytes`.
4447
4448 Returns:
4449 google.api_core.operation.Operation:
4450 An object representing a long-running operation.
4451
4452 The result type for the operation will be
4453 :class:`google.cloud.logging_v2.types.CopyLogEntriesResponse`
4454 Response type for CopyLogEntries long running
4455 operations.
4456
4457 """
4458 # Create or coerce a protobuf request object.
4459 # - Use the request object if provided (there's no risk of modifying the input as
4460 # there are no flattened fields), or create one.
4461 if not isinstance(request, logging_config.CopyLogEntriesRequest):
4462 request = logging_config.CopyLogEntriesRequest(request)
4463
4464 # Wrap the RPC method; this adds retry and timeout information,
4465 # and friendly error handling.
4466 rpc = self._transport._wrapped_methods[self._transport.copy_log_entries]
4467
4468 # Validate the universe domain.
4469 self._validate_universe_domain()
4470
4471 # Send the request.
4472 response = rpc(
4473 request,
4474 retry=retry,
4475 timeout=timeout,
4476 metadata=metadata,
4477 )
4478
4479 # Wrap the response in an operation future.
4480 response = operation.from_gapic(
4481 response,
4482 self._transport.operations_client,
4483 logging_config.CopyLogEntriesResponse,
4484 metadata_type=logging_config.CopyLogEntriesMetadata,
4485 )
4486
4487 # Done; return the response.
4488 return response
4489
4490 def __enter__(self) -> "ConfigServiceV2Client":
4491 return self
4492
4493 def __exit__(self, type, value, traceback):
4494 """Releases underlying transport's resources.
4495
4496 .. warning::
4497 ONLY use as a context manager if the transport is NOT shared
4498 with other clients! Exiting the with block will CLOSE the transport
4499 and may cause errors in other clients!
4500 """
4501 self.transport.close()
4502
4503 def list_operations(
4504 self,
4505 request: Optional[operations_pb2.ListOperationsRequest] = None,
4506 *,
4507 retry: OptionalRetry = gapic_v1.method.DEFAULT,
4508 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
4509 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
4510 ) -> operations_pb2.ListOperationsResponse:
4511 r"""Lists operations that match the specified filter in the request.
4512
4513 Args:
4514 request (:class:`~.operations_pb2.ListOperationsRequest`):
4515 The request object. Request message for
4516 `ListOperations` method.
4517 retry (google.api_core.retry.Retry): Designation of what errors,
4518 if any, should be retried.
4519 timeout (float): The timeout for this request.
4520 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
4521 sent along with the request as metadata. Normally, each value must be of type `str`,
4522 but for metadata keys ending with the suffix `-bin`, the corresponding values must
4523 be of type `bytes`.
4524 Returns:
4525 ~.operations_pb2.ListOperationsResponse:
4526 Response message for ``ListOperations`` method.
4527 """
4528 # Create or coerce a protobuf request object.
4529 # The request isn't a proto-plus wrapped type,
4530 # so it must be constructed via keyword expansion.
4531 if isinstance(request, dict):
4532 request = operations_pb2.ListOperationsRequest(**request)
4533
4534 # Wrap the RPC method; this adds retry and timeout information,
4535 # and friendly error handling.
4536 rpc = self._transport._wrapped_methods[self._transport.list_operations]
4537
4538 # Certain fields should be provided within the metadata header;
4539 # add these here.
4540 metadata = tuple(metadata) + (
4541 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
4542 )
4543
4544 # Validate the universe domain.
4545 self._validate_universe_domain()
4546
4547 try:
4548 # Send the request.
4549 response = rpc(
4550 request,
4551 retry=retry,
4552 timeout=timeout,
4553 metadata=metadata,
4554 )
4555
4556 # Done; return the response.
4557 return response
4558 except core_exceptions.GoogleAPICallError as e:
4559 self._add_cred_info_for_auth_errors(e)
4560 raise e
4561
4562 def get_operation(
4563 self,
4564 request: Optional[operations_pb2.GetOperationRequest] = None,
4565 *,
4566 retry: OptionalRetry = gapic_v1.method.DEFAULT,
4567 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
4568 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
4569 ) -> operations_pb2.Operation:
4570 r"""Gets the latest state of a long-running operation.
4571
4572 Args:
4573 request (:class:`~.operations_pb2.GetOperationRequest`):
4574 The request object. Request message for
4575 `GetOperation` method.
4576 retry (google.api_core.retry.Retry): Designation of what errors,
4577 if any, should be retried.
4578 timeout (float): The timeout for this request.
4579 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
4580 sent along with the request as metadata. Normally, each value must be of type `str`,
4581 but for metadata keys ending with the suffix `-bin`, the corresponding values must
4582 be of type `bytes`.
4583 Returns:
4584 ~.operations_pb2.Operation:
4585 An ``Operation`` object.
4586 """
4587 # Create or coerce a protobuf request object.
4588 # The request isn't a proto-plus wrapped type,
4589 # so it must be constructed via keyword expansion.
4590 if isinstance(request, dict):
4591 request = operations_pb2.GetOperationRequest(**request)
4592
4593 # Wrap the RPC method; this adds retry and timeout information,
4594 # and friendly error handling.
4595 rpc = self._transport._wrapped_methods[self._transport.get_operation]
4596
4597 # Certain fields should be provided within the metadata header;
4598 # add these here.
4599 metadata = tuple(metadata) + (
4600 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
4601 )
4602
4603 # Validate the universe domain.
4604 self._validate_universe_domain()
4605
4606 try:
4607 # Send the request.
4608 response = rpc(
4609 request,
4610 retry=retry,
4611 timeout=timeout,
4612 metadata=metadata,
4613 )
4614
4615 # Done; return the response.
4616 return response
4617 except core_exceptions.GoogleAPICallError as e:
4618 self._add_cred_info_for_auth_errors(e)
4619 raise e
4620
4621 def cancel_operation(
4622 self,
4623 request: Optional[operations_pb2.CancelOperationRequest] = None,
4624 *,
4625 retry: OptionalRetry = gapic_v1.method.DEFAULT,
4626 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
4627 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
4628 ) -> None:
4629 r"""Starts asynchronous cancellation on a long-running operation.
4630
4631 The server makes a best effort to cancel the operation, but success
4632 is not guaranteed. If the server doesn't support this method, it returns
4633 `google.rpc.Code.UNIMPLEMENTED`.
4634
4635 Args:
4636 request (:class:`~.operations_pb2.CancelOperationRequest`):
4637 The request object. Request message for
4638 `CancelOperation` method.
4639 retry (google.api_core.retry.Retry): Designation of what errors,
4640 if any, should be retried.
4641 timeout (float): The timeout for this request.
4642 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
4643 sent along with the request as metadata. Normally, each value must be of type `str`,
4644 but for metadata keys ending with the suffix `-bin`, the corresponding values must
4645 be of type `bytes`.
4646 Returns:
4647 None
4648 """
4649 # Create or coerce a protobuf request object.
4650 # The request isn't a proto-plus wrapped type,
4651 # so it must be constructed via keyword expansion.
4652 if isinstance(request, dict):
4653 request = operations_pb2.CancelOperationRequest(**request)
4654
4655 # Wrap the RPC method; this adds retry and timeout information,
4656 # and friendly error handling.
4657 rpc = self._transport._wrapped_methods[self._transport.cancel_operation]
4658
4659 # Certain fields should be provided within the metadata header;
4660 # add these here.
4661 metadata = tuple(metadata) + (
4662 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
4663 )
4664
4665 # Validate the universe domain.
4666 self._validate_universe_domain()
4667
4668 # Send the request.
4669 rpc(
4670 request,
4671 retry=retry,
4672 timeout=timeout,
4673 metadata=metadata,
4674 )
4675
4676
4677DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
4678 gapic_version=package_version.__version__
4679)
4680
4681
4682__all__ = ("ConfigServiceV2Client",)