diff --git a/.coveragerc b/.coveragerc index 0d8e6297d..cfcd5ac60 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,38 +1,18 @@ -# -*- coding: utf-8 -*- -# -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Generated by synthtool. DO NOT EDIT! [run] branch = True -omit = - google/cloud/__init__.py [report] fail_under = 100 show_missing = True +omit = + google/cloud/logging/__init__.py exclude_lines = # Re-enable the standard pragma pragma: NO COVER # Ignore debug-only repr def __repr__ - # Ignore abstract methods - raise NotImplementedError -omit = - */gapic/*.py - */proto/*.py - */core/*.py - */site-packages/*.py - google/cloud/__init__.py + # Ignore pkg_resources exceptions. + # This is added at the module level as a safeguard for if someone + # generates the code and tries to run it without pip installing. This + # makes it virtually impossible to test properly. + except pkg_resources.DistributionNotFound diff --git a/.kokoro/build.sh b/.kokoro/build.sh index a194a9ead..7145c57b0 100755 --- a/.kokoro/build.sh +++ b/.kokoro/build.sh @@ -15,7 +15,11 @@ set -eo pipefail -cd github/python-logging +if [[ -z "${PROJECT_ROOT:-}" ]]; then + PROJECT_ROOT="github/python-logging" +fi + +cd "${PROJECT_ROOT}" # Disable buffering, so that the logs stream through. export PYTHONUNBUFFERED=1 @@ -30,16 +34,16 @@ export GOOGLE_APPLICATION_CREDENTIALS=${KOKORO_GFILE_DIR}/service-account.json export PROJECT_ID=$(cat "${KOKORO_GFILE_DIR}/project-id.json") # Remove old nox -python3.6 -m pip uninstall --yes --quiet nox-automation +python3 -m pip uninstall --yes --quiet nox-automation # Install nox -python3.6 -m pip install --upgrade --quiet nox -python3.6 -m nox --version +python3 -m pip install --upgrade --quiet nox +python3 -m nox --version # If NOX_SESSION is set, it only runs the specified session, # otherwise run all the sessions. if [[ -n "${NOX_SESSION:-}" ]]; then - python3.6 -m nox -s "${NOX_SESSION:-}" + python3 -m nox -s ${NOX_SESSION:-} else - python3.6 -m nox + python3 -m nox fi diff --git a/.kokoro/docs/docs-presubmit.cfg b/.kokoro/docs/docs-presubmit.cfg index 111810782..3d5288bef 100644 --- a/.kokoro/docs/docs-presubmit.cfg +++ b/.kokoro/docs/docs-presubmit.cfg @@ -15,3 +15,14 @@ env_vars: { key: "TRAMPOLINE_IMAGE_UPLOAD" value: "false" } + +env_vars: { + key: "TRAMPOLINE_BUILD_FILE" + value: "github/python-logging/.kokoro/build.sh" +} + +# Only run this nox session. +env_vars: { + key: "NOX_SESSION" + value: "docs docfx" +} diff --git a/.trampolinerc b/.trampolinerc index 995ee2911..c7d663ae9 100644 --- a/.trampolinerc +++ b/.trampolinerc @@ -18,12 +18,14 @@ required_envvars+=( "STAGING_BUCKET" "V2_STAGING_BUCKET" + "NOX_SESSION" ) # Add env vars which are passed down into the container here. pass_down_envvars+=( "STAGING_BUCKET" "V2_STAGING_BUCKET" + "NOX_SESSION" ) # Prevent unintentional override on the default image. diff --git a/CHANGELOG.md b/CHANGELOG.md index b5808e4b0..b89976db1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,19 @@ [1]: https://pypi.org/project/google-cloud-logging/#history +## [2.2.0](https://www.github.com/googleapis/python-logging/compare/v2.1.1...v2.2.0) (2021-01-27) + + +### Features + +* add 'from_service_account_info' factory to clients ([a9ff2b7](https://www.github.com/googleapis/python-logging/commit/a9ff2b7984a54542963fc8d52864365ef1562f57)) + + +### Bug Fixes + +* django content length extraction bug ([#160](https://www.github.com/googleapis/python-logging/issues/160)) ([93eeaef](https://www.github.com/googleapis/python-logging/commit/93eeaef1cce286aa8aa830d2369212b912d184b6)) +* fix sphinx identifiers ([a9ff2b7](https://www.github.com/googleapis/python-logging/commit/a9ff2b7984a54542963fc8d52864365ef1562f57)) + ### [2.1.1](https://www.github.com/googleapis/python-logging/compare/v2.1.0...v2.1.1) (2021-01-14) diff --git a/google/cloud/logging_v2/handlers/_helpers.py b/google/cloud/logging_v2/handlers/_helpers.py index 5a4abdbcc..fff1e9a89 100644 --- a/google/cloud/logging_v2/handlers/_helpers.py +++ b/google/cloud/logging_v2/handlers/_helpers.py @@ -24,6 +24,7 @@ from google.cloud.logging_v2.handlers.middleware.request import _get_django_request +_DJANGO_CONTENT_LENGTH = "CONTENT_LENGTH" _DJANGO_TRACE_HEADER = "HTTP_X_CLOUD_TRACE_CONTEXT" _DJANGO_USERAGENT_HEADER = "HTTP_USER_AGENT" _DJANGO_REMOTE_ADDR_HEADER = "REMOTE_ADDR" @@ -93,11 +94,18 @@ def get_request_data_from_django(): if request is None: return None, None + + # convert content_length to int if it exists + content_length = None + try: + content_length = int(request.META.get(_DJANGO_CONTENT_LENGTH)) + except (ValueError, TypeError): + content_length = None # build http_request http_request = { "requestMethod": request.method, "requestUrl": request.build_absolute_uri(), - "requestSize": len(request.body), + "requestSize": content_length, "userAgent": request.META.get(_DJANGO_USERAGENT_HEADER), "remoteIp": request.META.get(_DJANGO_REMOTE_ADDR_HEADER), "referer": request.META.get(_DJANGO_REFERER_HEADER), diff --git a/google/cloud/logging_v2/services/config_service_v2/async_client.py b/google/cloud/logging_v2/services/config_service_v2/async_client.py index 73737c1d8..9603b3754 100644 --- a/google/cloud/logging_v2/services/config_service_v2/async_client.py +++ b/google/cloud/logging_v2/services/config_service_v2/async_client.py @@ -90,6 +90,7 @@ class ConfigServiceV2AsyncClient: ConfigServiceV2Client.parse_common_location_path ) + from_service_account_info = ConfigServiceV2Client.from_service_account_info from_service_account_file = ConfigServiceV2Client.from_service_account_file from_service_account_json = from_service_account_file @@ -166,7 +167,7 @@ async def list_buckets( r"""Lists buckets. Args: - request (:class:`~.logging_config.ListBucketsRequest`): + request (:class:`google.cloud.logging_v2.types.ListBucketsRequest`): The request object. The parameters to `ListBuckets`. parent (:class:`str`): Required. The parent resource whose buckets are to be @@ -182,6 +183,7 @@ async def list_buckets( Note: The locations portion of the resource must be specified, but supplying the character ``-`` in place of [LOCATION_ID] will return all buckets. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -193,7 +195,7 @@ async def list_buckets( sent along with the request as metadata. Returns: - ~.pagers.ListBucketsAsyncPager: + google.cloud.logging_v2.services.config_service_v2.pagers.ListBucketsAsyncPager: The response from ListBuckets. Iterating over this object will yield results and resolve additional pages @@ -255,7 +257,7 @@ async def get_bucket( r"""Gets a bucket. Args: - request (:class:`~.logging_config.GetBucketRequest`): + request (:class:`google.cloud.logging_v2.types.GetBucketRequest`): The request object. The parameters to `GetBucket`. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -265,7 +267,7 @@ async def get_bucket( sent along with the request as metadata. Returns: - ~.logging_config.LogBucket: + google.cloud.logging_v2.types.LogBucket: Describes a repository of logs. """ # Create or coerce a protobuf request object. @@ -305,7 +307,7 @@ async def create_bucket( cannot be changed. Args: - request (:class:`~.logging_config.CreateBucketRequest`): + request (:class:`google.cloud.logging_v2.types.CreateBucketRequest`): The request object. The parameters to `CreateBucket`. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -315,7 +317,7 @@ async def create_bucket( sent along with the request as metadata. Returns: - ~.logging_config.LogBucket: + google.cloud.logging_v2.types.LogBucket: Describes a repository of logs. """ # Create or coerce a protobuf request object. @@ -363,7 +365,7 @@ async def update_bucket( A buckets region may not be modified after it is created. Args: - request (:class:`~.logging_config.UpdateBucketRequest`): + request (:class:`google.cloud.logging_v2.types.UpdateBucketRequest`): The request object. The parameters to `UpdateBucket`. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -373,7 +375,7 @@ async def update_bucket( sent along with the request as metadata. Returns: - ~.logging_config.LogBucket: + google.cloud.logging_v2.types.LogBucket: Describes a repository of logs. """ # Create or coerce a protobuf request object. @@ -413,7 +415,7 @@ async def delete_bucket( the bucket will be permanently deleted. Args: - request (:class:`~.logging_config.DeleteBucketRequest`): + request (:class:`google.cloud.logging_v2.types.DeleteBucketRequest`): The request object. The parameters to `DeleteBucket`. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -457,7 +459,7 @@ async def undelete_bucket( may be undeleted within the grace period of 7 days. Args: - request (:class:`~.logging_config.UndeleteBucketRequest`): + request (:class:`google.cloud.logging_v2.types.UndeleteBucketRequest`): The request object. The parameters to `UndeleteBucket`. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -501,14 +503,15 @@ async def list_views( r"""Lists views on a bucket. Args: - request (:class:`~.logging_config.ListViewsRequest`): + request (:class:`google.cloud.logging_v2.types.ListViewsRequest`): The request object. The parameters to `ListViews`. parent (:class:`str`): Required. The bucket whose views are to be listed: :: - "projects/[PROJECT_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]". + "projects/[PROJECT_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]" + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -520,7 +523,7 @@ async def list_views( sent along with the request as metadata. Returns: - ~.pagers.ListViewsAsyncPager: + google.cloud.logging_v2.services.config_service_v2.pagers.ListViewsAsyncPager: The response from ListViews. Iterating over this object will yield results and resolve additional pages @@ -582,7 +585,7 @@ async def get_view( r"""Gets a view. Args: - request (:class:`~.logging_config.GetViewRequest`): + request (:class:`google.cloud.logging_v2.types.GetViewRequest`): The request object. The parameters to `GetView`. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -592,7 +595,7 @@ async def get_view( sent along with the request as metadata. Returns: - ~.logging_config.LogView: + google.cloud.logging_v2.types.LogView: Describes a view over logs in a bucket. @@ -633,7 +636,7 @@ async def create_view( contain a maximum of 50 views. Args: - request (:class:`~.logging_config.CreateViewRequest`): + request (:class:`google.cloud.logging_v2.types.CreateViewRequest`): The request object. The parameters to `CreateView`. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -643,7 +646,7 @@ async def create_view( sent along with the request as metadata. Returns: - ~.logging_config.LogView: + google.cloud.logging_v2.types.LogView: Describes a view over logs in a bucket. @@ -684,7 +687,7 @@ async def update_view( existing view with values from the new view: ``filter``. Args: - request (:class:`~.logging_config.UpdateViewRequest`): + request (:class:`google.cloud.logging_v2.types.UpdateViewRequest`): The request object. The parameters to `UpdateView`. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -694,7 +697,7 @@ async def update_view( sent along with the request as metadata. Returns: - ~.logging_config.LogView: + google.cloud.logging_v2.types.LogView: Describes a view over logs in a bucket. @@ -734,7 +737,7 @@ async def delete_view( r"""Deletes a view from a bucket. Args: - request (:class:`~.logging_config.DeleteViewRequest`): + request (:class:`google.cloud.logging_v2.types.DeleteViewRequest`): The request object. The parameters to `DeleteView`. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -778,7 +781,7 @@ async def list_sinks( r"""Lists sinks. Args: - request (:class:`~.logging_config.ListSinksRequest`): + request (:class:`google.cloud.logging_v2.types.ListSinksRequest`): The request object. The parameters to `ListSinks`. parent (:class:`str`): Required. The parent resource whose sinks are to be @@ -789,7 +792,8 @@ async def list_sinks( "projects/[PROJECT_ID]" "organizations/[ORGANIZATION_ID]" "billingAccounts/[BILLING_ACCOUNT_ID]" - "folders/[FOLDER_ID]". + "folders/[FOLDER_ID]" + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -801,8 +805,8 @@ async def list_sinks( sent along with the request as metadata. Returns: - ~.pagers.ListSinksAsyncPager: - Result returned from ``ListSinks``. + google.cloud.logging_v2.services.config_service_v2.pagers.ListSinksAsyncPager: + Result returned from ListSinks. Iterating over this object will yield results and resolve additional pages automatically. @@ -874,7 +878,7 @@ async def get_sink( r"""Gets a sink. Args: - request (:class:`~.logging_config.GetSinkRequest`): + request (:class:`google.cloud.logging_v2.types.GetSinkRequest`): The request object. The parameters to `GetSink`. sink_name (:class:`str`): Required. The resource name of the sink: @@ -887,6 +891,7 @@ async def get_sink( "folders/[FOLDER_ID]/sinks/[SINK_ID]" Example: ``"projects/my-project-id/sinks/my-sink-id"``. + This corresponds to the ``sink_name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -898,7 +903,7 @@ async def get_sink( sent along with the request as metadata. Returns: - ~.logging_config.LogSink: + google.cloud.logging_v2.types.LogSink: Describes a sink used to export log entries to one of the following destinations in any project: a Cloud @@ -977,7 +982,7 @@ async def create_sink( entries only from the resource owning the sink. Args: - request (:class:`~.logging_config.CreateSinkRequest`): + request (:class:`google.cloud.logging_v2.types.CreateSinkRequest`): The request object. The parameters to `CreateSink`. parent (:class:`str`): Required. The resource in which to create the sink: @@ -991,12 +996,14 @@ async def create_sink( Examples: ``"projects/my-logging-project"``, ``"organizations/123456789"``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - sink (:class:`~.logging_config.LogSink`): + sink (:class:`google.cloud.logging_v2.types.LogSink`): Required. The new sink, whose ``name`` parameter is a sink identifier that is not already in use. + This corresponds to the ``sink`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1008,7 +1015,7 @@ async def create_sink( sent along with the request as metadata. Returns: - ~.logging_config.LogSink: + google.cloud.logging_v2.types.LogSink: Describes a sink used to export log entries to one of the following destinations in any project: a Cloud @@ -1079,7 +1086,7 @@ async def update_sink( the ``unique_writer_identity`` field. Args: - request (:class:`~.logging_config.UpdateSinkRequest`): + request (:class:`google.cloud.logging_v2.types.UpdateSinkRequest`): The request object. The parameters to `UpdateSink`. sink_name (:class:`str`): Required. The full resource name of the sink to update, @@ -1093,16 +1100,18 @@ async def update_sink( "folders/[FOLDER_ID]/sinks/[SINK_ID]" Example: ``"projects/my-project-id/sinks/my-sink-id"``. + This corresponds to the ``sink_name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - sink (:class:`~.logging_config.LogSink`): + sink (:class:`google.cloud.logging_v2.types.LogSink`): Required. The updated sink, whose name is the same identifier that appears as part of ``sink_name``. + This corresponds to the ``sink`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - update_mask (:class:`~.field_mask.FieldMask`): + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): Optional. Field mask that specifies the fields in ``sink`` that need an update. A sink field will be overwritten if, and only if, it is in the update mask. @@ -1118,6 +1127,7 @@ async def update_sink( https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#google.protobuf.FieldMask Example: ``updateMask=filter``. + This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1129,7 +1139,7 @@ async def update_sink( sent along with the request as metadata. Returns: - ~.logging_config.LogSink: + google.cloud.logging_v2.types.LogSink: Describes a sink used to export log entries to one of the following destinations in any project: a Cloud @@ -1208,7 +1218,7 @@ async def delete_sink( then that service account is also deleted. Args: - request (:class:`~.logging_config.DeleteSinkRequest`): + request (:class:`google.cloud.logging_v2.types.DeleteSinkRequest`): The request object. The parameters to `DeleteSink`. sink_name (:class:`str`): Required. The full resource name of the sink to delete, @@ -1222,6 +1232,7 @@ async def delete_sink( "folders/[FOLDER_ID]/sinks/[SINK_ID]" Example: ``"projects/my-project-id/sinks/my-sink-id"``. + This corresponds to the ``sink_name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1293,7 +1304,7 @@ async def list_exclusions( r"""Lists all the exclusions in a parent resource. Args: - request (:class:`~.logging_config.ListExclusionsRequest`): + request (:class:`google.cloud.logging_v2.types.ListExclusionsRequest`): The request object. The parameters to `ListExclusions`. parent (:class:`str`): Required. The parent resource whose exclusions are to be @@ -1304,7 +1315,8 @@ async def list_exclusions( "projects/[PROJECT_ID]" "organizations/[ORGANIZATION_ID]" "billingAccounts/[BILLING_ACCOUNT_ID]" - "folders/[FOLDER_ID]". + "folders/[FOLDER_ID]" + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1316,8 +1328,8 @@ async def list_exclusions( sent along with the request as metadata. Returns: - ~.pagers.ListExclusionsAsyncPager: - Result returned from ``ListExclusions``. + google.cloud.logging_v2.services.config_service_v2.pagers.ListExclusionsAsyncPager: + Result returned from ListExclusions. Iterating over this object will yield results and resolve additional pages automatically. @@ -1389,7 +1401,7 @@ async def get_exclusion( r"""Gets the description of an exclusion. Args: - request (:class:`~.logging_config.GetExclusionRequest`): + request (:class:`google.cloud.logging_v2.types.GetExclusionRequest`): The request object. The parameters to `GetExclusion`. name (:class:`str`): Required. The resource name of an existing exclusion: @@ -1403,6 +1415,7 @@ async def get_exclusion( Example: ``"projects/my-project-id/exclusions/my-exclusion-id"``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1414,7 +1427,7 @@ async def get_exclusion( sent along with the request as metadata. Returns: - ~.logging_config.LogExclusion: + google.cloud.logging_v2.types.LogExclusion: Specifies a set of log entries that are not to be stored in Logging. If your GCP resource receives a large volume of @@ -1492,7 +1505,7 @@ async def create_exclusion( resource. Args: - request (:class:`~.logging_config.CreateExclusionRequest`): + request (:class:`google.cloud.logging_v2.types.CreateExclusionRequest`): The request object. The parameters to `CreateExclusion`. parent (:class:`str`): Required. The parent resource in which to create the @@ -1507,13 +1520,15 @@ async def create_exclusion( Examples: ``"projects/my-logging-project"``, ``"organizations/123456789"``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - exclusion (:class:`~.logging_config.LogExclusion`): + exclusion (:class:`google.cloud.logging_v2.types.LogExclusion`): Required. The new exclusion, whose ``name`` parameter is an exclusion name that is not already used in the parent resource. + This corresponds to the ``exclusion`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1525,7 +1540,7 @@ async def create_exclusion( sent along with the request as metadata. Returns: - ~.logging_config.LogExclusion: + google.cloud.logging_v2.types.LogExclusion: Specifies a set of log entries that are not to be stored in Logging. If your GCP resource receives a large volume of @@ -1594,7 +1609,7 @@ async def update_exclusion( exclusion. Args: - request (:class:`~.logging_config.UpdateExclusionRequest`): + request (:class:`google.cloud.logging_v2.types.UpdateExclusionRequest`): The request object. The parameters to `UpdateExclusion`. name (:class:`str`): Required. The resource name of the exclusion to update: @@ -1608,16 +1623,18 @@ async def update_exclusion( Example: ``"projects/my-project-id/exclusions/my-exclusion-id"``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - exclusion (:class:`~.logging_config.LogExclusion`): + exclusion (:class:`google.cloud.logging_v2.types.LogExclusion`): Required. New values for the existing exclusion. Only the fields specified in ``update_mask`` are relevant. + This corresponds to the ``exclusion`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - update_mask (:class:`~.field_mask.FieldMask`): + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): Required. A non-empty list of fields to change in the existing exclusion. New values for the fields are taken from the corresponding fields in the @@ -1628,6 +1645,7 @@ async def update_exclusion( For example, to change the filter and description of an exclusion, specify an ``update_mask`` of ``"filter,description"``. + This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1639,7 +1657,7 @@ async def update_exclusion( sent along with the request as metadata. Returns: - ~.logging_config.LogExclusion: + google.cloud.logging_v2.types.LogExclusion: Specifies a set of log entries that are not to be stored in Logging. If your GCP resource receives a large volume of @@ -1707,7 +1725,7 @@ async def delete_exclusion( r"""Deletes an exclusion. Args: - request (:class:`~.logging_config.DeleteExclusionRequest`): + request (:class:`google.cloud.logging_v2.types.DeleteExclusionRequest`): The request object. The parameters to `DeleteExclusion`. name (:class:`str`): Required. The resource name of an existing exclusion to @@ -1722,6 +1740,7 @@ async def delete_exclusion( Example: ``"projects/my-project-id/exclusions/my-exclusion-id"``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1798,7 +1817,7 @@ async def get_cmek_settings( for more information. Args: - request (:class:`~.logging_config.GetCmekSettingsRequest`): + request (:class:`google.cloud.logging_v2.types.GetCmekSettingsRequest`): The request object. The parameters to [GetCmekSettings][google.logging.v2.ConfigServiceV2.GetCmekSettings]. See [Enabling CMEK for Logs @@ -1812,19 +1831,19 @@ async def get_cmek_settings( sent along with the request as metadata. Returns: - ~.logging_config.CmekSettings: - Describes the customer-managed encryption key (CMEK) - settings associated with a project, folder, - organization, billing account, or flexible resource. + google.cloud.logging_v2.types.CmekSettings: + Describes the customer-managed encryption key (CMEK) settings associated with + a project, folder, organization, billing account, or + flexible resource. - Note: CMEK for the Logs Router can currently only be - configured for GCP organizations. Once configured, it - applies to all projects and folders in the GCP - organization. + Note: CMEK for the Logs Router can currently only be + configured for GCP organizations. Once configured, it + applies to all projects and folders in the GCP + organization. - See `Enabling CMEK for Logs - Router `__ - for more information. + See [Enabling CMEK for Logs + Router](\ https://cloud.google.com/logging/docs/routing/managed-encryption) + for more information. """ # Create or coerce a protobuf request object. @@ -1876,7 +1895,7 @@ async def update_cmek_settings( for more information. Args: - request (:class:`~.logging_config.UpdateCmekSettingsRequest`): + request (:class:`google.cloud.logging_v2.types.UpdateCmekSettingsRequest`): The request object. The parameters to [UpdateCmekSettings][google.logging.v2.ConfigServiceV2.UpdateCmekSettings]. See [Enabling CMEK for Logs @@ -1890,19 +1909,19 @@ async def update_cmek_settings( sent along with the request as metadata. Returns: - ~.logging_config.CmekSettings: - Describes the customer-managed encryption key (CMEK) - settings associated with a project, folder, - organization, billing account, or flexible resource. - - Note: CMEK for the Logs Router can currently only be - configured for GCP organizations. Once configured, it - applies to all projects and folders in the GCP - organization. - - See `Enabling CMEK for Logs - Router `__ - for more information. + google.cloud.logging_v2.types.CmekSettings: + Describes the customer-managed encryption key (CMEK) settings associated with + a project, folder, organization, billing account, or + flexible resource. + + Note: CMEK for the Logs Router can currently only be + configured for GCP organizations. Once configured, it + applies to all projects and folders in the GCP + organization. + + See [Enabling CMEK for Logs + Router](\ https://cloud.google.com/logging/docs/routing/managed-encryption) + for more information. """ # Create or coerce a protobuf request object. diff --git a/google/cloud/logging_v2/services/config_service_v2/client.py b/google/cloud/logging_v2/services/config_service_v2/client.py index a16f5f20b..7d6492ba0 100644 --- a/google/cloud/logging_v2/services/config_service_v2/client.py +++ b/google/cloud/logging_v2/services/config_service_v2/client.py @@ -112,6 +112,22 @@ def _get_default_mtls_endpoint(api_endpoint): DEFAULT_ENDPOINT ) + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + ConfigServiceV2Client: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_info(info) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials @@ -124,7 +140,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): kwargs: Additional arguments to pass to the constructor. Returns: - {@api.name}: The constructed client. + ConfigServiceV2Client: The constructed client. """ credentials = service_account.Credentials.from_service_account_file(filename) kwargs["credentials"] = credentials @@ -283,10 +299,10 @@ def __init__( credentials identify the application to the service; if none are specified, the client will attempt to ascertain the credentials from the environment. - transport (Union[str, ~.ConfigServiceV2Transport]): The + transport (Union[str, ConfigServiceV2Transport]): The transport to use. If set to None, a transport is chosen automatically. - client_options (client_options_lib.ClientOptions): Custom options for the + client_options (google.api_core.client_options.ClientOptions): Custom options for the client. It won't take effect if a ``transport`` instance is provided. (1) The ``api_endpoint`` property can be used to override the default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT @@ -396,9 +412,9 @@ def list_buckets( r"""Lists buckets. Args: - request (:class:`~.logging_config.ListBucketsRequest`): + request (google.cloud.logging_v2.types.ListBucketsRequest): The request object. The parameters to `ListBuckets`. - parent (:class:`str`): + parent (str): Required. The parent resource whose buckets are to be listed: @@ -412,6 +428,7 @@ def list_buckets( Note: The locations portion of the resource must be specified, but supplying the character ``-`` in place of [LOCATION_ID] will return all buckets. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -423,7 +440,7 @@ def list_buckets( sent along with the request as metadata. Returns: - ~.pagers.ListBucketsPager: + google.cloud.logging_v2.services.config_service_v2.pagers.ListBucketsPager: The response from ListBuckets. Iterating over this object will yield results and resolve additional pages @@ -486,7 +503,7 @@ def get_bucket( r"""Gets a bucket. Args: - request (:class:`~.logging_config.GetBucketRequest`): + request (google.cloud.logging_v2.types.GetBucketRequest): The request object. The parameters to `GetBucket`. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -496,7 +513,7 @@ def get_bucket( sent along with the request as metadata. Returns: - ~.logging_config.LogBucket: + google.cloud.logging_v2.types.LogBucket: Describes a repository of logs. """ # Create or coerce a protobuf request object. @@ -537,7 +554,7 @@ def create_bucket( cannot be changed. Args: - request (:class:`~.logging_config.CreateBucketRequest`): + request (google.cloud.logging_v2.types.CreateBucketRequest): The request object. The parameters to `CreateBucket`. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -547,7 +564,7 @@ def create_bucket( sent along with the request as metadata. Returns: - ~.logging_config.LogBucket: + google.cloud.logging_v2.types.LogBucket: Describes a repository of logs. """ # Create or coerce a protobuf request object. @@ -596,7 +613,7 @@ def update_bucket( A buckets region may not be modified after it is created. Args: - request (:class:`~.logging_config.UpdateBucketRequest`): + request (google.cloud.logging_v2.types.UpdateBucketRequest): The request object. The parameters to `UpdateBucket`. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -606,7 +623,7 @@ def update_bucket( sent along with the request as metadata. Returns: - ~.logging_config.LogBucket: + google.cloud.logging_v2.types.LogBucket: Describes a repository of logs. """ # Create or coerce a protobuf request object. @@ -647,7 +664,7 @@ def delete_bucket( the bucket will be permanently deleted. Args: - request (:class:`~.logging_config.DeleteBucketRequest`): + request (google.cloud.logging_v2.types.DeleteBucketRequest): The request object. The parameters to `DeleteBucket`. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -692,7 +709,7 @@ def undelete_bucket( may be undeleted within the grace period of 7 days. Args: - request (:class:`~.logging_config.UndeleteBucketRequest`): + request (google.cloud.logging_v2.types.UndeleteBucketRequest): The request object. The parameters to `UndeleteBucket`. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -737,14 +754,15 @@ def list_views( r"""Lists views on a bucket. Args: - request (:class:`~.logging_config.ListViewsRequest`): + request (google.cloud.logging_v2.types.ListViewsRequest): The request object. The parameters to `ListViews`. - parent (:class:`str`): + parent (str): Required. The bucket whose views are to be listed: :: - "projects/[PROJECT_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]". + "projects/[PROJECT_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]" + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -756,7 +774,7 @@ def list_views( sent along with the request as metadata. Returns: - ~.pagers.ListViewsPager: + google.cloud.logging_v2.services.config_service_v2.pagers.ListViewsPager: The response from ListViews. Iterating over this object will yield results and resolve additional pages @@ -819,7 +837,7 @@ def get_view( r"""Gets a view. Args: - request (:class:`~.logging_config.GetViewRequest`): + request (google.cloud.logging_v2.types.GetViewRequest): The request object. The parameters to `GetView`. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -829,7 +847,7 @@ def get_view( sent along with the request as metadata. Returns: - ~.logging_config.LogView: + google.cloud.logging_v2.types.LogView: Describes a view over logs in a bucket. @@ -871,7 +889,7 @@ def create_view( contain a maximum of 50 views. Args: - request (:class:`~.logging_config.CreateViewRequest`): + request (google.cloud.logging_v2.types.CreateViewRequest): The request object. The parameters to `CreateView`. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -881,7 +899,7 @@ def create_view( sent along with the request as metadata. Returns: - ~.logging_config.LogView: + google.cloud.logging_v2.types.LogView: Describes a view over logs in a bucket. @@ -923,7 +941,7 @@ def update_view( existing view with values from the new view: ``filter``. Args: - request (:class:`~.logging_config.UpdateViewRequest`): + request (google.cloud.logging_v2.types.UpdateViewRequest): The request object. The parameters to `UpdateView`. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -933,7 +951,7 @@ def update_view( sent along with the request as metadata. Returns: - ~.logging_config.LogView: + google.cloud.logging_v2.types.LogView: Describes a view over logs in a bucket. @@ -974,7 +992,7 @@ def delete_view( r"""Deletes a view from a bucket. Args: - request (:class:`~.logging_config.DeleteViewRequest`): + request (google.cloud.logging_v2.types.DeleteViewRequest): The request object. The parameters to `DeleteView`. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -1019,9 +1037,9 @@ def list_sinks( r"""Lists sinks. Args: - request (:class:`~.logging_config.ListSinksRequest`): + request (google.cloud.logging_v2.types.ListSinksRequest): The request object. The parameters to `ListSinks`. - parent (:class:`str`): + parent (str): Required. The parent resource whose sinks are to be listed: @@ -1030,7 +1048,8 @@ def list_sinks( "projects/[PROJECT_ID]" "organizations/[ORGANIZATION_ID]" "billingAccounts/[BILLING_ACCOUNT_ID]" - "folders/[FOLDER_ID]". + "folders/[FOLDER_ID]" + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1042,8 +1061,8 @@ def list_sinks( sent along with the request as metadata. Returns: - ~.pagers.ListSinksPager: - Result returned from ``ListSinks``. + google.cloud.logging_v2.services.config_service_v2.pagers.ListSinksPager: + Result returned from ListSinks. Iterating over this object will yield results and resolve additional pages automatically. @@ -1106,9 +1125,9 @@ def get_sink( r"""Gets a sink. Args: - request (:class:`~.logging_config.GetSinkRequest`): + request (google.cloud.logging_v2.types.GetSinkRequest): The request object. The parameters to `GetSink`. - sink_name (:class:`str`): + sink_name (str): Required. The resource name of the sink: :: @@ -1119,6 +1138,7 @@ def get_sink( "folders/[FOLDER_ID]/sinks/[SINK_ID]" Example: ``"projects/my-project-id/sinks/my-sink-id"``. + This corresponds to the ``sink_name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1130,7 +1150,7 @@ def get_sink( sent along with the request as metadata. Returns: - ~.logging_config.LogSink: + google.cloud.logging_v2.types.LogSink: Describes a sink used to export log entries to one of the following destinations in any project: a Cloud @@ -1200,9 +1220,9 @@ def create_sink( entries only from the resource owning the sink. Args: - request (:class:`~.logging_config.CreateSinkRequest`): + request (google.cloud.logging_v2.types.CreateSinkRequest): The request object. The parameters to `CreateSink`. - parent (:class:`str`): + parent (str): Required. The resource in which to create the sink: :: @@ -1214,12 +1234,14 @@ def create_sink( Examples: ``"projects/my-logging-project"``, ``"organizations/123456789"``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - sink (:class:`~.logging_config.LogSink`): + sink (google.cloud.logging_v2.types.LogSink): Required. The new sink, whose ``name`` parameter is a sink identifier that is not already in use. + This corresponds to the ``sink`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1231,7 +1253,7 @@ def create_sink( sent along with the request as metadata. Returns: - ~.logging_config.LogSink: + google.cloud.logging_v2.types.LogSink: Describes a sink used to export log entries to one of the following destinations in any project: a Cloud @@ -1303,9 +1325,9 @@ def update_sink( the ``unique_writer_identity`` field. Args: - request (:class:`~.logging_config.UpdateSinkRequest`): + request (google.cloud.logging_v2.types.UpdateSinkRequest): The request object. The parameters to `UpdateSink`. - sink_name (:class:`str`): + sink_name (str): Required. The full resource name of the sink to update, including the parent resource and the sink identifier: @@ -1317,16 +1339,18 @@ def update_sink( "folders/[FOLDER_ID]/sinks/[SINK_ID]" Example: ``"projects/my-project-id/sinks/my-sink-id"``. + This corresponds to the ``sink_name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - sink (:class:`~.logging_config.LogSink`): + sink (google.cloud.logging_v2.types.LogSink): Required. The updated sink, whose name is the same identifier that appears as part of ``sink_name``. + This corresponds to the ``sink`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - update_mask (:class:`~.field_mask.FieldMask`): + update_mask (google.protobuf.field_mask_pb2.FieldMask): Optional. Field mask that specifies the fields in ``sink`` that need an update. A sink field will be overwritten if, and only if, it is in the update mask. @@ -1342,6 +1366,7 @@ def update_sink( https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#google.protobuf.FieldMask Example: ``updateMask=filter``. + This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1353,7 +1378,7 @@ def update_sink( sent along with the request as metadata. Returns: - ~.logging_config.LogSink: + google.cloud.logging_v2.types.LogSink: Describes a sink used to export log entries to one of the following destinations in any project: a Cloud @@ -1423,9 +1448,9 @@ def delete_sink( then that service account is also deleted. Args: - request (:class:`~.logging_config.DeleteSinkRequest`): + request (google.cloud.logging_v2.types.DeleteSinkRequest): The request object. The parameters to `DeleteSink`. - sink_name (:class:`str`): + sink_name (str): Required. The full resource name of the sink to delete, including the parent resource and the sink identifier: @@ -1437,6 +1462,7 @@ def delete_sink( "folders/[FOLDER_ID]/sinks/[SINK_ID]" Example: ``"projects/my-project-id/sinks/my-sink-id"``. + This corresponds to the ``sink_name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1499,9 +1525,9 @@ def list_exclusions( r"""Lists all the exclusions in a parent resource. Args: - request (:class:`~.logging_config.ListExclusionsRequest`): + request (google.cloud.logging_v2.types.ListExclusionsRequest): The request object. The parameters to `ListExclusions`. - parent (:class:`str`): + parent (str): Required. The parent resource whose exclusions are to be listed. @@ -1510,7 +1536,8 @@ def list_exclusions( "projects/[PROJECT_ID]" "organizations/[ORGANIZATION_ID]" "billingAccounts/[BILLING_ACCOUNT_ID]" - "folders/[FOLDER_ID]". + "folders/[FOLDER_ID]" + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1522,8 +1549,8 @@ def list_exclusions( sent along with the request as metadata. Returns: - ~.pagers.ListExclusionsPager: - Result returned from ``ListExclusions``. + google.cloud.logging_v2.services.config_service_v2.pagers.ListExclusionsPager: + Result returned from ListExclusions. Iterating over this object will yield results and resolve additional pages automatically. @@ -1586,9 +1613,9 @@ def get_exclusion( r"""Gets the description of an exclusion. Args: - request (:class:`~.logging_config.GetExclusionRequest`): + request (google.cloud.logging_v2.types.GetExclusionRequest): The request object. The parameters to `GetExclusion`. - name (:class:`str`): + name (str): Required. The resource name of an existing exclusion: :: @@ -1600,6 +1627,7 @@ def get_exclusion( Example: ``"projects/my-project-id/exclusions/my-exclusion-id"``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1611,7 +1639,7 @@ def get_exclusion( sent along with the request as metadata. Returns: - ~.logging_config.LogExclusion: + google.cloud.logging_v2.types.LogExclusion: Specifies a set of log entries that are not to be stored in Logging. If your GCP resource receives a large volume of @@ -1680,9 +1708,9 @@ def create_exclusion( resource. Args: - request (:class:`~.logging_config.CreateExclusionRequest`): + request (google.cloud.logging_v2.types.CreateExclusionRequest): The request object. The parameters to `CreateExclusion`. - parent (:class:`str`): + parent (str): Required. The parent resource in which to create the exclusion: @@ -1695,13 +1723,15 @@ def create_exclusion( Examples: ``"projects/my-logging-project"``, ``"organizations/123456789"``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - exclusion (:class:`~.logging_config.LogExclusion`): + exclusion (google.cloud.logging_v2.types.LogExclusion): Required. The new exclusion, whose ``name`` parameter is an exclusion name that is not already used in the parent resource. + This corresponds to the ``exclusion`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1713,7 +1743,7 @@ def create_exclusion( sent along with the request as metadata. Returns: - ~.logging_config.LogExclusion: + google.cloud.logging_v2.types.LogExclusion: Specifies a set of log entries that are not to be stored in Logging. If your GCP resource receives a large volume of @@ -1783,9 +1813,9 @@ def update_exclusion( exclusion. Args: - request (:class:`~.logging_config.UpdateExclusionRequest`): + request (google.cloud.logging_v2.types.UpdateExclusionRequest): The request object. The parameters to `UpdateExclusion`. - name (:class:`str`): + name (str): Required. The resource name of the exclusion to update: :: @@ -1797,16 +1827,18 @@ def update_exclusion( Example: ``"projects/my-project-id/exclusions/my-exclusion-id"``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - exclusion (:class:`~.logging_config.LogExclusion`): + exclusion (google.cloud.logging_v2.types.LogExclusion): Required. New values for the existing exclusion. Only the fields specified in ``update_mask`` are relevant. + This corresponds to the ``exclusion`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - update_mask (:class:`~.field_mask.FieldMask`): + update_mask (google.protobuf.field_mask_pb2.FieldMask): Required. A non-empty list of fields to change in the existing exclusion. New values for the fields are taken from the corresponding fields in the @@ -1817,6 +1849,7 @@ def update_exclusion( For example, to change the filter and description of an exclusion, specify an ``update_mask`` of ``"filter,description"``. + This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1828,7 +1861,7 @@ def update_exclusion( sent along with the request as metadata. Returns: - ~.logging_config.LogExclusion: + google.cloud.logging_v2.types.LogExclusion: Specifies a set of log entries that are not to be stored in Logging. If your GCP resource receives a large volume of @@ -1897,9 +1930,9 @@ def delete_exclusion( r"""Deletes an exclusion. Args: - request (:class:`~.logging_config.DeleteExclusionRequest`): + request (google.cloud.logging_v2.types.DeleteExclusionRequest): The request object. The parameters to `DeleteExclusion`. - name (:class:`str`): + name (str): Required. The resource name of an existing exclusion to delete: @@ -1912,6 +1945,7 @@ def delete_exclusion( Example: ``"projects/my-project-id/exclusions/my-exclusion-id"``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1979,7 +2013,7 @@ def get_cmek_settings( for more information. Args: - request (:class:`~.logging_config.GetCmekSettingsRequest`): + request (google.cloud.logging_v2.types.GetCmekSettingsRequest): The request object. The parameters to [GetCmekSettings][google.logging.v2.ConfigServiceV2.GetCmekSettings]. See [Enabling CMEK for Logs @@ -1993,19 +2027,19 @@ def get_cmek_settings( sent along with the request as metadata. Returns: - ~.logging_config.CmekSettings: - Describes the customer-managed encryption key (CMEK) - settings associated with a project, folder, - organization, billing account, or flexible resource. + google.cloud.logging_v2.types.CmekSettings: + Describes the customer-managed encryption key (CMEK) settings associated with + a project, folder, organization, billing account, or + flexible resource. - Note: CMEK for the Logs Router can currently only be - configured for GCP organizations. Once configured, it - applies to all projects and folders in the GCP - organization. + Note: CMEK for the Logs Router can currently only be + configured for GCP organizations. Once configured, it + applies to all projects and folders in the GCP + organization. - See `Enabling CMEK for Logs - Router `__ - for more information. + See [Enabling CMEK for Logs + Router](\ https://cloud.google.com/logging/docs/routing/managed-encryption) + for more information. """ # Create or coerce a protobuf request object. @@ -2058,7 +2092,7 @@ def update_cmek_settings( for more information. Args: - request (:class:`~.logging_config.UpdateCmekSettingsRequest`): + request (google.cloud.logging_v2.types.UpdateCmekSettingsRequest): The request object. The parameters to [UpdateCmekSettings][google.logging.v2.ConfigServiceV2.UpdateCmekSettings]. See [Enabling CMEK for Logs @@ -2072,19 +2106,19 @@ def update_cmek_settings( sent along with the request as metadata. Returns: - ~.logging_config.CmekSettings: - Describes the customer-managed encryption key (CMEK) - settings associated with a project, folder, - organization, billing account, or flexible resource. - - Note: CMEK for the Logs Router can currently only be - configured for GCP organizations. Once configured, it - applies to all projects and folders in the GCP - organization. - - See `Enabling CMEK for Logs - Router `__ - for more information. + google.cloud.logging_v2.types.CmekSettings: + Describes the customer-managed encryption key (CMEK) settings associated with + a project, folder, organization, billing account, or + flexible resource. + + Note: CMEK for the Logs Router can currently only be + configured for GCP organizations. Once configured, it + applies to all projects and folders in the GCP + organization. + + See [Enabling CMEK for Logs + Router](\ https://cloud.google.com/logging/docs/routing/managed-encryption) + for more information. """ # Create or coerce a protobuf request object. diff --git a/google/cloud/logging_v2/services/config_service_v2/pagers.py b/google/cloud/logging_v2/services/config_service_v2/pagers.py index 8e1c4ee0d..af5c5faf6 100644 --- a/google/cloud/logging_v2/services/config_service_v2/pagers.py +++ b/google/cloud/logging_v2/services/config_service_v2/pagers.py @@ -24,7 +24,7 @@ class ListBucketsPager: """A pager for iterating through ``list_buckets`` requests. This class thinly wraps an initial - :class:`~.logging_config.ListBucketsResponse` object, and + :class:`google.cloud.logging_v2.types.ListBucketsResponse` object, and provides an ``__iter__`` method to iterate through its ``buckets`` field. @@ -33,7 +33,7 @@ class ListBucketsPager: through the ``buckets`` field on the corresponding responses. - All the usual :class:`~.logging_config.ListBucketsResponse` + All the usual :class:`google.cloud.logging_v2.types.ListBucketsResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -51,9 +51,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.logging_config.ListBucketsRequest`): + request (google.cloud.logging_v2.types.ListBucketsRequest): The initial request object. - response (:class:`~.logging_config.ListBucketsResponse`): + response (google.cloud.logging_v2.types.ListBucketsResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -86,7 +86,7 @@ class ListBucketsAsyncPager: """A pager for iterating through ``list_buckets`` requests. This class thinly wraps an initial - :class:`~.logging_config.ListBucketsResponse` object, and + :class:`google.cloud.logging_v2.types.ListBucketsResponse` object, and provides an ``__aiter__`` method to iterate through its ``buckets`` field. @@ -95,7 +95,7 @@ class ListBucketsAsyncPager: through the ``buckets`` field on the corresponding responses. - All the usual :class:`~.logging_config.ListBucketsResponse` + All the usual :class:`google.cloud.logging_v2.types.ListBucketsResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -113,9 +113,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.logging_config.ListBucketsRequest`): + request (google.cloud.logging_v2.types.ListBucketsRequest): The initial request object. - response (:class:`~.logging_config.ListBucketsResponse`): + response (google.cloud.logging_v2.types.ListBucketsResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -152,7 +152,7 @@ class ListViewsPager: """A pager for iterating through ``list_views`` requests. This class thinly wraps an initial - :class:`~.logging_config.ListViewsResponse` object, and + :class:`google.cloud.logging_v2.types.ListViewsResponse` object, and provides an ``__iter__`` method to iterate through its ``views`` field. @@ -161,7 +161,7 @@ class ListViewsPager: through the ``views`` field on the corresponding responses. - All the usual :class:`~.logging_config.ListViewsResponse` + All the usual :class:`google.cloud.logging_v2.types.ListViewsResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -179,9 +179,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.logging_config.ListViewsRequest`): + request (google.cloud.logging_v2.types.ListViewsRequest): The initial request object. - response (:class:`~.logging_config.ListViewsResponse`): + response (google.cloud.logging_v2.types.ListViewsResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -214,7 +214,7 @@ class ListViewsAsyncPager: """A pager for iterating through ``list_views`` requests. This class thinly wraps an initial - :class:`~.logging_config.ListViewsResponse` object, and + :class:`google.cloud.logging_v2.types.ListViewsResponse` object, and provides an ``__aiter__`` method to iterate through its ``views`` field. @@ -223,7 +223,7 @@ class ListViewsAsyncPager: through the ``views`` field on the corresponding responses. - All the usual :class:`~.logging_config.ListViewsResponse` + All the usual :class:`google.cloud.logging_v2.types.ListViewsResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -241,9 +241,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.logging_config.ListViewsRequest`): + request (google.cloud.logging_v2.types.ListViewsRequest): The initial request object. - response (:class:`~.logging_config.ListViewsResponse`): + response (google.cloud.logging_v2.types.ListViewsResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -280,7 +280,7 @@ class ListSinksPager: """A pager for iterating through ``list_sinks`` requests. This class thinly wraps an initial - :class:`~.logging_config.ListSinksResponse` object, and + :class:`google.cloud.logging_v2.types.ListSinksResponse` object, and provides an ``__iter__`` method to iterate through its ``sinks`` field. @@ -289,7 +289,7 @@ class ListSinksPager: through the ``sinks`` field on the corresponding responses. - All the usual :class:`~.logging_config.ListSinksResponse` + All the usual :class:`google.cloud.logging_v2.types.ListSinksResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -307,9 +307,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.logging_config.ListSinksRequest`): + request (google.cloud.logging_v2.types.ListSinksRequest): The initial request object. - response (:class:`~.logging_config.ListSinksResponse`): + response (google.cloud.logging_v2.types.ListSinksResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -342,7 +342,7 @@ class ListSinksAsyncPager: """A pager for iterating through ``list_sinks`` requests. This class thinly wraps an initial - :class:`~.logging_config.ListSinksResponse` object, and + :class:`google.cloud.logging_v2.types.ListSinksResponse` object, and provides an ``__aiter__`` method to iterate through its ``sinks`` field. @@ -351,7 +351,7 @@ class ListSinksAsyncPager: through the ``sinks`` field on the corresponding responses. - All the usual :class:`~.logging_config.ListSinksResponse` + All the usual :class:`google.cloud.logging_v2.types.ListSinksResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -369,9 +369,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.logging_config.ListSinksRequest`): + request (google.cloud.logging_v2.types.ListSinksRequest): The initial request object. - response (:class:`~.logging_config.ListSinksResponse`): + response (google.cloud.logging_v2.types.ListSinksResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -408,7 +408,7 @@ class ListExclusionsPager: """A pager for iterating through ``list_exclusions`` requests. This class thinly wraps an initial - :class:`~.logging_config.ListExclusionsResponse` object, and + :class:`google.cloud.logging_v2.types.ListExclusionsResponse` object, and provides an ``__iter__`` method to iterate through its ``exclusions`` field. @@ -417,7 +417,7 @@ class ListExclusionsPager: through the ``exclusions`` field on the corresponding responses. - All the usual :class:`~.logging_config.ListExclusionsResponse` + All the usual :class:`google.cloud.logging_v2.types.ListExclusionsResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -435,9 +435,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.logging_config.ListExclusionsRequest`): + request (google.cloud.logging_v2.types.ListExclusionsRequest): The initial request object. - response (:class:`~.logging_config.ListExclusionsResponse`): + response (google.cloud.logging_v2.types.ListExclusionsResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -470,7 +470,7 @@ class ListExclusionsAsyncPager: """A pager for iterating through ``list_exclusions`` requests. This class thinly wraps an initial - :class:`~.logging_config.ListExclusionsResponse` object, and + :class:`google.cloud.logging_v2.types.ListExclusionsResponse` object, and provides an ``__aiter__`` method to iterate through its ``exclusions`` field. @@ -479,7 +479,7 @@ class ListExclusionsAsyncPager: through the ``exclusions`` field on the corresponding responses. - All the usual :class:`~.logging_config.ListExclusionsResponse` + All the usual :class:`google.cloud.logging_v2.types.ListExclusionsResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -497,9 +497,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.logging_config.ListExclusionsRequest`): + request (google.cloud.logging_v2.types.ListExclusionsRequest): The initial request object. - response (:class:`~.logging_config.ListExclusionsResponse`): + response (google.cloud.logging_v2.types.ListExclusionsResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. diff --git a/google/cloud/logging_v2/services/logging_service_v2/async_client.py b/google/cloud/logging_v2/services/logging_service_v2/async_client.py index 82ee957a3..0c1ae3fae 100644 --- a/google/cloud/logging_v2/services/logging_service_v2/async_client.py +++ b/google/cloud/logging_v2/services/logging_service_v2/async_client.py @@ -87,6 +87,7 @@ class LoggingServiceV2AsyncClient: LoggingServiceV2Client.parse_common_location_path ) + from_service_account_info = LoggingServiceV2Client.from_service_account_info from_service_account_file = LoggingServiceV2Client.from_service_account_file from_service_account_json = from_service_account_file @@ -167,7 +168,7 @@ async def delete_log( with a timestamp before the operation will be deleted. Args: - request (:class:`~.logging.DeleteLogRequest`): + request (:class:`google.cloud.logging_v2.types.DeleteLogRequest`): The request object. The parameters to DeleteLog. log_name (:class:`str`): Required. The resource name of the log to delete: @@ -184,6 +185,7 @@ async def delete_log( ``"organizations/1234567890/logs/cloudresourcemanager.googleapis.com%2Factivity"``. For more information about log names, see [LogEntry][google.logging.v2.LogEntry]. + This corresponds to the ``log_name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -262,7 +264,7 @@ async def write_log_entries( organizations, billing accounts or folders) Args: - request (:class:`~.logging.WriteLogEntriesRequest`): + request (:class:`google.cloud.logging_v2.types.WriteLogEntriesRequest`): The request object. The parameters to WriteLogEntries. log_name (:class:`str`): Optional. A default log resource name that is assigned @@ -288,10 +290,11 @@ async def write_log_entries( folder that is receiving new log entries, whether the resource is specified in ``logName`` or in an individual log entry. + This corresponds to the ``log_name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - resource (:class:`~.monitored_resource.MonitoredResource`): + resource (:class:`google.api.monitored_resource_pb2.MonitoredResource`): Optional. A default monitored resource object that is assigned to all log entries in ``entries`` that do not specify a value for ``resource``. Example: @@ -303,19 +306,21 @@ async def write_log_entries( "zone": "us-central1-a", "instance_id": "00000000000000000000" }} See [LogEntry][google.logging.v2.LogEntry]. + This corresponds to the ``resource`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - labels (:class:`Sequence[~.logging.WriteLogEntriesRequest.LabelsEntry]`): + labels (:class:`Sequence[google.cloud.logging_v2.types.WriteLogEntriesRequest.LabelsEntry]`): Optional. Default labels that are added to the ``labels`` field of all log entries in ``entries``. If a log entry already has a label with the same key as a label in this parameter, then the log entry's label is not changed. See [LogEntry][google.logging.v2.LogEntry]. + This corresponds to the ``labels`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - entries (:class:`Sequence[~.log_entry.LogEntry]`): + entries (:class:`Sequence[google.cloud.logging_v2.types.LogEntry]`): Required. The log entries to send to Logging. The order of log entries in this list does not matter. Values supplied in this method's ``log_name``, ``resource``, @@ -345,6 +350,7 @@ async def write_log_entries( for calls to ``entries.write``, you should try to include several log entries in this list, rather than calling this method for each individual log entry. + This corresponds to the ``entries`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -356,7 +362,7 @@ async def write_log_entries( sent along with the request as metadata. Returns: - ~.logging.WriteLogEntriesResponse: + google.cloud.logging_v2.types.WriteLogEntriesResponse: Result returned from WriteLogEntries. """ # Create or coerce a protobuf request object. @@ -426,7 +432,7 @@ async def list_log_entries( Logs `__. Args: - request (:class:`~.logging.ListLogEntriesRequest`): + request (:class:`google.cloud.logging_v2.types.ListLogEntriesRequest`): The request object. The parameters to `ListLogEntries`. resource_names (:class:`Sequence[str]`): Required. Names of one or more parent resources from @@ -447,6 +453,7 @@ async def list_log_entries( Projects listed in the ``project_ids`` field are added to this list. + This corresponds to the ``resource_names`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -460,6 +467,7 @@ async def list_log_entries( resource that is not listed in ``resource_names`` will cause the filter to return no results. The maximum length of the filter is 20000 characters. + This corresponds to the ``filter`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -472,6 +480,7 @@ async def list_log_entries( option returns entries in order of decreasing timestamps (newest first). Entries with equal timestamps are returned in order of their ``insert_id`` values. + This corresponds to the ``order_by`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -483,8 +492,8 @@ async def list_log_entries( sent along with the request as metadata. Returns: - ~.pagers.ListLogEntriesAsyncPager: - Result returned from ``ListLogEntries``. + google.cloud.logging_v2.services.logging_service_v2.pagers.ListLogEntriesAsyncPager: + Result returned from ListLogEntries. Iterating over this object will yield results and resolve additional pages automatically. @@ -555,7 +564,7 @@ async def list_monitored_resource_descriptors( used by Logging. Args: - request (:class:`~.logging.ListMonitoredResourceDescriptorsRequest`): + request (:class:`google.cloud.logging_v2.types.ListMonitoredResourceDescriptorsRequest`): The request object. The parameters to ListMonitoredResourceDescriptors @@ -566,7 +575,7 @@ async def list_monitored_resource_descriptors( sent along with the request as metadata. Returns: - ~.pagers.ListMonitoredResourceDescriptorsAsyncPager: + google.cloud.logging_v2.services.logging_service_v2.pagers.ListMonitoredResourceDescriptorsAsyncPager: Result returned from ListMonitoredResourceDescriptors. Iterating over this object will yield @@ -622,7 +631,7 @@ async def list_logs( listed. Args: - request (:class:`~.logging.ListLogsRequest`): + request (:class:`google.cloud.logging_v2.types.ListLogsRequest`): The request object. The parameters to ListLogs. parent (:class:`str`): Required. The resource name that owns the logs: @@ -632,7 +641,8 @@ async def list_logs( "projects/[PROJECT_ID]" "organizations/[ORGANIZATION_ID]" "billingAccounts/[BILLING_ACCOUNT_ID]" - "folders/[FOLDER_ID]". + "folders/[FOLDER_ID]" + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -644,7 +654,7 @@ async def list_logs( sent along with the request as metadata. Returns: - ~.pagers.ListLogsAsyncPager: + google.cloud.logging_v2.services.logging_service_v2.pagers.ListLogsAsyncPager: Result returned from ListLogs. Iterating over this object will yield results and resolve additional pages @@ -718,7 +728,7 @@ def tail_log_entries( logs. Args: - requests (AsyncIterator[`~.logging.TailLogEntriesRequest`]): + requests (AsyncIterator[`google.cloud.logging_v2.types.TailLogEntriesRequest`]): The request object AsyncIterator. The parameters to `TailLogEntries`. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. @@ -727,8 +737,8 @@ def tail_log_entries( sent along with the request as metadata. Returns: - AsyncIterable[~.logging.TailLogEntriesResponse]: - Result returned from ``TailLogEntries``. + AsyncIterable[google.cloud.logging_v2.types.TailLogEntriesResponse]: + Result returned from TailLogEntries. """ # Wrap the RPC method; this adds retry and timeout information, diff --git a/google/cloud/logging_v2/services/logging_service_v2/client.py b/google/cloud/logging_v2/services/logging_service_v2/client.py index a54252bf7..a340eb205 100644 --- a/google/cloud/logging_v2/services/logging_service_v2/client.py +++ b/google/cloud/logging_v2/services/logging_service_v2/client.py @@ -122,6 +122,22 @@ def _get_default_mtls_endpoint(api_endpoint): DEFAULT_ENDPOINT ) + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + LoggingServiceV2Client: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_info(info) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials @@ -134,7 +150,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): kwargs: Additional arguments to pass to the constructor. Returns: - {@api.name}: The constructed client. + LoggingServiceV2Client: The constructed client. """ credentials = service_account.Credentials.from_service_account_file(filename) kwargs["credentials"] = credentials @@ -237,10 +253,10 @@ def __init__( credentials identify the application to the service; if none are specified, the client will attempt to ascertain the credentials from the environment. - transport (Union[str, ~.LoggingServiceV2Transport]): The + transport (Union[str, LoggingServiceV2Transport]): The transport to use. If set to None, a transport is chosen automatically. - client_options (client_options_lib.ClientOptions): Custom options for the + client_options (google.api_core.client_options.ClientOptions): Custom options for the client. It won't take effect if a ``transport`` instance is provided. (1) The ``api_endpoint`` property can be used to override the default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT @@ -354,9 +370,9 @@ def delete_log( with a timestamp before the operation will be deleted. Args: - request (:class:`~.logging.DeleteLogRequest`): + request (google.cloud.logging_v2.types.DeleteLogRequest): The request object. The parameters to DeleteLog. - log_name (:class:`str`): + log_name (str): Required. The resource name of the log to delete: :: @@ -371,6 +387,7 @@ def delete_log( ``"organizations/1234567890/logs/cloudresourcemanager.googleapis.com%2Factivity"``. For more information about log names, see [LogEntry][google.logging.v2.LogEntry]. + This corresponds to the ``log_name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -440,9 +457,9 @@ def write_log_entries( organizations, billing accounts or folders) Args: - request (:class:`~.logging.WriteLogEntriesRequest`): + request (google.cloud.logging_v2.types.WriteLogEntriesRequest): The request object. The parameters to WriteLogEntries. - log_name (:class:`str`): + log_name (str): Optional. A default log resource name that is assigned to all log entries in ``entries`` that do not specify a value for ``log_name``: @@ -466,10 +483,11 @@ def write_log_entries( folder that is receiving new log entries, whether the resource is specified in ``logName`` or in an individual log entry. + This corresponds to the ``log_name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - resource (:class:`~.monitored_resource.MonitoredResource`): + resource (google.api.monitored_resource_pb2.MonitoredResource): Optional. A default monitored resource object that is assigned to all log entries in ``entries`` that do not specify a value for ``resource``. Example: @@ -481,19 +499,21 @@ def write_log_entries( "zone": "us-central1-a", "instance_id": "00000000000000000000" }} See [LogEntry][google.logging.v2.LogEntry]. + This corresponds to the ``resource`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - labels (:class:`Sequence[~.logging.WriteLogEntriesRequest.LabelsEntry]`): + labels (Sequence[google.cloud.logging_v2.types.WriteLogEntriesRequest.LabelsEntry]): Optional. Default labels that are added to the ``labels`` field of all log entries in ``entries``. If a log entry already has a label with the same key as a label in this parameter, then the log entry's label is not changed. See [LogEntry][google.logging.v2.LogEntry]. + This corresponds to the ``labels`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - entries (:class:`Sequence[~.log_entry.LogEntry]`): + entries (Sequence[google.cloud.logging_v2.types.LogEntry]): Required. The log entries to send to Logging. The order of log entries in this list does not matter. Values supplied in this method's ``log_name``, ``resource``, @@ -523,6 +543,7 @@ def write_log_entries( for calls to ``entries.write``, you should try to include several log entries in this list, rather than calling this method for each individual log entry. + This corresponds to the ``entries`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -534,7 +555,7 @@ def write_log_entries( sent along with the request as metadata. Returns: - ~.logging.WriteLogEntriesResponse: + google.cloud.logging_v2.types.WriteLogEntriesResponse: Result returned from WriteLogEntries. """ # Create or coerce a protobuf request object. @@ -595,9 +616,9 @@ def list_log_entries( Logs `__. Args: - request (:class:`~.logging.ListLogEntriesRequest`): + request (google.cloud.logging_v2.types.ListLogEntriesRequest): The request object. The parameters to `ListLogEntries`. - resource_names (:class:`Sequence[str]`): + resource_names (Sequence[str]): Required. Names of one or more parent resources from which to retrieve log entries: @@ -616,10 +637,11 @@ def list_log_entries( Projects listed in the ``project_ids`` field are added to this list. + This corresponds to the ``resource_names`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - filter (:class:`str`): + filter (str): Optional. A filter that chooses which log entries to return. See `Advanced Logs Queries `__. @@ -629,10 +651,11 @@ def list_log_entries( resource that is not listed in ``resource_names`` will cause the filter to return no results. The maximum length of the filter is 20000 characters. + This corresponds to the ``filter`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - order_by (:class:`str`): + order_by (str): Optional. How the results should be sorted. Presently, the only permitted values are ``"timestamp asc"`` (default) and ``"timestamp desc"``. The first option @@ -641,6 +664,7 @@ def list_log_entries( option returns entries in order of decreasing timestamps (newest first). Entries with equal timestamps are returned in order of their ``insert_id`` values. + This corresponds to the ``order_by`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -652,8 +676,8 @@ def list_log_entries( sent along with the request as metadata. Returns: - ~.pagers.ListLogEntriesPager: - Result returned from ``ListLogEntries``. + google.cloud.logging_v2.services.logging_service_v2.pagers.ListLogEntriesPager: + Result returned from ListLogEntries. Iterating over this object will yield results and resolve additional pages automatically. @@ -715,7 +739,7 @@ def list_monitored_resource_descriptors( used by Logging. Args: - request (:class:`~.logging.ListMonitoredResourceDescriptorsRequest`): + request (google.cloud.logging_v2.types.ListMonitoredResourceDescriptorsRequest): The request object. The parameters to ListMonitoredResourceDescriptors @@ -726,7 +750,7 @@ def list_monitored_resource_descriptors( sent along with the request as metadata. Returns: - ~.pagers.ListMonitoredResourceDescriptorsPager: + google.cloud.logging_v2.services.logging_service_v2.pagers.ListMonitoredResourceDescriptorsPager: Result returned from ListMonitoredResourceDescriptors. Iterating over this object will yield @@ -775,9 +799,9 @@ def list_logs( listed. Args: - request (:class:`~.logging.ListLogsRequest`): + request (google.cloud.logging_v2.types.ListLogsRequest): The request object. The parameters to ListLogs. - parent (:class:`str`): + parent (str): Required. The resource name that owns the logs: :: @@ -785,7 +809,8 @@ def list_logs( "projects/[PROJECT_ID]" "organizations/[ORGANIZATION_ID]" "billingAccounts/[BILLING_ACCOUNT_ID]" - "folders/[FOLDER_ID]". + "folders/[FOLDER_ID]" + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -797,7 +822,7 @@ def list_logs( sent along with the request as metadata. Returns: - ~.pagers.ListLogsPager: + google.cloud.logging_v2.services.logging_service_v2.pagers.ListLogsPager: Result returned from ListLogs. Iterating over this object will yield results and resolve additional pages @@ -862,7 +887,7 @@ def tail_log_entries( logs. Args: - requests (Iterator[`~.logging.TailLogEntriesRequest`]): + requests (Iterator[google.cloud.logging_v2.types.TailLogEntriesRequest]): The request object iterator. The parameters to `TailLogEntries`. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. @@ -871,8 +896,8 @@ def tail_log_entries( sent along with the request as metadata. Returns: - Iterable[~.logging.TailLogEntriesResponse]: - Result returned from ``TailLogEntries``. + Iterable[google.cloud.logging_v2.types.TailLogEntriesResponse]: + Result returned from TailLogEntries. """ # Wrap the RPC method; this adds retry and timeout information, diff --git a/google/cloud/logging_v2/services/logging_service_v2/pagers.py b/google/cloud/logging_v2/services/logging_service_v2/pagers.py index 72bbe8e23..5492a3a30 100644 --- a/google/cloud/logging_v2/services/logging_service_v2/pagers.py +++ b/google/cloud/logging_v2/services/logging_service_v2/pagers.py @@ -26,7 +26,7 @@ class ListLogEntriesPager: """A pager for iterating through ``list_log_entries`` requests. This class thinly wraps an initial - :class:`~.logging.ListLogEntriesResponse` object, and + :class:`google.cloud.logging_v2.types.ListLogEntriesResponse` object, and provides an ``__iter__`` method to iterate through its ``entries`` field. @@ -35,7 +35,7 @@ class ListLogEntriesPager: through the ``entries`` field on the corresponding responses. - All the usual :class:`~.logging.ListLogEntriesResponse` + All the usual :class:`google.cloud.logging_v2.types.ListLogEntriesResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -53,9 +53,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.logging.ListLogEntriesRequest`): + request (google.cloud.logging_v2.types.ListLogEntriesRequest): The initial request object. - response (:class:`~.logging.ListLogEntriesResponse`): + response (google.cloud.logging_v2.types.ListLogEntriesResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -88,7 +88,7 @@ class ListLogEntriesAsyncPager: """A pager for iterating through ``list_log_entries`` requests. This class thinly wraps an initial - :class:`~.logging.ListLogEntriesResponse` object, and + :class:`google.cloud.logging_v2.types.ListLogEntriesResponse` object, and provides an ``__aiter__`` method to iterate through its ``entries`` field. @@ -97,7 +97,7 @@ class ListLogEntriesAsyncPager: through the ``entries`` field on the corresponding responses. - All the usual :class:`~.logging.ListLogEntriesResponse` + All the usual :class:`google.cloud.logging_v2.types.ListLogEntriesResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -115,9 +115,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.logging.ListLogEntriesRequest`): + request (google.cloud.logging_v2.types.ListLogEntriesRequest): The initial request object. - response (:class:`~.logging.ListLogEntriesResponse`): + response (google.cloud.logging_v2.types.ListLogEntriesResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -154,7 +154,7 @@ class ListMonitoredResourceDescriptorsPager: """A pager for iterating through ``list_monitored_resource_descriptors`` requests. This class thinly wraps an initial - :class:`~.logging.ListMonitoredResourceDescriptorsResponse` object, and + :class:`google.cloud.logging_v2.types.ListMonitoredResourceDescriptorsResponse` object, and provides an ``__iter__`` method to iterate through its ``resource_descriptors`` field. @@ -163,7 +163,7 @@ class ListMonitoredResourceDescriptorsPager: through the ``resource_descriptors`` field on the corresponding responses. - All the usual :class:`~.logging.ListMonitoredResourceDescriptorsResponse` + All the usual :class:`google.cloud.logging_v2.types.ListMonitoredResourceDescriptorsResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -181,9 +181,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.logging.ListMonitoredResourceDescriptorsRequest`): + request (google.cloud.logging_v2.types.ListMonitoredResourceDescriptorsRequest): The initial request object. - response (:class:`~.logging.ListMonitoredResourceDescriptorsResponse`): + response (google.cloud.logging_v2.types.ListMonitoredResourceDescriptorsResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -216,7 +216,7 @@ class ListMonitoredResourceDescriptorsAsyncPager: """A pager for iterating through ``list_monitored_resource_descriptors`` requests. This class thinly wraps an initial - :class:`~.logging.ListMonitoredResourceDescriptorsResponse` object, and + :class:`google.cloud.logging_v2.types.ListMonitoredResourceDescriptorsResponse` object, and provides an ``__aiter__`` method to iterate through its ``resource_descriptors`` field. @@ -225,7 +225,7 @@ class ListMonitoredResourceDescriptorsAsyncPager: through the ``resource_descriptors`` field on the corresponding responses. - All the usual :class:`~.logging.ListMonitoredResourceDescriptorsResponse` + All the usual :class:`google.cloud.logging_v2.types.ListMonitoredResourceDescriptorsResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -245,9 +245,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.logging.ListMonitoredResourceDescriptorsRequest`): + request (google.cloud.logging_v2.types.ListMonitoredResourceDescriptorsRequest): The initial request object. - response (:class:`~.logging.ListMonitoredResourceDescriptorsResponse`): + response (google.cloud.logging_v2.types.ListMonitoredResourceDescriptorsResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -288,7 +288,7 @@ class ListLogsPager: """A pager for iterating through ``list_logs`` requests. This class thinly wraps an initial - :class:`~.logging.ListLogsResponse` object, and + :class:`google.cloud.logging_v2.types.ListLogsResponse` object, and provides an ``__iter__`` method to iterate through its ``log_names`` field. @@ -297,7 +297,7 @@ class ListLogsPager: through the ``log_names`` field on the corresponding responses. - All the usual :class:`~.logging.ListLogsResponse` + All the usual :class:`google.cloud.logging_v2.types.ListLogsResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -315,9 +315,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.logging.ListLogsRequest`): + request (google.cloud.logging_v2.types.ListLogsRequest): The initial request object. - response (:class:`~.logging.ListLogsResponse`): + response (google.cloud.logging_v2.types.ListLogsResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -350,7 +350,7 @@ class ListLogsAsyncPager: """A pager for iterating through ``list_logs`` requests. This class thinly wraps an initial - :class:`~.logging.ListLogsResponse` object, and + :class:`google.cloud.logging_v2.types.ListLogsResponse` object, and provides an ``__aiter__`` method to iterate through its ``log_names`` field. @@ -359,7 +359,7 @@ class ListLogsAsyncPager: through the ``log_names`` field on the corresponding responses. - All the usual :class:`~.logging.ListLogsResponse` + All the usual :class:`google.cloud.logging_v2.types.ListLogsResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -377,9 +377,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.logging.ListLogsRequest`): + request (google.cloud.logging_v2.types.ListLogsRequest): The initial request object. - response (:class:`~.logging.ListLogsResponse`): + response (google.cloud.logging_v2.types.ListLogsResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. diff --git a/google/cloud/logging_v2/services/metrics_service_v2/async_client.py b/google/cloud/logging_v2/services/metrics_service_v2/async_client.py index bd3c759a1..2c592e685 100644 --- a/google/cloud/logging_v2/services/metrics_service_v2/async_client.py +++ b/google/cloud/logging_v2/services/metrics_service_v2/async_client.py @@ -80,6 +80,7 @@ class MetricsServiceV2AsyncClient: MetricsServiceV2Client.parse_common_location_path ) + from_service_account_info = MetricsServiceV2Client.from_service_account_info from_service_account_file = MetricsServiceV2Client.from_service_account_file from_service_account_json = from_service_account_file @@ -156,7 +157,7 @@ async def list_log_metrics( r"""Lists logs-based metrics. Args: - request (:class:`~.logging_metrics.ListLogMetricsRequest`): + request (:class:`google.cloud.logging_v2.types.ListLogMetricsRequest`): The request object. The parameters to ListLogMetrics. parent (:class:`str`): Required. The name of the project containing the @@ -164,7 +165,8 @@ async def list_log_metrics( :: - "projects/[PROJECT_ID]". + "projects/[PROJECT_ID]" + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -176,7 +178,7 @@ async def list_log_metrics( sent along with the request as metadata. Returns: - ~.pagers.ListLogMetricsAsyncPager: + google.cloud.logging_v2.services.metrics_service_v2.pagers.ListLogMetricsAsyncPager: Result returned from ListLogMetrics. Iterating over this object will yield results and resolve additional pages @@ -249,14 +251,15 @@ async def get_log_metric( r"""Gets a logs-based metric. Args: - request (:class:`~.logging_metrics.GetLogMetricRequest`): + request (:class:`google.cloud.logging_v2.types.GetLogMetricRequest`): The request object. The parameters to GetLogMetric. metric_name (:class:`str`): Required. The resource name of the desired metric: :: - "projects/[PROJECT_ID]/metrics/[METRIC_ID]". + "projects/[PROJECT_ID]/metrics/[METRIC_ID]" + This corresponds to the ``metric_name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -268,7 +271,7 @@ async def get_log_metric( sent along with the request as metadata. Returns: - ~.logging_metrics.LogMetric: + google.cloud.logging_v2.types.LogMetric: Describes a logs-based metric. The value of the metric is the number of log entries that match a logs filter in a @@ -345,7 +348,7 @@ async def create_log_metric( r"""Creates a logs-based metric. Args: - request (:class:`~.logging_metrics.CreateLogMetricRequest`): + request (:class:`google.cloud.logging_v2.types.CreateLogMetricRequest`): The request object. The parameters to CreateLogMetric. parent (:class:`str`): Required. The resource name of the project in which to @@ -356,13 +359,15 @@ async def create_log_metric( "projects/[PROJECT_ID]" The new metric must be provided in the request. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - metric (:class:`~.logging_metrics.LogMetric`): + metric (:class:`google.cloud.logging_v2.types.LogMetric`): Required. The new logs-based metric, which must not have an identifier that already exists. + This corresponds to the ``metric`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -374,7 +379,7 @@ async def create_log_metric( sent along with the request as metadata. Returns: - ~.logging_metrics.LogMetric: + google.cloud.logging_v2.types.LogMetric: Describes a logs-based metric. The value of the metric is the number of log entries that match a logs filter in a @@ -441,7 +446,7 @@ async def update_log_metric( r"""Creates or updates a logs-based metric. Args: - request (:class:`~.logging_metrics.UpdateLogMetricRequest`): + request (:class:`google.cloud.logging_v2.types.UpdateLogMetricRequest`): The request object. The parameters to UpdateLogMetric. metric_name (:class:`str`): Required. The resource name of the metric to update: @@ -454,10 +459,11 @@ async def update_log_metric( it's ``name`` field must be the same as ``[METRIC_ID]`` If the metric does not exist in ``[PROJECT_ID]``, then a new metric is created. + This corresponds to the ``metric_name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - metric (:class:`~.logging_metrics.LogMetric`): + metric (:class:`google.cloud.logging_v2.types.LogMetric`): Required. The updated metric. This corresponds to the ``metric`` field on the ``request`` instance; if ``request`` is provided, this @@ -470,7 +476,7 @@ async def update_log_metric( sent along with the request as metadata. Returns: - ~.logging_metrics.LogMetric: + google.cloud.logging_v2.types.LogMetric: Describes a logs-based metric. The value of the metric is the number of log entries that match a logs filter in a @@ -548,14 +554,15 @@ async def delete_log_metric( r"""Deletes a logs-based metric. Args: - request (:class:`~.logging_metrics.DeleteLogMetricRequest`): + request (:class:`google.cloud.logging_v2.types.DeleteLogMetricRequest`): The request object. The parameters to DeleteLogMetric. metric_name (:class:`str`): Required. The resource name of the metric to delete: :: - "projects/[PROJECT_ID]/metrics/[METRIC_ID]". + "projects/[PROJECT_ID]/metrics/[METRIC_ID]" + This corresponds to the ``metric_name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. diff --git a/google/cloud/logging_v2/services/metrics_service_v2/client.py b/google/cloud/logging_v2/services/metrics_service_v2/client.py index d03ce86cd..cc6e491fc 100644 --- a/google/cloud/logging_v2/services/metrics_service_v2/client.py +++ b/google/cloud/logging_v2/services/metrics_service_v2/client.py @@ -114,6 +114,22 @@ def _get_default_mtls_endpoint(api_endpoint): DEFAULT_ENDPOINT ) + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + MetricsServiceV2Client: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_info(info) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials @@ -126,7 +142,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): kwargs: Additional arguments to pass to the constructor. Returns: - {@api.name}: The constructed client. + MetricsServiceV2Client: The constructed client. """ credentials = service_account.Credentials.from_service_account_file(filename) kwargs["credentials"] = credentials @@ -231,10 +247,10 @@ def __init__( credentials identify the application to the service; if none are specified, the client will attempt to ascertain the credentials from the environment. - transport (Union[str, ~.MetricsServiceV2Transport]): The + transport (Union[str, MetricsServiceV2Transport]): The transport to use. If set to None, a transport is chosen automatically. - client_options (client_options_lib.ClientOptions): Custom options for the + client_options (google.api_core.client_options.ClientOptions): Custom options for the client. It won't take effect if a ``transport`` instance is provided. (1) The ``api_endpoint`` property can be used to override the default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT @@ -344,15 +360,16 @@ def list_log_metrics( r"""Lists logs-based metrics. Args: - request (:class:`~.logging_metrics.ListLogMetricsRequest`): + request (google.cloud.logging_v2.types.ListLogMetricsRequest): The request object. The parameters to ListLogMetrics. - parent (:class:`str`): + parent (str): Required. The name of the project containing the metrics: :: - "projects/[PROJECT_ID]". + "projects/[PROJECT_ID]" + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -364,7 +381,7 @@ def list_log_metrics( sent along with the request as metadata. Returns: - ~.pagers.ListLogMetricsPager: + google.cloud.logging_v2.services.metrics_service_v2.pagers.ListLogMetricsPager: Result returned from ListLogMetrics. Iterating over this object will yield results and resolve additional pages @@ -428,14 +445,15 @@ def get_log_metric( r"""Gets a logs-based metric. Args: - request (:class:`~.logging_metrics.GetLogMetricRequest`): + request (google.cloud.logging_v2.types.GetLogMetricRequest): The request object. The parameters to GetLogMetric. - metric_name (:class:`str`): + metric_name (str): Required. The resource name of the desired metric: :: - "projects/[PROJECT_ID]/metrics/[METRIC_ID]". + "projects/[PROJECT_ID]/metrics/[METRIC_ID]" + This corresponds to the ``metric_name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -447,7 +465,7 @@ def get_log_metric( sent along with the request as metadata. Returns: - ~.logging_metrics.LogMetric: + google.cloud.logging_v2.types.LogMetric: Describes a logs-based metric. The value of the metric is the number of log entries that match a logs filter in a @@ -515,9 +533,9 @@ def create_log_metric( r"""Creates a logs-based metric. Args: - request (:class:`~.logging_metrics.CreateLogMetricRequest`): + request (google.cloud.logging_v2.types.CreateLogMetricRequest): The request object. The parameters to CreateLogMetric. - parent (:class:`str`): + parent (str): Required. The resource name of the project in which to create the metric: @@ -526,13 +544,15 @@ def create_log_metric( "projects/[PROJECT_ID]" The new metric must be provided in the request. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - metric (:class:`~.logging_metrics.LogMetric`): + metric (google.cloud.logging_v2.types.LogMetric): Required. The new logs-based metric, which must not have an identifier that already exists. + This corresponds to the ``metric`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -544,7 +564,7 @@ def create_log_metric( sent along with the request as metadata. Returns: - ~.logging_metrics.LogMetric: + google.cloud.logging_v2.types.LogMetric: Describes a logs-based metric. The value of the metric is the number of log entries that match a logs filter in a @@ -612,9 +632,9 @@ def update_log_metric( r"""Creates or updates a logs-based metric. Args: - request (:class:`~.logging_metrics.UpdateLogMetricRequest`): + request (google.cloud.logging_v2.types.UpdateLogMetricRequest): The request object. The parameters to UpdateLogMetric. - metric_name (:class:`str`): + metric_name (str): Required. The resource name of the metric to update: :: @@ -625,10 +645,11 @@ def update_log_metric( it's ``name`` field must be the same as ``[METRIC_ID]`` If the metric does not exist in ``[PROJECT_ID]``, then a new metric is created. + This corresponds to the ``metric_name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - metric (:class:`~.logging_metrics.LogMetric`): + metric (google.cloud.logging_v2.types.LogMetric): Required. The updated metric. This corresponds to the ``metric`` field on the ``request`` instance; if ``request`` is provided, this @@ -641,7 +662,7 @@ def update_log_metric( sent along with the request as metadata. Returns: - ~.logging_metrics.LogMetric: + google.cloud.logging_v2.types.LogMetric: Describes a logs-based metric. The value of the metric is the number of log entries that match a logs filter in a @@ -710,14 +731,15 @@ def delete_log_metric( r"""Deletes a logs-based metric. Args: - request (:class:`~.logging_metrics.DeleteLogMetricRequest`): + request (google.cloud.logging_v2.types.DeleteLogMetricRequest): The request object. The parameters to DeleteLogMetric. - metric_name (:class:`str`): + metric_name (str): Required. The resource name of the metric to delete: :: - "projects/[PROJECT_ID]/metrics/[METRIC_ID]". + "projects/[PROJECT_ID]/metrics/[METRIC_ID]" + This corresponds to the ``metric_name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. diff --git a/google/cloud/logging_v2/services/metrics_service_v2/pagers.py b/google/cloud/logging_v2/services/metrics_service_v2/pagers.py index 09010a685..51c398598 100644 --- a/google/cloud/logging_v2/services/metrics_service_v2/pagers.py +++ b/google/cloud/logging_v2/services/metrics_service_v2/pagers.py @@ -24,7 +24,7 @@ class ListLogMetricsPager: """A pager for iterating through ``list_log_metrics`` requests. This class thinly wraps an initial - :class:`~.logging_metrics.ListLogMetricsResponse` object, and + :class:`google.cloud.logging_v2.types.ListLogMetricsResponse` object, and provides an ``__iter__`` method to iterate through its ``metrics`` field. @@ -33,7 +33,7 @@ class ListLogMetricsPager: through the ``metrics`` field on the corresponding responses. - All the usual :class:`~.logging_metrics.ListLogMetricsResponse` + All the usual :class:`google.cloud.logging_v2.types.ListLogMetricsResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -51,9 +51,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.logging_metrics.ListLogMetricsRequest`): + request (google.cloud.logging_v2.types.ListLogMetricsRequest): The initial request object. - response (:class:`~.logging_metrics.ListLogMetricsResponse`): + response (google.cloud.logging_v2.types.ListLogMetricsResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -86,7 +86,7 @@ class ListLogMetricsAsyncPager: """A pager for iterating through ``list_log_metrics`` requests. This class thinly wraps an initial - :class:`~.logging_metrics.ListLogMetricsResponse` object, and + :class:`google.cloud.logging_v2.types.ListLogMetricsResponse` object, and provides an ``__aiter__`` method to iterate through its ``metrics`` field. @@ -95,7 +95,7 @@ class ListLogMetricsAsyncPager: through the ``metrics`` field on the corresponding responses. - All the usual :class:`~.logging_metrics.ListLogMetricsResponse` + All the usual :class:`google.cloud.logging_v2.types.ListLogMetricsResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -113,9 +113,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.logging_metrics.ListLogMetricsRequest`): + request (google.cloud.logging_v2.types.ListLogMetricsRequest): The initial request object. - response (:class:`~.logging_metrics.ListLogMetricsResponse`): + response (google.cloud.logging_v2.types.ListLogMetricsResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. diff --git a/google/cloud/logging_v2/types/log_entry.py b/google/cloud/logging_v2/types/log_entry.py index a481557fd..e63d6086f 100644 --- a/google/cloud/logging_v2/types/log_entry.py +++ b/google/cloud/logging_v2/types/log_entry.py @@ -66,14 +66,14 @@ class LogEntry(proto.Message): Listing the log entry will not show the leading slash and filtering for a log name with a leading slash will never return any results. - resource (~.monitored_resource.MonitoredResource): + resource (google.api.monitored_resource_pb2.MonitoredResource): Required. The monitored resource that produced this log entry. Example: a log entry that reports a database error would be associated with the monitored resource designating the particular database that reported the error. - proto_payload (~.gp_any.Any): + proto_payload (google.protobuf.any_pb2.Any): The log entry payload, represented as a protocol buffer. Some Google Cloud Platform services use this field for their log entry @@ -86,10 +86,10 @@ class LogEntry(proto.Message): text_payload (str): The log entry payload, represented as a Unicode string (UTF-8). - json_payload (~.struct.Struct): + json_payload (google.protobuf.struct_pb2.Struct): The log entry payload, represented as a structure that is expressed as a JSON object. - timestamp (~.gp_timestamp.Timestamp): + timestamp (google.protobuf.timestamp_pb2.Timestamp): Optional. The time the event described by the log entry occurred. This time is used to compute the log entry's age and to enforce the logs retention period. If this field is @@ -104,10 +104,10 @@ class LogEntry(proto.Message): in the past, and that don't exceed 24 hours in the future. Log entries outside those time boundaries aren't ingested by Logging. - receive_timestamp (~.gp_timestamp.Timestamp): + receive_timestamp (google.protobuf.timestamp_pb2.Timestamp): Output only. The time the log entry was received by Logging. - severity (~.log_severity.LogSeverity): + severity (google.logging.type.log_severity_pb2.LogSeverity): Optional. The severity of the log entry. The default value is ``LogSeverity.DEFAULT``. insert_id (str): @@ -125,14 +125,14 @@ class LogEntry(proto.Message): In queries, the ``insert_id`` is also used to order log entries that have the same ``log_name`` and ``timestamp`` values. - http_request (~.glt_http_request.HttpRequest): + http_request (google.logging.type.http_request_pb2.HttpRequest): Optional. Information about the HTTP request associated with this log entry, if applicable. - labels (Sequence[~.log_entry.LogEntry.LabelsEntry]): + labels (Sequence[google.cloud.logging_v2.types.LogEntry.LabelsEntry]): Optional. A set of user-defined (key, value) data that provides additional information about the log entry. - operation (~.log_entry.LogEntryOperation): + operation (google.cloud.logging_v2.types.LogEntryOperation): Optional. Information about an operation associated with the log entry, if applicable. trace (str): @@ -158,7 +158,7 @@ class LogEntry(proto.Message): log entry was written, or the sampling decision was unknown at the time. A non-sampled ``trace`` value is still useful as a request correlation identifier. The default is False. - source_location (~.log_entry.LogEntrySourceLocation): + source_location (google.cloud.logging_v2.types.LogEntrySourceLocation): Optional. Source code location information associated with the log entry, if any. """ diff --git a/google/cloud/logging_v2/types/logging.py b/google/cloud/logging_v2/types/logging.py index cec8993f5..ca739c02c 100644 --- a/google/cloud/logging_v2/types/logging.py +++ b/google/cloud/logging_v2/types/logging.py @@ -94,7 +94,7 @@ class WriteLogEntriesRequest(proto.Message): each project, organization, billing account, or folder that is receiving new log entries, whether the resource is specified in ``logName`` or in an individual log entry. - resource (~.monitored_resource.MonitoredResource): + resource (google.api.monitored_resource_pb2.MonitoredResource): Optional. A default monitored resource object that is assigned to all log entries in ``entries`` that do not specify a value for ``resource``. Example: @@ -106,13 +106,13 @@ class WriteLogEntriesRequest(proto.Message): "zone": "us-central1-a", "instance_id": "00000000000000000000" }} See [LogEntry][google.logging.v2.LogEntry]. - labels (Sequence[~.logging.WriteLogEntriesRequest.LabelsEntry]): + labels (Sequence[google.cloud.logging_v2.types.WriteLogEntriesRequest.LabelsEntry]): Optional. Default labels that are added to the ``labels`` field of all log entries in ``entries``. If a log entry already has a label with the same key as a label in this parameter, then the log entry's label is not changed. See [LogEntry][google.logging.v2.LogEntry]. - entries (Sequence[~.log_entry.LogEntry]): + entries (Sequence[google.cloud.logging_v2.types.LogEntry]): Required. The log entries to send to Logging. The order of log entries in this list does not matter. Values supplied in this method's ``log_name``, ``resource``, and ``labels`` @@ -181,7 +181,7 @@ class WriteLogEntriesPartialErrors(proto.Message): r"""Error details for WriteLogEntries with partial success. Attributes: - log_entry_errors (Sequence[~.logging.WriteLogEntriesPartialErrors.LogEntryErrorsEntry]): + log_entry_errors (Sequence[google.cloud.logging_v2.types.WriteLogEntriesPartialErrors.LogEntryErrorsEntry]): When ``WriteLogEntriesRequest.partial_success`` is true, records the error status for entries that were not written due to a permanent error, keyed by the entry's zero-based @@ -267,7 +267,7 @@ class ListLogEntriesResponse(proto.Message): r"""Result returned from ``ListLogEntries``. Attributes: - entries (Sequence[~.log_entry.LogEntry]): + entries (Sequence[google.cloud.logging_v2.types.LogEntry]): A list of log entries. If ``entries`` is empty, ``nextPageToken`` may still be returned, indicating that more entries may exist. See ``nextPageToken`` for more @@ -323,7 +323,7 @@ class ListMonitoredResourceDescriptorsResponse(proto.Message): r"""Result returned from ListMonitoredResourceDescriptors. Attributes: - resource_descriptors (Sequence[~.monitored_resource.MonitoredResourceDescriptor]): + resource_descriptors (Sequence[google.api.monitored_resource_pb2.MonitoredResourceDescriptor]): A list of resource descriptors. next_page_token (str): If there might be more results than those appearing in this @@ -442,7 +442,7 @@ class TailLogEntriesRequest(proto.Message): not in ``resource_names`` will cause the filter to return no results. The maximum length of the filter is 20000 characters. - buffer_window (~.duration.Duration): + buffer_window (google.protobuf.duration_pb2.Duration): Optional. The amount of time to buffer log entries at the server before being returned to prevent out of order results due to late @@ -462,12 +462,12 @@ class TailLogEntriesResponse(proto.Message): r"""Result returned from ``TailLogEntries``. Attributes: - entries (Sequence[~.log_entry.LogEntry]): + entries (Sequence[google.cloud.logging_v2.types.LogEntry]): A list of log entries. Each response in the stream will order entries with increasing values of ``LogEntry.timestamp``. Ordering is not guaranteed between separate responses. - suppression_info (Sequence[~.logging.TailLogEntriesResponse.SuppressionInfo]): + suppression_info (Sequence[google.cloud.logging_v2.types.TailLogEntriesResponse.SuppressionInfo]): If entries that otherwise would have been included in the session were not sent back to the client, counts of relevant entries omitted @@ -482,7 +482,7 @@ class SuppressionInfo(proto.Message): r"""Information about entries that were omitted from the session. Attributes: - reason (~.logging.TailLogEntriesResponse.SuppressionInfo.Reason): + reason (google.cloud.logging_v2.types.TailLogEntriesResponse.SuppressionInfo.Reason): The reason that entries were omitted from the session. suppressed_count (int): diff --git a/google/cloud/logging_v2/types/logging_config.py b/google/cloud/logging_v2/types/logging_config.py index aaf057acf..0d1f896e0 100644 --- a/google/cloud/logging_v2/types/logging_config.py +++ b/google/cloud/logging_v2/types/logging_config.py @@ -84,11 +84,11 @@ class LogBucket(proto.Message): location can not be changed. description (str): Describes this bucket. - create_time (~.timestamp.Timestamp): + create_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The creation timestamp of the bucket. This is not set for any of the default buckets. - update_time (~.timestamp.Timestamp): + update_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The last update timestamp of the bucket. retention_days (int): @@ -103,7 +103,7 @@ class LogBucket(proto.Message): The retention period on a locked bucket may not be changed. Locked buckets may only be deleted if they are empty. - lifecycle_state (~.logging_config.LifecycleState): + lifecycle_state (google.cloud.logging_v2.types.LifecycleState): Output only. The bucket lifecycle state. """ @@ -133,10 +133,10 @@ class LogView(proto.Message): location/buckets/my-bucket-id/views/my-view description (str): Describes this view. - create_time (~.timestamp.Timestamp): + create_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The creation timestamp of the view. - update_time (~.timestamp.Timestamp): + update_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The last update timestamp of the view. filter (str): @@ -206,12 +206,12 @@ class LogSink(proto.Message): disabled (bool): Optional. If set to True, then this sink is disabled and it does not export any log entries. - exclusions (Sequence[~.logging_config.LogExclusion]): + exclusions (Sequence[google.cloud.logging_v2.types.LogExclusion]): Optional. Log entries that match any of the exclusion filters will not be exported. If a log entry is matched by both ``filter`` and one of ``exclusion_filters`` it will not be exported. - output_version_format (~.logging_config.LogSink.VersionFormat): + output_version_format (google.cloud.logging_v2.types.LogSink.VersionFormat): Deprecated. This field is unused. writer_identity (str): Output only. An IAM identity—a service account or @@ -248,14 +248,14 @@ class LogSink(proto.Message): logName:("projects/test-project1/" OR "projects/test-project2/") AND resource.type=gce_instance - bigquery_options (~.logging_config.BigQueryOptions): + bigquery_options (google.cloud.logging_v2.types.BigQueryOptions): Optional. Options that affect sinks exporting data to BigQuery. - create_time (~.timestamp.Timestamp): + create_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The creation timestamp of the sink. This field may not be present for older sinks. - update_time (~.timestamp.Timestamp): + update_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The last update timestamp of the sink. This field may not be present for older sinks. @@ -366,7 +366,7 @@ class ListBucketsResponse(proto.Message): r"""The response from ListBuckets. Attributes: - buckets (Sequence[~.logging_config.LogBucket]): + buckets (Sequence[google.cloud.logging_v2.types.LogBucket]): A list of buckets. next_page_token (str): If there might be more results than appear in this response, @@ -401,7 +401,7 @@ class CreateBucketRequest(proto.Message): ``"my-bucket"``. Identifiers are limited to 100 characters and can include only letters, digits, underscores, hyphens, and periods. - bucket (~.logging_config.LogBucket): + bucket (google.cloud.logging_v2.types.LogBucket): Required. The new bucket. The region specified in the new bucket must be compliant with any Location Restriction Org Policy. The @@ -434,9 +434,9 @@ class UpdateBucketRequest(proto.Message): Also requires permission "resourcemanager.projects.updateLiens" to set the locked property - bucket (~.logging_config.LogBucket): + bucket (google.cloud.logging_v2.types.LogBucket): Required. The updated bucket. - update_mask (~.field_mask.FieldMask): + update_mask (google.protobuf.field_mask_pb2.FieldMask): Required. Field mask that specifies the fields in ``bucket`` that need an update. A bucket field will be overwritten if, and only if, it is in the update mask. ``name`` and output @@ -552,7 +552,7 @@ class ListViewsResponse(proto.Message): r"""The response from ListViews. Attributes: - views (Sequence[~.logging_config.LogView]): + views (Sequence[google.cloud.logging_v2.types.LogView]): A list of views. next_page_token (str): If there might be more results than appear in this response, @@ -585,7 +585,7 @@ class CreateViewRequest(proto.Message): ``"projects/my-logging-project/locations/my-location/buckets/my-bucket"`` view_id (str): Required. The id to use for this view. - view (~.logging_config.LogView): + view (google.cloud.logging_v2.types.LogView): Required. The new view. """ @@ -609,9 +609,9 @@ class UpdateViewRequest(proto.Message): Example: ``"projects/my-project-id/locations/my-location/buckets/my-bucket-id/views/my-view-id"``. - view (~.logging_config.LogView): + view (google.cloud.logging_v2.types.LogView): Required. The updated view. - update_mask (~.field_mask.FieldMask): + update_mask (google.protobuf.field_mask_pb2.FieldMask): Optional. Field mask that specifies the fields in ``view`` that need an update. A field will be overwritten if, and only if, it is in the update mask. ``name`` and output only @@ -703,7 +703,7 @@ class ListSinksResponse(proto.Message): r"""Result returned from ``ListSinks``. Attributes: - sinks (Sequence[~.logging_config.LogSink]): + sinks (Sequence[google.cloud.logging_v2.types.LogSink]): A list of sinks. next_page_token (str): If there might be more results than appear in this response, @@ -757,7 +757,7 @@ class CreateSinkRequest(proto.Message): Examples: ``"projects/my-logging-project"``, ``"organizations/123456789"``. - sink (~.logging_config.LogSink): + sink (google.cloud.logging_v2.types.LogSink): Required. The new sink, whose ``name`` parameter is a sink identifier that is not already in use. unique_writer_identity (bool): @@ -800,7 +800,7 @@ class UpdateSinkRequest(proto.Message): "folders/[FOLDER_ID]/sinks/[SINK_ID]" Example: ``"projects/my-project-id/sinks/my-sink-id"``. - sink (~.logging_config.LogSink): + sink (google.cloud.logging_v2.types.LogSink): Required. The updated sink, whose name is the same identifier that appears as part of ``sink_name``. unique_writer_identity (bool): @@ -819,7 +819,7 @@ class UpdateSinkRequest(proto.Message): account. - It is an error if the old value is true and the new value is set to false or defaulted to false. - update_mask (~.field_mask.FieldMask): + update_mask (google.protobuf.field_mask_pb2.FieldMask): Optional. Field mask that specifies the fields in ``sink`` that need an update. A sink field will be overwritten if, and only if, it is in the update mask. ``name`` and output @@ -901,12 +901,12 @@ class LogExclusion(proto.Message): and it does not exclude any log entries. You can [update an exclusion][google.logging.v2.ConfigServiceV2.UpdateExclusion] to change the value of this field. - create_time (~.timestamp.Timestamp): + create_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The creation timestamp of the exclusion. This field may not be present for older exclusions. - update_time (~.timestamp.Timestamp): + update_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The last update timestamp of the exclusion. This field may not be present for older @@ -964,7 +964,7 @@ class ListExclusionsResponse(proto.Message): r"""Result returned from ``ListExclusions``. Attributes: - exclusions (Sequence[~.logging_config.LogExclusion]): + exclusions (Sequence[google.cloud.logging_v2.types.LogExclusion]): A list of exclusions. next_page_token (str): If there might be more results than appear in this response, @@ -1020,7 +1020,7 @@ class CreateExclusionRequest(proto.Message): Examples: ``"projects/my-logging-project"``, ``"organizations/123456789"``. - exclusion (~.logging_config.LogExclusion): + exclusion (google.cloud.logging_v2.types.LogExclusion): Required. The new exclusion, whose ``name`` parameter is an exclusion name that is not already used in the parent resource. @@ -1047,10 +1047,10 @@ class UpdateExclusionRequest(proto.Message): Example: ``"projects/my-project-id/exclusions/my-exclusion-id"``. - exclusion (~.logging_config.LogExclusion): + exclusion (google.cloud.logging_v2.types.LogExclusion): Required. New values for the existing exclusion. Only the fields specified in ``update_mask`` are relevant. - update_mask (~.field_mask.FieldMask): + update_mask (google.protobuf.field_mask_pb2.FieldMask): Required. A non-empty list of fields to change in the existing exclusion. New values for the fields are taken from the corresponding fields in the @@ -1145,13 +1145,13 @@ class UpdateCmekSettingsRequest(proto.Message): Note: CMEK for the Logs Router can currently only be configured for GCP organizations. Once configured, it applies to all projects and folders in the GCP organization. - cmek_settings (~.logging_config.CmekSettings): + cmek_settings (google.cloud.logging_v2.types.CmekSettings): Required. The CMEK settings to update. See `Enabling CMEK for Logs Router `__ for more information. - update_mask (~.field_mask.FieldMask): + update_mask (google.protobuf.field_mask_pb2.FieldMask): Optional. Field mask identifying which fields from ``cmek_settings`` should be updated. A field will be overwritten if and only if it is in the update mask. Output diff --git a/google/cloud/logging_v2/types/logging_metrics.py b/google/cloud/logging_v2/types/logging_metrics.py index a9642d13b..c2a8a6007 100644 --- a/google/cloud/logging_v2/types/logging_metrics.py +++ b/google/cloud/logging_v2/types/logging_metrics.py @@ -78,7 +78,7 @@ class LogMetric(proto.Message): "resource.type=gae_app AND severity>=ERROR" The maximum length of the filter is 20000 characters. - metric_descriptor (~.ga_metric.MetricDescriptor): + metric_descriptor (google.api.metric_pb2.MetricDescriptor): Optional. The metric descriptor associated with the logs-based metric. If unspecified, it uses a default metric descriptor with a DELTA metric kind, INT64 value type, with @@ -128,7 +128,7 @@ class LogMetric(proto.Message): Example: ``REGEXP_EXTRACT(jsonPayload.request, ".*quantity=(\d+).*")`` - label_extractors (Sequence[~.logging_metrics.LogMetric.LabelExtractorsEntry]): + label_extractors (Sequence[google.cloud.logging_v2.types.LogMetric.LabelExtractorsEntry]): Optional. A map from a label key string to an extractor expression which is used to extract data from a log entry field and assign as the label value. Each label key @@ -146,20 +146,20 @@ class LogMetric(proto.Message): Note that there are upper bounds on the maximum number of labels and the number of active time series that are allowed in a project. - bucket_options (~.distribution.Distribution.BucketOptions): + bucket_options (google.api.distribution_pb2.BucketOptions): Optional. The ``bucket_options`` are required when the logs-based metric is using a DISTRIBUTION value type and it describes the bucket boundaries used to create a histogram of the extracted values. - create_time (~.timestamp.Timestamp): + create_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The creation timestamp of the metric. This field may not be present for older metrics. - update_time (~.timestamp.Timestamp): + update_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The last update timestamp of the metric. This field may not be present for older metrics. - version (~.logging_metrics.LogMetric.ApiVersion): + version (google.cloud.logging_v2.types.LogMetric.ApiVersion): Deprecated. The API version that created or updated this metric. The v2 format is used by default and cannot be changed. @@ -229,7 +229,7 @@ class ListLogMetricsResponse(proto.Message): r"""Result returned from ListLogMetrics. Attributes: - metrics (Sequence[~.logging_metrics.LogMetric]): + metrics (Sequence[google.cloud.logging_v2.types.LogMetric]): A list of logs-based metrics. next_page_token (str): If there might be more results than appear in this response, @@ -275,7 +275,7 @@ class CreateLogMetricRequest(proto.Message): "projects/[PROJECT_ID]" The new metric must be provided in the request. - metric (~.logging_metrics.LogMetric): + metric (google.cloud.logging_v2.types.LogMetric): Required. The new logs-based metric, which must not have an identifier that already exists. """ @@ -300,7 +300,7 @@ class UpdateLogMetricRequest(proto.Message): ``name`` field must be the same as ``[METRIC_ID]`` If the metric does not exist in ``[PROJECT_ID]``, then a new metric is created. - metric (~.logging_metrics.LogMetric): + metric (google.cloud.logging_v2.types.LogMetric): Required. The updated metric. """ diff --git a/logging-v2-py.tar.gz b/logging-v2-py.tar.gz new file mode 100644 index 000000000..e69de29bb diff --git a/noxfile.py b/noxfile.py index 3db66c649..e68736640 100644 --- a/noxfile.py +++ b/noxfile.py @@ -30,6 +30,17 @@ SYSTEM_TEST_PYTHON_VERSIONS = ["3.8"] UNIT_TEST_PYTHON_VERSIONS = ["3.6", "3.7", "3.8", "3.9"] +# 'docfx' is excluded since it only needs to run in 'docs-presubmit' +nox.options.sessions = [ + "unit", + "system", + "cover", + "lint", + "lint_setup_py", + "blacken", + "docs", +] + @nox.session(python=DEFAULT_PYTHON_VERSION) def lint(session): diff --git a/samples/snippets/requirements.txt b/samples/snippets/requirements.txt index 759dba97e..db786f889 100644 --- a/samples/snippets/requirements.txt +++ b/samples/snippets/requirements.txt @@ -1,4 +1,4 @@ -google-cloud-logging==2.0.2 +google-cloud-logging==2.1.1 google-cloud-storage==1.35.0 google-cloud-pubsub==2.2.0 google-cloud-bigquery==2.6.2 diff --git a/setup.py b/setup.py index 4009bca9a..8ede9877e 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ name = "google-cloud-logging" description = "Stackdriver Logging API client library" -version = "2.1.1" +version = "2.2.0" # Should be one of: # 'Development Status :: 3 - Alpha' # 'Development Status :: 4 - Beta' diff --git a/synth.metadata b/synth.metadata index a74610af8..28c8b61cc 100644 --- a/synth.metadata +++ b/synth.metadata @@ -4,29 +4,29 @@ "git": { "name": ".", "remote": "https://github.com/googleapis/python-logging.git", - "sha": "212b4143d4e681356efc4bccff35cf7a435717ca" + "sha": "c89dea4899a2fd7175c2849f158fb921fc017a15" } }, { "git": { "name": "googleapis", "remote": "https://github.com/googleapis/googleapis.git", - "sha": "dd372aa22ded7a8ba6f0e03a80e06358a3fa0907", - "internalRef": "347055288" + "sha": "520682435235d9c503983a360a2090025aa47cd1", + "internalRef": "350246057" } }, { "git": { "name": "synthtool", "remote": "https://github.com/googleapis/synthtool.git", - "sha": "41a4e56982620d3edcf110d76f4fcdfdec471ac8" + "sha": "16ec872dd898d7de6e1822badfac32484b5d9031" } }, { "git": { "name": "synthtool", "remote": "https://github.com/googleapis/synthtool.git", - "sha": "41a4e56982620d3edcf110d76f4fcdfdec471ac8" + "sha": "16ec872dd898d7de6e1822badfac32484b5d9031" } } ], @@ -42,6 +42,7 @@ } ], "generatedFiles": [ + ".coveragerc", ".flake8", ".github/CONTRIBUTING.md", ".github/ISSUE_TEMPLATE/bug_report.md", @@ -130,6 +131,7 @@ "google/cloud/logging_v2/types/logging.py", "google/cloud/logging_v2/types/logging_config.py", "google/cloud/logging_v2/types/logging_metrics.py", + "logging-v2-py.tar.gz", "mypy.ini", "noxfile.py", "renovate.json", diff --git a/tests/system/test_system.py b/tests/system/test_system.py index 45126f5e5..9cd0ac253 100644 --- a/tests/system/test_system.py +++ b/tests/system/test_system.py @@ -12,7 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -import datetime +from datetime import datetime +from datetime import timedelta +from datetime import timezone import logging import os import pytest @@ -41,19 +43,21 @@ _RESOURCE_ID = unique_resource_id("-") DEFAULT_FILTER = "logName:syslog AND severity>=INFO" DEFAULT_DESCRIPTION = "System testing" +_TIME_FORMAT = "%Y-%m-%dT%H:%M:%S.%f%z" retry_429 = RetryErrors(TooManyRequests) +_ten_mins_ago = datetime.now(timezone.utc) - timedelta(minutes=10) +_time_filter = f'timestamp>="{_ten_mins_ago.strftime(_TIME_FORMAT)}"' -def _consume_entries(logger): - """Consume all log entries from logger iterator. +def _consume_entries(logger): + """Consume all recent log entries from logger iterator. :type logger: :class:`~google.cloud.logging.logger.Logger` :param logger: A Logger containing entries. - :rtype: list :returns: List of all entries consumed. """ - return list(logger.list_entries()) + return list(logger.list_entries(filter_=_time_filter)) def _list_entries(logger): @@ -68,9 +72,12 @@ def _list_entries(logger): :rtype: list :returns: List of all entries consumed. """ - inner = RetryResult(_has_entries, max_tries=9)(_consume_entries) + inner = RetryResult(_has_entries, delay=1, backoff=2, max_tries=6)(_consume_entries) outer = RetryErrors( - (ServiceUnavailable, ResourceExhausted, InternalServerError), max_tries=9 + (ServiceUnavailable, ResourceExhausted, InternalServerError), + delay=1, + backoff=2, + max_tries=6, )(inner) return outer(logger) @@ -147,7 +154,7 @@ def test_list_entry_with_unregistered(self): pool.FindMessageTypeByName(type_name) type_url = "type.googleapis.com/" + type_name - filter_ = self.TYPE_FILTER.format(type_url) + filter_ = self.TYPE_FILTER.format(type_url) + f" AND {_time_filter}" entry_iter = iter(Config.CLIENT.list_entries(page_size=1, filter_=filter_)) retry = RetryErrors(TooManyRequests) @@ -172,11 +179,9 @@ def test_log_text(self): self.assertEqual(entries[0].payload, TEXT_PAYLOAD) def test_log_text_with_timestamp(self): - import datetime - text_payload = "System test: test_log_text_with_timestamp" logger = Config.CLIENT.logger(self._logger_name("log_text_ts")) - now = datetime.datetime.utcnow() + now = datetime.utcnow() self.to_delete.append(logger) @@ -185,13 +190,13 @@ def test_log_text_with_timestamp(self): self.assertEqual(len(entries), 1) self.assertEqual(entries[0].payload, text_payload) self.assertEqual(entries[0].timestamp, now.replace(tzinfo=UTC)) - self.assertIsInstance(entries[0].received_timestamp, datetime.datetime) + self.assertIsInstance(entries[0].received_timestamp, datetime) def test_log_text_with_resource(self): text_payload = "System test: test_log_text_with_timestamp" logger = Config.CLIENT.logger(self._logger_name("log_text_res")) - now = datetime.datetime.utcnow() + now = datetime.utcnow() resource = Resource( type="gae_app", labels={"module_id": "default", "version_id": "test", "zone": ""}, diff --git a/tests/unit/gapic/logging_v2/test_config_service_v2.py b/tests/unit/gapic/logging_v2/test_config_service_v2.py index 47a41f25c..a2685b497 100644 --- a/tests/unit/gapic/logging_v2/test_config_service_v2.py +++ b/tests/unit/gapic/logging_v2/test_config_service_v2.py @@ -88,8 +88,21 @@ def test__get_default_mtls_endpoint(): ) +def test_config_service_v2_client_from_service_account_info(): + creds = credentials.AnonymousCredentials() + with mock.patch.object( + service_account.Credentials, "from_service_account_info" + ) as factory: + factory.return_value = creds + info = {"valid": True} + client = ConfigServiceV2Client.from_service_account_info(info) + assert client.transport._credentials == creds + + assert client.transport._host == "logging.googleapis.com:443" + + @pytest.mark.parametrize( - "client_class", [ConfigServiceV2Client, ConfigServiceV2AsyncClient] + "client_class", [ConfigServiceV2Client, ConfigServiceV2AsyncClient,] ) def test_config_service_v2_client_from_service_account_file(client_class): creds = credentials.AnonymousCredentials() @@ -108,7 +121,10 @@ def test_config_service_v2_client_from_service_account_file(client_class): def test_config_service_v2_client_get_transport_class(): transport = ConfigServiceV2Client.get_transport_class() - assert transport == transports.ConfigServiceV2GrpcTransport + available_transports = [ + transports.ConfigServiceV2GrpcTransport, + ] + assert transport in available_transports transport = ConfigServiceV2Client.get_transport_class("grpc") assert transport == transports.ConfigServiceV2GrpcTransport @@ -5311,7 +5327,7 @@ def test_config_service_v2_host_with_port(): def test_config_service_v2_grpc_transport_channel(): - channel = grpc.insecure_channel("http://localhost/") + channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.ConfigServiceV2GrpcTransport( @@ -5323,7 +5339,7 @@ def test_config_service_v2_grpc_transport_channel(): def test_config_service_v2_grpc_asyncio_transport_channel(): - channel = aio.insecure_channel("http://localhost/") + channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.ConfigServiceV2GrpcAsyncIOTransport( @@ -5348,7 +5364,7 @@ def test_config_service_v2_transport_channel_mtls_with_client_cert_source( "grpc.ssl_channel_credentials", autospec=True ) as grpc_ssl_channel_cred: with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_ssl_cred = mock.Mock() grpc_ssl_channel_cred.return_value = mock_ssl_cred @@ -5406,7 +5422,7 @@ def test_config_service_v2_transport_channel_mtls_with_adc(transport_class): ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), ): with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel diff --git a/tests/unit/gapic/logging_v2/test_logging_service_v2.py b/tests/unit/gapic/logging_v2/test_logging_service_v2.py index 2b8129f29..110a383c0 100644 --- a/tests/unit/gapic/logging_v2/test_logging_service_v2.py +++ b/tests/unit/gapic/logging_v2/test_logging_service_v2.py @@ -95,8 +95,21 @@ def test__get_default_mtls_endpoint(): ) +def test_logging_service_v2_client_from_service_account_info(): + creds = credentials.AnonymousCredentials() + with mock.patch.object( + service_account.Credentials, "from_service_account_info" + ) as factory: + factory.return_value = creds + info = {"valid": True} + client = LoggingServiceV2Client.from_service_account_info(info) + assert client.transport._credentials == creds + + assert client.transport._host == "logging.googleapis.com:443" + + @pytest.mark.parametrize( - "client_class", [LoggingServiceV2Client, LoggingServiceV2AsyncClient] + "client_class", [LoggingServiceV2Client, LoggingServiceV2AsyncClient,] ) def test_logging_service_v2_client_from_service_account_file(client_class): creds = credentials.AnonymousCredentials() @@ -115,7 +128,10 @@ def test_logging_service_v2_client_from_service_account_file(client_class): def test_logging_service_v2_client_get_transport_class(): transport = LoggingServiceV2Client.get_transport_class() - assert transport == transports.LoggingServiceV2GrpcTransport + available_transports = [ + transports.LoggingServiceV2GrpcTransport, + ] + assert transport in available_transports transport = LoggingServiceV2Client.get_transport_class("grpc") assert transport == transports.LoggingServiceV2GrpcTransport @@ -1976,7 +1992,7 @@ def test_logging_service_v2_host_with_port(): def test_logging_service_v2_grpc_transport_channel(): - channel = grpc.insecure_channel("http://localhost/") + channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.LoggingServiceV2GrpcTransport( @@ -1988,7 +2004,7 @@ def test_logging_service_v2_grpc_transport_channel(): def test_logging_service_v2_grpc_asyncio_transport_channel(): - channel = aio.insecure_channel("http://localhost/") + channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.LoggingServiceV2GrpcAsyncIOTransport( @@ -2013,7 +2029,7 @@ def test_logging_service_v2_transport_channel_mtls_with_client_cert_source( "grpc.ssl_channel_credentials", autospec=True ) as grpc_ssl_channel_cred: with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_ssl_cred = mock.Mock() grpc_ssl_channel_cred.return_value = mock_ssl_cred @@ -2072,7 +2088,7 @@ def test_logging_service_v2_transport_channel_mtls_with_adc(transport_class): ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), ): with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel diff --git a/tests/unit/gapic/logging_v2/test_metrics_service_v2.py b/tests/unit/gapic/logging_v2/test_metrics_service_v2.py index 0bc10e4bc..8ae5fdc54 100644 --- a/tests/unit/gapic/logging_v2/test_metrics_service_v2.py +++ b/tests/unit/gapic/logging_v2/test_metrics_service_v2.py @@ -94,8 +94,21 @@ def test__get_default_mtls_endpoint(): ) +def test_metrics_service_v2_client_from_service_account_info(): + creds = credentials.AnonymousCredentials() + with mock.patch.object( + service_account.Credentials, "from_service_account_info" + ) as factory: + factory.return_value = creds + info = {"valid": True} + client = MetricsServiceV2Client.from_service_account_info(info) + assert client.transport._credentials == creds + + assert client.transport._host == "logging.googleapis.com:443" + + @pytest.mark.parametrize( - "client_class", [MetricsServiceV2Client, MetricsServiceV2AsyncClient] + "client_class", [MetricsServiceV2Client, MetricsServiceV2AsyncClient,] ) def test_metrics_service_v2_client_from_service_account_file(client_class): creds = credentials.AnonymousCredentials() @@ -114,7 +127,10 @@ def test_metrics_service_v2_client_from_service_account_file(client_class): def test_metrics_service_v2_client_get_transport_class(): transport = MetricsServiceV2Client.get_transport_class() - assert transport == transports.MetricsServiceV2GrpcTransport + available_transports = [ + transports.MetricsServiceV2GrpcTransport, + ] + assert transport in available_transports transport = MetricsServiceV2Client.get_transport_class("grpc") assert transport == transports.MetricsServiceV2GrpcTransport @@ -1921,7 +1937,7 @@ def test_metrics_service_v2_host_with_port(): def test_metrics_service_v2_grpc_transport_channel(): - channel = grpc.insecure_channel("http://localhost/") + channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.MetricsServiceV2GrpcTransport( @@ -1933,7 +1949,7 @@ def test_metrics_service_v2_grpc_transport_channel(): def test_metrics_service_v2_grpc_asyncio_transport_channel(): - channel = aio.insecure_channel("http://localhost/") + channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.MetricsServiceV2GrpcAsyncIOTransport( @@ -1958,7 +1974,7 @@ def test_metrics_service_v2_transport_channel_mtls_with_client_cert_source( "grpc.ssl_channel_credentials", autospec=True ) as grpc_ssl_channel_cred: with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_ssl_cred = mock.Mock() grpc_ssl_channel_cred.return_value = mock_ssl_cred @@ -2017,7 +2033,7 @@ def test_metrics_service_v2_transport_channel_mtls_with_adc(transport_class): ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), ): with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel diff --git a/tests/unit/handlers/test__helpers.py b/tests/unit/handlers/test__helpers.py index f1d89dffc..fd17f6ffd 100644 --- a/tests/unit/handlers/test__helpers.py +++ b/tests/unit/handlers/test__helpers.py @@ -172,6 +172,9 @@ def test_http_request_populated(self): HTTP_USER_AGENT=expected_agent, HTTP_REFERER=expected_referrer, ) + # ensure test passes even after request has been read + # context: https://github.com/googleapis/python-logging/issues/159 + django_request.read() middleware = request.RequestMiddleware(None) middleware.process_request(django_request)