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