From 9d535ad9fc3ea4ffb3f1eecb5c7c97f49da83b66 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Fri, 14 May 2021 13:02:07 +0000 Subject: [PATCH] chore: upgrade gapic-generator-python to 0.46.3 (#65) PiperOrigin-RevId: 373649163 Source-Link: https://github.com/googleapis/googleapis/commit/7e1b14e6c7a9ab96d2db7e4a131981f162446d34 Source-Link: https://github.com/googleapis/googleapis-gen/commit/0a3c7d272d697796db75857bac73905c68e498c3 --- .../docs/dashboard_v1/dashboards_service.rst | 1 - .../cloud/monitoring_dashboard/__init__.py | 34 +- .../cloud/monitoring_dashboard_v1/__init__.py | 9 +- .../gapic_metadata.json | 73 +++ .../services/__init__.py | 1 - .../services/dashboards_service/__init__.py | 2 - .../dashboards_service/async_client.py | 34 +- .../services/dashboards_service/client.py | 71 ++- .../services/dashboards_service/pagers.py | 4 +- .../dashboards_service/transports/__init__.py | 2 - .../dashboards_service/transports/base.py | 122 +++-- .../dashboards_service/transports/grpc.py | 28 +- .../transports/grpc_asyncio.py | 31 +- .../monitoring_dashboard_v1/types/__init__.py | 2 - .../monitoring_dashboard_v1/types/common.py | 21 +- .../types/dashboard.py | 15 +- .../types/dashboards_service.py | 27 +- .../types/drilldowns.py | 1 - .../monitoring_dashboard_v1/types/layouts.py | 29 +- .../monitoring_dashboard_v1/types/metrics.py | 31 +- .../types/scorecard.py | 16 +- .../monitoring_dashboard_v1/types/service.py | 1 - .../monitoring_dashboard_v1/types/text.py | 6 +- .../monitoring_dashboard_v1/types/widget.py | 15 +- .../monitoring_dashboard_v1/types/xychart.py | 28 +- .../scripts/fixup_dashboard_v1_keywords.py | 15 +- .../tests/__init__.py | 15 + .../tests/unit/__init__.py | 15 + .../tests/unit/gapic/__init__.py | 15 + .../tests/unit/gapic/dashboard_v1/__init__.py | 1 - .../dashboard_v1/test_dashboards_service.py | 443 ++++++++++++------ 31 files changed, 664 insertions(+), 444 deletions(-) create mode 100644 packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/gapic_metadata.json create mode 100644 packages/google-cloud-monitoring-dashboards/tests/__init__.py create mode 100644 packages/google-cloud-monitoring-dashboards/tests/unit/__init__.py create mode 100644 packages/google-cloud-monitoring-dashboards/tests/unit/gapic/__init__.py diff --git a/packages/google-cloud-monitoring-dashboards/docs/dashboard_v1/dashboards_service.rst b/packages/google-cloud-monitoring-dashboards/docs/dashboard_v1/dashboards_service.rst index edd288014c35..80049e08a4a9 100644 --- a/packages/google-cloud-monitoring-dashboards/docs/dashboard_v1/dashboards_service.rst +++ b/packages/google-cloud-monitoring-dashboards/docs/dashboard_v1/dashboards_service.rst @@ -5,7 +5,6 @@ DashboardsService :members: :inherited-members: - .. automodule:: google.cloud.monitoring_dashboard_v1.services.dashboards_service.pagers :members: :inherited-members: diff --git a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard/__init__.py b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard/__init__.py index f3b20ee10d04..c3a499f791b7 100644 --- a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard/__init__.py +++ b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,12 +14,13 @@ # limitations under the License. # -from google.cloud.monitoring_dashboard_v1.services.dashboards_service.async_client import ( - DashboardsServiceAsyncClient, -) from google.cloud.monitoring_dashboard_v1.services.dashboards_service.client import ( DashboardsServiceClient, ) +from google.cloud.monitoring_dashboard_v1.services.dashboards_service.async_client import ( + DashboardsServiceAsyncClient, +) + from google.cloud.monitoring_dashboard_v1.types.common import Aggregation from google.cloud.monitoring_dashboard_v1.types.common import PickTimeSeriesFilter from google.cloud.monitoring_dashboard_v1.types.common import ( @@ -49,11 +49,11 @@ from google.cloud.monitoring_dashboard_v1.types.layouts import GridLayout from google.cloud.monitoring_dashboard_v1.types.layouts import MosaicLayout from google.cloud.monitoring_dashboard_v1.types.layouts import RowLayout -from google.cloud.monitoring_dashboard_v1.types.metrics import SparkChartType from google.cloud.monitoring_dashboard_v1.types.metrics import Threshold from google.cloud.monitoring_dashboard_v1.types.metrics import TimeSeriesFilter from google.cloud.monitoring_dashboard_v1.types.metrics import TimeSeriesFilterRatio from google.cloud.monitoring_dashboard_v1.types.metrics import TimeSeriesQuery +from google.cloud.monitoring_dashboard_v1.types.metrics import SparkChartType from google.cloud.monitoring_dashboard_v1.types.scorecard import Scorecard from google.cloud.monitoring_dashboard_v1.types.text import Text from google.cloud.monitoring_dashboard_v1.types.widget import Widget @@ -61,30 +61,30 @@ from google.cloud.monitoring_dashboard_v1.types.xychart import XyChart __all__ = ( + "DashboardsServiceClient", + "DashboardsServiceAsyncClient", "Aggregation", - "ChartOptions", - "ColumnLayout", - "CreateDashboardRequest", + "PickTimeSeriesFilter", + "StatisticalTimeSeriesFilter", "Dashboard", - "DashboardsServiceAsyncClient", - "DashboardsServiceClient", + "CreateDashboardRequest", "DeleteDashboardRequest", "GetDashboardRequest", - "GridLayout", "ListDashboardsRequest", "ListDashboardsResponse", + "UpdateDashboardRequest", + "ColumnLayout", + "GridLayout", "MosaicLayout", - "PickTimeSeriesFilter", "RowLayout", - "Scorecard", - "SparkChartType", - "StatisticalTimeSeriesFilter", - "Text", "Threshold", "TimeSeriesFilter", "TimeSeriesFilterRatio", "TimeSeriesQuery", - "UpdateDashboardRequest", + "SparkChartType", + "Scorecard", + "Text", "Widget", + "ChartOptions", "XyChart", ) diff --git a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/__init__.py b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/__init__.py index 9f7a33f88546..e7fb1de41376 100644 --- a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/__init__.py +++ b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,6 +15,8 @@ # from .services.dashboards_service import DashboardsServiceClient +from .services.dashboards_service import DashboardsServiceAsyncClient + from .types.common import Aggregation from .types.common import PickTimeSeriesFilter from .types.common import StatisticalTimeSeriesFilter @@ -30,24 +31,25 @@ from .types.layouts import GridLayout from .types.layouts import MosaicLayout from .types.layouts import RowLayout -from .types.metrics import SparkChartType from .types.metrics import Threshold from .types.metrics import TimeSeriesFilter from .types.metrics import TimeSeriesFilterRatio from .types.metrics import TimeSeriesQuery +from .types.metrics import SparkChartType from .types.scorecard import Scorecard from .types.text import Text from .types.widget import Widget from .types.xychart import ChartOptions from .types.xychart import XyChart - __all__ = ( + "DashboardsServiceAsyncClient", "Aggregation", "ChartOptions", "ColumnLayout", "CreateDashboardRequest", "Dashboard", + "DashboardsServiceClient", "DeleteDashboardRequest", "GetDashboardRequest", "GridLayout", @@ -67,5 +69,4 @@ "UpdateDashboardRequest", "Widget", "XyChart", - "DashboardsServiceClient", ) diff --git a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/gapic_metadata.json b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/gapic_metadata.json new file mode 100644 index 000000000000..94b72f39230d --- /dev/null +++ b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/gapic_metadata.json @@ -0,0 +1,73 @@ + { + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", + "language": "python", + "libraryPackage": "google.monitoring.dashboard_v1", + "protoPackage": "google.monitoring.dashboard.v1", + "schema": "1.0", + "services": { + "DashboardsService": { + "clients": { + "grpc": { + "libraryClient": "DashboardsServiceClient", + "rpcs": { + "CreateDashboard": { + "methods": [ + "create_dashboard" + ] + }, + "DeleteDashboard": { + "methods": [ + "delete_dashboard" + ] + }, + "GetDashboard": { + "methods": [ + "get_dashboard" + ] + }, + "ListDashboards": { + "methods": [ + "list_dashboards" + ] + }, + "UpdateDashboard": { + "methods": [ + "update_dashboard" + ] + } + } + }, + "grpc-async": { + "libraryClient": "DashboardsServiceAsyncClient", + "rpcs": { + "CreateDashboard": { + "methods": [ + "create_dashboard" + ] + }, + "DeleteDashboard": { + "methods": [ + "delete_dashboard" + ] + }, + "GetDashboard": { + "methods": [ + "get_dashboard" + ] + }, + "ListDashboards": { + "methods": [ + "list_dashboards" + ] + }, + "UpdateDashboard": { + "methods": [ + "update_dashboard" + ] + } + } + } + } + } + } +} diff --git a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/__init__.py b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/__init__.py index 42ffdf2bc43d..4de65971c238 100644 --- a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/__init__.py +++ b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/__init__.py b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/__init__.py index ad6c65ccadb5..05d6de680686 100644 --- a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/__init__.py +++ b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from .client import DashboardsServiceClient from .async_client import DashboardsServiceAsyncClient diff --git a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/async_client.py b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/async_client.py index 010cad153480..b75ef4d6aa53 100644 --- a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/async_client.py +++ b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/async_client.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict import functools import re @@ -22,17 +20,16 @@ import pkg_resources import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore from google.cloud.monitoring_dashboard_v1.services.dashboards_service import pagers from google.cloud.monitoring_dashboard_v1.types import dashboard from google.cloud.monitoring_dashboard_v1.types import dashboards_service from google.cloud.monitoring_dashboard_v1.types import layouts - from .transports.base import DashboardsServiceTransport, DEFAULT_CLIENT_INFO from .transports.grpc_asyncio import DashboardsServiceGrpcAsyncIOTransport from .client import DashboardsServiceClient @@ -50,31 +47,26 @@ class DashboardsServiceAsyncClient: dashboard_path = staticmethod(DashboardsServiceClient.dashboard_path) parse_dashboard_path = staticmethod(DashboardsServiceClient.parse_dashboard_path) - common_billing_account_path = staticmethod( DashboardsServiceClient.common_billing_account_path ) parse_common_billing_account_path = staticmethod( DashboardsServiceClient.parse_common_billing_account_path ) - common_folder_path = staticmethod(DashboardsServiceClient.common_folder_path) parse_common_folder_path = staticmethod( DashboardsServiceClient.parse_common_folder_path ) - common_organization_path = staticmethod( DashboardsServiceClient.common_organization_path ) parse_common_organization_path = staticmethod( DashboardsServiceClient.parse_common_organization_path ) - common_project_path = staticmethod(DashboardsServiceClient.common_project_path) parse_common_project_path = staticmethod( DashboardsServiceClient.parse_common_project_path ) - common_location_path = staticmethod(DashboardsServiceClient.common_location_path) parse_common_location_path = staticmethod( DashboardsServiceClient.parse_common_location_path @@ -82,7 +74,8 @@ class DashboardsServiceAsyncClient: @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -97,7 +90,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -114,7 +107,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> DashboardsServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: DashboardsServiceTransport: The transport used by the client instance. @@ -128,12 +121,12 @@ def transport(self) -> DashboardsServiceTransport: def __init__( self, *, - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, transport: Union[str, DashboardsServiceTransport] = "grpc_asyncio", client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the dashboards service client. + """Instantiates the dashboards service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -165,7 +158,6 @@ def __init__( google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport creation failed for any reason. """ - self._client = DashboardsServiceClient( credentials=credentials, transport=transport, @@ -192,7 +184,6 @@ async def create_dashboard( Args: request (:class:`google.cloud.monitoring_dashboard_v1.types.CreateDashboardRequest`): The request object. The `CreateDashboard` request. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -208,7 +199,6 @@ async def create_dashboard( """ # Create or coerce a protobuf request object. - request = dashboards_service.CreateDashboardRequest(request) # Wrap the RPC method; this adds retry and timeout information, @@ -249,7 +239,6 @@ async def list_dashboards( Args: request (:class:`google.cloud.monitoring_dashboard_v1.types.ListDashboardsRequest`): The request object. The `ListDashboards` request. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -265,7 +254,6 @@ async def list_dashboards( """ # Create or coerce a protobuf request object. - request = dashboards_service.ListDashboardsRequest(request) # Wrap the RPC method; this adds retry and timeout information, @@ -312,7 +300,6 @@ async def get_dashboard( Args: request (:class:`google.cloud.monitoring_dashboard_v1.types.GetDashboardRequest`): The request object. The `GetDashboard` request. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -328,7 +315,6 @@ async def get_dashboard( """ # Create or coerce a protobuf request object. - request = dashboards_service.GetDashboardRequest(request) # Wrap the RPC method; this adds retry and timeout information, @@ -369,7 +355,6 @@ async def delete_dashboard( Args: request (:class:`google.cloud.monitoring_dashboard_v1.types.DeleteDashboardRequest`): The request object. The `DeleteDashboard` request. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -377,7 +362,6 @@ async def delete_dashboard( sent along with the request as metadata. """ # Create or coerce a protobuf request object. - request = dashboards_service.DeleteDashboardRequest(request) # Wrap the RPC method; this adds retry and timeout information, @@ -417,7 +401,6 @@ async def update_dashboard( Args: request (:class:`google.cloud.monitoring_dashboard_v1.types.UpdateDashboardRequest`): The request object. The `UpdateDashboard` request. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -433,7 +416,6 @@ async def update_dashboard( """ # Create or coerce a protobuf request object. - request = dashboards_service.UpdateDashboardRequest(request) # Wrap the RPC method; this adds retry and timeout information, diff --git a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/client.py b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/client.py index 0ff30249aa3b..71fab17588c9 100644 --- a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/client.py +++ b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/client.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict from distutils import util import os @@ -23,10 +21,10 @@ import pkg_resources from google.api_core import client_options as client_options_lib # type: ignore -from google.api_core import exceptions # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport import mtls # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.auth.exceptions import MutualTLSChannelError # type: ignore @@ -36,7 +34,6 @@ from google.cloud.monitoring_dashboard_v1.types import dashboard from google.cloud.monitoring_dashboard_v1.types import dashboards_service from google.cloud.monitoring_dashboard_v1.types import layouts - from .transports.base import DashboardsServiceTransport, DEFAULT_CLIENT_INFO from .transports.grpc import DashboardsServiceGrpcTransport from .transports.grpc_asyncio import DashboardsServiceGrpcAsyncIOTransport @@ -59,7 +56,7 @@ class DashboardsServiceClientMeta(type): def get_transport_class( cls, label: str = None, ) -> Type[DashboardsServiceTransport]: - """Return an appropriate transport class. + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -84,7 +81,8 @@ class DashboardsServiceClient(metaclass=DashboardsServiceClientMeta): @staticmethod def _get_default_mtls_endpoint(api_endpoint): - """Convert api endpoint to mTLS endpoint. + """Converts api endpoint to mTLS endpoint. + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. Args: @@ -118,7 +116,8 @@ def _get_default_mtls_endpoint(api_endpoint): @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -135,7 +134,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -154,29 +153,30 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> DashboardsServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - DashboardsServiceTransport: The transport used by the client instance. + DashboardsServiceTransport: The transport used by the client + instance. """ return self._transport @staticmethod def dashboard_path(project: str, dashboard: str,) -> str: - """Return a fully-qualified dashboard string.""" + """Returns a fully-qualified dashboard string.""" return "projects/{project}/dashboards/{dashboard}".format( project=project, dashboard=dashboard, ) @staticmethod def parse_dashboard_path(path: str) -> Dict[str, str]: - """Parse a dashboard path into its component segments.""" + """Parses a dashboard path into its component segments.""" m = re.match(r"^projects/(?P.+?)/dashboards/(?P.+?)$", path) return m.groupdict() if m else {} @staticmethod def common_billing_account_path(billing_account: str,) -> str: - """Return a fully-qualified billing_account string.""" + """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -189,7 +189,7 @@ def parse_common_billing_account_path(path: str) -> Dict[str, str]: @staticmethod def common_folder_path(folder: str,) -> str: - """Return a fully-qualified folder string.""" + """Returns a fully-qualified folder string.""" return "folders/{folder}".format(folder=folder,) @staticmethod @@ -200,7 +200,7 @@ def parse_common_folder_path(path: str) -> Dict[str, str]: @staticmethod def common_organization_path(organization: str,) -> str: - """Return a fully-qualified organization string.""" + """Returns a fully-qualified organization string.""" return "organizations/{organization}".format(organization=organization,) @staticmethod @@ -211,7 +211,7 @@ def parse_common_organization_path(path: str) -> Dict[str, str]: @staticmethod def common_project_path(project: str,) -> str: - """Return a fully-qualified project string.""" + """Returns a fully-qualified project string.""" return "projects/{project}".format(project=project,) @staticmethod @@ -222,7 +222,7 @@ def parse_common_project_path(path: str) -> Dict[str, str]: @staticmethod def common_location_path(project: str, location: str,) -> str: - """Return a fully-qualified location string.""" + """Returns a fully-qualified location string.""" return "projects/{project}/locations/{location}".format( project=project, location=location, ) @@ -236,12 +236,12 @@ def parse_common_location_path(path: str) -> Dict[str, str]: def __init__( self, *, - credentials: Optional[credentials.Credentials] = None, + credentials: Optional[ga_credentials.Credentials] = None, transport: Union[str, DashboardsServiceTransport, None] = None, client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the dashboards service client. + """Instantiates the dashboards service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -296,9 +296,10 @@ def __init__( client_cert_source_func = client_options.client_cert_source else: is_mtls = mtls.has_default_client_cert_source() - client_cert_source_func = ( - mtls.default_client_cert_source() if is_mtls else None - ) + if is_mtls: + client_cert_source_func = mtls.default_client_cert_source() + else: + client_cert_source_func = None # Figure out which api endpoint to use. if client_options.api_endpoint is not None: @@ -310,12 +311,14 @@ def __init__( elif use_mtls_env == "always": api_endpoint = self.DEFAULT_MTLS_ENDPOINT elif use_mtls_env == "auto": - api_endpoint = ( - self.DEFAULT_MTLS_ENDPOINT if is_mtls else self.DEFAULT_ENDPOINT - ) + if is_mtls: + api_endpoint = self.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = self.DEFAULT_ENDPOINT else: raise MutualTLSChannelError( - "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted values: never, auto, always" + "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted " + "values: never, auto, always" ) # Save or instantiate the transport. @@ -330,8 +333,8 @@ def __init__( ) if client_options.scopes: raise ValueError( - "When providing a transport instance, " - "provide its scopes directly." + "When providing a transport instance, provide its scopes " + "directly." ) self._transport = transport else: @@ -365,7 +368,6 @@ def create_dashboard( Args: request (google.cloud.monitoring_dashboard_v1.types.CreateDashboardRequest): The request object. The `CreateDashboard` request. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -381,7 +383,6 @@ def create_dashboard( """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes # in a dashboards_service.CreateDashboardRequest. # There's no risk of modifying the input as we've already verified @@ -423,7 +424,6 @@ def list_dashboards( Args: request (google.cloud.monitoring_dashboard_v1.types.ListDashboardsRequest): The request object. The `ListDashboards` request. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -439,7 +439,6 @@ def list_dashboards( """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes # in a dashboards_service.ListDashboardsRequest. # There's no risk of modifying the input as we've already verified @@ -487,7 +486,6 @@ def get_dashboard( Args: request (google.cloud.monitoring_dashboard_v1.types.GetDashboardRequest): The request object. The `GetDashboard` request. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -503,7 +501,6 @@ def get_dashboard( """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes # in a dashboards_service.GetDashboardRequest. # There's no risk of modifying the input as we've already verified @@ -545,7 +542,6 @@ def delete_dashboard( Args: request (google.cloud.monitoring_dashboard_v1.types.DeleteDashboardRequest): The request object. The `DeleteDashboard` request. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -553,7 +549,6 @@ def delete_dashboard( sent along with the request as metadata. """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes # in a dashboards_service.DeleteDashboardRequest. # There's no risk of modifying the input as we've already verified @@ -594,7 +589,6 @@ def update_dashboard( Args: request (google.cloud.monitoring_dashboard_v1.types.UpdateDashboardRequest): The request object. The `UpdateDashboard` request. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -610,7 +604,6 @@ def update_dashboard( """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes # in a dashboards_service.UpdateDashboardRequest. # There's no risk of modifying the input as we've already verified diff --git a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/pagers.py b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/pagers.py index cda2bebac139..6dbf4e5f4deb 100644 --- a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/pagers.py +++ b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/pagers.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from typing import ( Any, AsyncIterable, @@ -118,7 +116,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and diff --git a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/__init__.py b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/__init__.py index 0d306cdedd7e..8c6023999a44 100644 --- a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/__init__.py +++ b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict from typing import Dict, Type diff --git a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/base.py b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/base.py index fc763a410da4..1363421b4954 100644 --- a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/base.py +++ b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/base.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,21 +13,21 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import abc -import typing +from typing import Awaitable, Callable, Dict, Optional, Sequence, Union +import packaging.version import pkg_resources -from google import auth # type: ignore -from google.api_core import exceptions # type: ignore +import google.auth # type: ignore +import google.api_core # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.cloud.monitoring_dashboard_v1.types import dashboard from google.cloud.monitoring_dashboard_v1.types import dashboards_service -from google.protobuf import empty_pb2 as empty # type: ignore - +from google.protobuf import empty_pb2 # type: ignore try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( @@ -39,6 +38,17 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() +try: + # google.auth.__version__ was added in 1.26.0 + _GOOGLE_AUTH_VERSION = google.auth.__version__ +except AttributeError: + try: # try pkg_resources if it is available + _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version + except pkg_resources.DistributionNotFound: # pragma: NO COVER + _GOOGLE_AUTH_VERSION = None + +_API_CORE_VERSION = google.api_core.__version__ + class DashboardsServiceTransport(abc.ABC): """Abstract transport class for DashboardsService.""" @@ -50,21 +60,24 @@ class DashboardsServiceTransport(abc.ABC): "https://www.googleapis.com/auth/monitoring.write", ) + DEFAULT_HOST: str = "monitoring.googleapis.com" + def __init__( self, *, - host: str = "monitoring.googleapis.com", - credentials: credentials.Credentials = None, - credentials_file: typing.Optional[str] = None, - scopes: typing.Optional[typing.Sequence[str]] = AUTH_SCOPES, - quota_project_id: typing.Optional[str] = None, + host: str = DEFAULT_HOST, + credentials: ga_credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, **kwargs, ) -> None: """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -73,7 +86,7 @@ def __init__( credentials_file (Optional[str]): A file with credentials that can be loaded with :func:`google.auth.load_credentials_from_file`. This argument is mutually exclusive with credentials. - scope (Optional[Sequence[str]]): A list of scopes. + scopes (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -87,29 +100,76 @@ def __init__( host += ":443" self._host = host + scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + # Save the scopes. self._scopes = scopes or self.AUTH_SCOPES # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: - raise exceptions.DuplicateCredentialArgs( + raise core_exceptions.DuplicateCredentialArgs( "'credentials_file' and 'credentials' are mutually exclusive" ) if credentials_file is not None: - credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=self._scopes, quota_project_id=quota_project_id + credentials, _ = google.auth.load_credentials_from_file( + credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) elif credentials is None: - credentials, _ = auth.default( - scopes=self._scopes, quota_project_id=quota_project_id + credentials, _ = google.auth.default( + **scopes_kwargs, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials + # TODO(busunkim): These two class methods are in the base transport + # to avoid duplicating code across the transport classes. These functions + # should be deleted once the minimum required versions of google-api-core + # and google-auth are increased. + + # TODO: Remove this function once google-auth >= 1.25.0 is required + @classmethod + def _get_scopes_kwargs( + cls, host: str, scopes: Optional[Sequence[str]] + ) -> Dict[str, Optional[Sequence[str]]]: + """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" + + scopes_kwargs = {} + + if _GOOGLE_AUTH_VERSION and ( + packaging.version.parse(_GOOGLE_AUTH_VERSION) + >= packaging.version.parse("1.25.0") + ): + scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} + else: + scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} + + return scopes_kwargs + + # TODO: Remove this function once google-api-core >= 1.26.0 is required + @classmethod + def _get_self_signed_jwt_kwargs( + cls, host: str, scopes: Optional[Sequence[str]] + ) -> Dict[str, Union[Optional[Sequence[str]], str]]: + """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" + + self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} + + if _API_CORE_VERSION and ( + packaging.version.parse(_API_CORE_VERSION) + >= packaging.version.parse("1.26.0") + ): + self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES + self_signed_jwt_kwargs["scopes"] = scopes + self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST + else: + self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES + + return self_signed_jwt_kwargs + def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { @@ -133,20 +193,20 @@ def _prep_wrapped_messages(self, client_info): @property def create_dashboard( self, - ) -> typing.Callable[ + ) -> Callable[ [dashboards_service.CreateDashboardRequest], - typing.Union[dashboard.Dashboard, typing.Awaitable[dashboard.Dashboard]], + Union[dashboard.Dashboard, Awaitable[dashboard.Dashboard]], ]: raise NotImplementedError() @property def list_dashboards( self, - ) -> typing.Callable[ + ) -> Callable[ [dashboards_service.ListDashboardsRequest], - typing.Union[ + Union[ dashboards_service.ListDashboardsResponse, - typing.Awaitable[dashboards_service.ListDashboardsResponse], + Awaitable[dashboards_service.ListDashboardsResponse], ], ]: raise NotImplementedError() @@ -154,27 +214,27 @@ def list_dashboards( @property def get_dashboard( self, - ) -> typing.Callable[ + ) -> Callable[ [dashboards_service.GetDashboardRequest], - typing.Union[dashboard.Dashboard, typing.Awaitable[dashboard.Dashboard]], + Union[dashboard.Dashboard, Awaitable[dashboard.Dashboard]], ]: raise NotImplementedError() @property def delete_dashboard( self, - ) -> typing.Callable[ + ) -> Callable[ [dashboards_service.DeleteDashboardRequest], - typing.Union[empty.Empty, typing.Awaitable[empty.Empty]], + Union[empty_pb2.Empty, Awaitable[empty_pb2.Empty]], ]: raise NotImplementedError() @property def update_dashboard( self, - ) -> typing.Callable[ + ) -> Callable[ [dashboards_service.UpdateDashboardRequest], - typing.Union[dashboard.Dashboard, typing.Awaitable[dashboard.Dashboard]], + Union[dashboard.Dashboard, Awaitable[dashboard.Dashboard]], ]: raise NotImplementedError() diff --git a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/grpc.py b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/grpc.py index 00e5009a3e1f..b5186b781cdb 100644 --- a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/grpc.py +++ b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/grpc.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,22 +13,20 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import warnings -from typing import Callable, Dict, Optional, Sequence, Tuple +from typing import Callable, Dict, Optional, Sequence, Tuple, Union from google.api_core import grpc_helpers # type: ignore from google.api_core import gapic_v1 # type: ignore -from google import auth # type: ignore -from google.auth import credentials # type: ignore +import google.auth # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore import grpc # type: ignore from google.cloud.monitoring_dashboard_v1.types import dashboard from google.cloud.monitoring_dashboard_v1.types import dashboards_service -from google.protobuf import empty_pb2 as empty # type: ignore - +from google.protobuf import empty_pb2 # type: ignore from .base import DashboardsServiceTransport, DEFAULT_CLIENT_INFO @@ -53,7 +50,7 @@ def __init__( self, *, host: str = "monitoring.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: str = None, scopes: Sequence[str] = None, channel: grpc.Channel = None, @@ -67,7 +64,8 @@ def __init__( """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -177,7 +175,7 @@ def __init__( def create_channel( cls, host: str = "monitoring.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: str = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, @@ -208,13 +206,15 @@ def create_channel( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ - scopes = scopes or cls.AUTH_SCOPES + + self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) + return grpc_helpers.create_channel( host, credentials=credentials, credentials_file=credentials_file, - scopes=scopes, quota_project_id=quota_project_id, + **self_signed_jwt_kwargs, **kwargs, ) @@ -324,7 +324,7 @@ def get_dashboard( @property def delete_dashboard( self, - ) -> Callable[[dashboards_service.DeleteDashboardRequest], empty.Empty]: + ) -> Callable[[dashboards_service.DeleteDashboardRequest], empty_pb2.Empty]: r"""Return a callable for the delete dashboard method over gRPC. Deletes an existing custom dashboard. @@ -348,7 +348,7 @@ def delete_dashboard( self._stubs["delete_dashboard"] = self.grpc_channel.unary_unary( "/google.monitoring.dashboard.v1.DashboardsService/DeleteDashboard", request_serializer=dashboards_service.DeleteDashboardRequest.serialize, - response_deserializer=empty.Empty.FromString, + response_deserializer=empty_pb2.Empty.FromString, ) return self._stubs["delete_dashboard"] diff --git a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/grpc_asyncio.py b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/grpc_asyncio.py index 495d820e3af4..7c8551dbf3dc 100644 --- a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/grpc_asyncio.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,23 +13,21 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import warnings -from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple +from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union from google.api_core import gapic_v1 # type: ignore from google.api_core import grpc_helpers_async # type: ignore -from google import auth # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore from google.cloud.monitoring_dashboard_v1.types import dashboard from google.cloud.monitoring_dashboard_v1.types import dashboards_service -from google.protobuf import empty_pb2 as empty # type: ignore - +from google.protobuf import empty_pb2 # type: ignore from .base import DashboardsServiceTransport, DEFAULT_CLIENT_INFO from .grpc import DashboardsServiceGrpcTransport @@ -56,7 +53,7 @@ class DashboardsServiceGrpcAsyncIOTransport(DashboardsServiceTransport): def create_channel( cls, host: str = "monitoring.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, @@ -83,13 +80,15 @@ def create_channel( Returns: aio.Channel: A gRPC AsyncIO channel object. """ - scopes = scopes or cls.AUTH_SCOPES + + self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) + return grpc_helpers_async.create_channel( host, credentials=credentials, credentials_file=credentials_file, - scopes=scopes, quota_project_id=quota_project_id, + **self_signed_jwt_kwargs, **kwargs, ) @@ -97,7 +96,7 @@ def __init__( self, *, host: str = "monitoring.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, channel: aio.Channel = None, @@ -111,7 +110,8 @@ def __init__( """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -169,7 +169,6 @@ def __init__( # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - else: if api_mtls_endpoint: host = api_mtls_endpoint @@ -332,7 +331,9 @@ def get_dashboard( @property def delete_dashboard( self, - ) -> Callable[[dashboards_service.DeleteDashboardRequest], Awaitable[empty.Empty]]: + ) -> Callable[ + [dashboards_service.DeleteDashboardRequest], Awaitable[empty_pb2.Empty] + ]: r"""Return a callable for the delete dashboard method over gRPC. Deletes an existing custom dashboard. @@ -356,7 +357,7 @@ def delete_dashboard( self._stubs["delete_dashboard"] = self.grpc_channel.unary_unary( "/google.monitoring.dashboard.v1.DashboardsService/DeleteDashboard", request_serializer=dashboards_service.DeleteDashboardRequest.serialize, - response_deserializer=empty.Empty.FromString, + response_deserializer=empty_pb2.Empty.FromString, ) return self._stubs["delete_dashboard"] diff --git a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/__init__.py b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/__init__.py index ec48e01a0b3a..1644bbbe354c 100644 --- a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/__init__.py +++ b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from .common import ( Aggregation, PickTimeSeriesFilter, diff --git a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/common.py b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/common.py index 3405b1df02c0..eb21a0254a62 100644 --- a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/common.py +++ b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/common.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,11 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - -from google.protobuf import duration_pb2 as duration # type: ignore +from google.protobuf import duration_pb2 # type: ignore __protobuf__ = proto.module( @@ -185,13 +182,12 @@ class Reducer(proto.Enum): REDUCE_PERCENTILE_50 = 11 REDUCE_PERCENTILE_05 = 12 - alignment_period = proto.Field(proto.MESSAGE, number=1, message=duration.Duration,) - + alignment_period = proto.Field( + proto.MESSAGE, number=1, message=duration_pb2.Duration, + ) per_series_aligner = proto.Field(proto.ENUM, number=2, enum=Aligner,) - cross_series_reducer = proto.Field(proto.ENUM, number=4, enum=Reducer,) - - group_by_fields = proto.RepeatedField(proto.STRING, number=5) + group_by_fields = proto.RepeatedField(proto.STRING, number=5,) class PickTimeSeriesFilter(proto.Message): @@ -236,9 +232,7 @@ class Direction(proto.Enum): BOTTOM = 2 ranking_method = proto.Field(proto.ENUM, number=1, enum=Method,) - - num_time_series = proto.Field(proto.INT32, number=2) - + num_time_series = proto.Field(proto.INT32, number=2,) direction = proto.Field(proto.ENUM, number=3, enum=Direction,) @@ -266,8 +260,7 @@ class Method(proto.Enum): METHOD_CLUSTER_OUTLIER = 1 ranking_method = proto.Field(proto.ENUM, number=1, enum=Method,) - - num_time_series = proto.Field(proto.INT32, number=2) + num_time_series = proto.Field(proto.INT32, number=2,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/dashboard.py b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/dashboard.py index 689f93c68af0..e6acaa45dafe 100644 --- a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/dashboard.py +++ b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/dashboard.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,10 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.monitoring_dashboard_v1.types import layouts @@ -61,24 +58,18 @@ class Dashboard(proto.Message): columns and the widgets are arranged vertically. """ - name = proto.Field(proto.STRING, number=1) - - display_name = proto.Field(proto.STRING, number=2) - - etag = proto.Field(proto.STRING, number=4) - + name = proto.Field(proto.STRING, number=1,) + display_name = proto.Field(proto.STRING, number=2,) + etag = proto.Field(proto.STRING, number=4,) grid_layout = proto.Field( proto.MESSAGE, number=5, oneof="layout", message=layouts.GridLayout, ) - mosaic_layout = proto.Field( proto.MESSAGE, number=6, oneof="layout", message=layouts.MosaicLayout, ) - row_layout = proto.Field( proto.MESSAGE, number=8, oneof="layout", message=layouts.RowLayout, ) - column_layout = proto.Field( proto.MESSAGE, number=9, oneof="layout", message=layouts.ColumnLayout, ) diff --git a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/dashboards_service.py b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/dashboards_service.py index 1e866ac6fa4d..6956e3459f14 100644 --- a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/dashboards_service.py +++ b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/dashboards_service.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,10 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.monitoring_dashboard_v1.types import dashboard as gmd_dashboard @@ -36,7 +33,6 @@ class CreateDashboardRequest(proto.Message): r"""The ``CreateDashboard`` request. - Attributes: parent (str): Required. The project on which to execute the request. The @@ -53,14 +49,12 @@ class CreateDashboardRequest(proto.Message): specification. """ - parent = proto.Field(proto.STRING, number=1) - + parent = proto.Field(proto.STRING, number=1,) dashboard = proto.Field(proto.MESSAGE, number=2, message=gmd_dashboard.Dashboard,) class ListDashboardsRequest(proto.Message): r"""The ``ListDashboards`` request. - Attributes: parent (str): Required. The scope of the dashboards to list. The format @@ -80,16 +74,13 @@ class ListDashboardsRequest(proto.Message): additional results from the previous method call. """ - parent = proto.Field(proto.STRING, number=1) - - page_size = proto.Field(proto.INT32, number=2) - - page_token = proto.Field(proto.STRING, number=3) + parent = proto.Field(proto.STRING, number=1,) + page_size = proto.Field(proto.INT32, number=2,) + page_token = proto.Field(proto.STRING, number=3,) class ListDashboardsResponse(proto.Message): r"""The ``ListDashboards`` request. - Attributes: dashboards (Sequence[google.cloud.monitoring_dashboard_v1.types.Dashboard]): The list of requested dashboards. @@ -107,13 +98,11 @@ def raw_page(self): dashboards = proto.RepeatedField( proto.MESSAGE, number=1, message=gmd_dashboard.Dashboard, ) - - next_page_token = proto.Field(proto.STRING, number=2) + next_page_token = proto.Field(proto.STRING, number=2,) class GetDashboardRequest(proto.Message): r"""The ``GetDashboard`` request. - Attributes: name (str): Required. The resource name of the Dashboard. The format is @@ -124,12 +113,11 @@ class GetDashboardRequest(proto.Message): (for custom dashboards). """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class DeleteDashboardRequest(proto.Message): r"""The ``DeleteDashboard`` request. - Attributes: name (str): Required. The resource name of the Dashboard. The format is: @@ -139,12 +127,11 @@ class DeleteDashboardRequest(proto.Message): projects/[PROJECT_ID_OR_NUMBER]/dashboards/[DASHBOARD_ID] """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class UpdateDashboardRequest(proto.Message): r"""The ``UpdateDashboard`` request. - Attributes: dashboard (google.cloud.monitoring_dashboard_v1.types.Dashboard): Required. The dashboard that will replace the diff --git a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/drilldowns.py b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/drilldowns.py index 7c1c13825039..c92c8dc0696d 100644 --- a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/drilldowns.py +++ b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/drilldowns.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/layouts.py b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/layouts.py index f87385a34624..fbfbb6bdafd8 100644 --- a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/layouts.py +++ b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/layouts.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,10 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.monitoring_dashboard_v1.types import widget as gmd_widget @@ -42,8 +39,7 @@ class GridLayout(proto.Message): into the columns row-first. """ - columns = proto.Field(proto.INT64, number=1) - + columns = proto.Field(proto.INT64, number=1,) widgets = proto.RepeatedField(proto.MESSAGE, number=2, message=gmd_widget.Widget,) @@ -87,18 +83,13 @@ class Tile(proto.Message): an ``XyChart``. """ - x_pos = proto.Field(proto.INT32, number=1) - - y_pos = proto.Field(proto.INT32, number=2) - - width = proto.Field(proto.INT32, number=3) - - height = proto.Field(proto.INT32, number=4) - + x_pos = proto.Field(proto.INT32, number=1,) + y_pos = proto.Field(proto.INT32, number=2,) + width = proto.Field(proto.INT32, number=3,) + height = proto.Field(proto.INT32, number=4,) widget = proto.Field(proto.MESSAGE, number=5, message=gmd_widget.Widget,) - columns = proto.Field(proto.INT32, number=1) - + columns = proto.Field(proto.INT32, number=1,) tiles = proto.RepeatedField(proto.MESSAGE, number=3, message=Tile,) @@ -113,7 +104,6 @@ class RowLayout(proto.Message): class Row(proto.Message): r"""Defines the layout properties and content for a row. - Attributes: weight (int): The relative weight of this row. The row @@ -127,8 +117,7 @@ class Row(proto.Message): this row. """ - weight = proto.Field(proto.INT64, number=1) - + weight = proto.Field(proto.INT64, number=1,) widgets = proto.RepeatedField( proto.MESSAGE, number=2, message=gmd_widget.Widget, ) @@ -148,7 +137,6 @@ class ColumnLayout(proto.Message): class Column(proto.Message): r"""Defines the layout properties and content for a column. - Attributes: weight (int): The relative weight of this column. The @@ -162,8 +150,7 @@ class Column(proto.Message): this column. """ - weight = proto.Field(proto.INT64, number=1) - + weight = proto.Field(proto.INT64, number=1,) widgets = proto.RepeatedField( proto.MESSAGE, number=2, message=gmd_widget.Widget, ) diff --git a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/metrics.py b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/metrics.py index 7526cb9c58f5..784d502fe9c0 100644 --- a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/metrics.py +++ b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/metrics.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,10 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.monitoring_dashboard_v1.types import common @@ -65,14 +62,11 @@ class TimeSeriesQuery(proto.Message): time_series_filter = proto.Field( proto.MESSAGE, number=1, oneof="source", message="TimeSeriesFilter", ) - time_series_filter_ratio = proto.Field( proto.MESSAGE, number=2, oneof="source", message="TimeSeriesFilterRatio", ) - - time_series_query_language = proto.Field(proto.STRING, number=3, oneof="source") - - unit_override = proto.Field(proto.STRING, number=5) + time_series_query_language = proto.Field(proto.STRING, number=3, oneof="source",) + unit_override = proto.Field(proto.STRING, number=5,) class TimeSeriesFilter(proto.Message): @@ -101,21 +95,17 @@ class TimeSeriesFilter(proto.Message): ignored by the API. """ - filter = proto.Field(proto.STRING, number=1) - + filter = proto.Field(proto.STRING, number=1,) aggregation = proto.Field(proto.MESSAGE, number=2, message=common.Aggregation,) - secondary_aggregation = proto.Field( proto.MESSAGE, number=3, message=common.Aggregation, ) - pick_time_series_filter = proto.Field( proto.MESSAGE, number=4, oneof="output_filter", message=common.PickTimeSeriesFilter, ) - statistical_time_series_filter = proto.Field( proto.MESSAGE, number=5, @@ -162,25 +152,20 @@ class RatioPart(proto.Message): time series for different views of the data. """ - filter = proto.Field(proto.STRING, number=1) - + filter = proto.Field(proto.STRING, number=1,) aggregation = proto.Field(proto.MESSAGE, number=2, message=common.Aggregation,) numerator = proto.Field(proto.MESSAGE, number=1, message=RatioPart,) - denominator = proto.Field(proto.MESSAGE, number=2, message=RatioPart,) - secondary_aggregation = proto.Field( proto.MESSAGE, number=3, message=common.Aggregation, ) - pick_time_series_filter = proto.Field( proto.MESSAGE, number=4, oneof="output_filter", message=common.PickTimeSeriesFilter, ) - statistical_time_series_filter = proto.Field( proto.MESSAGE, number=5, @@ -191,7 +176,6 @@ class RatioPart(proto.Message): class Threshold(proto.Message): r"""Defines a threshold for categorizing time series values. - Attributes: label (str): A label for the threshold. @@ -224,12 +208,9 @@ class Direction(proto.Enum): ABOVE = 1 BELOW = 2 - label = proto.Field(proto.STRING, number=1) - - value = proto.Field(proto.DOUBLE, number=2) - + label = proto.Field(proto.STRING, number=1,) + value = proto.Field(proto.DOUBLE, number=2,) color = proto.Field(proto.ENUM, number=3, enum=Color,) - direction = proto.Field(proto.ENUM, number=4, enum=Direction,) diff --git a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/scorecard.py b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/scorecard.py index e03bd1495695..7dc885bbe452 100644 --- a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/scorecard.py +++ b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/scorecard.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,12 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.monitoring_dashboard_v1.types import metrics -from google.protobuf import duration_pb2 as duration # type: ignore +from google.protobuf import duration_pb2 # type: ignore __protobuf__ = proto.module( @@ -100,9 +97,8 @@ class GaugeView(proto.Message): equal to this. """ - lower_bound = proto.Field(proto.DOUBLE, number=1) - - upper_bound = proto.Field(proto.DOUBLE, number=2) + lower_bound = proto.Field(proto.DOUBLE, number=1,) + upper_bound = proto.Field(proto.DOUBLE, number=2,) class SparkChartView(proto.Message): r"""A sparkChart is a small chart suitable for inclusion in a @@ -127,23 +123,19 @@ class SparkChartView(proto.Message): spark_chart_type = proto.Field( proto.ENUM, number=1, enum=metrics.SparkChartType, ) - min_alignment_period = proto.Field( - proto.MESSAGE, number=2, message=duration.Duration, + proto.MESSAGE, number=2, message=duration_pb2.Duration, ) time_series_query = proto.Field( proto.MESSAGE, number=1, message=metrics.TimeSeriesQuery, ) - gauge_view = proto.Field( proto.MESSAGE, number=4, oneof="data_view", message=GaugeView, ) - spark_chart_view = proto.Field( proto.MESSAGE, number=5, oneof="data_view", message=SparkChartView, ) - thresholds = proto.RepeatedField( proto.MESSAGE, number=6, message=metrics.Threshold, ) diff --git a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/service.py b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/service.py index 7c1c13825039..c92c8dc0696d 100644 --- a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/service.py +++ b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/service.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/text.py b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/text.py index e282af25fa93..81da18b21505 100644 --- a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/text.py +++ b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/text.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore @@ -25,7 +23,6 @@ class Text(proto.Message): r"""A widget that displays textual content. - Attributes: content (str): The text content to be displayed. @@ -39,8 +36,7 @@ class Format(proto.Enum): MARKDOWN = 1 RAW = 2 - content = proto.Field(proto.STRING, number=1) - + content = proto.Field(proto.STRING, number=1,) format_ = proto.Field(proto.ENUM, number=2, enum=Format,) diff --git a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/widget.py b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/widget.py index 282b2b059238..c70cddbf8929 100644 --- a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/widget.py +++ b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/widget.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,14 +13,12 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.monitoring_dashboard_v1.types import scorecard as gmd_scorecard from google.cloud.monitoring_dashboard_v1.types import text as gmd_text from google.cloud.monitoring_dashboard_v1.types import xychart -from google.protobuf import empty_pb2 as empty # type: ignore +from google.protobuf import empty_pb2 # type: ignore __protobuf__ = proto.module( @@ -47,19 +44,17 @@ class Widget(proto.Message): A blank space. """ - title = proto.Field(proto.STRING, number=1) - + title = proto.Field(proto.STRING, number=1,) xy_chart = proto.Field( proto.MESSAGE, number=2, oneof="content", message=xychart.XyChart, ) - scorecard = proto.Field( proto.MESSAGE, number=3, oneof="content", message=gmd_scorecard.Scorecard, ) - text = proto.Field(proto.MESSAGE, number=4, oneof="content", message=gmd_text.Text,) - - blank = proto.Field(proto.MESSAGE, number=5, oneof="content", message=empty.Empty,) + blank = proto.Field( + proto.MESSAGE, number=5, oneof="content", message=empty_pb2.Empty, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/xychart.py b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/xychart.py index 16a975d6ab09..66b5612149aa 100644 --- a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/xychart.py +++ b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/types/xychart.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,12 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.monitoring_dashboard_v1.types import metrics -from google.protobuf import duration_pb2 as duration # type: ignore +from google.protobuf import duration_pb2 # type: ignore __protobuf__ = proto.module( @@ -29,7 +26,6 @@ class XyChart(proto.Message): r"""A chart that displays data on a 2D (X and Y axes) plane. - Attributes: data_sets (Sequence[google.cloud.monitoring_dashboard_v1.types.XyChart.DataSet]): Required. The data displayed in this chart. @@ -54,7 +50,6 @@ class XyChart(proto.Message): class DataSet(proto.Message): r"""Groups a time series query definition with charting options. - Attributes: time_series_query (google.cloud.monitoring_dashboard_v1.types.TimeSeriesQuery): Required. Fields for querying time series @@ -69,7 +64,7 @@ class DataSet(proto.Message): min_alignment_period (google.protobuf.duration_pb2.Duration): Optional. The lower bound on data point frequency for this data set, implemented by specifying the minimum alignment - period to use in a time series query For example, if the + period to use in a time series query. For example, if the data is published once every 10 minutes, the ``min_alignment_period`` should be at least 10 minutes. It would not make sense to fetch and align data at one minute @@ -87,18 +82,14 @@ class PlotType(proto.Enum): time_series_query = proto.Field( proto.MESSAGE, number=1, message=metrics.TimeSeriesQuery, ) - plot_type = proto.Field(proto.ENUM, number=2, enum="XyChart.DataSet.PlotType",) - - legend_template = proto.Field(proto.STRING, number=3) - + legend_template = proto.Field(proto.STRING, number=3,) min_alignment_period = proto.Field( - proto.MESSAGE, number=4, message=duration.Duration, + proto.MESSAGE, number=4, message=duration_pb2.Duration, ) class Axis(proto.Message): r"""A chart axis. - Attributes: label (str): The label of the axis. @@ -113,30 +104,23 @@ class Scale(proto.Enum): LINEAR = 1 LOG10 = 2 - label = proto.Field(proto.STRING, number=1) - + label = proto.Field(proto.STRING, number=1,) scale = proto.Field(proto.ENUM, number=2, enum="XyChart.Axis.Scale",) data_sets = proto.RepeatedField(proto.MESSAGE, number=1, message=DataSet,) - timeshift_duration = proto.Field( - proto.MESSAGE, number=4, message=duration.Duration, + proto.MESSAGE, number=4, message=duration_pb2.Duration, ) - thresholds = proto.RepeatedField( proto.MESSAGE, number=5, message=metrics.Threshold, ) - x_axis = proto.Field(proto.MESSAGE, number=6, message=Axis,) - y_axis = proto.Field(proto.MESSAGE, number=7, message=Axis,) - chart_options = proto.Field(proto.MESSAGE, number=8, message="ChartOptions",) class ChartOptions(proto.Message): r"""Options to control visual rendering of a chart. - Attributes: mode (google.cloud.monitoring_dashboard_v1.types.ChartOptions.Mode): The chart mode. diff --git a/packages/google-cloud-monitoring-dashboards/scripts/fixup_dashboard_v1_keywords.py b/packages/google-cloud-monitoring-dashboards/scripts/fixup_dashboard_v1_keywords.py index fd8c73677316..db3aefda2e33 100644 --- a/packages/google-cloud-monitoring-dashboards/scripts/fixup_dashboard_v1_keywords.py +++ b/packages/google-cloud-monitoring-dashboards/scripts/fixup_dashboard_v1_keywords.py @@ -1,6 +1,5 @@ #! /usr/bin/env python3 # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,7 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import argparse import os import libcst as cst @@ -41,12 +39,11 @@ def partition( class dashboardCallTransformer(cst.CSTTransformer): CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { - 'create_dashboard': ('parent', 'dashboard', ), - 'delete_dashboard': ('name', ), - 'get_dashboard': ('name', ), - 'list_dashboards': ('parent', 'page_size', 'page_token', ), - 'update_dashboard': ('dashboard', ), - + 'create_dashboard': ('parent', 'dashboard', ), + 'delete_dashboard': ('name', ), + 'get_dashboard': ('name', ), + 'list_dashboards': ('parent', 'page_size', 'page_token', ), + 'update_dashboard': ('dashboard', ), } def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: @@ -77,7 +74,7 @@ def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: value=cst.Dict([ cst.DictElement( cst.SimpleString("'{}'".format(name)), - cst.Element(value=arg.value) +cst.Element(value=arg.value) ) # Note: the args + kwargs looks silly, but keep in mind that # the control parameters had to be stripped out, and that diff --git a/packages/google-cloud-monitoring-dashboards/tests/__init__.py b/packages/google-cloud-monitoring-dashboards/tests/__init__.py new file mode 100644 index 000000000000..4de65971c238 --- /dev/null +++ b/packages/google-cloud-monitoring-dashboards/tests/__init__.py @@ -0,0 +1,15 @@ +# -*- 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 +# +# http://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. +# diff --git a/packages/google-cloud-monitoring-dashboards/tests/unit/__init__.py b/packages/google-cloud-monitoring-dashboards/tests/unit/__init__.py new file mode 100644 index 000000000000..4de65971c238 --- /dev/null +++ b/packages/google-cloud-monitoring-dashboards/tests/unit/__init__.py @@ -0,0 +1,15 @@ +# -*- 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 +# +# http://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. +# diff --git a/packages/google-cloud-monitoring-dashboards/tests/unit/gapic/__init__.py b/packages/google-cloud-monitoring-dashboards/tests/unit/gapic/__init__.py new file mode 100644 index 000000000000..4de65971c238 --- /dev/null +++ b/packages/google-cloud-monitoring-dashboards/tests/unit/gapic/__init__.py @@ -0,0 +1,15 @@ +# -*- 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 +# +# http://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. +# diff --git a/packages/google-cloud-monitoring-dashboards/tests/unit/gapic/dashboard_v1/__init__.py b/packages/google-cloud-monitoring-dashboards/tests/unit/gapic/dashboard_v1/__init__.py index 42ffdf2bc43d..4de65971c238 100644 --- a/packages/google-cloud-monitoring-dashboards/tests/unit/gapic/dashboard_v1/__init__.py +++ b/packages/google-cloud-monitoring-dashboards/tests/unit/gapic/dashboard_v1/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/packages/google-cloud-monitoring-dashboards/tests/unit/gapic/dashboard_v1/test_dashboards_service.py b/packages/google-cloud-monitoring-dashboards/tests/unit/gapic/dashboard_v1/test_dashboards_service.py index 7b1fb1439761..2b6c847e5bc0 100644 --- a/packages/google-cloud-monitoring-dashboards/tests/unit/gapic/dashboard_v1/test_dashboards_service.py +++ b/packages/google-cloud-monitoring-dashboards/tests/unit/gapic/dashboard_v1/test_dashboards_service.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import os import mock +import packaging.version import grpc from grpc.experimental import aio @@ -24,13 +23,13 @@ import pytest from proto.marshal.rules.dates import DurationRule, TimestampRule -from google import auth + from google.api_core import client_options -from google.api_core import exceptions +from google.api_core import exceptions as core_exceptions from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async -from google.auth import credentials +from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.monitoring_dashboard_v1.services.dashboards_service import ( DashboardsServiceAsyncClient, @@ -40,6 +39,12 @@ ) from google.cloud.monitoring_dashboard_v1.services.dashboards_service import pagers from google.cloud.monitoring_dashboard_v1.services.dashboards_service import transports +from google.cloud.monitoring_dashboard_v1.services.dashboards_service.transports.base import ( + _API_CORE_VERSION, +) +from google.cloud.monitoring_dashboard_v1.services.dashboards_service.transports.base import ( + _GOOGLE_AUTH_VERSION, +) from google.cloud.monitoring_dashboard_v1.types import common from google.cloud.monitoring_dashboard_v1.types import dashboard from google.cloud.monitoring_dashboard_v1.types import dashboards_service @@ -50,7 +55,31 @@ from google.cloud.monitoring_dashboard_v1.types import widget from google.cloud.monitoring_dashboard_v1.types import xychart from google.oauth2 import service_account -from google.protobuf import duration_pb2 as duration # type: ignore +from google.protobuf import duration_pb2 # type: ignore +import google.auth + + +# TODO(busunkim): Once google-api-core >= 1.26.0 is required: +# - Delete all the api-core and auth "less than" test cases +# - Delete these pytest markers (Make the "greater than or equal to" tests the default). +requires_google_auth_lt_1_25_0 = pytest.mark.skipif( + packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), + reason="This test requires google-auth < 1.25.0", +) +requires_google_auth_gte_1_25_0 = pytest.mark.skipif( + packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), + reason="This test requires google-auth >= 1.25.0", +) + +requires_api_core_lt_1_26_0 = pytest.mark.skipif( + packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), + reason="This test requires google-api-core < 1.26.0", +) + +requires_api_core_gte_1_26_0 = pytest.mark.skipif( + packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), + reason="This test requires google-api-core >= 1.26.0", +) def client_cert_source_callback(): @@ -102,7 +131,7 @@ def test__get_default_mtls_endpoint(): "client_class", [DashboardsServiceClient, DashboardsServiceAsyncClient,] ) def test_dashboards_service_client_from_service_account_info(client_class): - creds = credentials.AnonymousCredentials() + creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -119,7 +148,7 @@ def test_dashboards_service_client_from_service_account_info(client_class): "client_class", [DashboardsServiceClient, DashboardsServiceAsyncClient,] ) def test_dashboards_service_client_from_service_account_file(client_class): - creds = credentials.AnonymousCredentials() + creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -172,7 +201,7 @@ def test_dashboards_service_client_client_options( ): # Check that if channel is provided we won't create a new one. with mock.patch.object(DashboardsServiceClient, "get_transport_class") as gtc: - transport = transport_class(credentials=credentials.AnonymousCredentials()) + transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) client = client_class(transport=transport) gtc.assert_not_called() @@ -470,7 +499,7 @@ def test_create_dashboard( transport: str = "grpc", request_type=dashboards_service.CreateDashboardRequest ): client = DashboardsServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -486,23 +515,17 @@ def test_create_dashboard( etag="etag_value", grid_layout=layouts.GridLayout(columns=769), ) - response = client.create_dashboard(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == dashboards_service.CreateDashboardRequest() # Establish that the response is the type that we expect. - assert isinstance(response, dashboard.Dashboard) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.etag == "etag_value" @@ -514,7 +537,7 @@ def test_create_dashboard_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DashboardsServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -522,7 +545,6 @@ def test_create_dashboard_empty_call(): client.create_dashboard() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == dashboards_service.CreateDashboardRequest() @@ -532,7 +554,7 @@ async def test_create_dashboard_async( request_type=dashboards_service.CreateDashboardRequest, ): client = DashboardsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -547,22 +569,17 @@ async def test_create_dashboard_async( name="name_value", display_name="display_name_value", etag="etag_value", ) ) - response = await client.create_dashboard(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == dashboards_service.CreateDashboardRequest() # Establish that the response is the type that we expect. assert isinstance(response, dashboard.Dashboard) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.etag == "etag_value" @@ -572,17 +589,17 @@ async def test_create_dashboard_async_from_dict(): def test_create_dashboard_field_headers(): - client = DashboardsServiceClient(credentials=credentials.AnonymousCredentials(),) + client = DashboardsServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = dashboards_service.CreateDashboardRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_dashboard), "__call__") as call: call.return_value = dashboard.Dashboard() - client.create_dashboard(request) # Establish that the underlying gRPC stub method was called. @@ -598,18 +615,18 @@ def test_create_dashboard_field_headers(): @pytest.mark.asyncio async def test_create_dashboard_field_headers_async(): client = DashboardsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = dashboards_service.CreateDashboardRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_dashboard), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(dashboard.Dashboard()) - await client.create_dashboard(request) # Establish that the underlying gRPC stub method was called. @@ -626,7 +643,7 @@ def test_list_dashboards( transport: str = "grpc", request_type=dashboards_service.ListDashboardsRequest ): client = DashboardsServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -639,19 +656,15 @@ def test_list_dashboards( call.return_value = dashboards_service.ListDashboardsResponse( next_page_token="next_page_token_value", ) - response = client.list_dashboards(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == dashboards_service.ListDashboardsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListDashboardsPager) - assert response.next_page_token == "next_page_token_value" @@ -663,7 +676,7 @@ def test_list_dashboards_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DashboardsServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -671,7 +684,6 @@ def test_list_dashboards_empty_call(): client.list_dashboards() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == dashboards_service.ListDashboardsRequest() @@ -681,7 +693,7 @@ async def test_list_dashboards_async( request_type=dashboards_service.ListDashboardsRequest, ): client = DashboardsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -696,18 +708,15 @@ async def test_list_dashboards_async( next_page_token="next_page_token_value", ) ) - response = await client.list_dashboards(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == dashboards_service.ListDashboardsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListDashboardsAsyncPager) - assert response.next_page_token == "next_page_token_value" @@ -717,17 +726,17 @@ async def test_list_dashboards_async_from_dict(): def test_list_dashboards_field_headers(): - client = DashboardsServiceClient(credentials=credentials.AnonymousCredentials(),) + client = DashboardsServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = dashboards_service.ListDashboardsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_dashboards), "__call__") as call: call.return_value = dashboards_service.ListDashboardsResponse() - client.list_dashboards(request) # Establish that the underlying gRPC stub method was called. @@ -743,12 +752,13 @@ def test_list_dashboards_field_headers(): @pytest.mark.asyncio async def test_list_dashboards_field_headers_async(): client = DashboardsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = dashboards_service.ListDashboardsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -756,7 +766,6 @@ async def test_list_dashboards_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( dashboards_service.ListDashboardsResponse() ) - await client.list_dashboards(request) # Establish that the underlying gRPC stub method was called. @@ -770,7 +779,7 @@ async def test_list_dashboards_field_headers_async(): def test_list_dashboards_pager(): - client = DashboardsServiceClient(credentials=credentials.AnonymousCredentials,) + client = DashboardsServiceClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_dashboards), "__call__") as call: @@ -810,7 +819,7 @@ def test_list_dashboards_pager(): def test_list_dashboards_pages(): - client = DashboardsServiceClient(credentials=credentials.AnonymousCredentials,) + client = DashboardsServiceClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_dashboards), "__call__") as call: @@ -842,7 +851,9 @@ def test_list_dashboards_pages(): @pytest.mark.asyncio async def test_list_dashboards_async_pager(): - client = DashboardsServiceAsyncClient(credentials=credentials.AnonymousCredentials,) + client = DashboardsServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -881,7 +892,9 @@ async def test_list_dashboards_async_pager(): @pytest.mark.asyncio async def test_list_dashboards_async_pages(): - client = DashboardsServiceAsyncClient(credentials=credentials.AnonymousCredentials,) + client = DashboardsServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -919,7 +932,7 @@ def test_get_dashboard( transport: str = "grpc", request_type=dashboards_service.GetDashboardRequest ): client = DashboardsServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -935,23 +948,17 @@ def test_get_dashboard( etag="etag_value", grid_layout=layouts.GridLayout(columns=769), ) - response = client.get_dashboard(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == dashboards_service.GetDashboardRequest() # Establish that the response is the type that we expect. - assert isinstance(response, dashboard.Dashboard) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.etag == "etag_value" @@ -963,7 +970,7 @@ def test_get_dashboard_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DashboardsServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -971,7 +978,6 @@ def test_get_dashboard_empty_call(): client.get_dashboard() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == dashboards_service.GetDashboardRequest() @@ -980,7 +986,7 @@ async def test_get_dashboard_async( transport: str = "grpc_asyncio", request_type=dashboards_service.GetDashboardRequest ): client = DashboardsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -995,22 +1001,17 @@ async def test_get_dashboard_async( name="name_value", display_name="display_name_value", etag="etag_value", ) ) - response = await client.get_dashboard(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == dashboards_service.GetDashboardRequest() # Establish that the response is the type that we expect. assert isinstance(response, dashboard.Dashboard) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.etag == "etag_value" @@ -1020,17 +1021,17 @@ async def test_get_dashboard_async_from_dict(): def test_get_dashboard_field_headers(): - client = DashboardsServiceClient(credentials=credentials.AnonymousCredentials(),) + client = DashboardsServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = dashboards_service.GetDashboardRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_dashboard), "__call__") as call: call.return_value = dashboard.Dashboard() - client.get_dashboard(request) # Establish that the underlying gRPC stub method was called. @@ -1046,18 +1047,18 @@ def test_get_dashboard_field_headers(): @pytest.mark.asyncio async def test_get_dashboard_field_headers_async(): client = DashboardsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = dashboards_service.GetDashboardRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_dashboard), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(dashboard.Dashboard()) - await client.get_dashboard(request) # Establish that the underlying gRPC stub method was called. @@ -1074,7 +1075,7 @@ def test_delete_dashboard( transport: str = "grpc", request_type=dashboards_service.DeleteDashboardRequest ): client = DashboardsServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1085,13 +1086,11 @@ def test_delete_dashboard( with mock.patch.object(type(client.transport.delete_dashboard), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None - response = client.delete_dashboard(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == dashboards_service.DeleteDashboardRequest() # Establish that the response is the type that we expect. @@ -1106,7 +1105,7 @@ def test_delete_dashboard_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DashboardsServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1114,7 +1113,6 @@ def test_delete_dashboard_empty_call(): client.delete_dashboard() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == dashboards_service.DeleteDashboardRequest() @@ -1124,7 +1122,7 @@ async def test_delete_dashboard_async( request_type=dashboards_service.DeleteDashboardRequest, ): client = DashboardsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1135,13 +1133,11 @@ async def test_delete_dashboard_async( with mock.patch.object(type(client.transport.delete_dashboard), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - response = await client.delete_dashboard(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == dashboards_service.DeleteDashboardRequest() # Establish that the response is the type that we expect. @@ -1154,17 +1150,17 @@ async def test_delete_dashboard_async_from_dict(): def test_delete_dashboard_field_headers(): - client = DashboardsServiceClient(credentials=credentials.AnonymousCredentials(),) + client = DashboardsServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = dashboards_service.DeleteDashboardRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_dashboard), "__call__") as call: call.return_value = None - client.delete_dashboard(request) # Establish that the underlying gRPC stub method was called. @@ -1180,18 +1176,18 @@ def test_delete_dashboard_field_headers(): @pytest.mark.asyncio async def test_delete_dashboard_field_headers_async(): client = DashboardsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = dashboards_service.DeleteDashboardRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_dashboard), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - await client.delete_dashboard(request) # Establish that the underlying gRPC stub method was called. @@ -1208,7 +1204,7 @@ def test_update_dashboard( transport: str = "grpc", request_type=dashboards_service.UpdateDashboardRequest ): client = DashboardsServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1224,23 +1220,17 @@ def test_update_dashboard( etag="etag_value", grid_layout=layouts.GridLayout(columns=769), ) - response = client.update_dashboard(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == dashboards_service.UpdateDashboardRequest() # Establish that the response is the type that we expect. - assert isinstance(response, dashboard.Dashboard) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.etag == "etag_value" @@ -1252,7 +1242,7 @@ def test_update_dashboard_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DashboardsServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1260,7 +1250,6 @@ def test_update_dashboard_empty_call(): client.update_dashboard() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == dashboards_service.UpdateDashboardRequest() @@ -1270,7 +1259,7 @@ async def test_update_dashboard_async( request_type=dashboards_service.UpdateDashboardRequest, ): client = DashboardsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1285,22 +1274,17 @@ async def test_update_dashboard_async( name="name_value", display_name="display_name_value", etag="etag_value", ) ) - response = await client.update_dashboard(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == dashboards_service.UpdateDashboardRequest() # Establish that the response is the type that we expect. assert isinstance(response, dashboard.Dashboard) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.etag == "etag_value" @@ -1310,17 +1294,17 @@ async def test_update_dashboard_async_from_dict(): def test_update_dashboard_field_headers(): - client = DashboardsServiceClient(credentials=credentials.AnonymousCredentials(),) + client = DashboardsServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = dashboards_service.UpdateDashboardRequest() + request.dashboard.name = "dashboard.name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_dashboard), "__call__") as call: call.return_value = dashboard.Dashboard() - client.update_dashboard(request) # Establish that the underlying gRPC stub method was called. @@ -1338,18 +1322,18 @@ def test_update_dashboard_field_headers(): @pytest.mark.asyncio async def test_update_dashboard_field_headers_async(): client = DashboardsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = dashboards_service.UpdateDashboardRequest() + request.dashboard.name = "dashboard.name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_dashboard), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(dashboard.Dashboard()) - await client.update_dashboard(request) # Establish that the underlying gRPC stub method was called. @@ -1367,16 +1351,16 @@ async def test_update_dashboard_field_headers_async(): def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.DashboardsServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = DashboardsServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.DashboardsServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = DashboardsServiceClient( @@ -1386,7 +1370,7 @@ def test_credentials_transport_error(): # It is an error to provide scopes and a transport instance. transport = transports.DashboardsServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = DashboardsServiceClient( @@ -1397,7 +1381,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.DashboardsServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) client = DashboardsServiceClient(transport=transport) assert client.transport is transport @@ -1406,13 +1390,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.DashboardsServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel transport = transports.DashboardsServiceGrpcAsyncIOTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel @@ -1427,23 +1411,23 @@ def test_transport_get_channel(): ) def test_transport_adc(transport_class): # Test default credentials are used if not provided. - with mock.patch.object(auth, "default") as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport_class() adc.assert_called_once() def test_transport_grpc_default(): # A client should use the gRPC transport by default. - client = DashboardsServiceClient(credentials=credentials.AnonymousCredentials(),) + client = DashboardsServiceClient(credentials=ga_credentials.AnonymousCredentials(),) assert isinstance(client.transport, transports.DashboardsServiceGrpcTransport,) def test_dashboards_service_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error - with pytest.raises(exceptions.DuplicateCredentialArgs): + with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.DashboardsServiceTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), credentials_file="credentials.json", ) @@ -1455,7 +1439,7 @@ def test_dashboards_service_base_transport(): ) as Transport: Transport.return_value = None transport = transports.DashboardsServiceTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Every method on the transport should just blindly @@ -1472,15 +1456,42 @@ def test_dashboards_service_base_transport(): getattr(transport, method)(request=object()) +@requires_google_auth_gte_1_25_0 def test_dashboards_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( - auth, "load_credentials_from_file" + google.auth, "load_credentials_from_file", autospec=True ) as load_creds, mock.patch( "google.cloud.monitoring_dashboard_v1.services.dashboards_service.transports.DashboardsServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (credentials.AnonymousCredentials(), None) + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.DashboardsServiceTransport( + credentials_file="credentials.json", quota_project_id="octopus", + ) + load_creds.assert_called_once_with( + "credentials.json", + scopes=None, + default_scopes=( + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/monitoring", + "https://www.googleapis.com/auth/monitoring.read", + "https://www.googleapis.com/auth/monitoring.write", + ), + quota_project_id="octopus", + ) + + +@requires_google_auth_lt_1_25_0 +def test_dashboards_service_base_transport_with_credentials_file_old_google_auth(): + # Instantiate the base transport with a credentials file + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch( + "google.cloud.monitoring_dashboard_v1.services.dashboards_service.transports.DashboardsServiceTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DashboardsServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", ) @@ -1498,19 +1509,38 @@ def test_dashboards_service_base_transport_with_credentials_file(): def test_dashboards_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(auth, "default") as adc, mock.patch( + with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( "google.cloud.monitoring_dashboard_v1.services.dashboards_service.transports.DashboardsServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (credentials.AnonymousCredentials(), None) + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DashboardsServiceTransport() adc.assert_called_once() +@requires_google_auth_gte_1_25_0 def test_dashboards_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(auth, "default") as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + DashboardsServiceClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=( + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/monitoring", + "https://www.googleapis.com/auth/monitoring.read", + "https://www.googleapis.com/auth/monitoring.write", + ), + quota_project_id=None, + ) + + +@requires_google_auth_lt_1_25_0 +def test_dashboards_service_auth_adc_old_google_auth(): + # If no credentials are provided, we should use ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) DashboardsServiceClient() adc.assert_called_once_with( scopes=( @@ -1523,14 +1553,46 @@ def test_dashboards_service_auth_adc(): ) -def test_dashboards_service_transport_auth_adc(): +@pytest.mark.parametrize( + "transport_class", + [ + transports.DashboardsServiceGrpcTransport, + transports.DashboardsServiceGrpcAsyncIOTransport, + ], +) +@requires_google_auth_gte_1_25_0 +def test_dashboards_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object(auth, "default") as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) - transports.DashboardsServiceGrpcTransport( - host="squid.clam.whelk", quota_project_id="octopus" + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + adc.assert_called_once_with( + scopes=["1", "2"], + default_scopes=( + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/monitoring", + "https://www.googleapis.com/auth/monitoring.read", + "https://www.googleapis.com/auth/monitoring.write", + ), + quota_project_id="octopus", ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.DashboardsServiceGrpcTransport, + transports.DashboardsServiceGrpcAsyncIOTransport, + ], +) +@requires_google_auth_lt_1_25_0 +def test_dashboards_service_transport_auth_adc_old_google_auth(transport_class): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus") adc.assert_called_once_with( scopes=( "https://www.googleapis.com/auth/cloud-platform", @@ -1542,6 +1604,125 @@ def test_dashboards_service_transport_auth_adc(): ) +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.DashboardsServiceGrpcTransport, grpc_helpers), + (transports.DashboardsServiceGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_gte_1_26_0 +def test_dashboards_service_transport_create_channel(transport_class, grpc_helpers): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + + create_channel.assert_called_with( + "monitoring.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=( + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/monitoring", + "https://www.googleapis.com/auth/monitoring.read", + "https://www.googleapis.com/auth/monitoring.write", + ), + scopes=["1", "2"], + default_host="monitoring.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.DashboardsServiceGrpcTransport, grpc_helpers), + (transports.DashboardsServiceGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_dashboards_service_transport_create_channel_old_api_core( + transport_class, grpc_helpers +): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class(quota_project_id="octopus") + + create_channel.assert_called_with( + "monitoring.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + scopes=( + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/monitoring", + "https://www.googleapis.com/auth/monitoring.read", + "https://www.googleapis.com/auth/monitoring.write", + ), + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.DashboardsServiceGrpcTransport, grpc_helpers), + (transports.DashboardsServiceGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_dashboards_service_transport_create_channel_user_scopes( + transport_class, grpc_helpers +): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + + create_channel.assert_called_with( + "monitoring.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + scopes=["1", "2"], + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + @pytest.mark.parametrize( "transport_class", [ @@ -1550,7 +1731,7 @@ def test_dashboards_service_transport_auth_adc(): ], ) def test_dashboards_service_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = credentials.AnonymousCredentials() + cred = ga_credentials.AnonymousCredentials() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -1594,7 +1775,7 @@ def test_dashboards_service_grpc_transport_client_cert_source_for_mtls(transport def test_dashboards_service_host_no_port(): client = DashboardsServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="monitoring.googleapis.com" ), @@ -1604,7 +1785,7 @@ def test_dashboards_service_host_no_port(): def test_dashboards_service_host_with_port(): client = DashboardsServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="monitoring.googleapis.com:8000" ), @@ -1660,9 +1841,9 @@ def test_dashboards_service_transport_channel_mtls_with_client_cert_source( mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = credentials.AnonymousCredentials() + cred = ga_credentials.AnonymousCredentials() with pytest.warns(DeprecationWarning): - with mock.patch.object(auth, "default") as adc: + with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) transport = transport_class( host="squid.clam.whelk", @@ -1749,7 +1930,6 @@ def test_dashboards_service_transport_channel_mtls_with_adc(transport_class): def test_dashboard_path(): project = "squid" dashboard = "clam" - expected = "projects/{project}/dashboards/{dashboard}".format( project=project, dashboard=dashboard, ) @@ -1771,7 +1951,6 @@ def test_parse_dashboard_path(): def test_common_billing_account_path(): billing_account = "oyster" - expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -1792,7 +1971,6 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "cuttlefish" - expected = "folders/{folder}".format(folder=folder,) actual = DashboardsServiceClient.common_folder_path(folder) assert expected == actual @@ -1811,7 +1989,6 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "winkle" - expected = "organizations/{organization}".format(organization=organization,) actual = DashboardsServiceClient.common_organization_path(organization) assert expected == actual @@ -1830,7 +2007,6 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "scallop" - expected = "projects/{project}".format(project=project,) actual = DashboardsServiceClient.common_project_path(project) assert expected == actual @@ -1850,7 +2026,6 @@ def test_parse_common_project_path(): def test_common_location_path(): project = "squid" location = "clam" - expected = "projects/{project}/locations/{location}".format( project=project, location=location, ) @@ -1877,7 +2052,7 @@ def test_client_withDEFAULT_CLIENT_INFO(): transports.DashboardsServiceTransport, "_prep_wrapped_messages" ) as prep: client = DashboardsServiceClient( - credentials=credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -1886,6 +2061,6 @@ def test_client_withDEFAULT_CLIENT_INFO(): ) as prep: transport_class = DashboardsServiceClient.get_transport_class() transport = transport_class( - credentials=credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info)