From 857db06e1b777e62eba0180655d059e2729ba898 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Thu, 20 May 2021 16:21:46 -0600 Subject: [PATCH] chore: upgrade gapic-generator-python to 0.46.3 (#73) feat: support self-signed JWT flow for service accounts fix: add async client to %name_%version/init.py chore: add autogenerated snippets chore: remove auth, policy, and options from the reserved names list chore: enable GAPIC metadata generation chore: sort subpackages in %namespace/%name/init.py --- google/cloud/oslogin/__init__.py | 12 +- google/cloud/oslogin_v1/__init__.py | 7 +- google/cloud/oslogin_v1/common/__init__.py | 7 +- .../oslogin_v1/common/gapic_metadata.json | 7 + .../cloud/oslogin_v1/common/types/__init__.py | 2 - .../cloud/oslogin_v1/common/types/common.py | 43 +- google/cloud/oslogin_v1/gapic_metadata.json | 83 +++ google/cloud/oslogin_v1/services/__init__.py | 1 - .../services/os_login_service/__init__.py | 2 - .../services/os_login_service/async_client.py | 66 +-- .../services/os_login_service/client.py | 95 ++- .../os_login_service/transports/__init__.py | 2 - .../os_login_service/transports/base.py | 144 +++-- .../os_login_service/transports/grpc.py | 32 +- .../transports/grpc_asyncio.py | 33 +- google/cloud/oslogin_v1/types/__init__.py | 2 - google/cloud/oslogin_v1/types/oslogin.py | 49 +- owlbot.py | 17 +- scripts/fixup_oslogin_v1_keywords.py | 17 +- setup.py | 1 + testing/constraints-3.6.txt | 4 +- tests/unit/gapic/oslogin_v1/__init__.py | 1 - .../gapic/oslogin_v1/test_os_login_service.py | 561 ++++++++++++------ 23 files changed, 723 insertions(+), 465 deletions(-) create mode 100644 google/cloud/oslogin_v1/common/gapic_metadata.json create mode 100644 google/cloud/oslogin_v1/gapic_metadata.json diff --git a/google/cloud/oslogin/__init__.py b/google/cloud/oslogin/__init__.py index 57af983..51d6c8a 100644 --- a/google/cloud/oslogin/__init__.py +++ b/google/cloud/oslogin/__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.oslogin_v1.services.os_login_service.async_client import ( - OsLoginServiceAsyncClient, -) from google.cloud.oslogin_v1.services.os_login_service.client import ( OsLoginServiceClient, ) +from google.cloud.oslogin_v1.services.os_login_service.async_client import ( + OsLoginServiceAsyncClient, +) + from google.cloud.oslogin_v1.types.oslogin import DeletePosixAccountRequest from google.cloud.oslogin_v1.types.oslogin import DeleteSshPublicKeyRequest from google.cloud.oslogin_v1.types.oslogin import GetLoginProfileRequest @@ -31,6 +31,8 @@ from google.cloud.oslogin_v1.types.oslogin import UpdateSshPublicKeyRequest __all__ = ( + "OsLoginServiceClient", + "OsLoginServiceAsyncClient", "DeletePosixAccountRequest", "DeleteSshPublicKeyRequest", "GetLoginProfileRequest", @@ -38,7 +40,5 @@ "ImportSshPublicKeyRequest", "ImportSshPublicKeyResponse", "LoginProfile", - "OsLoginServiceAsyncClient", - "OsLoginServiceClient", "UpdateSshPublicKeyRequest", ) diff --git a/google/cloud/oslogin_v1/__init__.py b/google/cloud/oslogin_v1/__init__.py index 41e41bf..91624cd 100644 --- a/google/cloud/oslogin_v1/__init__.py +++ b/google/cloud/oslogin_v1/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,6 +15,8 @@ # from .services.os_login_service import OsLoginServiceClient +from .services.os_login_service import OsLoginServiceAsyncClient + from .types.oslogin import DeletePosixAccountRequest from .types.oslogin import DeleteSshPublicKeyRequest from .types.oslogin import GetLoginProfileRequest @@ -25,8 +26,8 @@ from .types.oslogin import LoginProfile from .types.oslogin import UpdateSshPublicKeyRequest - __all__ = ( + "OsLoginServiceAsyncClient", "DeletePosixAccountRequest", "DeleteSshPublicKeyRequest", "GetLoginProfileRequest", @@ -34,6 +35,6 @@ "ImportSshPublicKeyRequest", "ImportSshPublicKeyResponse", "LoginProfile", - "UpdateSshPublicKeyRequest", "OsLoginServiceClient", + "UpdateSshPublicKeyRequest", ) diff --git a/google/cloud/oslogin_v1/common/__init__.py b/google/cloud/oslogin_v1/common/__init__.py index 6ac5dc1..3b7f14c 100644 --- a/google/cloud/oslogin_v1/common/__init__.py +++ b/google/cloud/oslogin_v1/common/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,13 +14,13 @@ # limitations under the License. # -from .types.common import OperatingSystemType + from .types.common import PosixAccount from .types.common import SshPublicKey - +from .types.common import OperatingSystemType __all__ = ( "OperatingSystemType", - "SshPublicKey", "PosixAccount", + "SshPublicKey", ) diff --git a/google/cloud/oslogin_v1/common/gapic_metadata.json b/google/cloud/oslogin_v1/common/gapic_metadata.json new file mode 100644 index 0000000..502c0a0 --- /dev/null +++ b/google/cloud/oslogin_v1/common/gapic_metadata.json @@ -0,0 +1,7 @@ + { + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", + "language": "python", + "libraryPackage": "google.cloud.oslogin.common", + "protoPackage": "google.cloud.oslogin.common", + "schema": "1.0" +} diff --git a/google/cloud/oslogin_v1/common/types/__init__.py b/google/cloud/oslogin_v1/common/types/__init__.py index 0fefd31..dc115fa 100644 --- a/google/cloud/oslogin_v1/common/types/__init__.py +++ b/google/cloud/oslogin_v1/common/types/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from .common import ( PosixAccount, SshPublicKey, diff --git a/google/cloud/oslogin_v1/common/types/common.py b/google/cloud/oslogin_v1/common/types/common.py index 50a0437..dbb90cb 100644 --- a/google/cloud/oslogin_v1/common/types/common.py +++ b/google/cloud/oslogin_v1/common/types/common.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore @@ -66,29 +64,19 @@ class PosixAccount(proto.Message): Output only. The canonical resource name. """ - primary = proto.Field(proto.BOOL, number=1) - - username = proto.Field(proto.STRING, number=2) - - uid = proto.Field(proto.INT64, number=3) - - gid = proto.Field(proto.INT64, number=4) - - home_directory = proto.Field(proto.STRING, number=5) - - shell = proto.Field(proto.STRING, number=6) - - gecos = proto.Field(proto.STRING, number=7) - - system_id = proto.Field(proto.STRING, number=8) - - account_id = proto.Field(proto.STRING, number=9) - + primary = proto.Field(proto.BOOL, number=1,) + username = proto.Field(proto.STRING, number=2,) + uid = proto.Field(proto.INT64, number=3,) + gid = proto.Field(proto.INT64, number=4,) + home_directory = proto.Field(proto.STRING, number=5,) + shell = proto.Field(proto.STRING, number=6,) + gecos = proto.Field(proto.STRING, number=7,) + system_id = proto.Field(proto.STRING, number=8,) + account_id = proto.Field(proto.STRING, number=9,) operating_system_type = proto.Field( proto.ENUM, number=10, enum="OperatingSystemType", ) - - name = proto.Field(proto.STRING, number=11) + name = proto.Field(proto.STRING, number=11,) class SshPublicKey(proto.Message): @@ -109,13 +97,10 @@ class SshPublicKey(proto.Message): Output only. The canonical resource name. """ - key = proto.Field(proto.STRING, number=1) - - expiration_time_usec = proto.Field(proto.INT64, number=2) - - fingerprint = proto.Field(proto.STRING, number=3) - - name = proto.Field(proto.STRING, number=4) + key = proto.Field(proto.STRING, number=1,) + expiration_time_usec = proto.Field(proto.INT64, number=2,) + fingerprint = proto.Field(proto.STRING, number=3,) + name = proto.Field(proto.STRING, number=4,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/oslogin_v1/gapic_metadata.json b/google/cloud/oslogin_v1/gapic_metadata.json new file mode 100644 index 0000000..a6f7ff2 --- /dev/null +++ b/google/cloud/oslogin_v1/gapic_metadata.json @@ -0,0 +1,83 @@ + { + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", + "language": "python", + "libraryPackage": "google.cloud.oslogin_v1", + "protoPackage": "google.cloud.oslogin.v1", + "schema": "1.0", + "services": { + "OsLoginService": { + "clients": { + "grpc": { + "libraryClient": "OsLoginServiceClient", + "rpcs": { + "DeletePosixAccount": { + "methods": [ + "delete_posix_account" + ] + }, + "DeleteSshPublicKey": { + "methods": [ + "delete_ssh_public_key" + ] + }, + "GetLoginProfile": { + "methods": [ + "get_login_profile" + ] + }, + "GetSshPublicKey": { + "methods": [ + "get_ssh_public_key" + ] + }, + "ImportSshPublicKey": { + "methods": [ + "import_ssh_public_key" + ] + }, + "UpdateSshPublicKey": { + "methods": [ + "update_ssh_public_key" + ] + } + } + }, + "grpc-async": { + "libraryClient": "OsLoginServiceAsyncClient", + "rpcs": { + "DeletePosixAccount": { + "methods": [ + "delete_posix_account" + ] + }, + "DeleteSshPublicKey": { + "methods": [ + "delete_ssh_public_key" + ] + }, + "GetLoginProfile": { + "methods": [ + "get_login_profile" + ] + }, + "GetSshPublicKey": { + "methods": [ + "get_ssh_public_key" + ] + }, + "ImportSshPublicKey": { + "methods": [ + "import_ssh_public_key" + ] + }, + "UpdateSshPublicKey": { + "methods": [ + "update_ssh_public_key" + ] + } + } + } + } + } + } +} diff --git a/google/cloud/oslogin_v1/services/__init__.py b/google/cloud/oslogin_v1/services/__init__.py index 42ffdf2..4de6597 100644 --- a/google/cloud/oslogin_v1/services/__init__.py +++ b/google/cloud/oslogin_v1/services/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/google/cloud/oslogin_v1/services/os_login_service/__init__.py b/google/cloud/oslogin_v1/services/os_login_service/__init__.py index 4e7ce22..10ae1c5 100644 --- a/google/cloud/oslogin_v1/services/os_login_service/__init__.py +++ b/google/cloud/oslogin_v1/services/os_login_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 OsLoginServiceClient from .async_client import OsLoginServiceAsyncClient diff --git a/google/cloud/oslogin_v1/services/os_login_service/async_client.py b/google/cloud/oslogin_v1/services/os_login_service/async_client.py index 2c38ecf..5905086 100644 --- a/google/cloud/oslogin_v1/services/os_login_service/async_client.py +++ b/google/cloud/oslogin_v1/services/os_login_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,16 +20,15 @@ import pkg_resources import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore from google.cloud.oslogin_v1 import common # type: ignore from google.cloud.oslogin_v1.types import oslogin -from google.protobuf import field_mask_pb2 as field_mask # type: ignore - +from google.protobuf import field_mask_pb2 # type: ignore from .transports.base import OsLoginServiceTransport, DEFAULT_CLIENT_INFO from .transports.grpc_asyncio import OsLoginServiceGrpcAsyncIOTransport from .client import OsLoginServiceClient @@ -57,31 +54,26 @@ class OsLoginServiceAsyncClient: parse_ssh_public_key_path = staticmethod( OsLoginServiceClient.parse_ssh_public_key_path ) - common_billing_account_path = staticmethod( OsLoginServiceClient.common_billing_account_path ) parse_common_billing_account_path = staticmethod( OsLoginServiceClient.parse_common_billing_account_path ) - common_folder_path = staticmethod(OsLoginServiceClient.common_folder_path) parse_common_folder_path = staticmethod( OsLoginServiceClient.parse_common_folder_path ) - common_organization_path = staticmethod( OsLoginServiceClient.common_organization_path ) parse_common_organization_path = staticmethod( OsLoginServiceClient.parse_common_organization_path ) - common_project_path = staticmethod(OsLoginServiceClient.common_project_path) parse_common_project_path = staticmethod( OsLoginServiceClient.parse_common_project_path ) - common_location_path = staticmethod(OsLoginServiceClient.common_location_path) parse_common_location_path = staticmethod( OsLoginServiceClient.parse_common_location_path @@ -89,7 +81,8 @@ class OsLoginServiceAsyncClient: @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. @@ -104,7 +97,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 @@ -121,7 +114,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> OsLoginServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: OsLoginServiceTransport: The transport used by the client instance. @@ -135,12 +128,12 @@ def transport(self) -> OsLoginServiceTransport: def __init__( self, *, - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, transport: Union[str, OsLoginServiceTransport] = "grpc_asyncio", client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the os login service client. + """Instantiates the os login service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -172,7 +165,6 @@ def __init__( google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport creation failed for any reason. """ - self._client = OsLoginServiceClient( credentials=credentials, transport=transport, @@ -204,7 +196,6 @@ async def delete_posix_account( 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. @@ -225,7 +216,6 @@ async def delete_posix_account( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -238,7 +228,8 @@ async def delete_posix_account( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=10.0, ), @@ -281,7 +272,6 @@ async def delete_ssh_public_key( 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. @@ -302,7 +292,6 @@ async def delete_ssh_public_key( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -315,7 +304,8 @@ async def delete_ssh_public_key( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=10.0, ), @@ -357,7 +347,6 @@ async def get_login_profile( 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. @@ -385,7 +374,6 @@ async def get_login_profile( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -398,7 +386,8 @@ async def get_login_profile( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=10.0, ), @@ -442,7 +431,6 @@ async def get_ssh_public_key( 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. @@ -450,7 +438,7 @@ async def get_ssh_public_key( sent along with the request as metadata. Returns: - google.cloud.oslogin.v1.common_pb2.SshPublicKey: + google.cloud.oslogin.v1.common.SshPublicKey: The SSH public key information associated with a Google account. @@ -469,7 +457,6 @@ async def get_ssh_public_key( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -482,7 +469,8 @@ async def get_ssh_public_key( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=10.0, ), @@ -529,7 +517,7 @@ async def import_ssh_public_key( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - ssh_public_key (:class:`google.cloud.oslogin.v1.common_pb2.SshPublicKey`): + ssh_public_key (:class:`google.cloud.oslogin.v1.common.SshPublicKey`): Optional. The SSH public key and expiration time. @@ -543,7 +531,6 @@ async def import_ssh_public_key( This corresponds to the ``project_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. @@ -570,7 +557,6 @@ async def import_ssh_public_key( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if ssh_public_key is not None: @@ -587,7 +573,8 @@ async def import_ssh_public_key( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=10.0, ), @@ -613,7 +600,7 @@ async def update_ssh_public_key( *, name: str = None, ssh_public_key: common.SshPublicKey = 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]] = (), @@ -634,7 +621,7 @@ async def update_ssh_public_key( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - ssh_public_key (:class:`google.cloud.oslogin.v1.common_pb2.SshPublicKey`): + ssh_public_key (:class:`google.cloud.oslogin.v1.common.SshPublicKey`): Required. The SSH public key and expiration time. @@ -648,7 +635,6 @@ async def update_ssh_public_key( 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. @@ -656,7 +642,7 @@ async def update_ssh_public_key( sent along with the request as metadata. Returns: - google.cloud.oslogin.v1.common_pb2.SshPublicKey: + google.cloud.oslogin.v1.common.SshPublicKey: The SSH public key information associated with a Google account. @@ -675,7 +661,6 @@ async def update_ssh_public_key( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if ssh_public_key is not None: @@ -692,7 +677,8 @@ async def update_ssh_public_key( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=10.0, ), diff --git a/google/cloud/oslogin_v1/services/os_login_service/client.py b/google/cloud/oslogin_v1/services/os_login_service/client.py index 967d579..1740b67 100644 --- a/google/cloud/oslogin_v1/services/os_login_service/client.py +++ b/google/cloud/oslogin_v1/services/os_login_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 @@ -34,8 +32,7 @@ from google.cloud.oslogin_v1 import common # type: ignore from google.cloud.oslogin_v1.types import oslogin -from google.protobuf import field_mask_pb2 as field_mask # type: ignore - +from google.protobuf import field_mask_pb2 # type: ignore from .transports.base import OsLoginServiceTransport, DEFAULT_CLIENT_INFO from .transports.grpc import OsLoginServiceGrpcTransport from .transports.grpc_asyncio import OsLoginServiceGrpcAsyncIOTransport @@ -56,7 +53,7 @@ class OsLoginServiceClientMeta(type): _transport_registry["grpc_asyncio"] = OsLoginServiceGrpcAsyncIOTransport def get_transport_class(cls, label: str = None,) -> Type[OsLoginServiceTransport]: - """Return an appropriate transport class. + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -83,7 +80,8 @@ class OsLoginServiceClient(metaclass=OsLoginServiceClientMeta): @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: @@ -117,7 +115,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. @@ -134,7 +133,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 @@ -153,40 +152,41 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> OsLoginServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - OsLoginServiceTransport: The transport used by the client instance. + OsLoginServiceTransport: The transport used by the client + instance. """ return self._transport @staticmethod def posix_account_path(user: str, project: str,) -> str: - """Return a fully-qualified posix_account string.""" + """Returns a fully-qualified posix_account string.""" return "users/{user}/projects/{project}".format(user=user, project=project,) @staticmethod def parse_posix_account_path(path: str) -> Dict[str, str]: - """Parse a posix_account path into its component segments.""" + """Parses a posix_account path into its component segments.""" m = re.match(r"^users/(?P.+?)/projects/(?P.+?)$", path) return m.groupdict() if m else {} @staticmethod def ssh_public_key_path(user: str, fingerprint: str,) -> str: - """Return a fully-qualified ssh_public_key string.""" + """Returns a fully-qualified ssh_public_key string.""" return "users/{user}/sshPublicKeys/{fingerprint}".format( user=user, fingerprint=fingerprint, ) @staticmethod def parse_ssh_public_key_path(path: str) -> Dict[str, str]: - """Parse a ssh_public_key path into its component segments.""" + """Parses a ssh_public_key path into its component segments.""" m = re.match(r"^users/(?P.+?)/sshPublicKeys/(?P.+?)$", path) return m.groupdict() if m else {} @staticmethod def common_billing_account_path(billing_account: str,) -> str: - """Return a fully-qualified billing_account string.""" + """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -199,7 +199,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 @@ -210,7 +210,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 @@ -221,7 +221,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 @@ -232,7 +232,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, ) @@ -246,12 +246,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, OsLoginServiceTransport, None] = None, client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the os login service client. + """Instantiates the os login service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -306,9 +306,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: @@ -320,12 +321,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. @@ -340,8 +343,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: @@ -380,7 +383,6 @@ def delete_posix_account( 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. @@ -403,10 +405,8 @@ def delete_posix_account( # there are no flattened fields. if not isinstance(request, oslogin.DeletePosixAccountRequest): request = oslogin.DeletePosixAccountRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -449,7 +449,6 @@ def delete_ssh_public_key( 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. @@ -472,10 +471,8 @@ def delete_ssh_public_key( # there are no flattened fields. if not isinstance(request, oslogin.DeleteSshPublicKeyRequest): request = oslogin.DeleteSshPublicKeyRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -517,7 +514,6 @@ def get_login_profile( 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. @@ -547,10 +543,8 @@ def get_login_profile( # there are no flattened fields. if not isinstance(request, oslogin.GetLoginProfileRequest): request = oslogin.GetLoginProfileRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -594,7 +588,6 @@ def get_ssh_public_key( 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. @@ -602,7 +595,7 @@ def get_ssh_public_key( sent along with the request as metadata. Returns: - google.cloud.oslogin.v1.common_pb2.SshPublicKey: + google.cloud.oslogin.v1.common.SshPublicKey: The SSH public key information associated with a Google account. @@ -623,10 +616,8 @@ def get_ssh_public_key( # there are no flattened fields. if not isinstance(request, oslogin.GetSshPublicKeyRequest): request = oslogin.GetSshPublicKeyRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -673,7 +664,7 @@ def import_ssh_public_key( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - ssh_public_key (google.cloud.oslogin.v1.common_pb2.SshPublicKey): + ssh_public_key (google.cloud.oslogin.v1.common.SshPublicKey): Optional. The SSH public key and expiration time. @@ -687,7 +678,6 @@ def import_ssh_public_key( This corresponds to the ``project_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. @@ -716,10 +706,8 @@ def import_ssh_public_key( # there are no flattened fields. if not isinstance(request, oslogin.ImportSshPublicKeyRequest): request = oslogin.ImportSshPublicKeyRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if ssh_public_key is not None: @@ -749,7 +737,7 @@ def update_ssh_public_key( *, name: str = None, ssh_public_key: common.SshPublicKey = 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]] = (), @@ -770,7 +758,7 @@ def update_ssh_public_key( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - ssh_public_key (google.cloud.oslogin.v1.common_pb2.SshPublicKey): + ssh_public_key (google.cloud.oslogin.v1.common.SshPublicKey): Required. The SSH public key and expiration time. @@ -784,7 +772,6 @@ def update_ssh_public_key( 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. @@ -792,7 +779,7 @@ def update_ssh_public_key( sent along with the request as metadata. Returns: - google.cloud.oslogin.v1.common_pb2.SshPublicKey: + google.cloud.oslogin.v1.common.SshPublicKey: The SSH public key information associated with a Google account. @@ -813,10 +800,8 @@ def update_ssh_public_key( # there are no flattened fields. if not isinstance(request, oslogin.UpdateSshPublicKeyRequest): request = oslogin.UpdateSshPublicKeyRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if ssh_public_key is not None: diff --git a/google/cloud/oslogin_v1/services/os_login_service/transports/__init__.py b/google/cloud/oslogin_v1/services/os_login_service/transports/__init__.py index bd59d48..7858ac4 100644 --- a/google/cloud/oslogin_v1/services/os_login_service/transports/__init__.py +++ b/google/cloud/oslogin_v1/services/os_login_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/google/cloud/oslogin_v1/services/os_login_service/transports/base.py b/google/cloud/oslogin_v1/services/os_login_service/transports/base.py index 0ccd280..a0117cb 100644 --- a/google/cloud/oslogin_v1/services/os_login_service/transports/base.py +++ b/google/cloud/oslogin_v1/services/os_login_service/transports/base.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,21 +13,21 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import abc -import typing +from typing import Awaitable, Callable, Dict, Optional, Sequence, Union +import packaging.version import pkg_resources -from google import auth # type: ignore -from google.api_core import exceptions # type: ignore +import google.auth # type: ignore +import google.api_core # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.cloud.oslogin_v1 import common # type: ignore from google.cloud.oslogin_v1.types import oslogin -from google.protobuf import empty_pb2 as empty # type: ignore - +from google.protobuf import empty_pb2 # type: ignore try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( @@ -37,6 +36,17 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() +try: + # google.auth.__version__ was added in 1.26.0 + _GOOGLE_AUTH_VERSION = google.auth.__version__ +except AttributeError: + try: # try pkg_resources if it is available + _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version + except pkg_resources.DistributionNotFound: # pragma: NO COVER + _GOOGLE_AUTH_VERSION = None + +_API_CORE_VERSION = google.api_core.__version__ + class OsLoginServiceTransport(abc.ABC): """Abstract transport class for OsLoginService.""" @@ -46,21 +56,24 @@ class OsLoginServiceTransport(abc.ABC): "https://www.googleapis.com/auth/compute", ) + DEFAULT_HOST: str = "oslogin.googleapis.com" + def __init__( self, *, - host: str = "oslogin.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 @@ -69,7 +82,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): @@ -83,29 +96,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 = { @@ -116,7 +176,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=10.0, ), @@ -130,7 +191,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=10.0, ), @@ -144,7 +206,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=10.0, ), @@ -158,7 +221,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=10.0, ), @@ -172,7 +236,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=10.0, ), @@ -186,7 +251,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=10.0, ), @@ -198,47 +264,47 @@ def _prep_wrapped_messages(self, client_info): @property def delete_posix_account( self, - ) -> typing.Callable[ + ) -> Callable[ [oslogin.DeletePosixAccountRequest], - typing.Union[empty.Empty, typing.Awaitable[empty.Empty]], + Union[empty_pb2.Empty, Awaitable[empty_pb2.Empty]], ]: raise NotImplementedError() @property def delete_ssh_public_key( self, - ) -> typing.Callable[ + ) -> Callable[ [oslogin.DeleteSshPublicKeyRequest], - typing.Union[empty.Empty, typing.Awaitable[empty.Empty]], + Union[empty_pb2.Empty, Awaitable[empty_pb2.Empty]], ]: raise NotImplementedError() @property def get_login_profile( self, - ) -> typing.Callable[ + ) -> Callable[ [oslogin.GetLoginProfileRequest], - typing.Union[oslogin.LoginProfile, typing.Awaitable[oslogin.LoginProfile]], + Union[oslogin.LoginProfile, Awaitable[oslogin.LoginProfile]], ]: raise NotImplementedError() @property def get_ssh_public_key( self, - ) -> typing.Callable[ + ) -> Callable[ [oslogin.GetSshPublicKeyRequest], - typing.Union[common.SshPublicKey, typing.Awaitable[common.SshPublicKey]], + Union[common.SshPublicKey, Awaitable[common.SshPublicKey]], ]: raise NotImplementedError() @property def import_ssh_public_key( self, - ) -> typing.Callable[ + ) -> Callable[ [oslogin.ImportSshPublicKeyRequest], - typing.Union[ + Union[ oslogin.ImportSshPublicKeyResponse, - typing.Awaitable[oslogin.ImportSshPublicKeyResponse], + Awaitable[oslogin.ImportSshPublicKeyResponse], ], ]: raise NotImplementedError() @@ -246,9 +312,9 @@ def import_ssh_public_key( @property def update_ssh_public_key( self, - ) -> typing.Callable[ + ) -> Callable[ [oslogin.UpdateSshPublicKeyRequest], - typing.Union[common.SshPublicKey, typing.Awaitable[common.SshPublicKey]], + Union[common.SshPublicKey, Awaitable[common.SshPublicKey]], ]: raise NotImplementedError() diff --git a/google/cloud/oslogin_v1/services/os_login_service/transports/grpc.py b/google/cloud/oslogin_v1/services/os_login_service/transports/grpc.py index 097225d..a2993d8 100644 --- a/google/cloud/oslogin_v1/services/os_login_service/transports/grpc.py +++ b/google/cloud/oslogin_v1/services/os_login_service/transports/grpc.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,22 +13,20 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import warnings -from typing import Callable, Dict, Optional, Sequence, Tuple +from typing import Callable, Dict, Optional, Sequence, Tuple, Union from google.api_core import grpc_helpers # type: ignore from google.api_core import gapic_v1 # type: ignore -from google import auth # type: ignore -from google.auth import credentials # type: ignore +import google.auth # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore import grpc # type: ignore from google.cloud.oslogin_v1 import common # type: ignore from google.cloud.oslogin_v1.types import oslogin -from google.protobuf import empty_pb2 as empty # type: ignore - +from google.protobuf import empty_pb2 # type: ignore from .base import OsLoginServiceTransport, DEFAULT_CLIENT_INFO @@ -55,7 +52,7 @@ def __init__( self, *, host: str = "oslogin.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: str = None, scopes: Sequence[str] = None, channel: grpc.Channel = None, @@ -69,7 +66,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 = "oslogin.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, ) @@ -229,7 +229,7 @@ def grpc_channel(self) -> grpc.Channel: @property def delete_posix_account( self, - ) -> Callable[[oslogin.DeletePosixAccountRequest], empty.Empty]: + ) -> Callable[[oslogin.DeletePosixAccountRequest], empty_pb2.Empty]: r"""Return a callable for the delete posix account method over gRPC. Deletes a POSIX account. @@ -248,14 +248,14 @@ def delete_posix_account( self._stubs["delete_posix_account"] = self.grpc_channel.unary_unary( "/google.cloud.oslogin.v1.OsLoginService/DeletePosixAccount", request_serializer=oslogin.DeletePosixAccountRequest.serialize, - response_deserializer=empty.Empty.FromString, + response_deserializer=empty_pb2.Empty.FromString, ) return self._stubs["delete_posix_account"] @property def delete_ssh_public_key( self, - ) -> Callable[[oslogin.DeleteSshPublicKeyRequest], empty.Empty]: + ) -> Callable[[oslogin.DeleteSshPublicKeyRequest], empty_pb2.Empty]: r"""Return a callable for the delete ssh public key method over gRPC. Deletes an SSH public key. @@ -274,7 +274,7 @@ def delete_ssh_public_key( self._stubs["delete_ssh_public_key"] = self.grpc_channel.unary_unary( "/google.cloud.oslogin.v1.OsLoginService/DeleteSshPublicKey", request_serializer=oslogin.DeleteSshPublicKeyRequest.serialize, - response_deserializer=empty.Empty.FromString, + response_deserializer=empty_pb2.Empty.FromString, ) return self._stubs["delete_ssh_public_key"] diff --git a/google/cloud/oslogin_v1/services/os_login_service/transports/grpc_asyncio.py b/google/cloud/oslogin_v1/services/os_login_service/transports/grpc_asyncio.py index ce4b9a8..542f394 100644 --- a/google/cloud/oslogin_v1/services/os_login_service/transports/grpc_asyncio.py +++ b/google/cloud/oslogin_v1/services/os_login_service/transports/grpc_asyncio.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,23 +13,21 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import warnings -from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple +from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union from google.api_core import gapic_v1 # type: ignore from google.api_core import grpc_helpers_async # type: ignore -from google import auth # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore from google.cloud.oslogin_v1 import common # type: ignore from google.cloud.oslogin_v1.types import oslogin -from google.protobuf import empty_pb2 as empty # type: ignore - +from google.protobuf import empty_pb2 # type: ignore from .base import OsLoginServiceTransport, DEFAULT_CLIENT_INFO from .grpc import OsLoginServiceGrpcTransport @@ -58,7 +55,7 @@ class OsLoginServiceGrpcAsyncIOTransport(OsLoginServiceTransport): def create_channel( cls, host: str = "oslogin.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, @@ -85,13 +82,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, ) @@ -99,7 +98,7 @@ def __init__( self, *, host: str = "oslogin.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, @@ -113,7 +112,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 @@ -233,7 +232,7 @@ def grpc_channel(self) -> aio.Channel: @property def delete_posix_account( self, - ) -> Callable[[oslogin.DeletePosixAccountRequest], Awaitable[empty.Empty]]: + ) -> Callable[[oslogin.DeletePosixAccountRequest], Awaitable[empty_pb2.Empty]]: r"""Return a callable for the delete posix account method over gRPC. Deletes a POSIX account. @@ -252,14 +251,14 @@ def delete_posix_account( self._stubs["delete_posix_account"] = self.grpc_channel.unary_unary( "/google.cloud.oslogin.v1.OsLoginService/DeletePosixAccount", request_serializer=oslogin.DeletePosixAccountRequest.serialize, - response_deserializer=empty.Empty.FromString, + response_deserializer=empty_pb2.Empty.FromString, ) return self._stubs["delete_posix_account"] @property def delete_ssh_public_key( self, - ) -> Callable[[oslogin.DeleteSshPublicKeyRequest], Awaitable[empty.Empty]]: + ) -> Callable[[oslogin.DeleteSshPublicKeyRequest], Awaitable[empty_pb2.Empty]]: r"""Return a callable for the delete ssh public key method over gRPC. Deletes an SSH public key. @@ -278,7 +277,7 @@ def delete_ssh_public_key( self._stubs["delete_ssh_public_key"] = self.grpc_channel.unary_unary( "/google.cloud.oslogin.v1.OsLoginService/DeleteSshPublicKey", request_serializer=oslogin.DeleteSshPublicKeyRequest.serialize, - response_deserializer=empty.Empty.FromString, + response_deserializer=empty_pb2.Empty.FromString, ) return self._stubs["delete_ssh_public_key"] diff --git a/google/cloud/oslogin_v1/types/__init__.py b/google/cloud/oslogin_v1/types/__init__.py index fb023fe..262ab25 100644 --- a/google/cloud/oslogin_v1/types/__init__.py +++ b/google/cloud/oslogin_v1/types/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from .oslogin import ( DeletePosixAccountRequest, DeleteSshPublicKeyRequest, diff --git a/google/cloud/oslogin_v1/types/oslogin.py b/google/cloud/oslogin_v1/types/oslogin.py index 03ad5f8..afb873a 100644 --- a/google/cloud/oslogin_v1/types/oslogin.py +++ b/google/cloud/oslogin_v1/types/oslogin.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,12 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.oslogin_v1 import common # type: ignore -from google.protobuf import field_mask_pb2 as field_mask # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore __protobuf__ = proto.module( @@ -44,7 +41,7 @@ class LoginProfile(proto.Message): Attributes: name (str): Required. A unique user ID. - posix_accounts (Sequence[google.cloud.oslogin.v1.common_pb2.PosixAccount]): + posix_accounts (Sequence[google.cloud.oslogin.v1.common.PosixAccount]): The list of POSIX accounts associated with the user. ssh_public_keys (Sequence[google.cloud.oslogin_v1.types.LoginProfile.SshPublicKeysEntry]): @@ -52,12 +49,10 @@ class LoginProfile(proto.Message): associated key object. """ - name = proto.Field(proto.STRING, number=1) - + name = proto.Field(proto.STRING, number=1,) posix_accounts = proto.RepeatedField( proto.MESSAGE, number=2, message=common.PosixAccount, ) - ssh_public_keys = proto.MapField( proto.STRING, proto.MESSAGE, number=3, message=common.SshPublicKey, ) @@ -65,7 +60,6 @@ class LoginProfile(proto.Message): class DeletePosixAccountRequest(proto.Message): r"""A request message for deleting a POSIX account entry. - Attributes: name (str): Required. A reference to the POSIX account to update. POSIX @@ -74,12 +68,11 @@ class DeletePosixAccountRequest(proto.Message): format ``users/{user}/projects/{project}``. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class DeleteSshPublicKeyRequest(proto.Message): r"""A request message for deleting an SSH public key. - Attributes: name (str): Required. The fingerprint of the public key to update. @@ -88,7 +81,7 @@ class DeleteSshPublicKeyRequest(proto.Message): ``users/{user}/sshPublicKeys/{fingerprint}``. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class GetLoginProfileRequest(proto.Message): @@ -107,16 +100,13 @@ class GetLoginProfileRequest(proto.Message): request. """ - name = proto.Field(proto.STRING, number=1) - - project_id = proto.Field(proto.STRING, number=2) - - system_id = proto.Field(proto.STRING, number=3) + name = proto.Field(proto.STRING, number=1,) + project_id = proto.Field(proto.STRING, number=2,) + system_id = proto.Field(proto.STRING, number=3,) class GetSshPublicKeyRequest(proto.Message): r"""A request message for retrieving an SSH public key. - Attributes: name (str): Required. The fingerprint of the public key to retrieve. @@ -125,17 +115,16 @@ class GetSshPublicKeyRequest(proto.Message): ``users/{user}/sshPublicKeys/{fingerprint}``. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class ImportSshPublicKeyRequest(proto.Message): r"""A request message for importing an SSH public key. - Attributes: parent (str): Required. The unique ID for the user in format ``users/{user}``. - ssh_public_key (google.cloud.oslogin.v1.common_pb2.SshPublicKey): + ssh_public_key (google.cloud.oslogin.v1.common.SshPublicKey): Optional. The SSH public key and expiration time. project_id (str): @@ -143,16 +132,13 @@ class ImportSshPublicKeyRequest(proto.Message): project. """ - parent = proto.Field(proto.STRING, number=1) - + parent = proto.Field(proto.STRING, number=1,) ssh_public_key = proto.Field(proto.MESSAGE, number=2, message=common.SshPublicKey,) - - project_id = proto.Field(proto.STRING, number=3) + project_id = proto.Field(proto.STRING, number=3,) class ImportSshPublicKeyResponse(proto.Message): r"""A response message for importing an SSH public key. - Attributes: login_profile (google.cloud.oslogin_v1.types.LoginProfile): The login profile information for the user. @@ -163,14 +149,13 @@ class ImportSshPublicKeyResponse(proto.Message): class UpdateSshPublicKeyRequest(proto.Message): r"""A request message for updating an SSH public key. - Attributes: name (str): Required. The fingerprint of the public key to update. Public keys are identified by their SHA-256 fingerprint. The fingerprint of the public key is in format ``users/{user}/sshPublicKeys/{fingerprint}``. - ssh_public_key (google.cloud.oslogin.v1.common_pb2.SshPublicKey): + ssh_public_key (google.cloud.oslogin.v1.common.SshPublicKey): Required. The SSH public key and expiration time. update_mask (google.protobuf.field_mask_pb2.FieldMask): @@ -178,11 +163,11 @@ class UpdateSshPublicKeyRequest(proto.Message): Updates all if not present. """ - name = proto.Field(proto.STRING, number=1) - + name = proto.Field(proto.STRING, number=1,) ssh_public_key = proto.Field(proto.MESSAGE, number=2, message=common.SshPublicKey,) - - update_mask = proto.Field(proto.MESSAGE, number=3, message=field_mask.FieldMask,) + update_mask = proto.Field( + proto.MESSAGE, number=3, message=field_mask_pb2.FieldMask, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owlbot.py b/owlbot.py index 5b442b5..4203446 100644 --- a/owlbot.py +++ b/owlbot.py @@ -43,12 +43,17 @@ "google-cloud-os-login", ) -for file in ["google/cloud/**/*.py", "tests/**/*.py"]: - s.replace( - file, - "from google.cloud.oslogin.common import common_pb2 as common", - "from google.cloud.oslogin_v1 import common" - ) +s.replace( + ["google/cloud/**/*.py", "tests/**/*.py"], + "from google.cloud.oslogin.common import common_pb2", + "from google.cloud.oslogin_v1 import common" +) +s.replace( + ["google/cloud/**/*.py", "tests/**/*.py"], + "common_pb2\.", + "common." +) + s.replace( "google/cloud/oslogin_v1/**/*.py", "google.cloud.oslogin.common", diff --git a/scripts/fixup_oslogin_v1_keywords.py b/scripts/fixup_oslogin_v1_keywords.py index be08c0e..ac09072 100644 --- a/scripts/fixup_oslogin_v1_keywords.py +++ b/scripts/fixup_oslogin_v1_keywords.py @@ -1,6 +1,5 @@ #! /usr/bin/env python3 # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,7 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import argparse import os import libcst as cst @@ -41,13 +39,12 @@ def partition( class osloginCallTransformer(cst.CSTTransformer): CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { - 'delete_posix_account': ('name', ), - 'delete_ssh_public_key': ('name', ), - 'get_login_profile': ('name', 'project_id', 'system_id', ), - 'get_ssh_public_key': ('name', ), - 'import_ssh_public_key': ('parent', 'ssh_public_key', 'project_id', ), - 'update_ssh_public_key': ('name', 'ssh_public_key', 'update_mask', ), - + 'delete_posix_account': ('name', ), + 'delete_ssh_public_key': ('name', ), + 'get_login_profile': ('name', 'project_id', 'system_id', ), + 'get_ssh_public_key': ('name', ), + 'import_ssh_public_key': ('parent', 'ssh_public_key', 'project_id', ), + 'update_ssh_public_key': ('name', 'ssh_public_key', 'update_mask', ), } def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: @@ -78,7 +75,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/setup.py b/setup.py index ad91f72..47b33ea 100644 --- a/setup.py +++ b/setup.py @@ -32,6 +32,7 @@ "google-api-core[grpc] >= 1.22.2, < 2.0.0dev", "proto-plus >= 1.4.0", "libcst >= 0.2.5", + "packaging >= 14.3", ] extras = {} diff --git a/testing/constraints-3.6.txt b/testing/constraints-3.6.txt index d071c72..85cd442 100644 --- a/testing/constraints-3.6.txt +++ b/testing/constraints-3.6.txt @@ -7,4 +7,6 @@ # Then this file should have foo==1.14.0 google-api-core==1.22.2 proto-plus==1.4.0 -libcst==0.2.5 \ No newline at end of file +libcst==0.2.5 +packaging==14.3 +google-auth==1.24.0 # TODO: remove when google-auth>=1.25.0 is transitively required through google-api-core diff --git a/tests/unit/gapic/oslogin_v1/__init__.py b/tests/unit/gapic/oslogin_v1/__init__.py index 42ffdf2..4de6597 100644 --- a/tests/unit/gapic/oslogin_v1/__init__.py +++ b/tests/unit/gapic/oslogin_v1/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/unit/gapic/oslogin_v1/test_os_login_service.py b/tests/unit/gapic/oslogin_v1/test_os_login_service.py index bc7002e..5f70482 100644 --- a/tests/unit/gapic/oslogin_v1/test_os_login_service.py +++ b/tests/unit/gapic/oslogin_v1/test_os_login_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,21 +23,51 @@ import pytest from proto.marshal.rules.dates import DurationRule, TimestampRule -from google import auth + from google.api_core import client_options -from google.api_core import exceptions +from google.api_core import exceptions as core_exceptions from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async -from google.auth import credentials +from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.oslogin_v1 import common # type: ignore from google.cloud.oslogin_v1.services.os_login_service import OsLoginServiceAsyncClient from google.cloud.oslogin_v1.services.os_login_service import OsLoginServiceClient from google.cloud.oslogin_v1.services.os_login_service import transports +from google.cloud.oslogin_v1.services.os_login_service.transports.base import ( + _API_CORE_VERSION, +) +from google.cloud.oslogin_v1.services.os_login_service.transports.base import ( + _GOOGLE_AUTH_VERSION, +) from google.cloud.oslogin_v1.types import oslogin from google.oauth2 import service_account -from google.protobuf import field_mask_pb2 as field_mask # type: ignore +from google.protobuf import field_mask_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(): @@ -89,7 +118,7 @@ def test__get_default_mtls_endpoint(): "client_class", [OsLoginServiceClient, OsLoginServiceAsyncClient,] ) def test_os_login_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: @@ -106,7 +135,7 @@ def test_os_login_service_client_from_service_account_info(client_class): "client_class", [OsLoginServiceClient, OsLoginServiceAsyncClient,] ) def test_os_login_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: @@ -159,7 +188,7 @@ def test_os_login_service_client_client_options( ): # Check that if channel is provided we won't create a new one. with mock.patch.object(OsLoginServiceClient, "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() @@ -447,7 +476,7 @@ def test_delete_posix_account( transport: str = "grpc", request_type=oslogin.DeletePosixAccountRequest ): client = OsLoginServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -460,13 +489,11 @@ def test_delete_posix_account( ) as call: # Designate an appropriate return value for the call. call.return_value = None - response = client.delete_posix_account(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == oslogin.DeletePosixAccountRequest() # Establish that the response is the type that we expect. @@ -481,7 +508,7 @@ def test_delete_posix_account_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 = OsLoginServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -491,7 +518,6 @@ def test_delete_posix_account_empty_call(): client.delete_posix_account() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == oslogin.DeletePosixAccountRequest() @@ -500,7 +526,7 @@ async def test_delete_posix_account_async( transport: str = "grpc_asyncio", request_type=oslogin.DeletePosixAccountRequest ): client = OsLoginServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -513,13 +539,11 @@ async def test_delete_posix_account_async( ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - response = await client.delete_posix_account(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == oslogin.DeletePosixAccountRequest() # Establish that the response is the type that we expect. @@ -532,11 +556,12 @@ async def test_delete_posix_account_async_from_dict(): def test_delete_posix_account_field_headers(): - client = OsLoginServiceClient(credentials=credentials.AnonymousCredentials(),) + client = OsLoginServiceClient(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 = oslogin.DeletePosixAccountRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -544,7 +569,6 @@ def test_delete_posix_account_field_headers(): type(client.transport.delete_posix_account), "__call__" ) as call: call.return_value = None - client.delete_posix_account(request) # Establish that the underlying gRPC stub method was called. @@ -559,11 +583,14 @@ def test_delete_posix_account_field_headers(): @pytest.mark.asyncio async def test_delete_posix_account_field_headers_async(): - client = OsLoginServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = OsLoginServiceAsyncClient( + 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 = oslogin.DeletePosixAccountRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -571,7 +598,6 @@ async def test_delete_posix_account_field_headers_async(): type(client.transport.delete_posix_account), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - await client.delete_posix_account(request) # Establish that the underlying gRPC stub method was called. @@ -585,7 +611,7 @@ async def test_delete_posix_account_field_headers_async(): def test_delete_posix_account_flattened(): - client = OsLoginServiceClient(credentials=credentials.AnonymousCredentials(),) + client = OsLoginServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -593,7 +619,6 @@ def test_delete_posix_account_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = None - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.delete_posix_account(name="name_value",) @@ -602,12 +627,11 @@ def test_delete_posix_account_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_delete_posix_account_flattened_error(): - client = OsLoginServiceClient(credentials=credentials.AnonymousCredentials(),) + client = OsLoginServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -619,7 +643,9 @@ def test_delete_posix_account_flattened_error(): @pytest.mark.asyncio async def test_delete_posix_account_flattened_async(): - client = OsLoginServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = OsLoginServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -637,13 +663,14 @@ async def test_delete_posix_account_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_posix_account_flattened_error_async(): - client = OsLoginServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = OsLoginServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -657,7 +684,7 @@ def test_delete_ssh_public_key( transport: str = "grpc", request_type=oslogin.DeleteSshPublicKeyRequest ): client = OsLoginServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -670,13 +697,11 @@ def test_delete_ssh_public_key( ) as call: # Designate an appropriate return value for the call. call.return_value = None - response = client.delete_ssh_public_key(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == oslogin.DeleteSshPublicKeyRequest() # Establish that the response is the type that we expect. @@ -691,7 +716,7 @@ def test_delete_ssh_public_key_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 = OsLoginServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -701,7 +726,6 @@ def test_delete_ssh_public_key_empty_call(): client.delete_ssh_public_key() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == oslogin.DeleteSshPublicKeyRequest() @@ -710,7 +734,7 @@ async def test_delete_ssh_public_key_async( transport: str = "grpc_asyncio", request_type=oslogin.DeleteSshPublicKeyRequest ): client = OsLoginServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -723,13 +747,11 @@ async def test_delete_ssh_public_key_async( ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - response = await client.delete_ssh_public_key(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == oslogin.DeleteSshPublicKeyRequest() # Establish that the response is the type that we expect. @@ -742,11 +764,12 @@ async def test_delete_ssh_public_key_async_from_dict(): def test_delete_ssh_public_key_field_headers(): - client = OsLoginServiceClient(credentials=credentials.AnonymousCredentials(),) + client = OsLoginServiceClient(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 = oslogin.DeleteSshPublicKeyRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -754,7 +777,6 @@ def test_delete_ssh_public_key_field_headers(): type(client.transport.delete_ssh_public_key), "__call__" ) as call: call.return_value = None - client.delete_ssh_public_key(request) # Establish that the underlying gRPC stub method was called. @@ -769,11 +791,14 @@ def test_delete_ssh_public_key_field_headers(): @pytest.mark.asyncio async def test_delete_ssh_public_key_field_headers_async(): - client = OsLoginServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = OsLoginServiceAsyncClient( + 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 = oslogin.DeleteSshPublicKeyRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -781,7 +806,6 @@ async def test_delete_ssh_public_key_field_headers_async(): type(client.transport.delete_ssh_public_key), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - await client.delete_ssh_public_key(request) # Establish that the underlying gRPC stub method was called. @@ -795,7 +819,7 @@ async def test_delete_ssh_public_key_field_headers_async(): def test_delete_ssh_public_key_flattened(): - client = OsLoginServiceClient(credentials=credentials.AnonymousCredentials(),) + client = OsLoginServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -803,7 +827,6 @@ def test_delete_ssh_public_key_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = None - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.delete_ssh_public_key(name="name_value",) @@ -812,12 +835,11 @@ def test_delete_ssh_public_key_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_delete_ssh_public_key_flattened_error(): - client = OsLoginServiceClient(credentials=credentials.AnonymousCredentials(),) + client = OsLoginServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -829,7 +851,9 @@ def test_delete_ssh_public_key_flattened_error(): @pytest.mark.asyncio async def test_delete_ssh_public_key_flattened_async(): - client = OsLoginServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = OsLoginServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -847,13 +871,14 @@ async def test_delete_ssh_public_key_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_ssh_public_key_flattened_error_async(): - client = OsLoginServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = OsLoginServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -867,7 +892,7 @@ def test_get_login_profile( transport: str = "grpc", request_type=oslogin.GetLoginProfileRequest ): client = OsLoginServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -880,19 +905,15 @@ def test_get_login_profile( ) as call: # Designate an appropriate return value for the call. call.return_value = oslogin.LoginProfile(name="name_value",) - response = client.get_login_profile(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == oslogin.GetLoginProfileRequest() # Establish that the response is the type that we expect. - assert isinstance(response, oslogin.LoginProfile) - assert response.name == "name_value" @@ -904,7 +925,7 @@ def test_get_login_profile_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 = OsLoginServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -914,7 +935,6 @@ def test_get_login_profile_empty_call(): client.get_login_profile() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == oslogin.GetLoginProfileRequest() @@ -923,7 +943,7 @@ async def test_get_login_profile_async( transport: str = "grpc_asyncio", request_type=oslogin.GetLoginProfileRequest ): client = OsLoginServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -938,18 +958,15 @@ async def test_get_login_profile_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( oslogin.LoginProfile(name="name_value",) ) - response = await client.get_login_profile(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == oslogin.GetLoginProfileRequest() # Establish that the response is the type that we expect. assert isinstance(response, oslogin.LoginProfile) - assert response.name == "name_value" @@ -959,11 +976,12 @@ async def test_get_login_profile_async_from_dict(): def test_get_login_profile_field_headers(): - client = OsLoginServiceClient(credentials=credentials.AnonymousCredentials(),) + client = OsLoginServiceClient(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 = oslogin.GetLoginProfileRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -971,7 +989,6 @@ def test_get_login_profile_field_headers(): type(client.transport.get_login_profile), "__call__" ) as call: call.return_value = oslogin.LoginProfile() - client.get_login_profile(request) # Establish that the underlying gRPC stub method was called. @@ -986,11 +1003,14 @@ def test_get_login_profile_field_headers(): @pytest.mark.asyncio async def test_get_login_profile_field_headers_async(): - client = OsLoginServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = OsLoginServiceAsyncClient( + 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 = oslogin.GetLoginProfileRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1000,7 +1020,6 @@ async def test_get_login_profile_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( oslogin.LoginProfile() ) - await client.get_login_profile(request) # Establish that the underlying gRPC stub method was called. @@ -1014,7 +1033,7 @@ async def test_get_login_profile_field_headers_async(): def test_get_login_profile_flattened(): - client = OsLoginServiceClient(credentials=credentials.AnonymousCredentials(),) + client = OsLoginServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1022,7 +1041,6 @@ def test_get_login_profile_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = oslogin.LoginProfile() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.get_login_profile(name="name_value",) @@ -1031,12 +1049,11 @@ def test_get_login_profile_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_get_login_profile_flattened_error(): - client = OsLoginServiceClient(credentials=credentials.AnonymousCredentials(),) + client = OsLoginServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1048,7 +1065,9 @@ def test_get_login_profile_flattened_error(): @pytest.mark.asyncio async def test_get_login_profile_flattened_async(): - client = OsLoginServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = OsLoginServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1068,13 +1087,14 @@ async def test_get_login_profile_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_login_profile_flattened_error_async(): - client = OsLoginServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = OsLoginServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1088,7 +1108,7 @@ def test_get_ssh_public_key( transport: str = "grpc", request_type=oslogin.GetSshPublicKeyRequest ): client = OsLoginServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1106,25 +1126,18 @@ def test_get_ssh_public_key( fingerprint="fingerprint_value", name="name_value", ) - response = client.get_ssh_public_key(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == oslogin.GetSshPublicKeyRequest() # Establish that the response is the type that we expect. - assert isinstance(response, common.SshPublicKey) - assert response.key == "key_value" - assert response.expiration_time_usec == 2144 - assert response.fingerprint == "fingerprint_value" - assert response.name == "name_value" @@ -1136,7 +1149,7 @@ def test_get_ssh_public_key_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 = OsLoginServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1146,7 +1159,6 @@ def test_get_ssh_public_key_empty_call(): client.get_ssh_public_key() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == oslogin.GetSshPublicKeyRequest() @@ -1155,7 +1167,7 @@ async def test_get_ssh_public_key_async( transport: str = "grpc_asyncio", request_type=oslogin.GetSshPublicKeyRequest ): client = OsLoginServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1175,24 +1187,18 @@ async def test_get_ssh_public_key_async( name="name_value", ) ) - response = await client.get_ssh_public_key(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == oslogin.GetSshPublicKeyRequest() # Establish that the response is the type that we expect. assert isinstance(response, common.SshPublicKey) - assert response.key == "key_value" - assert response.expiration_time_usec == 2144 - assert response.fingerprint == "fingerprint_value" - assert response.name == "name_value" @@ -1202,11 +1208,12 @@ async def test_get_ssh_public_key_async_from_dict(): def test_get_ssh_public_key_field_headers(): - client = OsLoginServiceClient(credentials=credentials.AnonymousCredentials(),) + client = OsLoginServiceClient(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 = oslogin.GetSshPublicKeyRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1214,7 +1221,6 @@ def test_get_ssh_public_key_field_headers(): type(client.transport.get_ssh_public_key), "__call__" ) as call: call.return_value = common.SshPublicKey() - client.get_ssh_public_key(request) # Establish that the underlying gRPC stub method was called. @@ -1229,11 +1235,14 @@ def test_get_ssh_public_key_field_headers(): @pytest.mark.asyncio async def test_get_ssh_public_key_field_headers_async(): - client = OsLoginServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = OsLoginServiceAsyncClient( + 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 = oslogin.GetSshPublicKeyRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1241,7 +1250,6 @@ async def test_get_ssh_public_key_field_headers_async(): type(client.transport.get_ssh_public_key), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(common.SshPublicKey()) - await client.get_ssh_public_key(request) # Establish that the underlying gRPC stub method was called. @@ -1255,7 +1263,7 @@ async def test_get_ssh_public_key_field_headers_async(): def test_get_ssh_public_key_flattened(): - client = OsLoginServiceClient(credentials=credentials.AnonymousCredentials(),) + client = OsLoginServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1263,7 +1271,6 @@ def test_get_ssh_public_key_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = common.SshPublicKey() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.get_ssh_public_key(name="name_value",) @@ -1272,12 +1279,11 @@ def test_get_ssh_public_key_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_get_ssh_public_key_flattened_error(): - client = OsLoginServiceClient(credentials=credentials.AnonymousCredentials(),) + client = OsLoginServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1289,7 +1295,9 @@ def test_get_ssh_public_key_flattened_error(): @pytest.mark.asyncio async def test_get_ssh_public_key_flattened_async(): - client = OsLoginServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = OsLoginServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1307,13 +1315,14 @@ async def test_get_ssh_public_key_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_ssh_public_key_flattened_error_async(): - client = OsLoginServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = OsLoginServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1327,7 +1336,7 @@ def test_import_ssh_public_key( transport: str = "grpc", request_type=oslogin.ImportSshPublicKeyRequest ): client = OsLoginServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1340,17 +1349,14 @@ def test_import_ssh_public_key( ) as call: # Designate an appropriate return value for the call. call.return_value = oslogin.ImportSshPublicKeyResponse() - response = client.import_ssh_public_key(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == oslogin.ImportSshPublicKeyRequest() # Establish that the response is the type that we expect. - assert isinstance(response, oslogin.ImportSshPublicKeyResponse) @@ -1362,7 +1368,7 @@ def test_import_ssh_public_key_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 = OsLoginServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1372,7 +1378,6 @@ def test_import_ssh_public_key_empty_call(): client.import_ssh_public_key() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == oslogin.ImportSshPublicKeyRequest() @@ -1381,7 +1386,7 @@ async def test_import_ssh_public_key_async( transport: str = "grpc_asyncio", request_type=oslogin.ImportSshPublicKeyRequest ): client = OsLoginServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1396,13 +1401,11 @@ async def test_import_ssh_public_key_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( oslogin.ImportSshPublicKeyResponse() ) - response = await client.import_ssh_public_key(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == oslogin.ImportSshPublicKeyRequest() # Establish that the response is the type that we expect. @@ -1415,11 +1418,12 @@ async def test_import_ssh_public_key_async_from_dict(): def test_import_ssh_public_key_field_headers(): - client = OsLoginServiceClient(credentials=credentials.AnonymousCredentials(),) + client = OsLoginServiceClient(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 = oslogin.ImportSshPublicKeyRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1427,7 +1431,6 @@ def test_import_ssh_public_key_field_headers(): type(client.transport.import_ssh_public_key), "__call__" ) as call: call.return_value = oslogin.ImportSshPublicKeyResponse() - client.import_ssh_public_key(request) # Establish that the underlying gRPC stub method was called. @@ -1442,11 +1445,14 @@ def test_import_ssh_public_key_field_headers(): @pytest.mark.asyncio async def test_import_ssh_public_key_field_headers_async(): - client = OsLoginServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = OsLoginServiceAsyncClient( + 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 = oslogin.ImportSshPublicKeyRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1456,7 +1462,6 @@ async def test_import_ssh_public_key_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( oslogin.ImportSshPublicKeyResponse() ) - await client.import_ssh_public_key(request) # Establish that the underlying gRPC stub method was called. @@ -1470,7 +1475,7 @@ async def test_import_ssh_public_key_field_headers_async(): def test_import_ssh_public_key_flattened(): - client = OsLoginServiceClient(credentials=credentials.AnonymousCredentials(),) + client = OsLoginServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1478,7 +1483,6 @@ def test_import_ssh_public_key_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = oslogin.ImportSshPublicKeyResponse() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.import_ssh_public_key( @@ -1491,16 +1495,13 @@ def test_import_ssh_public_key_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].ssh_public_key == common.SshPublicKey(key="key_value") - assert args[0].project_id == "project_id_value" def test_import_ssh_public_key_flattened_error(): - client = OsLoginServiceClient(credentials=credentials.AnonymousCredentials(),) + client = OsLoginServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1515,7 +1516,9 @@ def test_import_ssh_public_key_flattened_error(): @pytest.mark.asyncio async def test_import_ssh_public_key_flattened_async(): - client = OsLoginServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = OsLoginServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1539,17 +1542,16 @@ async def test_import_ssh_public_key_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].ssh_public_key == common.SshPublicKey(key="key_value") - assert args[0].project_id == "project_id_value" @pytest.mark.asyncio async def test_import_ssh_public_key_flattened_error_async(): - client = OsLoginServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = OsLoginServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1566,7 +1568,7 @@ def test_update_ssh_public_key( transport: str = "grpc", request_type=oslogin.UpdateSshPublicKeyRequest ): client = OsLoginServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1584,25 +1586,18 @@ def test_update_ssh_public_key( fingerprint="fingerprint_value", name="name_value", ) - response = client.update_ssh_public_key(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == oslogin.UpdateSshPublicKeyRequest() # Establish that the response is the type that we expect. - assert isinstance(response, common.SshPublicKey) - assert response.key == "key_value" - assert response.expiration_time_usec == 2144 - assert response.fingerprint == "fingerprint_value" - assert response.name == "name_value" @@ -1614,7 +1609,7 @@ def test_update_ssh_public_key_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 = OsLoginServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1624,7 +1619,6 @@ def test_update_ssh_public_key_empty_call(): client.update_ssh_public_key() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == oslogin.UpdateSshPublicKeyRequest() @@ -1633,7 +1627,7 @@ async def test_update_ssh_public_key_async( transport: str = "grpc_asyncio", request_type=oslogin.UpdateSshPublicKeyRequest ): client = OsLoginServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1653,24 +1647,18 @@ async def test_update_ssh_public_key_async( name="name_value", ) ) - response = await client.update_ssh_public_key(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == oslogin.UpdateSshPublicKeyRequest() # Establish that the response is the type that we expect. assert isinstance(response, common.SshPublicKey) - assert response.key == "key_value" - assert response.expiration_time_usec == 2144 - assert response.fingerprint == "fingerprint_value" - assert response.name == "name_value" @@ -1680,11 +1668,12 @@ async def test_update_ssh_public_key_async_from_dict(): def test_update_ssh_public_key_field_headers(): - client = OsLoginServiceClient(credentials=credentials.AnonymousCredentials(),) + client = OsLoginServiceClient(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 = oslogin.UpdateSshPublicKeyRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1692,7 +1681,6 @@ def test_update_ssh_public_key_field_headers(): type(client.transport.update_ssh_public_key), "__call__" ) as call: call.return_value = common.SshPublicKey() - client.update_ssh_public_key(request) # Establish that the underlying gRPC stub method was called. @@ -1707,11 +1695,14 @@ def test_update_ssh_public_key_field_headers(): @pytest.mark.asyncio async def test_update_ssh_public_key_field_headers_async(): - client = OsLoginServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = OsLoginServiceAsyncClient( + 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 = oslogin.UpdateSshPublicKeyRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1719,7 +1710,6 @@ async def test_update_ssh_public_key_field_headers_async(): type(client.transport.update_ssh_public_key), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(common.SshPublicKey()) - await client.update_ssh_public_key(request) # Establish that the underlying gRPC stub method was called. @@ -1733,7 +1723,7 @@ async def test_update_ssh_public_key_field_headers_async(): def test_update_ssh_public_key_flattened(): - client = OsLoginServiceClient(credentials=credentials.AnonymousCredentials(),) + client = OsLoginServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1741,29 +1731,25 @@ def test_update_ssh_public_key_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = common.SshPublicKey() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.update_ssh_public_key( name="name_value", ssh_public_key=common.SshPublicKey(key="key_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].ssh_public_key == common.SshPublicKey(key="key_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_ssh_public_key_flattened_error(): - client = OsLoginServiceClient(credentials=credentials.AnonymousCredentials(),) + client = OsLoginServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1772,13 +1758,15 @@ def test_update_ssh_public_key_flattened_error(): oslogin.UpdateSshPublicKeyRequest(), name="name_value", ssh_public_key=common.SshPublicKey(key="key_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_ssh_public_key_flattened_async(): - client = OsLoginServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = OsLoginServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1793,24 +1781,23 @@ async def test_update_ssh_public_key_flattened_async(): response = await client.update_ssh_public_key( name="name_value", ssh_public_key=common.SshPublicKey(key="key_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].ssh_public_key == common.SshPublicKey(key="key_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_ssh_public_key_flattened_error_async(): - client = OsLoginServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = OsLoginServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1819,23 +1806,23 @@ async def test_update_ssh_public_key_flattened_error_async(): oslogin.UpdateSshPublicKeyRequest(), name="name_value", ssh_public_key=common.SshPublicKey(key="key_value"), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.OsLoginServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = OsLoginServiceClient( - 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.OsLoginServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = OsLoginServiceClient( @@ -1845,7 +1832,7 @@ def test_credentials_transport_error(): # It is an error to provide scopes and a transport instance. transport = transports.OsLoginServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = OsLoginServiceClient( @@ -1856,7 +1843,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.OsLoginServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) client = OsLoginServiceClient(transport=transport) assert client.transport is transport @@ -1865,13 +1852,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.OsLoginServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel transport = transports.OsLoginServiceGrpcAsyncIOTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel @@ -1886,23 +1873,23 @@ def test_transport_get_channel(): ) def test_transport_adc(transport_class): # Test default credentials are used if not provided. - with mock.patch.object(auth, "default") as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport_class() adc.assert_called_once() def test_transport_grpc_default(): # A client should use the gRPC transport by default. - client = OsLoginServiceClient(credentials=credentials.AnonymousCredentials(),) + client = OsLoginServiceClient(credentials=ga_credentials.AnonymousCredentials(),) assert isinstance(client.transport, transports.OsLoginServiceGrpcTransport,) def test_os_login_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.OsLoginServiceTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), credentials_file="credentials.json", ) @@ -1914,7 +1901,7 @@ def test_os_login_service_base_transport(): ) as Transport: Transport.return_value = None transport = transports.OsLoginServiceTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Every method on the transport should just blindly @@ -1932,15 +1919,40 @@ def test_os_login_service_base_transport(): getattr(transport, method)(request=object()) +@requires_google_auth_gte_1_25_0 def test_os_login_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.oslogin_v1.services.os_login_service.transports.OsLoginServiceTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.OsLoginServiceTransport( + credentials_file="credentials.json", quota_project_id="octopus", + ) + load_creds.assert_called_once_with( + "credentials.json", + scopes=None, + default_scopes=( + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/compute", + ), + quota_project_id="octopus", + ) + + +@requires_google_auth_lt_1_25_0 +def test_os_login_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.oslogin_v1.services.os_login_service.transports.OsLoginServiceTransport._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.OsLoginServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", ) @@ -1956,19 +1968,36 @@ def test_os_login_service_base_transport_with_credentials_file(): def test_os_login_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.oslogin_v1.services.os_login_service.transports.OsLoginServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (credentials.AnonymousCredentials(), None) + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.OsLoginServiceTransport() adc.assert_called_once() +@requires_google_auth_gte_1_25_0 def test_os_login_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) + OsLoginServiceClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=( + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/compute", + ), + quota_project_id=None, + ) + + +@requires_google_auth_lt_1_25_0 +def test_os_login_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) OsLoginServiceClient() adc.assert_called_once_with( scopes=( @@ -1979,14 +2008,44 @@ def test_os_login_service_auth_adc(): ) -def test_os_login_service_transport_auth_adc(): +@pytest.mark.parametrize( + "transport_class", + [ + transports.OsLoginServiceGrpcTransport, + transports.OsLoginServiceGrpcAsyncIOTransport, + ], +) +@requires_google_auth_gte_1_25_0 +def test_os_login_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.OsLoginServiceGrpcTransport( - host="squid.clam.whelk", quota_project_id="octopus" + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + adc.assert_called_once_with( + scopes=["1", "2"], + default_scopes=( + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/compute", + ), + quota_project_id="octopus", ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.OsLoginServiceGrpcTransport, + transports.OsLoginServiceGrpcAsyncIOTransport, + ], +) +@requires_google_auth_lt_1_25_0 +def test_os_login_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", @@ -1996,6 +2055,121 @@ def test_os_login_service_transport_auth_adc(): ) +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.OsLoginServiceGrpcTransport, grpc_helpers), + (transports.OsLoginServiceGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_gte_1_26_0 +def test_os_login_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( + "oslogin.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=( + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/compute", + ), + scopes=["1", "2"], + default_host="oslogin.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.OsLoginServiceGrpcTransport, grpc_helpers), + (transports.OsLoginServiceGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_os_login_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( + "oslogin.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + scopes=( + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/compute", + ), + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.OsLoginServiceGrpcTransport, grpc_helpers), + (transports.OsLoginServiceGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_os_login_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( + "oslogin.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", [ @@ -2004,7 +2178,7 @@ def test_os_login_service_transport_auth_adc(): ], ) def test_os_login_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: @@ -2046,7 +2220,7 @@ def test_os_login_service_grpc_transport_client_cert_source_for_mtls(transport_c def test_os_login_service_host_no_port(): client = OsLoginServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="oslogin.googleapis.com" ), @@ -2056,7 +2230,7 @@ def test_os_login_service_host_no_port(): def test_os_login_service_host_with_port(): client = OsLoginServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="oslogin.googleapis.com:8000" ), @@ -2112,9 +2286,9 @@ def test_os_login_service_transport_channel_mtls_with_client_cert_source( mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = credentials.AnonymousCredentials() + cred = ga_credentials.AnonymousCredentials() with pytest.warns(DeprecationWarning): - with mock.patch.object(auth, "default") as adc: + with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) transport = transport_class( host="squid.clam.whelk", @@ -2197,7 +2371,6 @@ def test_os_login_service_transport_channel_mtls_with_adc(transport_class): def test_posix_account_path(): user = "squid" project = "clam" - expected = "users/{user}/projects/{project}".format(user=user, project=project,) actual = OsLoginServiceClient.posix_account_path(user, project) assert expected == actual @@ -2218,7 +2391,6 @@ def test_parse_posix_account_path(): def test_ssh_public_key_path(): user = "oyster" fingerprint = "nudibranch" - expected = "users/{user}/sshPublicKeys/{fingerprint}".format( user=user, fingerprint=fingerprint, ) @@ -2240,7 +2412,6 @@ def test_parse_ssh_public_key_path(): def test_common_billing_account_path(): billing_account = "winkle" - expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -2261,7 +2432,6 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "scallop" - expected = "folders/{folder}".format(folder=folder,) actual = OsLoginServiceClient.common_folder_path(folder) assert expected == actual @@ -2280,7 +2450,6 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "squid" - expected = "organizations/{organization}".format(organization=organization,) actual = OsLoginServiceClient.common_organization_path(organization) assert expected == actual @@ -2299,7 +2468,6 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "whelk" - expected = "projects/{project}".format(project=project,) actual = OsLoginServiceClient.common_project_path(project) assert expected == actual @@ -2319,7 +2487,6 @@ def test_parse_common_project_path(): def test_common_location_path(): project = "oyster" location = "nudibranch" - expected = "projects/{project}/locations/{location}".format( project=project, location=location, ) @@ -2346,7 +2513,7 @@ def test_client_withDEFAULT_CLIENT_INFO(): transports.OsLoginServiceTransport, "_prep_wrapped_messages" ) as prep: client = OsLoginServiceClient( - credentials=credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -2355,6 +2522,6 @@ def test_client_withDEFAULT_CLIENT_INFO(): ) as prep: transport_class = OsLoginServiceClient.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)