1# -*- coding: utf-8 -*- 2# Copyright 2020 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 distutils import util 18import os 19import re 20from typing import Dict, Optional, Sequence, Tuple, Type, Union 21import pkg_resources 22 23from google.api_core import client_options as client_options_lib # type: ignore 24from google.api_core import exceptions as core_exceptions # type: ignore 25from google.api_core import gapic_v1 # type: ignore 26from google.api_core import retry as retries # type: ignore 27from google.auth import credentials as ga_credentials # type: ignore 28from google.auth.transport import mtls # type: ignore 29from google.auth.transport.grpc import SslCredentials # type: ignore 30from google.auth.exceptions import MutualTLSChannelError # type: ignore 31from google.oauth2 import service_account # type: ignore 32 33OptionalRetry = Union[retries.Retry, object] 34 35from google.cloud.logging_v2.services.config_service_v2 import pagers 36from google.cloud.logging_v2.types import logging_config 37from google.protobuf import field_mask_pb2 # type: ignore 38from google.protobuf import timestamp_pb2 # type: ignore 39from .transports.base import ConfigServiceV2Transport, DEFAULT_CLIENT_INFO 40from .transports.grpc import ConfigServiceV2GrpcTransport 41from .transports.grpc_asyncio import ConfigServiceV2GrpcAsyncIOTransport 42 43 44class ConfigServiceV2ClientMeta(type): 45 """Metaclass for the ConfigServiceV2 client. 46 47 This provides class-level methods for building and retrieving 48 support objects (e.g. transport) without polluting the client instance 49 objects. 50 """ 51 52 _transport_registry = ( 53 OrderedDict() 54 ) # type: Dict[str, Type[ConfigServiceV2Transport]] 55 _transport_registry["grpc"] = ConfigServiceV2GrpcTransport 56 _transport_registry["grpc_asyncio"] = ConfigServiceV2GrpcAsyncIOTransport 57 58 def get_transport_class(cls, label: str = None,) -> Type[ConfigServiceV2Transport]: 59 """Returns an appropriate transport class. 60 61 Args: 62 label: The name of the desired transport. If none is 63 provided, then the first transport in the registry is used. 64 65 Returns: 66 The transport class to use. 67 """ 68 # If a specific transport is requested, return that one. 69 if label: 70 return cls._transport_registry[label] 71 72 # No transport is requested; return the default (that is, the first one 73 # in the dictionary). 74 return next(iter(cls._transport_registry.values())) 75 76 77class ConfigServiceV2Client(metaclass=ConfigServiceV2ClientMeta): 78 """Service for configuring sinks used to route log entries.""" 79 80 @staticmethod 81 def _get_default_mtls_endpoint(api_endpoint): 82 """Converts api endpoint to mTLS endpoint. 83 84 Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to 85 "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. 86 Args: 87 api_endpoint (Optional[str]): the api endpoint to convert. 88 Returns: 89 str: converted mTLS api endpoint. 90 """ 91 if not api_endpoint: 92 return api_endpoint 93 94 mtls_endpoint_re = re.compile( 95 r"(?P<name>[^.]+)(?P<mtls>\.mtls)?(?P<sandbox>\.sandbox)?(?P<googledomain>\.googleapis\.com)?" 96 ) 97 98 m = mtls_endpoint_re.match(api_endpoint) 99 name, mtls, sandbox, googledomain = m.groups() 100 if mtls or not googledomain: 101 return api_endpoint 102 103 if sandbox: 104 return api_endpoint.replace( 105 "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" 106 ) 107 108 return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") 109 110 DEFAULT_ENDPOINT = "logging.googleapis.com" 111 DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore 112 DEFAULT_ENDPOINT 113 ) 114 115 @classmethod 116 def from_service_account_info(cls, info: dict, *args, **kwargs): 117 """Creates an instance of this client using the provided credentials 118 info. 119 120 Args: 121 info (dict): The service account private key info. 122 args: Additional arguments to pass to the constructor. 123 kwargs: Additional arguments to pass to the constructor. 124 125 Returns: 126 ConfigServiceV2Client: The constructed client. 127 """ 128 credentials = service_account.Credentials.from_service_account_info(info) 129 kwargs["credentials"] = credentials 130 return cls(*args, **kwargs) 131 132 @classmethod 133 def from_service_account_file(cls, filename: str, *args, **kwargs): 134 """Creates an instance of this client using the provided credentials 135 file. 136 137 Args: 138 filename (str): The path to the service account private key json 139 file. 140 args: Additional arguments to pass to the constructor. 141 kwargs: Additional arguments to pass to the constructor. 142 143 Returns: 144 ConfigServiceV2Client: The constructed client. 145 """ 146 credentials = service_account.Credentials.from_service_account_file(filename) 147 kwargs["credentials"] = credentials 148 return cls(*args, **kwargs) 149 150 from_service_account_json = from_service_account_file 151 152 @property 153 def transport(self) -> ConfigServiceV2Transport: 154 """Returns the transport used by the client instance. 155 156 Returns: 157 ConfigServiceV2Transport: The transport used by the client 158 instance. 159 """ 160 return self._transport 161 162 @staticmethod 163 def cmek_settings_path(project: str,) -> str: 164 """Returns a fully-qualified cmek_settings string.""" 165 return "projects/{project}/cmekSettings".format(project=project,) 166 167 @staticmethod 168 def parse_cmek_settings_path(path: str) -> Dict[str, str]: 169 """Parses a cmek_settings path into its component segments.""" 170 m = re.match(r"^projects/(?P<project>.+?)/cmekSettings$", path) 171 return m.groupdict() if m else {} 172 173 @staticmethod 174 def log_bucket_path(project: str, location: str, bucket: str,) -> str: 175 """Returns a fully-qualified log_bucket string.""" 176 return "projects/{project}/locations/{location}/buckets/{bucket}".format( 177 project=project, location=location, bucket=bucket, 178 ) 179 180 @staticmethod 181 def parse_log_bucket_path(path: str) -> Dict[str, str]: 182 """Parses a log_bucket path into its component segments.""" 183 m = re.match( 184 r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)/buckets/(?P<bucket>.+?)$", 185 path, 186 ) 187 return m.groupdict() if m else {} 188 189 @staticmethod 190 def log_exclusion_path(project: str, exclusion: str,) -> str: 191 """Returns a fully-qualified log_exclusion string.""" 192 return "projects/{project}/exclusions/{exclusion}".format( 193 project=project, exclusion=exclusion, 194 ) 195 196 @staticmethod 197 def parse_log_exclusion_path(path: str) -> Dict[str, str]: 198 """Parses a log_exclusion path into its component segments.""" 199 m = re.match(r"^projects/(?P<project>.+?)/exclusions/(?P<exclusion>.+?)$", path) 200 return m.groupdict() if m else {} 201 202 @staticmethod 203 def log_sink_path(project: str, sink: str,) -> str: 204 """Returns a fully-qualified log_sink string.""" 205 return "projects/{project}/sinks/{sink}".format(project=project, sink=sink,) 206 207 @staticmethod 208 def parse_log_sink_path(path: str) -> Dict[str, str]: 209 """Parses a log_sink path into its component segments.""" 210 m = re.match(r"^projects/(?P<project>.+?)/sinks/(?P<sink>.+?)$", path) 211 return m.groupdict() if m else {} 212 213 @staticmethod 214 def log_view_path(project: str, location: str, bucket: str, view: str,) -> str: 215 """Returns a fully-qualified log_view string.""" 216 return "projects/{project}/locations/{location}/buckets/{bucket}/views/{view}".format( 217 project=project, location=location, bucket=bucket, view=view, 218 ) 219 220 @staticmethod 221 def parse_log_view_path(path: str) -> Dict[str, str]: 222 """Parses a log_view path into its component segments.""" 223 m = re.match( 224 r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)/buckets/(?P<bucket>.+?)/views/(?P<view>.+?)$", 225 path, 226 ) 227 return m.groupdict() if m else {} 228 229 @staticmethod 230 def common_billing_account_path(billing_account: str,) -> str: 231 """Returns a fully-qualified billing_account string.""" 232 return "billingAccounts/{billing_account}".format( 233 billing_account=billing_account, 234 ) 235 236 @staticmethod 237 def parse_common_billing_account_path(path: str) -> Dict[str, str]: 238 """Parse a billing_account path into its component segments.""" 239 m = re.match(r"^billingAccounts/(?P<billing_account>.+?)$", path) 240 return m.groupdict() if m else {} 241 242 @staticmethod 243 def common_folder_path(folder: str,) -> str: 244 """Returns a fully-qualified folder string.""" 245 return "folders/{folder}".format(folder=folder,) 246 247 @staticmethod 248 def parse_common_folder_path(path: str) -> Dict[str, str]: 249 """Parse a folder path into its component segments.""" 250 m = re.match(r"^folders/(?P<folder>.+?)$", path) 251 return m.groupdict() if m else {} 252 253 @staticmethod 254 def common_organization_path(organization: str,) -> str: 255 """Returns a fully-qualified organization string.""" 256 return "organizations/{organization}".format(organization=organization,) 257 258 @staticmethod 259 def parse_common_organization_path(path: str) -> Dict[str, str]: 260 """Parse a organization path into its component segments.""" 261 m = re.match(r"^organizations/(?P<organization>.+?)$", path) 262 return m.groupdict() if m else {} 263 264 @staticmethod 265 def common_project_path(project: str,) -> str: 266 """Returns a fully-qualified project string.""" 267 return "projects/{project}".format(project=project,) 268 269 @staticmethod 270 def parse_common_project_path(path: str) -> Dict[str, str]: 271 """Parse a project path into its component segments.""" 272 m = re.match(r"^projects/(?P<project>.+?)$", path) 273 return m.groupdict() if m else {} 274 275 @staticmethod 276 def common_location_path(project: str, location: str,) -> str: 277 """Returns a fully-qualified location string.""" 278 return "projects/{project}/locations/{location}".format( 279 project=project, location=location, 280 ) 281 282 @staticmethod 283 def parse_common_location_path(path: str) -> Dict[str, str]: 284 """Parse a location path into its component segments.""" 285 m = re.match(r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)$", path) 286 return m.groupdict() if m else {} 287 288 def __init__( 289 self, 290 *, 291 credentials: Optional[ga_credentials.Credentials] = None, 292 transport: Union[str, ConfigServiceV2Transport, None] = None, 293 client_options: Optional[client_options_lib.ClientOptions] = None, 294 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, 295 ) -> None: 296 """Instantiates the config service v2 client. 297 298 Args: 299 credentials (Optional[google.auth.credentials.Credentials]): The 300 authorization credentials to attach to requests. These 301 credentials identify the application to the service; if none 302 are specified, the client will attempt to ascertain the 303 credentials from the environment. 304 transport (Union[str, ConfigServiceV2Transport]): The 305 transport to use. If set to None, a transport is chosen 306 automatically. 307 client_options (google.api_core.client_options.ClientOptions): Custom options for the 308 client. It won't take effect if a ``transport`` instance is provided. 309 (1) The ``api_endpoint`` property can be used to override the 310 default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT 311 environment variable can also be used to override the endpoint: 312 "always" (always use the default mTLS endpoint), "never" (always 313 use the default regular endpoint) and "auto" (auto switch to the 314 default mTLS endpoint if client certificate is present, this is 315 the default value). However, the ``api_endpoint`` property takes 316 precedence if provided. 317 (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable 318 is "true", then the ``client_cert_source`` property can be used 319 to provide client certificate for mutual TLS transport. If 320 not provided, the default SSL client certificate will be used if 321 present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not 322 set, no client certificate will be used. 323 client_info (google.api_core.gapic_v1.client_info.ClientInfo): 324 The client info used to send a user-agent string along with 325 API requests. If ``None``, then default info will be used. 326 Generally, you only need to set this if you're developing 327 your own client library. 328 329 Raises: 330 google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport 331 creation failed for any reason. 332 """ 333 if isinstance(client_options, dict): 334 client_options = client_options_lib.from_dict(client_options) 335 if client_options is None: 336 client_options = client_options_lib.ClientOptions() 337 338 # Create SSL credentials for mutual TLS if needed. 339 use_client_cert = bool( 340 util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")) 341 ) 342 343 client_cert_source_func = None 344 is_mtls = False 345 if use_client_cert: 346 if client_options.client_cert_source: 347 is_mtls = True 348 client_cert_source_func = client_options.client_cert_source 349 else: 350 is_mtls = mtls.has_default_client_cert_source() 351 if is_mtls: 352 client_cert_source_func = mtls.default_client_cert_source() 353 else: 354 client_cert_source_func = None 355 356 # Figure out which api endpoint to use. 357 if client_options.api_endpoint is not None: 358 api_endpoint = client_options.api_endpoint 359 else: 360 use_mtls_env = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") 361 if use_mtls_env == "never": 362 api_endpoint = self.DEFAULT_ENDPOINT 363 elif use_mtls_env == "always": 364 api_endpoint = self.DEFAULT_MTLS_ENDPOINT 365 elif use_mtls_env == "auto": 366 if is_mtls: 367 api_endpoint = self.DEFAULT_MTLS_ENDPOINT 368 else: 369 api_endpoint = self.DEFAULT_ENDPOINT 370 else: 371 raise MutualTLSChannelError( 372 "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted " 373 "values: never, auto, always" 374 ) 375 376 # Save or instantiate the transport. 377 # Ordinarily, we provide the transport, but allowing a custom transport 378 # instance provides an extensibility point for unusual situations. 379 if isinstance(transport, ConfigServiceV2Transport): 380 # transport is a ConfigServiceV2Transport instance. 381 if credentials or client_options.credentials_file: 382 raise ValueError( 383 "When providing a transport instance, " 384 "provide its credentials directly." 385 ) 386 if client_options.scopes: 387 raise ValueError( 388 "When providing a transport instance, provide its scopes " 389 "directly." 390 ) 391 self._transport = transport 392 else: 393 Transport = type(self).get_transport_class(transport) 394 self._transport = Transport( 395 credentials=credentials, 396 credentials_file=client_options.credentials_file, 397 host=api_endpoint, 398 scopes=client_options.scopes, 399 client_cert_source_for_mtls=client_cert_source_func, 400 quota_project_id=client_options.quota_project_id, 401 client_info=client_info, 402 always_use_jwt_access=True, 403 ) 404 405 def list_buckets( 406 self, 407 request: Union[logging_config.ListBucketsRequest, dict] = None, 408 *, 409 parent: str = None, 410 retry: OptionalRetry = gapic_v1.method.DEFAULT, 411 timeout: float = None, 412 metadata: Sequence[Tuple[str, str]] = (), 413 ) -> pagers.ListBucketsPager: 414 r"""Lists buckets. 415 416 Args: 417 request (Union[google.cloud.logging_v2.types.ListBucketsRequest, dict]): 418 The request object. The parameters to `ListBuckets`. 419 parent (str): 420 Required. The parent resource whose buckets are to be 421 listed: 422 423 :: 424 425 "projects/[PROJECT_ID]/locations/[LOCATION_ID]" 426 "organizations/[ORGANIZATION_ID]/locations/[LOCATION_ID]" 427 "billingAccounts/[BILLING_ACCOUNT_ID]/locations/[LOCATION_ID]" 428 "folders/[FOLDER_ID]/locations/[LOCATION_ID]" 429 430 Note: The locations portion of the resource must be 431 specified, but supplying the character ``-`` in place of 432 [LOCATION_ID] will return all buckets. 433 434 This corresponds to the ``parent`` field 435 on the ``request`` instance; if ``request`` is provided, this 436 should not be set. 437 retry (google.api_core.retry.Retry): Designation of what errors, if any, 438 should be retried. 439 timeout (float): The timeout for this request. 440 metadata (Sequence[Tuple[str, str]]): Strings which should be 441 sent along with the request as metadata. 442 443 Returns: 444 google.cloud.logging_v2.services.config_service_v2.pagers.ListBucketsPager: 445 The response from ListBuckets. 446 Iterating over this object will yield 447 results and resolve additional pages 448 automatically. 449 450 """ 451 # Create or coerce a protobuf request object. 452 # Sanity check: If we got a request object, we should *not* have 453 # gotten any keyword arguments that map to the request. 454 has_flattened_params = any([parent]) 455 if request is not None and has_flattened_params: 456 raise ValueError( 457 "If the `request` argument is set, then none of " 458 "the individual field arguments should be set." 459 ) 460 461 # Minor optimization to avoid making a copy if the user passes 462 # in a logging_config.ListBucketsRequest. 463 # There's no risk of modifying the input as we've already verified 464 # there are no flattened fields. 465 if not isinstance(request, logging_config.ListBucketsRequest): 466 request = logging_config.ListBucketsRequest(request) 467 # If we have keyword arguments corresponding to fields on the 468 # request, apply these. 469 if parent is not None: 470 request.parent = parent 471 472 # Wrap the RPC method; this adds retry and timeout information, 473 # and friendly error handling. 474 rpc = self._transport._wrapped_methods[self._transport.list_buckets] 475 476 # Certain fields should be provided within the metadata header; 477 # add these here. 478 metadata = tuple(metadata) + ( 479 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), 480 ) 481 482 # Send the request. 483 response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) 484 485 # This method is paged; wrap the response in a pager, which provides 486 # an `__iter__` convenience method. 487 response = pagers.ListBucketsPager( 488 method=rpc, request=request, response=response, metadata=metadata, 489 ) 490 491 # Done; return the response. 492 return response 493 494 def get_bucket( 495 self, 496 request: Union[logging_config.GetBucketRequest, dict] = None, 497 *, 498 retry: OptionalRetry = gapic_v1.method.DEFAULT, 499 timeout: float = None, 500 metadata: Sequence[Tuple[str, str]] = (), 501 ) -> logging_config.LogBucket: 502 r"""Gets a bucket. 503 504 Args: 505 request (Union[google.cloud.logging_v2.types.GetBucketRequest, dict]): 506 The request object. The parameters to `GetBucket`. 507 retry (google.api_core.retry.Retry): Designation of what errors, if any, 508 should be retried. 509 timeout (float): The timeout for this request. 510 metadata (Sequence[Tuple[str, str]]): Strings which should be 511 sent along with the request as metadata. 512 513 Returns: 514 google.cloud.logging_v2.types.LogBucket: 515 Describes a repository of logs. 516 """ 517 # Create or coerce a protobuf request object. 518 # Minor optimization to avoid making a copy if the user passes 519 # in a logging_config.GetBucketRequest. 520 # There's no risk of modifying the input as we've already verified 521 # there are no flattened fields. 522 if not isinstance(request, logging_config.GetBucketRequest): 523 request = logging_config.GetBucketRequest(request) 524 525 # Wrap the RPC method; this adds retry and timeout information, 526 # and friendly error handling. 527 rpc = self._transport._wrapped_methods[self._transport.get_bucket] 528 529 # Certain fields should be provided within the metadata header; 530 # add these here. 531 metadata = tuple(metadata) + ( 532 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), 533 ) 534 535 # Send the request. 536 response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) 537 538 # Done; return the response. 539 return response 540 541 def create_bucket( 542 self, 543 request: Union[logging_config.CreateBucketRequest, dict] = None, 544 *, 545 retry: OptionalRetry = gapic_v1.method.DEFAULT, 546 timeout: float = None, 547 metadata: Sequence[Tuple[str, str]] = (), 548 ) -> logging_config.LogBucket: 549 r"""Creates a bucket that can be used to store log 550 entries. Once a bucket has been created, the region 551 cannot be changed. 552 553 Args: 554 request (Union[google.cloud.logging_v2.types.CreateBucketRequest, dict]): 555 The request object. The parameters to `CreateBucket`. 556 retry (google.api_core.retry.Retry): Designation of what errors, if any, 557 should be retried. 558 timeout (float): The timeout for this request. 559 metadata (Sequence[Tuple[str, str]]): Strings which should be 560 sent along with the request as metadata. 561 562 Returns: 563 google.cloud.logging_v2.types.LogBucket: 564 Describes a repository of logs. 565 """ 566 # Create or coerce a protobuf request object. 567 # Minor optimization to avoid making a copy if the user passes 568 # in a logging_config.CreateBucketRequest. 569 # There's no risk of modifying the input as we've already verified 570 # there are no flattened fields. 571 if not isinstance(request, logging_config.CreateBucketRequest): 572 request = logging_config.CreateBucketRequest(request) 573 574 # Wrap the RPC method; this adds retry and timeout information, 575 # and friendly error handling. 576 rpc = self._transport._wrapped_methods[self._transport.create_bucket] 577 578 # Certain fields should be provided within the metadata header; 579 # add these here. 580 metadata = tuple(metadata) + ( 581 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), 582 ) 583 584 # Send the request. 585 response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) 586 587 # Done; return the response. 588 return response 589 590 def update_bucket( 591 self, 592 request: Union[logging_config.UpdateBucketRequest, dict] = None, 593 *, 594 retry: OptionalRetry = gapic_v1.method.DEFAULT, 595 timeout: float = None, 596 metadata: Sequence[Tuple[str, str]] = (), 597 ) -> logging_config.LogBucket: 598 r"""Updates a bucket. This method replaces the following fields in 599 the existing bucket with values from the new bucket: 600 ``retention_period`` 601 602 If the retention period is decreased and the bucket is locked, 603 FAILED_PRECONDITION will be returned. 604 605 If the bucket has a LifecycleState of DELETE_REQUESTED, 606 FAILED_PRECONDITION will be returned. 607 608 A buckets region may not be modified after it is created. 609 610 Args: 611 request (Union[google.cloud.logging_v2.types.UpdateBucketRequest, dict]): 612 The request object. The parameters to `UpdateBucket`. 613 retry (google.api_core.retry.Retry): Designation of what errors, if any, 614 should be retried. 615 timeout (float): The timeout for this request. 616 metadata (Sequence[Tuple[str, str]]): Strings which should be 617 sent along with the request as metadata. 618 619 Returns: 620 google.cloud.logging_v2.types.LogBucket: 621 Describes a repository of logs. 622 """ 623 # Create or coerce a protobuf request object. 624 # Minor optimization to avoid making a copy if the user passes 625 # in a logging_config.UpdateBucketRequest. 626 # There's no risk of modifying the input as we've already verified 627 # there are no flattened fields. 628 if not isinstance(request, logging_config.UpdateBucketRequest): 629 request = logging_config.UpdateBucketRequest(request) 630 631 # Wrap the RPC method; this adds retry and timeout information, 632 # and friendly error handling. 633 rpc = self._transport._wrapped_methods[self._transport.update_bucket] 634 635 # Certain fields should be provided within the metadata header; 636 # add these here. 637 metadata = tuple(metadata) + ( 638 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), 639 ) 640 641 # Send the request. 642 response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) 643 644 # Done; return the response. 645 return response 646 647 def delete_bucket( 648 self, 649 request: Union[logging_config.DeleteBucketRequest, dict] = None, 650 *, 651 retry: OptionalRetry = gapic_v1.method.DEFAULT, 652 timeout: float = None, 653 metadata: Sequence[Tuple[str, str]] = (), 654 ) -> None: 655 r"""Deletes a bucket. Moves the bucket to the DELETE_REQUESTED 656 state. After 7 days, the bucket will be purged and all logs in 657 the bucket will be permanently deleted. 658 659 Args: 660 request (Union[google.cloud.logging_v2.types.DeleteBucketRequest, dict]): 661 The request object. The parameters to `DeleteBucket`. 662 retry (google.api_core.retry.Retry): Designation of what errors, if any, 663 should be retried. 664 timeout (float): The timeout for this request. 665 metadata (Sequence[Tuple[str, str]]): Strings which should be 666 sent along with the request as metadata. 667 """ 668 # Create or coerce a protobuf request object. 669 # Minor optimization to avoid making a copy if the user passes 670 # in a logging_config.DeleteBucketRequest. 671 # There's no risk of modifying the input as we've already verified 672 # there are no flattened fields. 673 if not isinstance(request, logging_config.DeleteBucketRequest): 674 request = logging_config.DeleteBucketRequest(request) 675 676 # Wrap the RPC method; this adds retry and timeout information, 677 # and friendly error handling. 678 rpc = self._transport._wrapped_methods[self._transport.delete_bucket] 679 680 # Certain fields should be provided within the metadata header; 681 # add these here. 682 metadata = tuple(metadata) + ( 683 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), 684 ) 685 686 # Send the request. 687 rpc( 688 request, retry=retry, timeout=timeout, metadata=metadata, 689 ) 690 691 def undelete_bucket( 692 self, 693 request: Union[logging_config.UndeleteBucketRequest, dict] = None, 694 *, 695 retry: OptionalRetry = gapic_v1.method.DEFAULT, 696 timeout: float = None, 697 metadata: Sequence[Tuple[str, str]] = (), 698 ) -> None: 699 r"""Undeletes a bucket. A bucket that has been deleted 700 may be undeleted within the grace period of 7 days. 701 702 Args: 703 request (Union[google.cloud.logging_v2.types.UndeleteBucketRequest, dict]): 704 The request object. The parameters to `UndeleteBucket`. 705 retry (google.api_core.retry.Retry): Designation of what errors, if any, 706 should be retried. 707 timeout (float): The timeout for this request. 708 metadata (Sequence[Tuple[str, str]]): Strings which should be 709 sent along with the request as metadata. 710 """ 711 # Create or coerce a protobuf request object. 712 # Minor optimization to avoid making a copy if the user passes 713 # in a logging_config.UndeleteBucketRequest. 714 # There's no risk of modifying the input as we've already verified 715 # there are no flattened fields. 716 if not isinstance(request, logging_config.UndeleteBucketRequest): 717 request = logging_config.UndeleteBucketRequest(request) 718 719 # Wrap the RPC method; this adds retry and timeout information, 720 # and friendly error handling. 721 rpc = self._transport._wrapped_methods[self._transport.undelete_bucket] 722 723 # Certain fields should be provided within the metadata header; 724 # add these here. 725 metadata = tuple(metadata) + ( 726 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), 727 ) 728 729 # Send the request. 730 rpc( 731 request, retry=retry, timeout=timeout, metadata=metadata, 732 ) 733 734 def list_views( 735 self, 736 request: Union[logging_config.ListViewsRequest, dict] = None, 737 *, 738 parent: str = None, 739 retry: OptionalRetry = gapic_v1.method.DEFAULT, 740 timeout: float = None, 741 metadata: Sequence[Tuple[str, str]] = (), 742 ) -> pagers.ListViewsPager: 743 r"""Lists views on a bucket. 744 745 Args: 746 request (Union[google.cloud.logging_v2.types.ListViewsRequest, dict]): 747 The request object. The parameters to `ListViews`. 748 parent (str): 749 Required. The bucket whose views are to be listed: 750 751 :: 752 753 "projects/[PROJECT_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]" 754 755 This corresponds to the ``parent`` field 756 on the ``request`` instance; if ``request`` is provided, this 757 should not be set. 758 retry (google.api_core.retry.Retry): Designation of what errors, if any, 759 should be retried. 760 timeout (float): The timeout for this request. 761 metadata (Sequence[Tuple[str, str]]): Strings which should be 762 sent along with the request as metadata. 763 764 Returns: 765 google.cloud.logging_v2.services.config_service_v2.pagers.ListViewsPager: 766 The response from ListViews. 767 Iterating over this object will yield 768 results and resolve additional pages 769 automatically. 770 771 """ 772 # Create or coerce a protobuf request object. 773 # Sanity check: If we got a request object, we should *not* have 774 # gotten any keyword arguments that map to the request. 775 has_flattened_params = any([parent]) 776 if request is not None and has_flattened_params: 777 raise ValueError( 778 "If the `request` argument is set, then none of " 779 "the individual field arguments should be set." 780 ) 781 782 # Minor optimization to avoid making a copy if the user passes 783 # in a logging_config.ListViewsRequest. 784 # There's no risk of modifying the input as we've already verified 785 # there are no flattened fields. 786 if not isinstance(request, logging_config.ListViewsRequest): 787 request = logging_config.ListViewsRequest(request) 788 # If we have keyword arguments corresponding to fields on the 789 # request, apply these. 790 if parent is not None: 791 request.parent = parent 792 793 # Wrap the RPC method; this adds retry and timeout information, 794 # and friendly error handling. 795 rpc = self._transport._wrapped_methods[self._transport.list_views] 796 797 # Certain fields should be provided within the metadata header; 798 # add these here. 799 metadata = tuple(metadata) + ( 800 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), 801 ) 802 803 # Send the request. 804 response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) 805 806 # This method is paged; wrap the response in a pager, which provides 807 # an `__iter__` convenience method. 808 response = pagers.ListViewsPager( 809 method=rpc, request=request, response=response, metadata=metadata, 810 ) 811 812 # Done; return the response. 813 return response 814 815 def get_view( 816 self, 817 request: Union[logging_config.GetViewRequest, dict] = None, 818 *, 819 retry: OptionalRetry = gapic_v1.method.DEFAULT, 820 timeout: float = None, 821 metadata: Sequence[Tuple[str, str]] = (), 822 ) -> logging_config.LogView: 823 r"""Gets a view. 824 825 Args: 826 request (Union[google.cloud.logging_v2.types.GetViewRequest, dict]): 827 The request object. The parameters to `GetView`. 828 retry (google.api_core.retry.Retry): Designation of what errors, if any, 829 should be retried. 830 timeout (float): The timeout for this request. 831 metadata (Sequence[Tuple[str, str]]): Strings which should be 832 sent along with the request as metadata. 833 834 Returns: 835 google.cloud.logging_v2.types.LogView: 836 Describes a view over logs in a 837 bucket. 838 839 """ 840 # Create or coerce a protobuf request object. 841 # Minor optimization to avoid making a copy if the user passes 842 # in a logging_config.GetViewRequest. 843 # There's no risk of modifying the input as we've already verified 844 # there are no flattened fields. 845 if not isinstance(request, logging_config.GetViewRequest): 846 request = logging_config.GetViewRequest(request) 847 848 # Wrap the RPC method; this adds retry and timeout information, 849 # and friendly error handling. 850 rpc = self._transport._wrapped_methods[self._transport.get_view] 851 852 # Certain fields should be provided within the metadata header; 853 # add these here. 854 metadata = tuple(metadata) + ( 855 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), 856 ) 857 858 # Send the request. 859 response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) 860 861 # Done; return the response. 862 return response 863 864 def create_view( 865 self, 866 request: Union[logging_config.CreateViewRequest, dict] = None, 867 *, 868 retry: OptionalRetry = gapic_v1.method.DEFAULT, 869 timeout: float = None, 870 metadata: Sequence[Tuple[str, str]] = (), 871 ) -> logging_config.LogView: 872 r"""Creates a view over logs in a bucket. A bucket may 873 contain a maximum of 50 views. 874 875 Args: 876 request (Union[google.cloud.logging_v2.types.CreateViewRequest, dict]): 877 The request object. The parameters to `CreateView`. 878 retry (google.api_core.retry.Retry): Designation of what errors, if any, 879 should be retried. 880 timeout (float): The timeout for this request. 881 metadata (Sequence[Tuple[str, str]]): Strings which should be 882 sent along with the request as metadata. 883 884 Returns: 885 google.cloud.logging_v2.types.LogView: 886 Describes a view over logs in a 887 bucket. 888 889 """ 890 # Create or coerce a protobuf request object. 891 # Minor optimization to avoid making a copy if the user passes 892 # in a logging_config.CreateViewRequest. 893 # There's no risk of modifying the input as we've already verified 894 # there are no flattened fields. 895 if not isinstance(request, logging_config.CreateViewRequest): 896 request = logging_config.CreateViewRequest(request) 897 898 # Wrap the RPC method; this adds retry and timeout information, 899 # and friendly error handling. 900 rpc = self._transport._wrapped_methods[self._transport.create_view] 901 902 # Certain fields should be provided within the metadata header; 903 # add these here. 904 metadata = tuple(metadata) + ( 905 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), 906 ) 907 908 # Send the request. 909 response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) 910 911 # Done; return the response. 912 return response 913 914 def update_view( 915 self, 916 request: Union[logging_config.UpdateViewRequest, dict] = None, 917 *, 918 retry: OptionalRetry = gapic_v1.method.DEFAULT, 919 timeout: float = None, 920 metadata: Sequence[Tuple[str, str]] = (), 921 ) -> logging_config.LogView: 922 r"""Updates a view. This method replaces the following fields in the 923 existing view with values from the new view: ``filter``. 924 925 Args: 926 request (Union[google.cloud.logging_v2.types.UpdateViewRequest, dict]): 927 The request object. The parameters to `UpdateView`. 928 retry (google.api_core.retry.Retry): Designation of what errors, if any, 929 should be retried. 930 timeout (float): The timeout for this request. 931 metadata (Sequence[Tuple[str, str]]): Strings which should be 932 sent along with the request as metadata. 933 934 Returns: 935 google.cloud.logging_v2.types.LogView: 936 Describes a view over logs in a 937 bucket. 938 939 """ 940 # Create or coerce a protobuf request object. 941 # Minor optimization to avoid making a copy if the user passes 942 # in a logging_config.UpdateViewRequest. 943 # There's no risk of modifying the input as we've already verified 944 # there are no flattened fields. 945 if not isinstance(request, logging_config.UpdateViewRequest): 946 request = logging_config.UpdateViewRequest(request) 947 948 # Wrap the RPC method; this adds retry and timeout information, 949 # and friendly error handling. 950 rpc = self._transport._wrapped_methods[self._transport.update_view] 951 952 # Certain fields should be provided within the metadata header; 953 # add these here. 954 metadata = tuple(metadata) + ( 955 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), 956 ) 957 958 # Send the request. 959 response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) 960 961 # Done; return the response. 962 return response 963 964 def delete_view( 965 self, 966 request: Union[logging_config.DeleteViewRequest, dict] = None, 967 *, 968 retry: OptionalRetry = gapic_v1.method.DEFAULT, 969 timeout: float = None, 970 metadata: Sequence[Tuple[str, str]] = (), 971 ) -> None: 972 r"""Deletes a view from a bucket. 973 974 Args: 975 request (Union[google.cloud.logging_v2.types.DeleteViewRequest, dict]): 976 The request object. The parameters to `DeleteView`. 977 retry (google.api_core.retry.Retry): Designation of what errors, if any, 978 should be retried. 979 timeout (float): The timeout for this request. 980 metadata (Sequence[Tuple[str, str]]): Strings which should be 981 sent along with the request as metadata. 982 """ 983 # Create or coerce a protobuf request object. 984 # Minor optimization to avoid making a copy if the user passes 985 # in a logging_config.DeleteViewRequest. 986 # There's no risk of modifying the input as we've already verified 987 # there are no flattened fields. 988 if not isinstance(request, logging_config.DeleteViewRequest): 989 request = logging_config.DeleteViewRequest(request) 990 991 # Wrap the RPC method; this adds retry and timeout information, 992 # and friendly error handling. 993 rpc = self._transport._wrapped_methods[self._transport.delete_view] 994 995 # Certain fields should be provided within the metadata header; 996 # add these here. 997 metadata = tuple(metadata) + ( 998 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), 999 ) 1000 1001 # Send the request. 1002 rpc( 1003 request, retry=retry, timeout=timeout, metadata=metadata, 1004 ) 1005 1006 def list_sinks( 1007 self, 1008 request: Union[logging_config.ListSinksRequest, dict] = None, 1009 *, 1010 parent: str = None, 1011 retry: OptionalRetry = gapic_v1.method.DEFAULT, 1012 timeout: float = None, 1013 metadata: Sequence[Tuple[str, str]] = (), 1014 ) -> pagers.ListSinksPager: 1015 r"""Lists sinks. 1016 1017 Args: 1018 request (Union[google.cloud.logging_v2.types.ListSinksRequest, dict]): 1019 The request object. The parameters to `ListSinks`. 1020 parent (str): 1021 Required. The parent resource whose sinks are to be 1022 listed: 1023 1024 :: 1025 1026 "projects/[PROJECT_ID]" 1027 "organizations/[ORGANIZATION_ID]" 1028 "billingAccounts/[BILLING_ACCOUNT_ID]" 1029 "folders/[FOLDER_ID]" 1030 1031 This corresponds to the ``parent`` field 1032 on the ``request`` instance; if ``request`` is provided, this 1033 should not be set. 1034 retry (google.api_core.retry.Retry): Designation of what errors, if any, 1035 should be retried. 1036 timeout (float): The timeout for this request. 1037 metadata (Sequence[Tuple[str, str]]): Strings which should be 1038 sent along with the request as metadata. 1039 1040 Returns: 1041 google.cloud.logging_v2.services.config_service_v2.pagers.ListSinksPager: 1042 Result returned from ListSinks. 1043 1044 Iterating over this object will yield results and 1045 resolve additional pages automatically. 1046 1047 """ 1048 # Create or coerce a protobuf request object. 1049 # Sanity check: If we got a request object, we should *not* have 1050 # gotten any keyword arguments that map to the request. 1051 has_flattened_params = any([parent]) 1052 if request is not None and has_flattened_params: 1053 raise ValueError( 1054 "If the `request` argument is set, then none of " 1055 "the individual field arguments should be set." 1056 ) 1057 1058 # Minor optimization to avoid making a copy if the user passes 1059 # in a logging_config.ListSinksRequest. 1060 # There's no risk of modifying the input as we've already verified 1061 # there are no flattened fields. 1062 if not isinstance(request, logging_config.ListSinksRequest): 1063 request = logging_config.ListSinksRequest(request) 1064 # If we have keyword arguments corresponding to fields on the 1065 # request, apply these. 1066 if parent is not None: 1067 request.parent = parent 1068 1069 # Wrap the RPC method; this adds retry and timeout information, 1070 # and friendly error handling. 1071 rpc = self._transport._wrapped_methods[self._transport.list_sinks] 1072 1073 # Certain fields should be provided within the metadata header; 1074 # add these here. 1075 metadata = tuple(metadata) + ( 1076 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), 1077 ) 1078 1079 # Send the request. 1080 response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) 1081 1082 # This method is paged; wrap the response in a pager, which provides 1083 # an `__iter__` convenience method. 1084 response = pagers.ListSinksPager( 1085 method=rpc, request=request, response=response, metadata=metadata, 1086 ) 1087 1088 # Done; return the response. 1089 return response 1090 1091 def get_sink( 1092 self, 1093 request: Union[logging_config.GetSinkRequest, dict] = None, 1094 *, 1095 sink_name: str = None, 1096 retry: OptionalRetry = gapic_v1.method.DEFAULT, 1097 timeout: float = None, 1098 metadata: Sequence[Tuple[str, str]] = (), 1099 ) -> logging_config.LogSink: 1100 r"""Gets a sink. 1101 1102 Args: 1103 request (Union[google.cloud.logging_v2.types.GetSinkRequest, dict]): 1104 The request object. The parameters to `GetSink`. 1105 sink_name (str): 1106 Required. The resource name of the sink: 1107 1108 :: 1109 1110 "projects/[PROJECT_ID]/sinks/[SINK_ID]" 1111 "organizations/[ORGANIZATION_ID]/sinks/[SINK_ID]" 1112 "billingAccounts/[BILLING_ACCOUNT_ID]/sinks/[SINK_ID]" 1113 "folders/[FOLDER_ID]/sinks/[SINK_ID]" 1114 1115 Example: ``"projects/my-project-id/sinks/my-sink-id"``. 1116 1117 This corresponds to the ``sink_name`` field 1118 on the ``request`` instance; if ``request`` is provided, this 1119 should not be set. 1120 retry (google.api_core.retry.Retry): Designation of what errors, if any, 1121 should be retried. 1122 timeout (float): The timeout for this request. 1123 metadata (Sequence[Tuple[str, str]]): Strings which should be 1124 sent along with the request as metadata. 1125 1126 Returns: 1127 google.cloud.logging_v2.types.LogSink: 1128 Describes a sink used to export log 1129 entries to one of the following 1130 destinations in any project: a Cloud 1131 Storage bucket, a BigQuery dataset, or a 1132 Cloud Pub/Sub topic. A logs filter 1133 controls which log entries are exported. 1134 The sink must be created within a 1135 project, organization, billing account, 1136 or folder. 1137 1138 """ 1139 # Create or coerce a protobuf request object. 1140 # Sanity check: If we got a request object, we should *not* have 1141 # gotten any keyword arguments that map to the request. 1142 has_flattened_params = any([sink_name]) 1143 if request is not None and has_flattened_params: 1144 raise ValueError( 1145 "If the `request` argument is set, then none of " 1146 "the individual field arguments should be set." 1147 ) 1148 1149 # Minor optimization to avoid making a copy if the user passes 1150 # in a logging_config.GetSinkRequest. 1151 # There's no risk of modifying the input as we've already verified 1152 # there are no flattened fields. 1153 if not isinstance(request, logging_config.GetSinkRequest): 1154 request = logging_config.GetSinkRequest(request) 1155 # If we have keyword arguments corresponding to fields on the 1156 # request, apply these. 1157 if sink_name is not None: 1158 request.sink_name = sink_name 1159 1160 # Wrap the RPC method; this adds retry and timeout information, 1161 # and friendly error handling. 1162 rpc = self._transport._wrapped_methods[self._transport.get_sink] 1163 1164 # Certain fields should be provided within the metadata header; 1165 # add these here. 1166 metadata = tuple(metadata) + ( 1167 gapic_v1.routing_header.to_grpc_metadata( 1168 (("sink_name", request.sink_name),) 1169 ), 1170 ) 1171 1172 # Send the request. 1173 response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) 1174 1175 # Done; return the response. 1176 return response 1177 1178 def create_sink( 1179 self, 1180 request: Union[logging_config.CreateSinkRequest, dict] = None, 1181 *, 1182 parent: str = None, 1183 sink: logging_config.LogSink = None, 1184 retry: OptionalRetry = gapic_v1.method.DEFAULT, 1185 timeout: float = None, 1186 metadata: Sequence[Tuple[str, str]] = (), 1187 ) -> logging_config.LogSink: 1188 r"""Creates a sink that exports specified log entries to a 1189 destination. The export of newly-ingested log entries begins 1190 immediately, unless the sink's ``writer_identity`` is not 1191 permitted to write to the destination. A sink can export log 1192 entries only from the resource owning the sink. 1193 1194 Args: 1195 request (Union[google.cloud.logging_v2.types.CreateSinkRequest, dict]): 1196 The request object. The parameters to `CreateSink`. 1197 parent (str): 1198 Required. The resource in which to create the sink: 1199 1200 :: 1201 1202 "projects/[PROJECT_ID]" 1203 "organizations/[ORGANIZATION_ID]" 1204 "billingAccounts/[BILLING_ACCOUNT_ID]" 1205 "folders/[FOLDER_ID]" 1206 1207 Examples: ``"projects/my-logging-project"``, 1208 ``"organizations/123456789"``. 1209 1210 This corresponds to the ``parent`` field 1211 on the ``request`` instance; if ``request`` is provided, this 1212 should not be set. 1213 sink (google.cloud.logging_v2.types.LogSink): 1214 Required. The new sink, whose ``name`` parameter is a 1215 sink identifier that is not already in use. 1216 1217 This corresponds to the ``sink`` field 1218 on the ``request`` instance; if ``request`` is provided, this 1219 should not be set. 1220 retry (google.api_core.retry.Retry): Designation of what errors, if any, 1221 should be retried. 1222 timeout (float): The timeout for this request. 1223 metadata (Sequence[Tuple[str, str]]): Strings which should be 1224 sent along with the request as metadata. 1225 1226 Returns: 1227 google.cloud.logging_v2.types.LogSink: 1228 Describes a sink used to export log 1229 entries to one of the following 1230 destinations in any project: a Cloud 1231 Storage bucket, a BigQuery dataset, or a 1232 Cloud Pub/Sub topic. A logs filter 1233 controls which log entries are exported. 1234 The sink must be created within a 1235 project, organization, billing account, 1236 or folder. 1237 1238 """ 1239 # Create or coerce a protobuf request object. 1240 # Sanity check: If we got a request object, we should *not* have 1241 # gotten any keyword arguments that map to the request. 1242 has_flattened_params = any([parent, sink]) 1243 if request is not None and has_flattened_params: 1244 raise ValueError( 1245 "If the `request` argument is set, then none of " 1246 "the individual field arguments should be set." 1247 ) 1248 1249 # Minor optimization to avoid making a copy if the user passes 1250 # in a logging_config.CreateSinkRequest. 1251 # There's no risk of modifying the input as we've already verified 1252 # there are no flattened fields. 1253 if not isinstance(request, logging_config.CreateSinkRequest): 1254 request = logging_config.CreateSinkRequest(request) 1255 # If we have keyword arguments corresponding to fields on the 1256 # request, apply these. 1257 if parent is not None: 1258 request.parent = parent 1259 if sink is not None: 1260 request.sink = sink 1261 1262 # Wrap the RPC method; this adds retry and timeout information, 1263 # and friendly error handling. 1264 rpc = self._transport._wrapped_methods[self._transport.create_sink] 1265 1266 # Certain fields should be provided within the metadata header; 1267 # add these here. 1268 metadata = tuple(metadata) + ( 1269 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), 1270 ) 1271 1272 # Send the request. 1273 response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) 1274 1275 # Done; return the response. 1276 return response 1277 1278 def update_sink( 1279 self, 1280 request: Union[logging_config.UpdateSinkRequest, dict] = None, 1281 *, 1282 sink_name: str = None, 1283 sink: logging_config.LogSink = None, 1284 update_mask: field_mask_pb2.FieldMask = None, 1285 retry: OptionalRetry = gapic_v1.method.DEFAULT, 1286 timeout: float = None, 1287 metadata: Sequence[Tuple[str, str]] = (), 1288 ) -> logging_config.LogSink: 1289 r"""Updates a sink. This method replaces the following fields in the 1290 existing sink with values from the new sink: ``destination``, 1291 and ``filter``. 1292 1293 The updated sink might also have a new ``writer_identity``; see 1294 the ``unique_writer_identity`` field. 1295 1296 Args: 1297 request (Union[google.cloud.logging_v2.types.UpdateSinkRequest, dict]): 1298 The request object. The parameters to `UpdateSink`. 1299 sink_name (str): 1300 Required. The full resource name of the sink to update, 1301 including the parent resource and the sink identifier: 1302 1303 :: 1304 1305 "projects/[PROJECT_ID]/sinks/[SINK_ID]" 1306 "organizations/[ORGANIZATION_ID]/sinks/[SINK_ID]" 1307 "billingAccounts/[BILLING_ACCOUNT_ID]/sinks/[SINK_ID]" 1308 "folders/[FOLDER_ID]/sinks/[SINK_ID]" 1309 1310 Example: ``"projects/my-project-id/sinks/my-sink-id"``. 1311 1312 This corresponds to the ``sink_name`` field 1313 on the ``request`` instance; if ``request`` is provided, this 1314 should not be set. 1315 sink (google.cloud.logging_v2.types.LogSink): 1316 Required. The updated sink, whose name is the same 1317 identifier that appears as part of ``sink_name``. 1318 1319 This corresponds to the ``sink`` field 1320 on the ``request`` instance; if ``request`` is provided, this 1321 should not be set. 1322 update_mask (google.protobuf.field_mask_pb2.FieldMask): 1323 Optional. Field mask that specifies the fields in 1324 ``sink`` that need an update. A sink field will be 1325 overwritten if, and only if, it is in the update mask. 1326 ``name`` and output only fields cannot be updated. 1327 1328 An empty updateMask is temporarily treated as using the 1329 following mask for backwards compatibility purposes: 1330 destination,filter,includeChildren At some point in the 1331 future, behavior will be removed and specifying an empty 1332 updateMask will be an error. 1333 1334 For a detailed ``FieldMask`` definition, see 1335 https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#google.protobuf.FieldMask 1336 1337 Example: ``updateMask=filter``. 1338 1339 This corresponds to the ``update_mask`` field 1340 on the ``request`` instance; if ``request`` is provided, this 1341 should not be set. 1342 retry (google.api_core.retry.Retry): Designation of what errors, if any, 1343 should be retried. 1344 timeout (float): The timeout for this request. 1345 metadata (Sequence[Tuple[str, str]]): Strings which should be 1346 sent along with the request as metadata. 1347 1348 Returns: 1349 google.cloud.logging_v2.types.LogSink: 1350 Describes a sink used to export log 1351 entries to one of the following 1352 destinations in any project: a Cloud 1353 Storage bucket, a BigQuery dataset, or a 1354 Cloud Pub/Sub topic. A logs filter 1355 controls which log entries are exported. 1356 The sink must be created within a 1357 project, organization, billing account, 1358 or folder. 1359 1360 """ 1361 # Create or coerce a protobuf request object. 1362 # Sanity check: If we got a request object, we should *not* have 1363 # gotten any keyword arguments that map to the request. 1364 has_flattened_params = any([sink_name, sink, update_mask]) 1365 if request is not None and has_flattened_params: 1366 raise ValueError( 1367 "If the `request` argument is set, then none of " 1368 "the individual field arguments should be set." 1369 ) 1370 1371 # Minor optimization to avoid making a copy if the user passes 1372 # in a logging_config.UpdateSinkRequest. 1373 # There's no risk of modifying the input as we've already verified 1374 # there are no flattened fields. 1375 if not isinstance(request, logging_config.UpdateSinkRequest): 1376 request = logging_config.UpdateSinkRequest(request) 1377 # If we have keyword arguments corresponding to fields on the 1378 # request, apply these. 1379 if sink_name is not None: 1380 request.sink_name = sink_name 1381 if sink is not None: 1382 request.sink = sink 1383 if update_mask is not None: 1384 request.update_mask = update_mask 1385 1386 # Wrap the RPC method; this adds retry and timeout information, 1387 # and friendly error handling. 1388 rpc = self._transport._wrapped_methods[self._transport.update_sink] 1389 1390 # Certain fields should be provided within the metadata header; 1391 # add these here. 1392 metadata = tuple(metadata) + ( 1393 gapic_v1.routing_header.to_grpc_metadata( 1394 (("sink_name", request.sink_name),) 1395 ), 1396 ) 1397 1398 # Send the request. 1399 response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) 1400 1401 # Done; return the response. 1402 return response 1403 1404 def delete_sink( 1405 self, 1406 request: Union[logging_config.DeleteSinkRequest, dict] = None, 1407 *, 1408 sink_name: str = None, 1409 retry: OptionalRetry = gapic_v1.method.DEFAULT, 1410 timeout: float = None, 1411 metadata: Sequence[Tuple[str, str]] = (), 1412 ) -> None: 1413 r"""Deletes a sink. If the sink has a unique ``writer_identity``, 1414 then that service account is also deleted. 1415 1416 Args: 1417 request (Union[google.cloud.logging_v2.types.DeleteSinkRequest, dict]): 1418 The request object. The parameters to `DeleteSink`. 1419 sink_name (str): 1420 Required. The full resource name of the sink to delete, 1421 including the parent resource and the sink identifier: 1422 1423 :: 1424 1425 "projects/[PROJECT_ID]/sinks/[SINK_ID]" 1426 "organizations/[ORGANIZATION_ID]/sinks/[SINK_ID]" 1427 "billingAccounts/[BILLING_ACCOUNT_ID]/sinks/[SINK_ID]" 1428 "folders/[FOLDER_ID]/sinks/[SINK_ID]" 1429 1430 Example: ``"projects/my-project-id/sinks/my-sink-id"``. 1431 1432 This corresponds to the ``sink_name`` field 1433 on the ``request`` instance; if ``request`` is provided, this 1434 should not be set. 1435 retry (google.api_core.retry.Retry): Designation of what errors, if any, 1436 should be retried. 1437 timeout (float): The timeout for this request. 1438 metadata (Sequence[Tuple[str, str]]): Strings which should be 1439 sent along with the request as metadata. 1440 """ 1441 # Create or coerce a protobuf request object. 1442 # Sanity check: If we got a request object, we should *not* have 1443 # gotten any keyword arguments that map to the request. 1444 has_flattened_params = any([sink_name]) 1445 if request is not None and has_flattened_params: 1446 raise ValueError( 1447 "If the `request` argument is set, then none of " 1448 "the individual field arguments should be set." 1449 ) 1450 1451 # Minor optimization to avoid making a copy if the user passes 1452 # in a logging_config.DeleteSinkRequest. 1453 # There's no risk of modifying the input as we've already verified 1454 # there are no flattened fields. 1455 if not isinstance(request, logging_config.DeleteSinkRequest): 1456 request = logging_config.DeleteSinkRequest(request) 1457 # If we have keyword arguments corresponding to fields on the 1458 # request, apply these. 1459 if sink_name is not None: 1460 request.sink_name = sink_name 1461 1462 # Wrap the RPC method; this adds retry and timeout information, 1463 # and friendly error handling. 1464 rpc = self._transport._wrapped_methods[self._transport.delete_sink] 1465 1466 # Certain fields should be provided within the metadata header; 1467 # add these here. 1468 metadata = tuple(metadata) + ( 1469 gapic_v1.routing_header.to_grpc_metadata( 1470 (("sink_name", request.sink_name),) 1471 ), 1472 ) 1473 1474 # Send the request. 1475 rpc( 1476 request, retry=retry, timeout=timeout, metadata=metadata, 1477 ) 1478 1479 def list_exclusions( 1480 self, 1481 request: Union[logging_config.ListExclusionsRequest, dict] = None, 1482 *, 1483 parent: str = None, 1484 retry: OptionalRetry = gapic_v1.method.DEFAULT, 1485 timeout: float = None, 1486 metadata: Sequence[Tuple[str, str]] = (), 1487 ) -> pagers.ListExclusionsPager: 1488 r"""Lists all the exclusions in a parent resource. 1489 1490 Args: 1491 request (Union[google.cloud.logging_v2.types.ListExclusionsRequest, dict]): 1492 The request object. The parameters to `ListExclusions`. 1493 parent (str): 1494 Required. The parent resource whose exclusions are to be 1495 listed. 1496 1497 :: 1498 1499 "projects/[PROJECT_ID]" 1500 "organizations/[ORGANIZATION_ID]" 1501 "billingAccounts/[BILLING_ACCOUNT_ID]" 1502 "folders/[FOLDER_ID]" 1503 1504 This corresponds to the ``parent`` field 1505 on the ``request`` instance; if ``request`` is provided, this 1506 should not be set. 1507 retry (google.api_core.retry.Retry): Designation of what errors, if any, 1508 should be retried. 1509 timeout (float): The timeout for this request. 1510 metadata (Sequence[Tuple[str, str]]): Strings which should be 1511 sent along with the request as metadata. 1512 1513 Returns: 1514 google.cloud.logging_v2.services.config_service_v2.pagers.ListExclusionsPager: 1515 Result returned from ListExclusions. 1516 1517 Iterating over this object will yield results and 1518 resolve additional pages automatically. 1519 1520 """ 1521 # Create or coerce a protobuf request object. 1522 # Sanity check: If we got a request object, we should *not* have 1523 # gotten any keyword arguments that map to the request. 1524 has_flattened_params = any([parent]) 1525 if request is not None and has_flattened_params: 1526 raise ValueError( 1527 "If the `request` argument is set, then none of " 1528 "the individual field arguments should be set." 1529 ) 1530 1531 # Minor optimization to avoid making a copy if the user passes 1532 # in a logging_config.ListExclusionsRequest. 1533 # There's no risk of modifying the input as we've already verified 1534 # there are no flattened fields. 1535 if not isinstance(request, logging_config.ListExclusionsRequest): 1536 request = logging_config.ListExclusionsRequest(request) 1537 # If we have keyword arguments corresponding to fields on the 1538 # request, apply these. 1539 if parent is not None: 1540 request.parent = parent 1541 1542 # Wrap the RPC method; this adds retry and timeout information, 1543 # and friendly error handling. 1544 rpc = self._transport._wrapped_methods[self._transport.list_exclusions] 1545 1546 # Certain fields should be provided within the metadata header; 1547 # add these here. 1548 metadata = tuple(metadata) + ( 1549 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), 1550 ) 1551 1552 # Send the request. 1553 response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) 1554 1555 # This method is paged; wrap the response in a pager, which provides 1556 # an `__iter__` convenience method. 1557 response = pagers.ListExclusionsPager( 1558 method=rpc, request=request, response=response, metadata=metadata, 1559 ) 1560 1561 # Done; return the response. 1562 return response 1563 1564 def get_exclusion( 1565 self, 1566 request: Union[logging_config.GetExclusionRequest, dict] = None, 1567 *, 1568 name: str = None, 1569 retry: OptionalRetry = gapic_v1.method.DEFAULT, 1570 timeout: float = None, 1571 metadata: Sequence[Tuple[str, str]] = (), 1572 ) -> logging_config.LogExclusion: 1573 r"""Gets the description of an exclusion. 1574 1575 Args: 1576 request (Union[google.cloud.logging_v2.types.GetExclusionRequest, dict]): 1577 The request object. The parameters to `GetExclusion`. 1578 name (str): 1579 Required. The resource name of an existing exclusion: 1580 1581 :: 1582 1583 "projects/[PROJECT_ID]/exclusions/[EXCLUSION_ID]" 1584 "organizations/[ORGANIZATION_ID]/exclusions/[EXCLUSION_ID]" 1585 "billingAccounts/[BILLING_ACCOUNT_ID]/exclusions/[EXCLUSION_ID]" 1586 "folders/[FOLDER_ID]/exclusions/[EXCLUSION_ID]" 1587 1588 Example: 1589 ``"projects/my-project-id/exclusions/my-exclusion-id"``. 1590 1591 This corresponds to the ``name`` field 1592 on the ``request`` instance; if ``request`` is provided, this 1593 should not be set. 1594 retry (google.api_core.retry.Retry): Designation of what errors, if any, 1595 should be retried. 1596 timeout (float): The timeout for this request. 1597 metadata (Sequence[Tuple[str, str]]): Strings which should be 1598 sent along with the request as metadata. 1599 1600 Returns: 1601 google.cloud.logging_v2.types.LogExclusion: 1602 Specifies a set of log entries that 1603 are not to be stored in Logging. If your 1604 GCP resource receives a large volume of 1605 logs, you can use exclusions to reduce 1606 your chargeable logs. Exclusions are 1607 processed after log sinks, so you can 1608 export log entries before they are 1609 excluded. Note that organization-level 1610 and folder-level exclusions don't apply 1611 to child resources, and that you can't 1612 exclude audit log entries. 1613 1614 """ 1615 # Create or coerce a protobuf request object. 1616 # Sanity check: If we got a request object, we should *not* have 1617 # gotten any keyword arguments that map to the request. 1618 has_flattened_params = any([name]) 1619 if request is not None and has_flattened_params: 1620 raise ValueError( 1621 "If the `request` argument is set, then none of " 1622 "the individual field arguments should be set." 1623 ) 1624 1625 # Minor optimization to avoid making a copy if the user passes 1626 # in a logging_config.GetExclusionRequest. 1627 # There's no risk of modifying the input as we've already verified 1628 # there are no flattened fields. 1629 if not isinstance(request, logging_config.GetExclusionRequest): 1630 request = logging_config.GetExclusionRequest(request) 1631 # If we have keyword arguments corresponding to fields on the 1632 # request, apply these. 1633 if name is not None: 1634 request.name = name 1635 1636 # Wrap the RPC method; this adds retry and timeout information, 1637 # and friendly error handling. 1638 rpc = self._transport._wrapped_methods[self._transport.get_exclusion] 1639 1640 # Certain fields should be provided within the metadata header; 1641 # add these here. 1642 metadata = tuple(metadata) + ( 1643 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), 1644 ) 1645 1646 # Send the request. 1647 response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) 1648 1649 # Done; return the response. 1650 return response 1651 1652 def create_exclusion( 1653 self, 1654 request: Union[logging_config.CreateExclusionRequest, dict] = None, 1655 *, 1656 parent: str = None, 1657 exclusion: logging_config.LogExclusion = None, 1658 retry: OptionalRetry = gapic_v1.method.DEFAULT, 1659 timeout: float = None, 1660 metadata: Sequence[Tuple[str, str]] = (), 1661 ) -> logging_config.LogExclusion: 1662 r"""Creates a new exclusion in a specified parent 1663 resource. Only log entries belonging to that resource 1664 can be excluded. You can have up to 10 exclusions in a 1665 resource. 1666 1667 Args: 1668 request (Union[google.cloud.logging_v2.types.CreateExclusionRequest, dict]): 1669 The request object. The parameters to `CreateExclusion`. 1670 parent (str): 1671 Required. The parent resource in which to create the 1672 exclusion: 1673 1674 :: 1675 1676 "projects/[PROJECT_ID]" 1677 "organizations/[ORGANIZATION_ID]" 1678 "billingAccounts/[BILLING_ACCOUNT_ID]" 1679 "folders/[FOLDER_ID]" 1680 1681 Examples: ``"projects/my-logging-project"``, 1682 ``"organizations/123456789"``. 1683 1684 This corresponds to the ``parent`` field 1685 on the ``request`` instance; if ``request`` is provided, this 1686 should not be set. 1687 exclusion (google.cloud.logging_v2.types.LogExclusion): 1688 Required. The new exclusion, whose ``name`` parameter is 1689 an exclusion name that is not already used in the parent 1690 resource. 1691 1692 This corresponds to the ``exclusion`` field 1693 on the ``request`` instance; if ``request`` is provided, this 1694 should not be set. 1695 retry (google.api_core.retry.Retry): Designation of what errors, if any, 1696 should be retried. 1697 timeout (float): The timeout for this request. 1698 metadata (Sequence[Tuple[str, str]]): Strings which should be 1699 sent along with the request as metadata. 1700 1701 Returns: 1702 google.cloud.logging_v2.types.LogExclusion: 1703 Specifies a set of log entries that 1704 are not to be stored in Logging. If your 1705 GCP resource receives a large volume of 1706 logs, you can use exclusions to reduce 1707 your chargeable logs. Exclusions are 1708 processed after log sinks, so you can 1709 export log entries before they are 1710 excluded. Note that organization-level 1711 and folder-level exclusions don't apply 1712 to child resources, and that you can't 1713 exclude audit log entries. 1714 1715 """ 1716 # Create or coerce a protobuf request object. 1717 # Sanity check: If we got a request object, we should *not* have 1718 # gotten any keyword arguments that map to the request. 1719 has_flattened_params = any([parent, exclusion]) 1720 if request is not None and has_flattened_params: 1721 raise ValueError( 1722 "If the `request` argument is set, then none of " 1723 "the individual field arguments should be set." 1724 ) 1725 1726 # Minor optimization to avoid making a copy if the user passes 1727 # in a logging_config.CreateExclusionRequest. 1728 # There's no risk of modifying the input as we've already verified 1729 # there are no flattened fields. 1730 if not isinstance(request, logging_config.CreateExclusionRequest): 1731 request = logging_config.CreateExclusionRequest(request) 1732 # If we have keyword arguments corresponding to fields on the 1733 # request, apply these. 1734 if parent is not None: 1735 request.parent = parent 1736 if exclusion is not None: 1737 request.exclusion = exclusion 1738 1739 # Wrap the RPC method; this adds retry and timeout information, 1740 # and friendly error handling. 1741 rpc = self._transport._wrapped_methods[self._transport.create_exclusion] 1742 1743 # Certain fields should be provided within the metadata header; 1744 # add these here. 1745 metadata = tuple(metadata) + ( 1746 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), 1747 ) 1748 1749 # Send the request. 1750 response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) 1751 1752 # Done; return the response. 1753 return response 1754 1755 def update_exclusion( 1756 self, 1757 request: Union[logging_config.UpdateExclusionRequest, dict] = None, 1758 *, 1759 name: str = None, 1760 exclusion: logging_config.LogExclusion = None, 1761 update_mask: field_mask_pb2.FieldMask = None, 1762 retry: OptionalRetry = gapic_v1.method.DEFAULT, 1763 timeout: float = None, 1764 metadata: Sequence[Tuple[str, str]] = (), 1765 ) -> logging_config.LogExclusion: 1766 r"""Changes one or more properties of an existing 1767 exclusion. 1768 1769 Args: 1770 request (Union[google.cloud.logging_v2.types.UpdateExclusionRequest, dict]): 1771 The request object. The parameters to `UpdateExclusion`. 1772 name (str): 1773 Required. The resource name of the exclusion to update: 1774 1775 :: 1776 1777 "projects/[PROJECT_ID]/exclusions/[EXCLUSION_ID]" 1778 "organizations/[ORGANIZATION_ID]/exclusions/[EXCLUSION_ID]" 1779 "billingAccounts/[BILLING_ACCOUNT_ID]/exclusions/[EXCLUSION_ID]" 1780 "folders/[FOLDER_ID]/exclusions/[EXCLUSION_ID]" 1781 1782 Example: 1783 ``"projects/my-project-id/exclusions/my-exclusion-id"``. 1784 1785 This corresponds to the ``name`` field 1786 on the ``request`` instance; if ``request`` is provided, this 1787 should not be set. 1788 exclusion (google.cloud.logging_v2.types.LogExclusion): 1789 Required. New values for the existing exclusion. Only 1790 the fields specified in ``update_mask`` are relevant. 1791 1792 This corresponds to the ``exclusion`` field 1793 on the ``request`` instance; if ``request`` is provided, this 1794 should not be set. 1795 update_mask (google.protobuf.field_mask_pb2.FieldMask): 1796 Required. A non-empty list of fields to change in the 1797 existing exclusion. New values for the fields are taken 1798 from the corresponding fields in the 1799 [LogExclusion][google.logging.v2.LogExclusion] included 1800 in this request. Fields not mentioned in ``update_mask`` 1801 are not changed and are ignored in the request. 1802 1803 For example, to change the filter and description of an 1804 exclusion, specify an ``update_mask`` of 1805 ``"filter,description"``. 1806 1807 This corresponds to the ``update_mask`` field 1808 on the ``request`` instance; if ``request`` is provided, this 1809 should not be set. 1810 retry (google.api_core.retry.Retry): Designation of what errors, if any, 1811 should be retried. 1812 timeout (float): The timeout for this request. 1813 metadata (Sequence[Tuple[str, str]]): Strings which should be 1814 sent along with the request as metadata. 1815 1816 Returns: 1817 google.cloud.logging_v2.types.LogExclusion: 1818 Specifies a set of log entries that 1819 are not to be stored in Logging. If your 1820 GCP resource receives a large volume of 1821 logs, you can use exclusions to reduce 1822 your chargeable logs. Exclusions are 1823 processed after log sinks, so you can 1824 export log entries before they are 1825 excluded. Note that organization-level 1826 and folder-level exclusions don't apply 1827 to child resources, and that you can't 1828 exclude audit log entries. 1829 1830 """ 1831 # Create or coerce a protobuf request object. 1832 # Sanity check: If we got a request object, we should *not* have 1833 # gotten any keyword arguments that map to the request. 1834 has_flattened_params = any([name, exclusion, update_mask]) 1835 if request is not None and has_flattened_params: 1836 raise ValueError( 1837 "If the `request` argument is set, then none of " 1838 "the individual field arguments should be set." 1839 ) 1840 1841 # Minor optimization to avoid making a copy if the user passes 1842 # in a logging_config.UpdateExclusionRequest. 1843 # There's no risk of modifying the input as we've already verified 1844 # there are no flattened fields. 1845 if not isinstance(request, logging_config.UpdateExclusionRequest): 1846 request = logging_config.UpdateExclusionRequest(request) 1847 # If we have keyword arguments corresponding to fields on the 1848 # request, apply these. 1849 if name is not None: 1850 request.name = name 1851 if exclusion is not None: 1852 request.exclusion = exclusion 1853 if update_mask is not None: 1854 request.update_mask = update_mask 1855 1856 # Wrap the RPC method; this adds retry and timeout information, 1857 # and friendly error handling. 1858 rpc = self._transport._wrapped_methods[self._transport.update_exclusion] 1859 1860 # Certain fields should be provided within the metadata header; 1861 # add these here. 1862 metadata = tuple(metadata) + ( 1863 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), 1864 ) 1865 1866 # Send the request. 1867 response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) 1868 1869 # Done; return the response. 1870 return response 1871 1872 def delete_exclusion( 1873 self, 1874 request: Union[logging_config.DeleteExclusionRequest, dict] = None, 1875 *, 1876 name: str = None, 1877 retry: OptionalRetry = gapic_v1.method.DEFAULT, 1878 timeout: float = None, 1879 metadata: Sequence[Tuple[str, str]] = (), 1880 ) -> None: 1881 r"""Deletes an exclusion. 1882 1883 Args: 1884 request (Union[google.cloud.logging_v2.types.DeleteExclusionRequest, dict]): 1885 The request object. The parameters to `DeleteExclusion`. 1886 name (str): 1887 Required. The resource name of an existing exclusion to 1888 delete: 1889 1890 :: 1891 1892 "projects/[PROJECT_ID]/exclusions/[EXCLUSION_ID]" 1893 "organizations/[ORGANIZATION_ID]/exclusions/[EXCLUSION_ID]" 1894 "billingAccounts/[BILLING_ACCOUNT_ID]/exclusions/[EXCLUSION_ID]" 1895 "folders/[FOLDER_ID]/exclusions/[EXCLUSION_ID]" 1896 1897 Example: 1898 ``"projects/my-project-id/exclusions/my-exclusion-id"``. 1899 1900 This corresponds to the ``name`` field 1901 on the ``request`` instance; if ``request`` is provided, this 1902 should not be set. 1903 retry (google.api_core.retry.Retry): Designation of what errors, if any, 1904 should be retried. 1905 timeout (float): The timeout for this request. 1906 metadata (Sequence[Tuple[str, str]]): Strings which should be 1907 sent along with the request as metadata. 1908 """ 1909 # Create or coerce a protobuf request object. 1910 # Sanity check: If we got a request object, we should *not* have 1911 # gotten any keyword arguments that map to the request. 1912 has_flattened_params = any([name]) 1913 if request is not None and has_flattened_params: 1914 raise ValueError( 1915 "If the `request` argument is set, then none of " 1916 "the individual field arguments should be set." 1917 ) 1918 1919 # Minor optimization to avoid making a copy if the user passes 1920 # in a logging_config.DeleteExclusionRequest. 1921 # There's no risk of modifying the input as we've already verified 1922 # there are no flattened fields. 1923 if not isinstance(request, logging_config.DeleteExclusionRequest): 1924 request = logging_config.DeleteExclusionRequest(request) 1925 # If we have keyword arguments corresponding to fields on the 1926 # request, apply these. 1927 if name is not None: 1928 request.name = name 1929 1930 # Wrap the RPC method; this adds retry and timeout information, 1931 # and friendly error handling. 1932 rpc = self._transport._wrapped_methods[self._transport.delete_exclusion] 1933 1934 # Certain fields should be provided within the metadata header; 1935 # add these here. 1936 metadata = tuple(metadata) + ( 1937 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), 1938 ) 1939 1940 # Send the request. 1941 rpc( 1942 request, retry=retry, timeout=timeout, metadata=metadata, 1943 ) 1944 1945 def get_cmek_settings( 1946 self, 1947 request: Union[logging_config.GetCmekSettingsRequest, dict] = None, 1948 *, 1949 retry: OptionalRetry = gapic_v1.method.DEFAULT, 1950 timeout: float = None, 1951 metadata: Sequence[Tuple[str, str]] = (), 1952 ) -> logging_config.CmekSettings: 1953 r"""Gets the Logs Router CMEK settings for the given resource. 1954 1955 Note: CMEK for the Logs Router can currently only be configured 1956 for GCP organizations. Once configured, it applies to all 1957 projects and folders in the GCP organization. 1958 1959 See `Enabling CMEK for Logs 1960 Router <https://cloud.google.com/logging/docs/routing/managed-encryption>`__ 1961 for more information. 1962 1963 Args: 1964 request (Union[google.cloud.logging_v2.types.GetCmekSettingsRequest, dict]): 1965 The request object. The parameters to 1966 [GetCmekSettings][google.logging.v2.ConfigServiceV2.GetCmekSettings]. 1967 See [Enabling CMEK for Logs 1968 Router](https://cloud.google.com/logging/docs/routing/managed- 1969 encryption) for more information. 1970 retry (google.api_core.retry.Retry): Designation of what errors, if any, 1971 should be retried. 1972 timeout (float): The timeout for this request. 1973 metadata (Sequence[Tuple[str, str]]): Strings which should be 1974 sent along with the request as metadata. 1975 1976 Returns: 1977 google.cloud.logging_v2.types.CmekSettings: 1978 Describes the customer-managed encryption key (CMEK) settings associated with 1979 a project, folder, organization, billing account, or 1980 flexible resource. 1981 1982 Note: CMEK for the Logs Router can currently only be 1983 configured for GCP organizations. Once configured, it 1984 applies to all projects and folders in the GCP 1985 organization. 1986 1987 See [Enabling CMEK for Logs 1988 Router](\ https://cloud.google.com/logging/docs/routing/managed-encryption) 1989 for more information. 1990 1991 """ 1992 # Create or coerce a protobuf request object. 1993 # Minor optimization to avoid making a copy if the user passes 1994 # in a logging_config.GetCmekSettingsRequest. 1995 # There's no risk of modifying the input as we've already verified 1996 # there are no flattened fields. 1997 if not isinstance(request, logging_config.GetCmekSettingsRequest): 1998 request = logging_config.GetCmekSettingsRequest(request) 1999 2000 # Wrap the RPC method; this adds retry and timeout information, 2001 # and friendly error handling. 2002 rpc = self._transport._wrapped_methods[self._transport.get_cmek_settings] 2003 2004 # Certain fields should be provided within the metadata header; 2005 # add these here. 2006 metadata = tuple(metadata) + ( 2007 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), 2008 ) 2009 2010 # Send the request. 2011 response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) 2012 2013 # Done; return the response. 2014 return response 2015 2016 def update_cmek_settings( 2017 self, 2018 request: Union[logging_config.UpdateCmekSettingsRequest, dict] = None, 2019 *, 2020 retry: OptionalRetry = gapic_v1.method.DEFAULT, 2021 timeout: float = None, 2022 metadata: Sequence[Tuple[str, str]] = (), 2023 ) -> logging_config.CmekSettings: 2024 r"""Updates the Logs Router CMEK settings for the given resource. 2025 2026 Note: CMEK for the Logs Router can currently only be configured 2027 for GCP organizations. Once configured, it applies to all 2028 projects and folders in the GCP organization. 2029 2030 [UpdateCmekSettings][google.logging.v2.ConfigServiceV2.UpdateCmekSettings] 2031 will fail if 1) ``kms_key_name`` is invalid, or 2) the 2032 associated service account does not have the required 2033 ``roles/cloudkms.cryptoKeyEncrypterDecrypter`` role assigned for 2034 the key, or 3) access to the key is disabled. 2035 2036 See `Enabling CMEK for Logs 2037 Router <https://cloud.google.com/logging/docs/routing/managed-encryption>`__ 2038 for more information. 2039 2040 Args: 2041 request (Union[google.cloud.logging_v2.types.UpdateCmekSettingsRequest, dict]): 2042 The request object. The parameters to 2043 [UpdateCmekSettings][google.logging.v2.ConfigServiceV2.UpdateCmekSettings]. 2044 See [Enabling CMEK for Logs 2045 Router](https://cloud.google.com/logging/docs/routing/managed- 2046 encryption) for more information. 2047 retry (google.api_core.retry.Retry): Designation of what errors, if any, 2048 should be retried. 2049 timeout (float): The timeout for this request. 2050 metadata (Sequence[Tuple[str, str]]): Strings which should be 2051 sent along with the request as metadata. 2052 2053 Returns: 2054 google.cloud.logging_v2.types.CmekSettings: 2055 Describes the customer-managed encryption key (CMEK) settings associated with 2056 a project, folder, organization, billing account, or 2057 flexible resource. 2058 2059 Note: CMEK for the Logs Router can currently only be 2060 configured for GCP organizations. Once configured, it 2061 applies to all projects and folders in the GCP 2062 organization. 2063 2064 See [Enabling CMEK for Logs 2065 Router](\ https://cloud.google.com/logging/docs/routing/managed-encryption) 2066 for more information. 2067 2068 """ 2069 # Create or coerce a protobuf request object. 2070 # Minor optimization to avoid making a copy if the user passes 2071 # in a logging_config.UpdateCmekSettingsRequest. 2072 # There's no risk of modifying the input as we've already verified 2073 # there are no flattened fields. 2074 if not isinstance(request, logging_config.UpdateCmekSettingsRequest): 2075 request = logging_config.UpdateCmekSettingsRequest(request) 2076 2077 # Wrap the RPC method; this adds retry and timeout information, 2078 # and friendly error handling. 2079 rpc = self._transport._wrapped_methods[self._transport.update_cmek_settings] 2080 2081 # Certain fields should be provided within the metadata header; 2082 # add these here. 2083 metadata = tuple(metadata) + ( 2084 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), 2085 ) 2086 2087 # Send the request. 2088 response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) 2089 2090 # Done; return the response. 2091 return response 2092 2093 def __enter__(self): 2094 return self 2095 2096 def __exit__(self, type, value, traceback): 2097 """Releases underlying transport's resources. 2098 2099 .. warning:: 2100 ONLY use as a context manager if the transport is NOT shared 2101 with other clients! Exiting the with block will CLOSE the transport 2102 and may cause errors in other clients! 2103 """ 2104 self.transport.close() 2105 2106 2107try: 2108 DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( 2109 gapic_version=pkg_resources.get_distribution("google-cloud-logging",).version, 2110 ) 2111except pkg_resources.DistributionNotFound: 2112 DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() 2113 2114 2115__all__ = ("ConfigServiceV2Client",) 2116