From 91963eaaa72d6604a6e10fbbe6058fb7a36b39d6 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 12:52:07 +0000 Subject: [PATCH] chore: upgrade gapic-generator-python to 0.46.3 (#30) PiperOrigin-RevId: 373649163 Source-Link: https://github.com/googleapis/googleapis/commit/7e1b14e6c7a9ab96d2db7e4a131981f162446d34 Source-Link: https://github.com/googleapis/googleapis-gen/commit/0a3c7d272d697796db75857bac73905c68e498c3 --- .../gke_hub_membership_service.rst | 1 - .../google/cloud/gkehub/__init__.py | 12 +- .../google/cloud/gkehub_v1beta1/__init__.py | 7 +- .../cloud/gkehub_v1beta1/gapic_metadata.json | 103 ++++ .../cloud/gkehub_v1beta1/services/__init__.py | 1 - .../gke_hub_membership_service/__init__.py | 2 - .../async_client.py | 52 +- .../gke_hub_membership_service/client.py | 94 ++- .../gke_hub_membership_service/pagers.py | 4 +- .../transports/__init__.py | 2 - .../transports/base.py | 140 +++-- .../transports/grpc.py | 36 +- .../transports/grpc_asyncio.py | 37 +- .../cloud/gkehub_v1beta1/types/__init__.py | 2 - .../cloud/gkehub_v1beta1/types/membership.py | 211 +++---- .../scripts/fixup_gkehub_v1beta1_keywords.py | 21 +- .../google-cloud-gke-hub/tests/__init__.py | 15 + .../tests/unit/__init__.py | 15 + .../tests/unit/gapic/__init__.py | 15 + .../unit/gapic/gkehub_v1beta1/__init__.py | 1 - .../test_gke_hub_membership_service.py | 555 +++++++++++------- 21 files changed, 763 insertions(+), 563 deletions(-) create mode 100644 packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/gapic_metadata.json create mode 100644 packages/google-cloud-gke-hub/tests/__init__.py create mode 100644 packages/google-cloud-gke-hub/tests/unit/__init__.py create mode 100644 packages/google-cloud-gke-hub/tests/unit/gapic/__init__.py diff --git a/packages/google-cloud-gke-hub/docs/gkehub_v1beta1/gke_hub_membership_service.rst b/packages/google-cloud-gke-hub/docs/gkehub_v1beta1/gke_hub_membership_service.rst index 45ba077f659b..d2345338f5b5 100644 --- a/packages/google-cloud-gke-hub/docs/gkehub_v1beta1/gke_hub_membership_service.rst +++ b/packages/google-cloud-gke-hub/docs/gkehub_v1beta1/gke_hub_membership_service.rst @@ -5,7 +5,6 @@ GkeHubMembershipService :members: :inherited-members: - .. automodule:: google.cloud.gkehub_v1beta1.services.gke_hub_membership_service.pagers :members: :inherited-members: diff --git a/packages/google-cloud-gke-hub/google/cloud/gkehub/__init__.py b/packages/google-cloud-gke-hub/google/cloud/gkehub/__init__.py index bee0e9b6c502..39cf6987a79a 100644 --- a/packages/google-cloud-gke-hub/google/cloud/gkehub/__init__.py +++ b/packages/google-cloud-gke-hub/google/cloud/gkehub/__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.gkehub_v1beta1.services.gke_hub_membership_service.async_client import ( - GkeHubMembershipServiceAsyncClient, -) from google.cloud.gkehub_v1beta1.services.gke_hub_membership_service.client import ( GkeHubMembershipServiceClient, ) +from google.cloud.gkehub_v1beta1.services.gke_hub_membership_service.async_client import ( + GkeHubMembershipServiceAsyncClient, +) + from google.cloud.gkehub_v1beta1.types.membership import Authority from google.cloud.gkehub_v1beta1.types.membership import ConnectAgent from google.cloud.gkehub_v1beta1.types.membership import ConnectAgentResource @@ -52,6 +52,8 @@ from google.cloud.gkehub_v1beta1.types.membership import ValidateExclusivityResponse __all__ = ( + "GkeHubMembershipServiceClient", + "GkeHubMembershipServiceAsyncClient", "Authority", "ConnectAgent", "ConnectAgentResource", @@ -63,8 +65,6 @@ "GenerateExclusivityManifestResponse", "GetMembershipRequest", "GkeCluster", - "GkeHubMembershipServiceAsyncClient", - "GkeHubMembershipServiceClient", "KubernetesMetadata", "KubernetesResource", "ListMembershipsRequest", diff --git a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/__init__.py b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/__init__.py index c42a045d0f3d..c1a2e5514a43 100644 --- a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/__init__.py +++ b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/__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.gke_hub_membership_service import GkeHubMembershipServiceClient +from .services.gke_hub_membership_service import GkeHubMembershipServiceAsyncClient + from .types.membership import Authority from .types.membership import ConnectAgent from .types.membership import ConnectAgentResource @@ -42,8 +43,8 @@ from .types.membership import ValidateExclusivityRequest from .types.membership import ValidateExclusivityResponse - __all__ = ( + "GkeHubMembershipServiceAsyncClient", "Authority", "ConnectAgent", "ConnectAgentResource", @@ -55,6 +56,7 @@ "GenerateExclusivityManifestResponse", "GetMembershipRequest", "GkeCluster", + "GkeHubMembershipServiceClient", "KubernetesMetadata", "KubernetesResource", "ListMembershipsRequest", @@ -69,5 +71,4 @@ "UpdateMembershipRequest", "ValidateExclusivityRequest", "ValidateExclusivityResponse", - "GkeHubMembershipServiceClient", ) diff --git a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/gapic_metadata.json b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/gapic_metadata.json new file mode 100644 index 000000000000..9f0aee44b79c --- /dev/null +++ b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/gapic_metadata.json @@ -0,0 +1,103 @@ + { + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", + "language": "python", + "libraryPackage": "google.cloud.gkehub_v1beta1", + "protoPackage": "google.cloud.gkehub.v1beta1", + "schema": "1.0", + "services": { + "GkeHubMembershipService": { + "clients": { + "grpc": { + "libraryClient": "GkeHubMembershipServiceClient", + "rpcs": { + "CreateMembership": { + "methods": [ + "create_membership" + ] + }, + "DeleteMembership": { + "methods": [ + "delete_membership" + ] + }, + "GenerateConnectManifest": { + "methods": [ + "generate_connect_manifest" + ] + }, + "GenerateExclusivityManifest": { + "methods": [ + "generate_exclusivity_manifest" + ] + }, + "GetMembership": { + "methods": [ + "get_membership" + ] + }, + "ListMemberships": { + "methods": [ + "list_memberships" + ] + }, + "UpdateMembership": { + "methods": [ + "update_membership" + ] + }, + "ValidateExclusivity": { + "methods": [ + "validate_exclusivity" + ] + } + } + }, + "grpc-async": { + "libraryClient": "GkeHubMembershipServiceAsyncClient", + "rpcs": { + "CreateMembership": { + "methods": [ + "create_membership" + ] + }, + "DeleteMembership": { + "methods": [ + "delete_membership" + ] + }, + "GenerateConnectManifest": { + "methods": [ + "generate_connect_manifest" + ] + }, + "GenerateExclusivityManifest": { + "methods": [ + "generate_exclusivity_manifest" + ] + }, + "GetMembership": { + "methods": [ + "get_membership" + ] + }, + "ListMemberships": { + "methods": [ + "list_memberships" + ] + }, + "UpdateMembership": { + "methods": [ + "update_membership" + ] + }, + "ValidateExclusivity": { + "methods": [ + "validate_exclusivity" + ] + } + } + } + } + } + } +} diff --git a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/__init__.py b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/__init__.py index 42ffdf2bc43d..4de65971c238 100644 --- a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/__init__.py +++ b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/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-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/__init__.py b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/__init__.py index ddd4c8c2d636..73820c3b51df 100644 --- a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/__init__.py +++ b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_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 GkeHubMembershipServiceClient from .async_client import GkeHubMembershipServiceAsyncClient diff --git a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/async_client.py b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/async_client.py index 3fc94ceef55b..4ce26f4b44c8 100644 --- a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/async_client.py +++ b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_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,21 +20,20 @@ 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.gkehub_v1beta1.services.gke_hub_membership_service import pagers from google.cloud.gkehub_v1beta1.types import membership -from google.protobuf import empty_pb2 as empty # type: ignore -from google.protobuf import field_mask_pb2 as field_mask # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore -from google.rpc import status_pb2 as status # type: ignore - +from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +from google.rpc import status_pb2 # type: ignore from .transports.base import GkeHubMembershipServiceTransport, DEFAULT_CLIENT_INFO from .transports.grpc_asyncio import GkeHubMembershipServiceGrpcAsyncIOTransport from .client import GkeHubMembershipServiceClient @@ -57,33 +54,28 @@ class GkeHubMembershipServiceAsyncClient: parse_membership_path = staticmethod( GkeHubMembershipServiceClient.parse_membership_path ) - common_billing_account_path = staticmethod( GkeHubMembershipServiceClient.common_billing_account_path ) parse_common_billing_account_path = staticmethod( GkeHubMembershipServiceClient.parse_common_billing_account_path ) - common_folder_path = staticmethod(GkeHubMembershipServiceClient.common_folder_path) parse_common_folder_path = staticmethod( GkeHubMembershipServiceClient.parse_common_folder_path ) - common_organization_path = staticmethod( GkeHubMembershipServiceClient.common_organization_path ) parse_common_organization_path = staticmethod( GkeHubMembershipServiceClient.parse_common_organization_path ) - common_project_path = staticmethod( GkeHubMembershipServiceClient.common_project_path ) parse_common_project_path = staticmethod( GkeHubMembershipServiceClient.parse_common_project_path ) - common_location_path = staticmethod( GkeHubMembershipServiceClient.common_location_path ) @@ -93,7 +85,8 @@ class GkeHubMembershipServiceAsyncClient: @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. @@ -108,7 +101,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 @@ -125,7 +118,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> GkeHubMembershipServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: GkeHubMembershipServiceTransport: The transport used by the client instance. @@ -140,12 +133,12 @@ def transport(self) -> GkeHubMembershipServiceTransport: def __init__( self, *, - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, transport: Union[str, GkeHubMembershipServiceTransport] = "grpc_asyncio", client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the gke hub membership service client. + """Instantiates the gke hub membership service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -177,7 +170,6 @@ def __init__( google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport creation failed for any reason. """ - self._client = GkeHubMembershipServiceClient( credentials=credentials, transport=transport, @@ -208,7 +200,6 @@ async def list_memberships( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -238,7 +229,6 @@ async def list_memberships( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -290,7 +280,6 @@ async def get_membership( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -317,7 +306,6 @@ async def get_membership( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -388,7 +376,6 @@ async def create_membership( This corresponds to the ``membership_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -418,7 +405,6 @@ async def create_membership( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if resource is not None: @@ -476,7 +462,6 @@ async def delete_membership( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -516,7 +501,6 @@ async def delete_membership( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -541,7 +525,7 @@ async def delete_membership( response = operation_async.from_gapic( response, self._client._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=membership.OperationMetadata, ) @@ -554,7 +538,7 @@ async def update_membership( *, name: str = None, resource: membership.Membership = None, - update_mask: field_mask.FieldMask = None, + update_mask: field_mask_pb2.FieldMask = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), @@ -592,7 +576,6 @@ async def update_membership( This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -622,7 +605,6 @@ async def update_membership( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if resource is not None: @@ -674,7 +656,6 @@ async def generate_connect_manifest( The request object. Request message for `GkeHubMembershipService.GenerateConnectManifest` method. . - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -689,7 +670,6 @@ async def generate_connect_manifest( """ # Create or coerce a protobuf request object. - request = membership.GenerateConnectManifestRequest(request) # Wrap the RPC method; this adds retry and timeout information, @@ -728,7 +708,6 @@ async def validate_exclusivity( request (:class:`google.cloud.gkehub_v1beta1.types.ValidateExclusivityRequest`): The request object. The request to validate the existing state of the membership CR in the cluster. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -742,7 +721,6 @@ async def validate_exclusivity( """ # Create or coerce a protobuf request object. - request = membership.ValidateExclusivityRequest(request) # Wrap the RPC method; this adds retry and timeout information, @@ -792,7 +770,6 @@ async def generate_exclusivity_manifest( request (:class:`google.cloud.gkehub_v1beta1.types.GenerateExclusivityManifestRequest`): The request object. The request to generate the manifests for exclusivity artifacts. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -807,7 +784,6 @@ async def generate_exclusivity_manifest( """ # Create or coerce a protobuf request object. - request = membership.GenerateExclusivityManifestRequest(request) # Wrap the RPC method; this adds retry and timeout information, diff --git a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/client.py b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/client.py index fe59f2852c4b..5fa44ce48459 100644 --- a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/client.py +++ b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_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,11 +34,10 @@ from google.api_core import operation_async # type: ignore from google.cloud.gkehub_v1beta1.services.gke_hub_membership_service import pagers from google.cloud.gkehub_v1beta1.types import membership -from google.protobuf import empty_pb2 as empty # type: ignore -from google.protobuf import field_mask_pb2 as field_mask # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore -from google.rpc import status_pb2 as status # type: ignore - +from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +from google.rpc import status_pb2 # type: ignore from .transports.base import GkeHubMembershipServiceTransport, DEFAULT_CLIENT_INFO from .transports.grpc import GkeHubMembershipServiceGrpcTransport from .transports.grpc_asyncio import GkeHubMembershipServiceGrpcAsyncIOTransport @@ -63,7 +60,7 @@ class GkeHubMembershipServiceClientMeta(type): def get_transport_class( cls, label: str = None, ) -> Type[GkeHubMembershipServiceTransport]: - """Return an appropriate transport class. + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -89,7 +86,8 @@ class GkeHubMembershipServiceClient(metaclass=GkeHubMembershipServiceClientMeta) @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: @@ -123,7 +121,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. @@ -140,7 +139,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 @@ -159,23 +158,24 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> GkeHubMembershipServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - GkeHubMembershipServiceTransport: The transport used by the client instance. + GkeHubMembershipServiceTransport: The transport used by the client + instance. """ return self._transport @staticmethod def membership_path(project: str, location: str, membership: str,) -> str: - """Return a fully-qualified membership string.""" + """Returns a fully-qualified membership string.""" return "projects/{project}/locations/{location}/memberships/{membership}".format( project=project, location=location, membership=membership, ) @staticmethod def parse_membership_path(path: str) -> Dict[str, str]: - """Parse a membership path into its component segments.""" + """Parses a membership path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/memberships/(?P.+?)$", path, @@ -184,7 +184,7 @@ def parse_membership_path(path: str) -> Dict[str, str]: @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, ) @@ -197,7 +197,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 @@ -208,7 +208,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 @@ -219,7 +219,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 @@ -230,7 +230,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, ) @@ -244,12 +244,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, GkeHubMembershipServiceTransport, None] = None, client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the gke hub membership service client. + """Instantiates the gke hub membership service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -304,9 +304,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: @@ -318,12 +319,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. @@ -338,8 +341,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: @@ -377,7 +380,6 @@ def list_memberships( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -409,10 +411,8 @@ def list_memberships( # there are no flattened fields. if not isinstance(request, membership.ListMembershipsRequest): request = membership.ListMembershipsRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -460,7 +460,6 @@ def get_membership( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -489,10 +488,8 @@ def get_membership( # there are no flattened fields. if not isinstance(request, membership.GetMembershipRequest): request = membership.GetMembershipRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -559,7 +556,6 @@ def create_membership( This corresponds to the ``membership_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -591,10 +587,8 @@ def create_membership( # there are no flattened fields. if not isinstance(request, membership.CreateMembershipRequest): request = membership.CreateMembershipRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if resource is not None: @@ -648,7 +642,6 @@ def delete_membership( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -690,10 +683,8 @@ def delete_membership( # there are no flattened fields. if not isinstance(request, membership.DeleteMembershipRequest): request = membership.DeleteMembershipRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -714,7 +705,7 @@ def delete_membership( response = operation.from_gapic( response, self._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=membership.OperationMetadata, ) @@ -727,7 +718,7 @@ def update_membership( *, name: str = None, resource: membership.Membership = None, - update_mask: field_mask.FieldMask = None, + update_mask: field_mask_pb2.FieldMask = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), @@ -765,7 +756,6 @@ def update_membership( This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -797,10 +787,8 @@ def update_membership( # there are no flattened fields. if not isinstance(request, membership.UpdateMembershipRequest): request = membership.UpdateMembershipRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if resource is not None: @@ -848,7 +836,6 @@ def generate_connect_manifest( The request object. Request message for `GkeHubMembershipService.GenerateConnectManifest` method. . - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -863,7 +850,6 @@ def generate_connect_manifest( """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes # in a membership.GenerateConnectManifestRequest. # There's no risk of modifying the input as we've already verified @@ -905,7 +891,6 @@ def validate_exclusivity( request (google.cloud.gkehub_v1beta1.types.ValidateExclusivityRequest): The request object. The request to validate the existing state of the membership CR in the cluster. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -919,7 +904,6 @@ def validate_exclusivity( """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes # in a membership.ValidateExclusivityRequest. # There's no risk of modifying the input as we've already verified @@ -970,7 +954,6 @@ def generate_exclusivity_manifest( request (google.cloud.gkehub_v1beta1.types.GenerateExclusivityManifestRequest): The request object. The request to generate the manifests for exclusivity artifacts. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -985,7 +968,6 @@ def generate_exclusivity_manifest( """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes # in a membership.GenerateExclusivityManifestRequest. # There's no risk of modifying the input as we've already verified diff --git a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/pagers.py b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/pagers.py index 5dd0f1b61a30..81a020826583 100644 --- a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/pagers.py +++ b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_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, @@ -117,7 +115,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-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/transports/__init__.py b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/transports/__init__.py index 243e19196982..84ccd6faf7b9 100644 --- a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/transports/__init__.py +++ b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_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-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/transports/base.py b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/transports/base.py index 14ec26f5248c..9e6c9ffd96e0 100644 --- a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/transports/base.py +++ b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_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.api_core import operations_v1 # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.cloud.gkehub_v1beta1.types import membership -from google.longrunning import operations_pb2 as operations # type: ignore - +from google.longrunning import operations_pb2 # type: ignore try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( @@ -37,27 +36,41 @@ 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 GkeHubMembershipServiceTransport(abc.ABC): """Abstract transport class for GkeHubMembershipService.""" AUTH_SCOPES = ("https://www.googleapis.com/auth/cloud-platform",) + DEFAULT_HOST: str = "gkehub.googleapis.com" + def __init__( self, *, - host: str = "gkehub.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 @@ -66,7 +79,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): @@ -80,29 +93,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 = { @@ -146,11 +206,11 @@ def operations_client(self) -> operations_v1.OperationsClient: @property def list_memberships( self, - ) -> typing.Callable[ + ) -> Callable[ [membership.ListMembershipsRequest], - typing.Union[ + Union[ membership.ListMembershipsResponse, - typing.Awaitable[membership.ListMembershipsResponse], + Awaitable[membership.ListMembershipsResponse], ], ]: raise NotImplementedError() @@ -158,47 +218,47 @@ def list_memberships( @property def get_membership( self, - ) -> typing.Callable[ + ) -> Callable[ [membership.GetMembershipRequest], - typing.Union[membership.Membership, typing.Awaitable[membership.Membership]], + Union[membership.Membership, Awaitable[membership.Membership]], ]: raise NotImplementedError() @property def create_membership( self, - ) -> typing.Callable[ + ) -> Callable[ [membership.CreateMembershipRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def delete_membership( self, - ) -> typing.Callable[ + ) -> Callable[ [membership.DeleteMembershipRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def update_membership( self, - ) -> typing.Callable[ + ) -> Callable[ [membership.UpdateMembershipRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def generate_connect_manifest( self, - ) -> typing.Callable[ + ) -> Callable[ [membership.GenerateConnectManifestRequest], - typing.Union[ + Union[ membership.GenerateConnectManifestResponse, - typing.Awaitable[membership.GenerateConnectManifestResponse], + Awaitable[membership.GenerateConnectManifestResponse], ], ]: raise NotImplementedError() @@ -206,11 +266,11 @@ def generate_connect_manifest( @property def validate_exclusivity( self, - ) -> typing.Callable[ + ) -> Callable[ [membership.ValidateExclusivityRequest], - typing.Union[ + Union[ membership.ValidateExclusivityResponse, - typing.Awaitable[membership.ValidateExclusivityResponse], + Awaitable[membership.ValidateExclusivityResponse], ], ]: raise NotImplementedError() @@ -218,11 +278,11 @@ def validate_exclusivity( @property def generate_exclusivity_manifest( self, - ) -> typing.Callable[ + ) -> Callable[ [membership.GenerateExclusivityManifestRequest], - typing.Union[ + Union[ membership.GenerateExclusivityManifestResponse, - typing.Awaitable[membership.GenerateExclusivityManifestResponse], + Awaitable[membership.GenerateExclusivityManifestResponse], ], ]: raise NotImplementedError() diff --git a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/transports/grpc.py b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/transports/grpc.py index a5b692dec1a0..bd0a6c6de113 100644 --- a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/transports/grpc.py +++ b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_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 operations_v1 # 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.gkehub_v1beta1.types import membership -from google.longrunning import operations_pb2 as operations # type: ignore - +from google.longrunning import operations_pb2 # type: ignore from .base import GkeHubMembershipServiceTransport, DEFAULT_CLIENT_INFO @@ -54,7 +51,7 @@ def __init__( self, *, host: str = "gkehub.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: str = None, scopes: Sequence[str] = None, channel: grpc.Channel = None, @@ -68,7 +65,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 @@ -179,7 +177,7 @@ def __init__( def create_channel( cls, host: str = "gkehub.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, @@ -210,13 +208,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, ) @@ -297,7 +297,7 @@ def get_membership( @property def create_membership( self, - ) -> Callable[[membership.CreateMembershipRequest], operations.Operation]: + ) -> Callable[[membership.CreateMembershipRequest], operations_pb2.Operation]: r"""Return a callable for the create membership method over gRPC. Adds a new Membership. @@ -316,14 +316,14 @@ def create_membership( self._stubs["create_membership"] = self.grpc_channel.unary_unary( "/google.cloud.gkehub.v1beta1.GkeHubMembershipService/CreateMembership", request_serializer=membership.CreateMembershipRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["create_membership"] @property def delete_membership( self, - ) -> Callable[[membership.DeleteMembershipRequest], operations.Operation]: + ) -> Callable[[membership.DeleteMembershipRequest], operations_pb2.Operation]: r"""Return a callable for the delete membership method over gRPC. Removes a Membership. @@ -342,14 +342,14 @@ def delete_membership( self._stubs["delete_membership"] = self.grpc_channel.unary_unary( "/google.cloud.gkehub.v1beta1.GkeHubMembershipService/DeleteMembership", request_serializer=membership.DeleteMembershipRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["delete_membership"] @property def update_membership( self, - ) -> Callable[[membership.UpdateMembershipRequest], operations.Operation]: + ) -> Callable[[membership.UpdateMembershipRequest], operations_pb2.Operation]: r"""Return a callable for the update membership method over gRPC. Updates an existing Membership. @@ -368,7 +368,7 @@ def update_membership( self._stubs["update_membership"] = self.grpc_channel.unary_unary( "/google.cloud.gkehub.v1beta1.GkeHubMembershipService/UpdateMembership", request_serializer=membership.UpdateMembershipRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["update_membership"] diff --git a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/transports/grpc_asyncio.py b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/transports/grpc_asyncio.py index 75f29336a102..abd6fca7ce31 100644 --- a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_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.api_core import operations_v1 # 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.gkehub_v1beta1.types import membership -from google.longrunning import operations_pb2 as operations # type: ignore - +from google.longrunning import operations_pb2 # type: ignore from .base import GkeHubMembershipServiceTransport, DEFAULT_CLIENT_INFO from .grpc import GkeHubMembershipServiceGrpcTransport @@ -57,7 +54,7 @@ class GkeHubMembershipServiceGrpcAsyncIOTransport(GkeHubMembershipServiceTranspo def create_channel( cls, host: str = "gkehub.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, @@ -84,13 +81,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, ) @@ -98,7 +97,7 @@ def __init__( self, *, host: str = "gkehub.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, @@ -112,7 +111,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 @@ -171,7 +171,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 @@ -305,7 +304,7 @@ def get_membership( def create_membership( self, ) -> Callable[ - [membership.CreateMembershipRequest], Awaitable[operations.Operation] + [membership.CreateMembershipRequest], Awaitable[operations_pb2.Operation] ]: r"""Return a callable for the create membership method over gRPC. @@ -325,7 +324,7 @@ def create_membership( self._stubs["create_membership"] = self.grpc_channel.unary_unary( "/google.cloud.gkehub.v1beta1.GkeHubMembershipService/CreateMembership", request_serializer=membership.CreateMembershipRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["create_membership"] @@ -333,7 +332,7 @@ def create_membership( def delete_membership( self, ) -> Callable[ - [membership.DeleteMembershipRequest], Awaitable[operations.Operation] + [membership.DeleteMembershipRequest], Awaitable[operations_pb2.Operation] ]: r"""Return a callable for the delete membership method over gRPC. @@ -353,7 +352,7 @@ def delete_membership( self._stubs["delete_membership"] = self.grpc_channel.unary_unary( "/google.cloud.gkehub.v1beta1.GkeHubMembershipService/DeleteMembership", request_serializer=membership.DeleteMembershipRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["delete_membership"] @@ -361,7 +360,7 @@ def delete_membership( def update_membership( self, ) -> Callable[ - [membership.UpdateMembershipRequest], Awaitable[operations.Operation] + [membership.UpdateMembershipRequest], Awaitable[operations_pb2.Operation] ]: r"""Return a callable for the update membership method over gRPC. @@ -381,7 +380,7 @@ def update_membership( self._stubs["update_membership"] = self.grpc_channel.unary_unary( "/google.cloud.gkehub.v1beta1.GkeHubMembershipService/UpdateMembership", request_serializer=membership.UpdateMembershipRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["update_membership"] diff --git a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/types/__init__.py b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/types/__init__.py index 2998f765f5bd..6e0e0ba04f0e 100644 --- a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/types/__init__.py +++ b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/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 .membership import ( Authority, ConnectAgent, diff --git a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/types/membership.py b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/types/membership.py index f63fd1b07f24..af7c0d7a7cf0 100644 --- a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/types/membership.py +++ b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/types/membership.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,13 +13,11 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - -from google.protobuf import field_mask_pb2 as field_mask # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore -from google.rpc import status_pb2 as gr_status # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +from google.rpc import status_pb2 # type: ignore __protobuf__ = proto.module( @@ -57,7 +54,6 @@ class Membership(proto.Message): r"""Membership contains information about a member cluster. - Attributes: name (str): Output only. The full, unique name of this Membership @@ -143,34 +139,22 @@ class InfrastructureType(proto.Enum): ON_PREM = 1 MULTI_CLOUD = 2 - name = proto.Field(proto.STRING, number=1) - - labels = proto.MapField(proto.STRING, proto.STRING, number=2) - - description = proto.Field(proto.STRING, number=3) - + name = proto.Field(proto.STRING, number=1,) + labels = proto.MapField(proto.STRING, proto.STRING, number=2,) + description = proto.Field(proto.STRING, number=3,) endpoint = proto.Field( proto.MESSAGE, number=4, oneof="type", message="MembershipEndpoint", ) - state = proto.Field(proto.MESSAGE, number=5, message="MembershipState",) - authority = proto.Field(proto.MESSAGE, number=9, message="Authority",) - - create_time = proto.Field(proto.MESSAGE, number=6, message=timestamp.Timestamp,) - - update_time = proto.Field(proto.MESSAGE, number=7, message=timestamp.Timestamp,) - - delete_time = proto.Field(proto.MESSAGE, number=8, message=timestamp.Timestamp,) - - external_id = proto.Field(proto.STRING, number=10) - + create_time = proto.Field(proto.MESSAGE, number=6, message=timestamp_pb2.Timestamp,) + update_time = proto.Field(proto.MESSAGE, number=7, message=timestamp_pb2.Timestamp,) + delete_time = proto.Field(proto.MESSAGE, number=8, message=timestamp_pb2.Timestamp,) + external_id = proto.Field(proto.STRING, number=10,) last_connection_time = proto.Field( - proto.MESSAGE, number=11, message=timestamp.Timestamp, + proto.MESSAGE, number=11, message=timestamp_pb2.Timestamp, ) - - unique_id = proto.Field(proto.STRING, number=12) - + unique_id = proto.Field(proto.STRING, number=12,) infrastructure_type = proto.Field(proto.ENUM, number=13, enum=InfrastructureType,) @@ -199,11 +183,9 @@ class MembershipEndpoint(proto.Message): """ gke_cluster = proto.Field(proto.MESSAGE, number=4, message="GkeCluster",) - kubernetes_metadata = proto.Field( proto.MESSAGE, number=5, message="KubernetesMetadata", ) - kubernetes_resource = proto.Field( proto.MESSAGE, number=6, message="KubernetesResource", ) @@ -254,16 +236,13 @@ class KubernetesResource(proto.Message): generation. """ - membership_cr_manifest = proto.Field(proto.STRING, number=1) - + membership_cr_manifest = proto.Field(proto.STRING, number=1,) membership_resources = proto.RepeatedField( proto.MESSAGE, number=2, message="ResourceManifest", ) - connect_resources = proto.RepeatedField( proto.MESSAGE, number=3, message="ResourceManifest", ) - resource_options = proto.Field(proto.MESSAGE, number=4, message="ResourceOptions",) @@ -284,9 +263,8 @@ class ResourceOptions(proto.Message): apiserver versions <1.16. """ - connect_version = proto.Field(proto.STRING, number=1) - - v1beta1_crd = proto.Field(proto.BOOL, number=2) + connect_version = proto.Field(proto.STRING, number=1,) + v1beta1_crd = proto.Field(proto.BOOL, number=2,) class ResourceManifest(proto.Message): @@ -305,14 +283,12 @@ class ResourceManifest(proto.Message): resource in a cluster. """ - manifest = proto.Field(proto.STRING, number=1) - - cluster_scoped = proto.Field(proto.BOOL, number=2) + manifest = proto.Field(proto.STRING, number=1,) + cluster_scoped = proto.Field(proto.BOOL, number=2,) class GkeCluster(proto.Message): r"""GkeCluster contains information specific to GKE clusters. - Attributes: resource_link (str): Immutable. Self-link of the GCP resource for @@ -322,7 +298,7 @@ class GkeCluster(proto.Message): Zonal clusters are also supported. """ - resource_link = proto.Field(proto.STRING, number=1) + resource_link = proto.Field(proto.STRING, number=1,) class KubernetesMetadata(proto.Message): @@ -356,17 +332,14 @@ class KubernetesMetadata(proto.Message): updated internally for API consumers. """ - kubernetes_api_server_version = proto.Field(proto.STRING, number=1) - - node_provider_id = proto.Field(proto.STRING, number=2) - - node_count = proto.Field(proto.INT32, number=3) - - vcpu_count = proto.Field(proto.INT32, number=4) - - memory_mb = proto.Field(proto.INT32, number=5) - - update_time = proto.Field(proto.MESSAGE, number=100, message=timestamp.Timestamp,) + kubernetes_api_server_version = proto.Field(proto.STRING, number=1,) + node_provider_id = proto.Field(proto.STRING, number=2,) + node_count = proto.Field(proto.INT32, number=3,) + vcpu_count = proto.Field(proto.INT32, number=4,) + memory_mb = proto.Field(proto.INT32, number=5,) + update_time = proto.Field( + proto.MESSAGE, number=100, message=timestamp_pb2.Timestamp, + ) class Authority(proto.Message): @@ -411,18 +384,14 @@ class Authority(proto.Message): using this field. """ - issuer = proto.Field(proto.STRING, number=1) - - workload_identity_pool = proto.Field(proto.STRING, number=2) - - identity_provider = proto.Field(proto.STRING, number=3) - - oidc_jwks = proto.Field(proto.BYTES, number=4) + issuer = proto.Field(proto.STRING, number=1,) + workload_identity_pool = proto.Field(proto.STRING, number=2,) + identity_provider = proto.Field(proto.STRING, number=3,) + oidc_jwks = proto.Field(proto.BYTES, number=4,) class MembershipState(proto.Message): r"""State of the Membership resource. - Attributes: code (google.cloud.gkehub_v1beta1.types.MembershipState.Code): Output only. The current state of the @@ -443,10 +412,8 @@ class Code(proto.Enum): SERVICE_UPDATING = 5 code = proto.Field(proto.ENUM, number=1, enum=Code,) - - description = proto.Field(proto.STRING, number=2) - - update_time = proto.Field(proto.MESSAGE, number=3, message=timestamp.Timestamp,) + description = proto.Field(proto.STRING, number=2,) + update_time = proto.Field(proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp,) class ListMembershipsRequest(proto.Message): @@ -497,15 +464,11 @@ class ListMembershipsRequest(proto.Message): https://google.aip.dev/132#ordering. """ - parent = proto.Field(proto.STRING, number=1) - - page_size = proto.Field(proto.INT32, number=2) - - page_token = proto.Field(proto.STRING, number=3) - - filter = proto.Field(proto.STRING, number=4) - - order_by = proto.Field(proto.STRING, number=5) + parent = proto.Field(proto.STRING, number=1,) + page_size = proto.Field(proto.INT32, number=2,) + page_token = proto.Field(proto.STRING, number=3,) + filter = proto.Field(proto.STRING, number=4,) + order_by = proto.Field(proto.STRING, number=5,) class ListMembershipsResponse(proto.Message): @@ -529,10 +492,8 @@ def raw_page(self): return self resources = proto.RepeatedField(proto.MESSAGE, number=1, message="Membership",) - - next_page_token = proto.Field(proto.STRING, number=2) - - unreachable = proto.RepeatedField(proto.STRING, number=3) + next_page_token = proto.Field(proto.STRING, number=2,) + unreachable = proto.RepeatedField(proto.STRING, number=3,) class GetMembershipRequest(proto.Message): @@ -545,7 +506,7 @@ class GetMembershipRequest(proto.Message): ``projects/*/locations/*/memberships/*``. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class CreateMembershipRequest(proto.Message): @@ -574,10 +535,8 @@ class CreateMembershipRequest(proto.Message): Required. The membership to create. """ - parent = proto.Field(proto.STRING, number=1) - - membership_id = proto.Field(proto.STRING, number=2) - + parent = proto.Field(proto.STRING, number=1,) + membership_id = proto.Field(proto.STRING, number=2,) resource = proto.Field(proto.MESSAGE, number=3, message="Membership",) @@ -591,7 +550,7 @@ class DeleteMembershipRequest(proto.Message): ``projects/*/locations/*/memberships/*``. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class UpdateMembershipRequest(proto.Message): @@ -614,10 +573,10 @@ class UpdateMembershipRequest(proto.Message): possible to update a key's value to the empty string. """ - name = proto.Field(proto.STRING, number=1) - - update_mask = proto.Field(proto.MESSAGE, number=2, message=field_mask.FieldMask,) - + name = proto.Field(proto.STRING, number=1,) + update_mask = proto.Field( + proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask, + ) resource = proto.Field(proto.MESSAGE, number=3, message="Membership",) @@ -648,17 +607,12 @@ class GenerateConnectManifestRequest(proto.Message): the registry, if not public. """ - name = proto.Field(proto.STRING, number=1) - + name = proto.Field(proto.STRING, number=1,) connect_agent = proto.Field(proto.MESSAGE, number=2, message="ConnectAgent",) - - version = proto.Field(proto.STRING, number=3) - - is_upgrade = proto.Field(proto.BOOL, number=4) - - registry = proto.Field(proto.STRING, number=5) - - image_pull_secret_content = proto.Field(proto.BYTES, number=6) + version = proto.Field(proto.STRING, number=3,) + is_upgrade = proto.Field(proto.BOOL, number=4,) + registry = proto.Field(proto.STRING, number=5,) + image_pull_secret_content = proto.Field(proto.BYTES, number=6,) class GenerateConnectManifestResponse(proto.Message): @@ -689,8 +643,7 @@ class ConnectAgentResource(proto.Message): """ type_ = proto.Field(proto.MESSAGE, number=1, message="TypeMeta",) - - manifest = proto.Field(proto.STRING, number=2) + manifest = proto.Field(proto.STRING, number=2,) class TypeMeta(proto.Message): @@ -704,14 +657,12 @@ class TypeMeta(proto.Message): APIVersion of the resource (e.g. v1). """ - kind = proto.Field(proto.STRING, number=1) - - api_version = proto.Field(proto.STRING, number=2) + kind = proto.Field(proto.STRING, number=1,) + api_version = proto.Field(proto.STRING, number=2,) class ConnectAgent(proto.Message): r"""The information required from end users to use GKE Connect. - Attributes: name (str): Do not set. @@ -731,11 +682,9 @@ class ConnectAgent(proto.Message): must be granted with an additional IAM binding. """ - name = proto.Field(proto.STRING, number=1) - - proxy = proto.Field(proto.BYTES, number=2) - - namespace = proto.Field(proto.STRING, number=3) + name = proto.Field(proto.STRING, number=1,) + proxy = proto.Field(proto.BYTES, number=2,) + namespace = proto.Field(proto.STRING, number=3,) class ValidateExclusivityRequest(proto.Message): @@ -757,11 +706,9 @@ class ValidateExclusivityRequest(proto.Message): CreateMembership call with the same name. """ - parent = proto.Field(proto.STRING, number=1) - - cr_manifest = proto.Field(proto.STRING, number=2) - - intended_membership = proto.Field(proto.STRING, number=3) + parent = proto.Field(proto.STRING, number=1,) + cr_manifest = proto.Field(proto.STRING, number=2,) + intended_membership = proto.Field(proto.STRING, number=3,) class ValidateExclusivityResponse(proto.Message): @@ -780,7 +727,7 @@ class ValidateExclusivityResponse(proto.Message): more information. """ - status = proto.Field(proto.MESSAGE, number=1, message=gr_status.Status,) + status = proto.Field(proto.MESSAGE, number=1, message=status_pb2.Status,) class GenerateExclusivityManifestRequest(proto.Message): @@ -801,11 +748,9 @@ class GenerateExclusivityManifestRequest(proto.Message): the resource does not exist. """ - name = proto.Field(proto.STRING, number=1) - - crd_manifest = proto.Field(proto.STRING, number=2) - - cr_manifest = proto.Field(proto.STRING, number=3) + name = proto.Field(proto.STRING, number=1,) + crd_manifest = proto.Field(proto.STRING, number=2,) + cr_manifest = proto.Field(proto.STRING, number=3,) class GenerateExclusivityManifestResponse(proto.Message): @@ -824,14 +769,12 @@ class GenerateExclusivityManifestResponse(proto.Message): Empty if no update needs to be applied. """ - crd_manifest = proto.Field(proto.STRING, number=1) - - cr_manifest = proto.Field(proto.STRING, number=2) + crd_manifest = proto.Field(proto.STRING, number=1,) + cr_manifest = proto.Field(proto.STRING, number=2,) class OperationMetadata(proto.Message): r"""Represents the metadata of the long-running operation. - Attributes: create_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The time the operation was @@ -859,19 +802,13 @@ class OperationMetadata(proto.Message): operation. """ - create_time = proto.Field(proto.MESSAGE, number=1, message=timestamp.Timestamp,) - - end_time = proto.Field(proto.MESSAGE, number=2, message=timestamp.Timestamp,) - - target = proto.Field(proto.STRING, number=3) - - verb = proto.Field(proto.STRING, number=4) - - status_detail = proto.Field(proto.STRING, number=5) - - cancel_requested = proto.Field(proto.BOOL, number=6) - - api_version = proto.Field(proto.STRING, number=7) + create_time = proto.Field(proto.MESSAGE, number=1, message=timestamp_pb2.Timestamp,) + end_time = proto.Field(proto.MESSAGE, number=2, message=timestamp_pb2.Timestamp,) + target = proto.Field(proto.STRING, number=3,) + verb = proto.Field(proto.STRING, number=4,) + status_detail = proto.Field(proto.STRING, number=5,) + cancel_requested = proto.Field(proto.BOOL, number=6,) + api_version = proto.Field(proto.STRING, number=7,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/packages/google-cloud-gke-hub/scripts/fixup_gkehub_v1beta1_keywords.py b/packages/google-cloud-gke-hub/scripts/fixup_gkehub_v1beta1_keywords.py index 4b3b3b4e42e7..b7bb67bd3df0 100644 --- a/packages/google-cloud-gke-hub/scripts/fixup_gkehub_v1beta1_keywords.py +++ b/packages/google-cloud-gke-hub/scripts/fixup_gkehub_v1beta1_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,15 +39,14 @@ def partition( class gkehubCallTransformer(cst.CSTTransformer): CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { - 'create_membership': ('parent', 'membership_id', 'resource', ), - 'delete_membership': ('name', ), - 'generate_connect_manifest': ('name', 'connect_agent', 'version', 'is_upgrade', 'registry', 'image_pull_secret_content', ), - 'generate_exclusivity_manifest': ('name', 'crd_manifest', 'cr_manifest', ), - 'get_membership': ('name', ), - 'list_memberships': ('parent', 'page_size', 'page_token', 'filter', 'order_by', ), - 'update_membership': ('name', 'update_mask', 'resource', ), - 'validate_exclusivity': ('parent', 'intended_membership', 'cr_manifest', ), - + 'create_membership': ('parent', 'membership_id', 'resource', ), + 'delete_membership': ('name', ), + 'generate_connect_manifest': ('name', 'connect_agent', 'version', 'is_upgrade', 'registry', 'image_pull_secret_content', ), + 'generate_exclusivity_manifest': ('name', 'crd_manifest', 'cr_manifest', ), + 'get_membership': ('name', ), + 'list_memberships': ('parent', 'page_size', 'page_token', 'filter', 'order_by', ), + 'update_membership': ('name', 'update_mask', 'resource', ), + 'validate_exclusivity': ('parent', 'intended_membership', 'cr_manifest', ), } def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: @@ -80,7 +77,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-gke-hub/tests/__init__.py b/packages/google-cloud-gke-hub/tests/__init__.py new file mode 100644 index 000000000000..4de65971c238 --- /dev/null +++ b/packages/google-cloud-gke-hub/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-gke-hub/tests/unit/__init__.py b/packages/google-cloud-gke-hub/tests/unit/__init__.py new file mode 100644 index 000000000000..4de65971c238 --- /dev/null +++ b/packages/google-cloud-gke-hub/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-gke-hub/tests/unit/gapic/__init__.py b/packages/google-cloud-gke-hub/tests/unit/gapic/__init__.py new file mode 100644 index 000000000000..4de65971c238 --- /dev/null +++ b/packages/google-cloud-gke-hub/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-gke-hub/tests/unit/gapic/gkehub_v1beta1/__init__.py b/packages/google-cloud-gke-hub/tests/unit/gapic/gkehub_v1beta1/__init__.py index 42ffdf2bc43d..4de65971c238 100644 --- a/packages/google-cloud-gke-hub/tests/unit/gapic/gkehub_v1beta1/__init__.py +++ b/packages/google-cloud-gke-hub/tests/unit/gapic/gkehub_v1beta1/__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-gke-hub/tests/unit/gapic/gkehub_v1beta1/test_gke_hub_membership_service.py b/packages/google-cloud-gke-hub/tests/unit/gapic/gkehub_v1beta1/test_gke_hub_membership_service.py index c37cdea9e887..3629ec2a4485 100644 --- a/packages/google-cloud-gke-hub/tests/unit/gapic/gkehub_v1beta1/test_gke_hub_membership_service.py +++ b/packages/google-cloud-gke-hub/tests/unit/gapic/gkehub_v1beta1/test_gke_hub_membership_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,16 +23,16 @@ 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 future from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 -from google.auth import credentials +from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.gkehub_v1beta1.services.gke_hub_membership_service import ( GkeHubMembershipServiceAsyncClient, @@ -43,12 +42,42 @@ ) from google.cloud.gkehub_v1beta1.services.gke_hub_membership_service import pagers from google.cloud.gkehub_v1beta1.services.gke_hub_membership_service import transports +from google.cloud.gkehub_v1beta1.services.gke_hub_membership_service.transports.base import ( + _API_CORE_VERSION, +) +from google.cloud.gkehub_v1beta1.services.gke_hub_membership_service.transports.base import ( + _GOOGLE_AUTH_VERSION, +) from google.cloud.gkehub_v1beta1.types import membership from google.longrunning import operations_pb2 from google.oauth2 import service_account -from google.protobuf import field_mask_pb2 as field_mask # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore -from google.rpc import status_pb2 as status # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +from google.rpc import status_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(): @@ -100,7 +129,7 @@ def test__get_default_mtls_endpoint(): "client_class", [GkeHubMembershipServiceClient, GkeHubMembershipServiceAsyncClient,] ) def test_gke_hub_membership_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: @@ -117,7 +146,7 @@ def test_gke_hub_membership_service_client_from_service_account_info(client_clas "client_class", [GkeHubMembershipServiceClient, GkeHubMembershipServiceAsyncClient,] ) def test_gke_hub_membership_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: @@ -174,7 +203,7 @@ def test_gke_hub_membership_service_client_client_options( ): # Check that if channel is provided we won't create a new one. with mock.patch.object(GkeHubMembershipServiceClient, "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() @@ -480,7 +509,7 @@ def test_list_memberships( transport: str = "grpc", request_type=membership.ListMembershipsRequest ): client = GkeHubMembershipServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -493,21 +522,16 @@ def test_list_memberships( call.return_value = membership.ListMembershipsResponse( next_page_token="next_page_token_value", unreachable=["unreachable_value"], ) - response = client.list_memberships(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == membership.ListMembershipsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListMembershipsPager) - assert response.next_page_token == "next_page_token_value" - assert response.unreachable == ["unreachable_value"] @@ -519,7 +543,7 @@ def test_list_memberships_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 = GkeHubMembershipServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -527,7 +551,6 @@ def test_list_memberships_empty_call(): client.list_memberships() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == membership.ListMembershipsRequest() @@ -536,7 +559,7 @@ async def test_list_memberships_async( transport: str = "grpc_asyncio", request_type=membership.ListMembershipsRequest ): client = GkeHubMembershipServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -552,20 +575,16 @@ async def test_list_memberships_async( unreachable=["unreachable_value"], ) ) - response = await client.list_memberships(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == membership.ListMembershipsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListMembershipsAsyncPager) - assert response.next_page_token == "next_page_token_value" - assert response.unreachable == ["unreachable_value"] @@ -576,18 +595,18 @@ async def test_list_memberships_async_from_dict(): def test_list_memberships_field_headers(): client = GkeHubMembershipServiceClient( - 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 = membership.ListMembershipsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_memberships), "__call__") as call: call.return_value = membership.ListMembershipsResponse() - client.list_memberships(request) # Establish that the underlying gRPC stub method was called. @@ -603,12 +622,13 @@ def test_list_memberships_field_headers(): @pytest.mark.asyncio async def test_list_memberships_field_headers_async(): client = GkeHubMembershipServiceAsyncClient( - 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 = membership.ListMembershipsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -616,7 +636,6 @@ async def test_list_memberships_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( membership.ListMembershipsResponse() ) - await client.list_memberships(request) # Establish that the underlying gRPC stub method was called. @@ -631,14 +650,13 @@ async def test_list_memberships_field_headers_async(): def test_list_memberships_flattened(): client = GkeHubMembershipServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_memberships), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = membership.ListMembershipsResponse() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.list_memberships(parent="parent_value",) @@ -647,13 +665,12 @@ def test_list_memberships_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" def test_list_memberships_flattened_error(): client = GkeHubMembershipServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -667,7 +684,7 @@ def test_list_memberships_flattened_error(): @pytest.mark.asyncio async def test_list_memberships_flattened_async(): client = GkeHubMembershipServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -686,14 +703,13 @@ async def test_list_memberships_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" @pytest.mark.asyncio async def test_list_memberships_flattened_error_async(): client = GkeHubMembershipServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -706,7 +722,7 @@ async def test_list_memberships_flattened_error_async(): def test_list_memberships_pager(): client = GkeHubMembershipServiceClient( - credentials=credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -746,7 +762,7 @@ def test_list_memberships_pager(): def test_list_memberships_pages(): client = GkeHubMembershipServiceClient( - credentials=credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -778,7 +794,7 @@ def test_list_memberships_pages(): @pytest.mark.asyncio async def test_list_memberships_async_pager(): client = GkeHubMembershipServiceAsyncClient( - credentials=credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -817,7 +833,7 @@ async def test_list_memberships_async_pager(): @pytest.mark.asyncio async def test_list_memberships_async_pages(): client = GkeHubMembershipServiceAsyncClient( - credentials=credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -854,7 +870,7 @@ def test_get_membership( transport: str = "grpc", request_type=membership.GetMembershipRequest ): client = GkeHubMembershipServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -874,27 +890,19 @@ def test_get_membership( gke_cluster=membership.GkeCluster(resource_link="resource_link_value") ), ) - response = client.get_membership(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == membership.GetMembershipRequest() # Establish that the response is the type that we expect. - assert isinstance(response, membership.Membership) - assert response.name == "name_value" - assert response.description == "description_value" - assert response.external_id == "external_id_value" - assert response.unique_id == "unique_id_value" - assert ( response.infrastructure_type == membership.Membership.InfrastructureType.ON_PREM ) @@ -908,7 +916,7 @@ def test_get_membership_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 = GkeHubMembershipServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -916,7 +924,6 @@ def test_get_membership_empty_call(): client.get_membership() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == membership.GetMembershipRequest() @@ -925,7 +932,7 @@ async def test_get_membership_async( transport: str = "grpc_asyncio", request_type=membership.GetMembershipRequest ): client = GkeHubMembershipServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -944,26 +951,19 @@ async def test_get_membership_async( infrastructure_type=membership.Membership.InfrastructureType.ON_PREM, ) ) - response = await client.get_membership(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == membership.GetMembershipRequest() # Establish that the response is the type that we expect. assert isinstance(response, membership.Membership) - assert response.name == "name_value" - assert response.description == "description_value" - assert response.external_id == "external_id_value" - assert response.unique_id == "unique_id_value" - assert ( response.infrastructure_type == membership.Membership.InfrastructureType.ON_PREM ) @@ -976,18 +976,18 @@ async def test_get_membership_async_from_dict(): def test_get_membership_field_headers(): client = GkeHubMembershipServiceClient( - 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 = membership.GetMembershipRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_membership), "__call__") as call: call.return_value = membership.Membership() - client.get_membership(request) # Establish that the underlying gRPC stub method was called. @@ -1003,12 +1003,13 @@ def test_get_membership_field_headers(): @pytest.mark.asyncio async def test_get_membership_field_headers_async(): client = GkeHubMembershipServiceAsyncClient( - 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 = membership.GetMembershipRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1016,7 +1017,6 @@ async def test_get_membership_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( membership.Membership() ) - await client.get_membership(request) # Establish that the underlying gRPC stub method was called. @@ -1031,14 +1031,13 @@ async def test_get_membership_field_headers_async(): def test_get_membership_flattened(): client = GkeHubMembershipServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_membership), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = membership.Membership() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.get_membership(name="name_value",) @@ -1047,13 +1046,12 @@ def test_get_membership_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_get_membership_flattened_error(): client = GkeHubMembershipServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1067,7 +1065,7 @@ def test_get_membership_flattened_error(): @pytest.mark.asyncio async def test_get_membership_flattened_async(): client = GkeHubMembershipServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1086,14 +1084,13 @@ async def test_get_membership_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @pytest.mark.asyncio async def test_get_membership_flattened_error_async(): client = GkeHubMembershipServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1108,7 +1105,7 @@ def test_create_membership( transport: str = "grpc", request_type=membership.CreateMembershipRequest ): client = GkeHubMembershipServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1121,13 +1118,11 @@ def test_create_membership( ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.create_membership(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == membership.CreateMembershipRequest() # Establish that the response is the type that we expect. @@ -1142,7 +1137,7 @@ def test_create_membership_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 = GkeHubMembershipServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1152,7 +1147,6 @@ def test_create_membership_empty_call(): client.create_membership() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == membership.CreateMembershipRequest() @@ -1161,7 +1155,7 @@ async def test_create_membership_async( transport: str = "grpc_asyncio", request_type=membership.CreateMembershipRequest ): client = GkeHubMembershipServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1176,13 +1170,11 @@ async def test_create_membership_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.create_membership(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == membership.CreateMembershipRequest() # Establish that the response is the type that we expect. @@ -1196,12 +1188,13 @@ async def test_create_membership_async_from_dict(): def test_create_membership_field_headers(): client = GkeHubMembershipServiceClient( - 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 = membership.CreateMembershipRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1209,7 +1202,6 @@ def test_create_membership_field_headers(): type(client.transport.create_membership), "__call__" ) as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.create_membership(request) # Establish that the underlying gRPC stub method was called. @@ -1225,12 +1217,13 @@ def test_create_membership_field_headers(): @pytest.mark.asyncio async def test_create_membership_field_headers_async(): client = GkeHubMembershipServiceAsyncClient( - 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 = membership.CreateMembershipRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1240,7 +1233,6 @@ async def test_create_membership_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.create_membership(request) # Establish that the underlying gRPC stub method was called. @@ -1255,7 +1247,7 @@ async def test_create_membership_field_headers_async(): def test_create_membership_flattened(): client = GkeHubMembershipServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1264,7 +1256,6 @@ def test_create_membership_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.create_membership( @@ -1277,17 +1268,14 @@ def test_create_membership_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].resource == membership.Membership(name="name_value") - assert args[0].membership_id == "membership_id_value" def test_create_membership_flattened_error(): client = GkeHubMembershipServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1304,7 +1292,7 @@ def test_create_membership_flattened_error(): @pytest.mark.asyncio async def test_create_membership_flattened_async(): client = GkeHubMembershipServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1329,18 +1317,15 @@ async def test_create_membership_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].resource == membership.Membership(name="name_value") - assert args[0].membership_id == "membership_id_value" @pytest.mark.asyncio async def test_create_membership_flattened_error_async(): client = GkeHubMembershipServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1358,7 +1343,7 @@ def test_delete_membership( transport: str = "grpc", request_type=membership.DeleteMembershipRequest ): client = GkeHubMembershipServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1371,13 +1356,11 @@ def test_delete_membership( ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.delete_membership(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == membership.DeleteMembershipRequest() # Establish that the response is the type that we expect. @@ -1392,7 +1375,7 @@ def test_delete_membership_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 = GkeHubMembershipServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1402,7 +1385,6 @@ def test_delete_membership_empty_call(): client.delete_membership() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == membership.DeleteMembershipRequest() @@ -1411,7 +1393,7 @@ async def test_delete_membership_async( transport: str = "grpc_asyncio", request_type=membership.DeleteMembershipRequest ): client = GkeHubMembershipServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1426,13 +1408,11 @@ async def test_delete_membership_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.delete_membership(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == membership.DeleteMembershipRequest() # Establish that the response is the type that we expect. @@ -1446,12 +1426,13 @@ async def test_delete_membership_async_from_dict(): def test_delete_membership_field_headers(): client = GkeHubMembershipServiceClient( - 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 = membership.DeleteMembershipRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1459,7 +1440,6 @@ def test_delete_membership_field_headers(): type(client.transport.delete_membership), "__call__" ) as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.delete_membership(request) # Establish that the underlying gRPC stub method was called. @@ -1475,12 +1455,13 @@ def test_delete_membership_field_headers(): @pytest.mark.asyncio async def test_delete_membership_field_headers_async(): client = GkeHubMembershipServiceAsyncClient( - 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 = membership.DeleteMembershipRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1490,7 +1471,6 @@ async def test_delete_membership_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.delete_membership(request) # Establish that the underlying gRPC stub method was called. @@ -1505,7 +1485,7 @@ async def test_delete_membership_field_headers_async(): def test_delete_membership_flattened(): client = GkeHubMembershipServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1514,7 +1494,6 @@ def test_delete_membership_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.delete_membership(name="name_value",) @@ -1523,13 +1502,12 @@ def test_delete_membership_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_delete_membership_flattened_error(): client = GkeHubMembershipServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1543,7 +1521,7 @@ def test_delete_membership_flattened_error(): @pytest.mark.asyncio async def test_delete_membership_flattened_async(): client = GkeHubMembershipServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1564,14 +1542,13 @@ async def test_delete_membership_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @pytest.mark.asyncio async def test_delete_membership_flattened_error_async(): client = GkeHubMembershipServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1586,7 +1563,7 @@ def test_update_membership( transport: str = "grpc", request_type=membership.UpdateMembershipRequest ): client = GkeHubMembershipServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1599,13 +1576,11 @@ def test_update_membership( ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.update_membership(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == membership.UpdateMembershipRequest() # Establish that the response is the type that we expect. @@ -1620,7 +1595,7 @@ def test_update_membership_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 = GkeHubMembershipServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1630,7 +1605,6 @@ def test_update_membership_empty_call(): client.update_membership() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == membership.UpdateMembershipRequest() @@ -1639,7 +1613,7 @@ async def test_update_membership_async( transport: str = "grpc_asyncio", request_type=membership.UpdateMembershipRequest ): client = GkeHubMembershipServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1654,13 +1628,11 @@ async def test_update_membership_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.update_membership(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == membership.UpdateMembershipRequest() # Establish that the response is the type that we expect. @@ -1674,12 +1646,13 @@ async def test_update_membership_async_from_dict(): def test_update_membership_field_headers(): client = GkeHubMembershipServiceClient( - 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 = membership.UpdateMembershipRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1687,7 +1660,6 @@ def test_update_membership_field_headers(): type(client.transport.update_membership), "__call__" ) as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.update_membership(request) # Establish that the underlying gRPC stub method was called. @@ -1703,12 +1675,13 @@ def test_update_membership_field_headers(): @pytest.mark.asyncio async def test_update_membership_field_headers_async(): client = GkeHubMembershipServiceAsyncClient( - 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 = membership.UpdateMembershipRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1718,7 +1691,6 @@ async def test_update_membership_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.update_membership(request) # Establish that the underlying gRPC stub method was called. @@ -1733,7 +1705,7 @@ async def test_update_membership_field_headers_async(): def test_update_membership_flattened(): client = GkeHubMembershipServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1742,30 +1714,26 @@ def test_update_membership_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.update_membership( name="name_value", resource=membership.Membership(name="name_value"), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].resource == membership.Membership(name="name_value") - - assert args[0].update_mask == field_mask.FieldMask(paths=["paths_value"]) + assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) def test_update_membership_flattened_error(): client = GkeHubMembershipServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1775,14 +1743,14 @@ def test_update_membership_flattened_error(): membership.UpdateMembershipRequest(), name="name_value", resource=membership.Membership(name="name_value"), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @pytest.mark.asyncio async def test_update_membership_flattened_async(): client = GkeHubMembershipServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1800,25 +1768,22 @@ async def test_update_membership_flattened_async(): response = await client.update_membership( name="name_value", resource=membership.Membership(name="name_value"), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].resource == membership.Membership(name="name_value") - - assert args[0].update_mask == field_mask.FieldMask(paths=["paths_value"]) + assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) @pytest.mark.asyncio async def test_update_membership_flattened_error_async(): client = GkeHubMembershipServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1828,7 +1793,7 @@ async def test_update_membership_flattened_error_async(): membership.UpdateMembershipRequest(), name="name_value", resource=membership.Membership(name="name_value"), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @@ -1836,7 +1801,7 @@ def test_generate_connect_manifest( transport: str = "grpc", request_type=membership.GenerateConnectManifestRequest ): client = GkeHubMembershipServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1849,17 +1814,14 @@ def test_generate_connect_manifest( ) as call: # Designate an appropriate return value for the call. call.return_value = membership.GenerateConnectManifestResponse() - response = client.generate_connect_manifest(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == membership.GenerateConnectManifestRequest() # Establish that the response is the type that we expect. - assert isinstance(response, membership.GenerateConnectManifestResponse) @@ -1871,7 +1833,7 @@ def test_generate_connect_manifest_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 = GkeHubMembershipServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1881,7 +1843,6 @@ def test_generate_connect_manifest_empty_call(): client.generate_connect_manifest() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == membership.GenerateConnectManifestRequest() @@ -1891,7 +1852,7 @@ async def test_generate_connect_manifest_async( request_type=membership.GenerateConnectManifestRequest, ): client = GkeHubMembershipServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1906,13 +1867,11 @@ async def test_generate_connect_manifest_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( membership.GenerateConnectManifestResponse() ) - response = await client.generate_connect_manifest(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == membership.GenerateConnectManifestRequest() # Establish that the response is the type that we expect. @@ -1926,12 +1885,13 @@ async def test_generate_connect_manifest_async_from_dict(): def test_generate_connect_manifest_field_headers(): client = GkeHubMembershipServiceClient( - 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 = membership.GenerateConnectManifestRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1939,7 +1899,6 @@ def test_generate_connect_manifest_field_headers(): type(client.transport.generate_connect_manifest), "__call__" ) as call: call.return_value = membership.GenerateConnectManifestResponse() - client.generate_connect_manifest(request) # Establish that the underlying gRPC stub method was called. @@ -1955,12 +1914,13 @@ def test_generate_connect_manifest_field_headers(): @pytest.mark.asyncio async def test_generate_connect_manifest_field_headers_async(): client = GkeHubMembershipServiceAsyncClient( - 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 = membership.GenerateConnectManifestRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1970,7 +1930,6 @@ async def test_generate_connect_manifest_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( membership.GenerateConnectManifestResponse() ) - await client.generate_connect_manifest(request) # Establish that the underlying gRPC stub method was called. @@ -1987,7 +1946,7 @@ def test_validate_exclusivity( transport: str = "grpc", request_type=membership.ValidateExclusivityRequest ): client = GkeHubMembershipServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2000,17 +1959,14 @@ def test_validate_exclusivity( ) as call: # Designate an appropriate return value for the call. call.return_value = membership.ValidateExclusivityResponse() - response = client.validate_exclusivity(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == membership.ValidateExclusivityRequest() # Establish that the response is the type that we expect. - assert isinstance(response, membership.ValidateExclusivityResponse) @@ -2022,7 +1978,7 @@ def test_validate_exclusivity_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 = GkeHubMembershipServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2032,7 +1988,6 @@ def test_validate_exclusivity_empty_call(): client.validate_exclusivity() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == membership.ValidateExclusivityRequest() @@ -2041,7 +1996,7 @@ async def test_validate_exclusivity_async( transport: str = "grpc_asyncio", request_type=membership.ValidateExclusivityRequest ): client = GkeHubMembershipServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2056,13 +2011,11 @@ async def test_validate_exclusivity_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( membership.ValidateExclusivityResponse() ) - response = await client.validate_exclusivity(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == membership.ValidateExclusivityRequest() # Establish that the response is the type that we expect. @@ -2076,12 +2029,13 @@ async def test_validate_exclusivity_async_from_dict(): def test_validate_exclusivity_field_headers(): client = GkeHubMembershipServiceClient( - 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 = membership.ValidateExclusivityRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2089,7 +2043,6 @@ def test_validate_exclusivity_field_headers(): type(client.transport.validate_exclusivity), "__call__" ) as call: call.return_value = membership.ValidateExclusivityResponse() - client.validate_exclusivity(request) # Establish that the underlying gRPC stub method was called. @@ -2105,12 +2058,13 @@ def test_validate_exclusivity_field_headers(): @pytest.mark.asyncio async def test_validate_exclusivity_field_headers_async(): client = GkeHubMembershipServiceAsyncClient( - 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 = membership.ValidateExclusivityRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2120,7 +2074,6 @@ async def test_validate_exclusivity_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( membership.ValidateExclusivityResponse() ) - await client.validate_exclusivity(request) # Establish that the underlying gRPC stub method was called. @@ -2137,7 +2090,7 @@ def test_generate_exclusivity_manifest( transport: str = "grpc", request_type=membership.GenerateExclusivityManifestRequest ): client = GkeHubMembershipServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2152,21 +2105,16 @@ def test_generate_exclusivity_manifest( call.return_value = membership.GenerateExclusivityManifestResponse( crd_manifest="crd_manifest_value", cr_manifest="cr_manifest_value", ) - response = client.generate_exclusivity_manifest(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == membership.GenerateExclusivityManifestRequest() # Establish that the response is the type that we expect. - assert isinstance(response, membership.GenerateExclusivityManifestResponse) - assert response.crd_manifest == "crd_manifest_value" - assert response.cr_manifest == "cr_manifest_value" @@ -2178,7 +2126,7 @@ def test_generate_exclusivity_manifest_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 = GkeHubMembershipServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2188,7 +2136,6 @@ def test_generate_exclusivity_manifest_empty_call(): client.generate_exclusivity_manifest() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == membership.GenerateExclusivityManifestRequest() @@ -2198,7 +2145,7 @@ async def test_generate_exclusivity_manifest_async( request_type=membership.GenerateExclusivityManifestRequest, ): client = GkeHubMembershipServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2215,20 +2162,16 @@ async def test_generate_exclusivity_manifest_async( crd_manifest="crd_manifest_value", cr_manifest="cr_manifest_value", ) ) - response = await client.generate_exclusivity_manifest(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == membership.GenerateExclusivityManifestRequest() # Establish that the response is the type that we expect. assert isinstance(response, membership.GenerateExclusivityManifestResponse) - assert response.crd_manifest == "crd_manifest_value" - assert response.cr_manifest == "cr_manifest_value" @@ -2239,12 +2182,13 @@ async def test_generate_exclusivity_manifest_async_from_dict(): def test_generate_exclusivity_manifest_field_headers(): client = GkeHubMembershipServiceClient( - 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 = membership.GenerateExclusivityManifestRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2252,7 +2196,6 @@ def test_generate_exclusivity_manifest_field_headers(): type(client.transport.generate_exclusivity_manifest), "__call__" ) as call: call.return_value = membership.GenerateExclusivityManifestResponse() - client.generate_exclusivity_manifest(request) # Establish that the underlying gRPC stub method was called. @@ -2268,12 +2211,13 @@ def test_generate_exclusivity_manifest_field_headers(): @pytest.mark.asyncio async def test_generate_exclusivity_manifest_field_headers_async(): client = GkeHubMembershipServiceAsyncClient( - 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 = membership.GenerateExclusivityManifestRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2283,7 +2227,6 @@ async def test_generate_exclusivity_manifest_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( membership.GenerateExclusivityManifestResponse() ) - await client.generate_exclusivity_manifest(request) # Establish that the underlying gRPC stub method was called. @@ -2299,16 +2242,16 @@ async def test_generate_exclusivity_manifest_field_headers_async(): def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.GkeHubMembershipServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = GkeHubMembershipServiceClient( - 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.GkeHubMembershipServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = GkeHubMembershipServiceClient( @@ -2318,7 +2261,7 @@ def test_credentials_transport_error(): # It is an error to provide scopes and a transport instance. transport = transports.GkeHubMembershipServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = GkeHubMembershipServiceClient( @@ -2329,7 +2272,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.GkeHubMembershipServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) client = GkeHubMembershipServiceClient(transport=transport) assert client.transport is transport @@ -2338,13 +2281,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.GkeHubMembershipServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel transport = transports.GkeHubMembershipServiceGrpcAsyncIOTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel @@ -2359,8 +2302,8 @@ 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() @@ -2368,7 +2311,7 @@ def test_transport_adc(transport_class): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = GkeHubMembershipServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) assert isinstance( client.transport, transports.GkeHubMembershipServiceGrpcTransport, @@ -2377,9 +2320,9 @@ def test_transport_grpc_default(): def test_gke_hub_membership_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.GkeHubMembershipServiceTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), credentials_file="credentials.json", ) @@ -2391,7 +2334,7 @@ def test_gke_hub_membership_service_base_transport(): ) as Transport: Transport.return_value = None transport = transports.GkeHubMembershipServiceTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Every method on the transport should just blindly @@ -2416,15 +2359,37 @@ def test_gke_hub_membership_service_base_transport(): transport.operations_client +@requires_google_auth_gte_1_25_0 def test_gke_hub_membership_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.gkehub_v1beta1.services.gke_hub_membership_service.transports.GkeHubMembershipServiceTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.GkeHubMembershipServiceTransport( + 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",), + quota_project_id="octopus", + ) + + +@requires_google_auth_lt_1_25_0 +def test_gke_hub_membership_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.gkehub_v1beta1.services.gke_hub_membership_service.transports.GkeHubMembershipServiceTransport._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.GkeHubMembershipServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", ) @@ -2437,19 +2402,33 @@ def test_gke_hub_membership_service_base_transport_with_credentials_file(): def test_gke_hub_membership_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.gkehub_v1beta1.services.gke_hub_membership_service.transports.GkeHubMembershipServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (credentials.AnonymousCredentials(), None) + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GkeHubMembershipServiceTransport() adc.assert_called_once() +@requires_google_auth_gte_1_25_0 def test_gke_hub_membership_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) + GkeHubMembershipServiceClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id=None, + ) + + +@requires_google_auth_lt_1_25_0 +def test_gke_hub_membership_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) GkeHubMembershipServiceClient() adc.assert_called_once_with( scopes=("https://www.googleapis.com/auth/cloud-platform",), @@ -2457,20 +2436,158 @@ def test_gke_hub_membership_service_auth_adc(): ) -def test_gke_hub_membership_service_transport_auth_adc(): +@pytest.mark.parametrize( + "transport_class", + [ + transports.GkeHubMembershipServiceGrpcTransport, + transports.GkeHubMembershipServiceGrpcAsyncIOTransport, + ], +) +@requires_google_auth_gte_1_25_0 +def test_gke_hub_membership_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.GkeHubMembershipServiceGrpcTransport( - 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",), + quota_project_id="octopus", ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.GkeHubMembershipServiceGrpcTransport, + transports.GkeHubMembershipServiceGrpcAsyncIOTransport, + ], +) +@requires_google_auth_lt_1_25_0 +def test_gke_hub_membership_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",), quota_project_id="octopus", ) +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.GkeHubMembershipServiceGrpcTransport, grpc_helpers), + (transports.GkeHubMembershipServiceGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_gte_1_26_0 +def test_gke_hub_membership_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( + "gkehub.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=["1", "2"], + default_host="gkehub.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.GkeHubMembershipServiceGrpcTransport, grpc_helpers), + (transports.GkeHubMembershipServiceGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_gke_hub_membership_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( + "gkehub.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + scopes=("https://www.googleapis.com/auth/cloud-platform",), + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.GkeHubMembershipServiceGrpcTransport, grpc_helpers), + (transports.GkeHubMembershipServiceGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_gke_hub_membership_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( + "gkehub.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", [ @@ -2481,7 +2598,7 @@ def test_gke_hub_membership_service_transport_auth_adc(): def test_gke_hub_membership_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: @@ -2520,7 +2637,7 @@ def test_gke_hub_membership_service_grpc_transport_client_cert_source_for_mtls( def test_gke_hub_membership_service_host_no_port(): client = GkeHubMembershipServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="gkehub.googleapis.com" ), @@ -2530,7 +2647,7 @@ def test_gke_hub_membership_service_host_no_port(): def test_gke_hub_membership_service_host_with_port(): client = GkeHubMembershipServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="gkehub.googleapis.com:8000" ), @@ -2586,9 +2703,9 @@ def test_gke_hub_membership_service_transport_channel_mtls_with_client_cert_sour 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", @@ -2664,7 +2781,7 @@ def test_gke_hub_membership_service_transport_channel_mtls_with_adc(transport_cl def test_gke_hub_membership_service_grpc_lro_client(): client = GkeHubMembershipServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) transport = client.transport @@ -2677,7 +2794,7 @@ def test_gke_hub_membership_service_grpc_lro_client(): def test_gke_hub_membership_service_grpc_lro_async_client(): client = GkeHubMembershipServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", ) transport = client.transport @@ -2692,7 +2809,6 @@ def test_membership_path(): project = "squid" location = "clam" membership = "whelk" - expected = "projects/{project}/locations/{location}/memberships/{membership}".format( project=project, location=location, membership=membership, ) @@ -2717,7 +2833,6 @@ def test_parse_membership_path(): def test_common_billing_account_path(): billing_account = "cuttlefish" - expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -2738,7 +2853,6 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "winkle" - expected = "folders/{folder}".format(folder=folder,) actual = GkeHubMembershipServiceClient.common_folder_path(folder) assert expected == actual @@ -2757,7 +2871,6 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "scallop" - expected = "organizations/{organization}".format(organization=organization,) actual = GkeHubMembershipServiceClient.common_organization_path(organization) assert expected == actual @@ -2776,7 +2889,6 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "squid" - expected = "projects/{project}".format(project=project,) actual = GkeHubMembershipServiceClient.common_project_path(project) assert expected == actual @@ -2796,7 +2908,6 @@ def test_parse_common_project_path(): def test_common_location_path(): project = "whelk" location = "octopus" - expected = "projects/{project}/locations/{location}".format( project=project, location=location, ) @@ -2823,7 +2934,7 @@ def test_client_withDEFAULT_CLIENT_INFO(): transports.GkeHubMembershipServiceTransport, "_prep_wrapped_messages" ) as prep: client = GkeHubMembershipServiceClient( - credentials=credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -2832,6 +2943,6 @@ def test_client_withDEFAULT_CLIENT_INFO(): ) as prep: transport_class = GkeHubMembershipServiceClient.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)