diff --git a/docs/managedidentities_v1/managed_identities_service.rst b/docs/managedidentities_v1/managed_identities_service.rst index 7860185..d08b52d 100644 --- a/docs/managedidentities_v1/managed_identities_service.rst +++ b/docs/managedidentities_v1/managed_identities_service.rst @@ -5,7 +5,6 @@ ManagedIdentitiesService :members: :inherited-members: - .. automodule:: google.cloud.managedidentities_v1.services.managed_identities_service.pagers :members: :inherited-members: diff --git a/google/cloud/managedidentities/__init__.py b/google/cloud/managedidentities/__init__.py index 0e27a12..3dac09f 100644 --- a/google/cloud/managedidentities/__init__.py +++ b/google/cloud/managedidentities/__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.managedidentities_v1.services.managed_identities_service.async_client import ( - ManagedIdentitiesServiceAsyncClient, -) from google.cloud.managedidentities_v1.services.managed_identities_service.client import ( ManagedIdentitiesServiceClient, ) +from google.cloud.managedidentities_v1.services.managed_identities_service.async_client import ( + ManagedIdentitiesServiceAsyncClient, +) + from google.cloud.managedidentities_v1.types.managed_identities_service import ( AttachTrustRequest, ) @@ -64,21 +64,21 @@ from google.cloud.managedidentities_v1.types.resource import Trust __all__ = ( + "ManagedIdentitiesServiceClient", + "ManagedIdentitiesServiceAsyncClient", "AttachTrustRequest", "CreateMicrosoftAdDomainRequest", "DeleteDomainRequest", "DetachTrustRequest", - "Domain", "GetDomainRequest", "ListDomainsRequest", "ListDomainsResponse", - "ManagedIdentitiesServiceAsyncClient", - "ManagedIdentitiesServiceClient", "OpMetadata", "ReconfigureTrustRequest", "ResetAdminPasswordRequest", "ResetAdminPasswordResponse", - "Trust", "UpdateDomainRequest", "ValidateTrustRequest", + "Domain", + "Trust", ) diff --git a/google/cloud/managedidentities_v1/__init__.py b/google/cloud/managedidentities_v1/__init__.py index 7181a0f..096d391 100644 --- a/google/cloud/managedidentities_v1/__init__.py +++ b/google/cloud/managedidentities_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.managed_identities_service import ManagedIdentitiesServiceClient +from .services.managed_identities_service import ManagedIdentitiesServiceAsyncClient + from .types.managed_identities_service import AttachTrustRequest from .types.managed_identities_service import CreateMicrosoftAdDomainRequest from .types.managed_identities_service import DeleteDomainRequest @@ -32,8 +33,8 @@ from .types.resource import Domain from .types.resource import Trust - __all__ = ( + "ManagedIdentitiesServiceAsyncClient", "AttachTrustRequest", "CreateMicrosoftAdDomainRequest", "DeleteDomainRequest", @@ -42,6 +43,7 @@ "GetDomainRequest", "ListDomainsRequest", "ListDomainsResponse", + "ManagedIdentitiesServiceClient", "OpMetadata", "ReconfigureTrustRequest", "ResetAdminPasswordRequest", @@ -49,5 +51,4 @@ "Trust", "UpdateDomainRequest", "ValidateTrustRequest", - "ManagedIdentitiesServiceClient", ) diff --git a/google/cloud/managedidentities_v1/gapic_metadata.json b/google/cloud/managedidentities_v1/gapic_metadata.json new file mode 100644 index 0000000..8b5405a --- /dev/null +++ b/google/cloud/managedidentities_v1/gapic_metadata.json @@ -0,0 +1,123 @@ + { + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", + "language": "python", + "libraryPackage": "google.cloud.managedidentities_v1", + "protoPackage": "google.cloud.managedidentities.v1", + "schema": "1.0", + "services": { + "ManagedIdentitiesService": { + "clients": { + "grpc": { + "libraryClient": "ManagedIdentitiesServiceClient", + "rpcs": { + "AttachTrust": { + "methods": [ + "attach_trust" + ] + }, + "CreateMicrosoftAdDomain": { + "methods": [ + "create_microsoft_ad_domain" + ] + }, + "DeleteDomain": { + "methods": [ + "delete_domain" + ] + }, + "DetachTrust": { + "methods": [ + "detach_trust" + ] + }, + "GetDomain": { + "methods": [ + "get_domain" + ] + }, + "ListDomains": { + "methods": [ + "list_domains" + ] + }, + "ReconfigureTrust": { + "methods": [ + "reconfigure_trust" + ] + }, + "ResetAdminPassword": { + "methods": [ + "reset_admin_password" + ] + }, + "UpdateDomain": { + "methods": [ + "update_domain" + ] + }, + "ValidateTrust": { + "methods": [ + "validate_trust" + ] + } + } + }, + "grpc-async": { + "libraryClient": "ManagedIdentitiesServiceAsyncClient", + "rpcs": { + "AttachTrust": { + "methods": [ + "attach_trust" + ] + }, + "CreateMicrosoftAdDomain": { + "methods": [ + "create_microsoft_ad_domain" + ] + }, + "DeleteDomain": { + "methods": [ + "delete_domain" + ] + }, + "DetachTrust": { + "methods": [ + "detach_trust" + ] + }, + "GetDomain": { + "methods": [ + "get_domain" + ] + }, + "ListDomains": { + "methods": [ + "list_domains" + ] + }, + "ReconfigureTrust": { + "methods": [ + "reconfigure_trust" + ] + }, + "ResetAdminPassword": { + "methods": [ + "reset_admin_password" + ] + }, + "UpdateDomain": { + "methods": [ + "update_domain" + ] + }, + "ValidateTrust": { + "methods": [ + "validate_trust" + ] + } + } + } + } + } + } +} diff --git a/google/cloud/managedidentities_v1/services/__init__.py b/google/cloud/managedidentities_v1/services/__init__.py index 42ffdf2..4de6597 100644 --- a/google/cloud/managedidentities_v1/services/__init__.py +++ b/google/cloud/managedidentities_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/managedidentities_v1/services/managed_identities_service/__init__.py b/google/cloud/managedidentities_v1/services/managed_identities_service/__init__.py index 9f17b1f..ea59d4f 100644 --- a/google/cloud/managedidentities_v1/services/managed_identities_service/__init__.py +++ b/google/cloud/managedidentities_v1/services/managed_identities_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 ManagedIdentitiesServiceClient from .async_client import ManagedIdentitiesServiceAsyncClient diff --git a/google/cloud/managedidentities_v1/services/managed_identities_service/async_client.py b/google/cloud/managedidentities_v1/services/managed_identities_service/async_client.py index e8e22a3..430dec6 100644 --- a/google/cloud/managedidentities_v1/services/managed_identities_service/async_client.py +++ b/google/cloud/managedidentities_v1/services/managed_identities_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,10 +20,10 @@ import pkg_resources import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore from google.api_core import operation # type: ignore @@ -33,10 +31,9 @@ from google.cloud.managedidentities_v1.services.managed_identities_service import pagers from google.cloud.managedidentities_v1.types import managed_identities_service from google.cloud.managedidentities_v1.types import resource -from google.protobuf import empty_pb2 as empty # type: ignore -from google.protobuf import field_mask_pb2 as field_mask # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore - +from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore from .transports.base import ManagedIdentitiesServiceTransport, DEFAULT_CLIENT_INFO from .transports.grpc_asyncio import ManagedIdentitiesServiceGrpcAsyncIOTransport from .client import ManagedIdentitiesServiceClient @@ -87,33 +84,28 @@ class ManagedIdentitiesServiceAsyncClient: domain_path = staticmethod(ManagedIdentitiesServiceClient.domain_path) parse_domain_path = staticmethod(ManagedIdentitiesServiceClient.parse_domain_path) - common_billing_account_path = staticmethod( ManagedIdentitiesServiceClient.common_billing_account_path ) parse_common_billing_account_path = staticmethod( ManagedIdentitiesServiceClient.parse_common_billing_account_path ) - common_folder_path = staticmethod(ManagedIdentitiesServiceClient.common_folder_path) parse_common_folder_path = staticmethod( ManagedIdentitiesServiceClient.parse_common_folder_path ) - common_organization_path = staticmethod( ManagedIdentitiesServiceClient.common_organization_path ) parse_common_organization_path = staticmethod( ManagedIdentitiesServiceClient.parse_common_organization_path ) - common_project_path = staticmethod( ManagedIdentitiesServiceClient.common_project_path ) parse_common_project_path = staticmethod( ManagedIdentitiesServiceClient.parse_common_project_path ) - common_location_path = staticmethod( ManagedIdentitiesServiceClient.common_location_path ) @@ -123,7 +115,8 @@ class ManagedIdentitiesServiceAsyncClient: @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. @@ -138,7 +131,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 @@ -155,7 +148,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> ManagedIdentitiesServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: ManagedIdentitiesServiceTransport: The transport used by the client instance. @@ -170,12 +163,12 @@ def transport(self) -> ManagedIdentitiesServiceTransport: def __init__( self, *, - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, transport: Union[str, ManagedIdentitiesServiceTransport] = "grpc_asyncio", client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the managed identities service client. + """Instantiates the managed identities service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -207,7 +200,6 @@ def __init__( google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport creation failed for any reason. """ - self._client = ManagedIdentitiesServiceClient( credentials=credentials, transport=transport, @@ -265,7 +257,6 @@ async def create_microsoft_ad_domain( This corresponds to the ``domain`` 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. @@ -295,7 +286,6 @@ async def create_microsoft_ad_domain( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if domain_name is not None: @@ -353,7 +343,6 @@ async def reset_admin_password( 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. @@ -380,7 +369,6 @@ async def reset_admin_password( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -426,7 +414,6 @@ async def list_domains( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -456,7 +443,6 @@ async def list_domains( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -508,7 +494,6 @@ async def get_domain( 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. @@ -535,7 +520,6 @@ async def get_domain( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -564,7 +548,7 @@ async def update_domain( request: managed_identities_service.UpdateDomainRequest = None, *, domain: resource.Domain = 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]] = (), @@ -595,7 +579,6 @@ async def update_domain( 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. @@ -625,7 +608,6 @@ async def update_domain( # If we have keyword arguments corresponding to fields on the # request, apply these. - if domain is not None: request.domain = domain if update_mask is not None: @@ -683,7 +665,6 @@ async def delete_domain( 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. @@ -723,7 +704,6 @@ async def delete_domain( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -748,7 +728,7 @@ async def delete_domain( response = operation_async.from_gapic( response, self._client._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=managed_identities_service.OpMetadata, ) @@ -784,7 +764,6 @@ async def attach_trust( This corresponds to the ``trust`` 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. @@ -814,7 +793,6 @@ async def attach_trust( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if trust is not None: @@ -889,7 +867,6 @@ async def reconfigure_trust( This corresponds to the ``target_dns_ip_addresses`` 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. @@ -919,12 +896,10 @@ async def reconfigure_trust( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if target_domain_name is not None: request.target_domain_name = target_domain_name - if target_dns_ip_addresses: request.target_dns_ip_addresses.extend(target_dns_ip_addresses) @@ -987,7 +962,6 @@ async def detach_trust( This corresponds to the ``trust`` 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. @@ -1017,7 +991,6 @@ async def detach_trust( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if trust is not None: @@ -1084,7 +1057,6 @@ async def validate_trust( This corresponds to the ``trust`` 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. @@ -1114,7 +1086,6 @@ async def validate_trust( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if trust is not None: diff --git a/google/cloud/managedidentities_v1/services/managed_identities_service/client.py b/google/cloud/managedidentities_v1/services/managed_identities_service/client.py index 2c5a272..9925e2a 100644 --- a/google/cloud/managedidentities_v1/services/managed_identities_service/client.py +++ b/google/cloud/managedidentities_v1/services/managed_identities_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 @@ -37,10 +35,9 @@ from google.cloud.managedidentities_v1.services.managed_identities_service import pagers from google.cloud.managedidentities_v1.types import managed_identities_service from google.cloud.managedidentities_v1.types import resource -from google.protobuf import empty_pb2 as empty # type: ignore -from google.protobuf import field_mask_pb2 as field_mask # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore - +from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore from .transports.base import ManagedIdentitiesServiceTransport, DEFAULT_CLIENT_INFO from .transports.grpc import ManagedIdentitiesServiceGrpcTransport from .transports.grpc_asyncio import ManagedIdentitiesServiceGrpcAsyncIOTransport @@ -63,7 +60,7 @@ class ManagedIdentitiesServiceClientMeta(type): def get_transport_class( cls, label: str = None, ) -> Type[ManagedIdentitiesServiceTransport]: - """Return an appropriate transport class. + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -121,7 +118,8 @@ class ManagedIdentitiesServiceClient(metaclass=ManagedIdentitiesServiceClientMet @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: @@ -155,7 +153,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. @@ -172,7 +171,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 @@ -191,23 +190,24 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> ManagedIdentitiesServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - ManagedIdentitiesServiceTransport: The transport used by the client instance. + ManagedIdentitiesServiceTransport: The transport used by the client + instance. """ return self._transport @staticmethod def domain_path(project: str, location: str, domain: str,) -> str: - """Return a fully-qualified domain string.""" + """Returns a fully-qualified domain string.""" return "projects/{project}/locations/{location}/domains/{domain}".format( project=project, location=location, domain=domain, ) @staticmethod def parse_domain_path(path: str) -> Dict[str, str]: - """Parse a domain path into its component segments.""" + """Parses a domain path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/domains/(?P.+?)$", path, @@ -216,7 +216,7 @@ def parse_domain_path(path: str) -> Dict[str, str]: @staticmethod def common_billing_account_path(billing_account: str,) -> str: - """Return a fully-qualified billing_account string.""" + """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -229,7 +229,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 @@ -240,7 +240,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 @@ -251,7 +251,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 @@ -262,7 +262,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, ) @@ -276,12 +276,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, ManagedIdentitiesServiceTransport, None] = None, client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the managed identities service client. + """Instantiates the managed identities service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -336,9 +336,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: @@ -350,12 +351,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. @@ -370,8 +373,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: @@ -436,7 +439,6 @@ def create_microsoft_ad_domain( This corresponds to the ``domain`` 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. @@ -470,10 +472,8 @@ def create_microsoft_ad_domain( request, managed_identities_service.CreateMicrosoftAdDomainRequest ): request = managed_identities_service.CreateMicrosoftAdDomainRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if domain_name is not None: @@ -529,7 +529,6 @@ def reset_admin_password( 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. @@ -560,10 +559,8 @@ def reset_admin_password( request, managed_identities_service.ResetAdminPasswordRequest ): request = managed_identities_service.ResetAdminPasswordRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -605,7 +602,6 @@ def list_domains( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -637,10 +633,8 @@ def list_domains( # there are no flattened fields. if not isinstance(request, managed_identities_service.ListDomainsRequest): request = managed_identities_service.ListDomainsRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -688,7 +682,6 @@ def get_domain( 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. @@ -717,10 +710,8 @@ def get_domain( # there are no flattened fields. if not isinstance(request, managed_identities_service.GetDomainRequest): request = managed_identities_service.GetDomainRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -745,7 +736,7 @@ def update_domain( request: managed_identities_service.UpdateDomainRequest = None, *, domain: resource.Domain = 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]] = (), @@ -776,7 +767,6 @@ def update_domain( 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. @@ -808,10 +798,8 @@ def update_domain( # there are no flattened fields. if not isinstance(request, managed_identities_service.UpdateDomainRequest): request = managed_identities_service.UpdateDomainRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if domain is not None: request.domain = domain if update_mask is not None: @@ -865,7 +853,6 @@ def delete_domain( 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. @@ -907,10 +894,8 @@ def delete_domain( # there are no flattened fields. if not isinstance(request, managed_identities_service.DeleteDomainRequest): request = managed_identities_service.DeleteDomainRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -931,7 +916,7 @@ def delete_domain( response = operation.from_gapic( response, self._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=managed_identities_service.OpMetadata, ) @@ -967,7 +952,6 @@ def attach_trust( This corresponds to the ``trust`` 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. @@ -999,10 +983,8 @@ def attach_trust( # there are no flattened fields. if not isinstance(request, managed_identities_service.AttachTrustRequest): request = managed_identities_service.AttachTrustRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if trust is not None: @@ -1073,7 +1055,6 @@ def reconfigure_trust( This corresponds to the ``target_dns_ip_addresses`` 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. @@ -1105,10 +1086,8 @@ def reconfigure_trust( # there are no flattened fields. if not isinstance(request, managed_identities_service.ReconfigureTrustRequest): request = managed_identities_service.ReconfigureTrustRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if target_domain_name is not None: @@ -1171,7 +1150,6 @@ def detach_trust( This corresponds to the ``trust`` 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. @@ -1203,10 +1181,8 @@ def detach_trust( # there are no flattened fields. if not isinstance(request, managed_identities_service.DetachTrustRequest): request = managed_identities_service.DetachTrustRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if trust is not None: @@ -1269,7 +1245,6 @@ def validate_trust( This corresponds to the ``trust`` 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. @@ -1301,10 +1276,8 @@ def validate_trust( # there are no flattened fields. if not isinstance(request, managed_identities_service.ValidateTrustRequest): request = managed_identities_service.ValidateTrustRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if trust is not None: diff --git a/google/cloud/managedidentities_v1/services/managed_identities_service/pagers.py b/google/cloud/managedidentities_v1/services/managed_identities_service/pagers.py index 5d5035b..9107d11 100644 --- a/google/cloud/managedidentities_v1/services/managed_identities_service/pagers.py +++ b/google/cloud/managedidentities_v1/services/managed_identities_service/pagers.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from typing import ( Any, AsyncIterable, @@ -120,7 +118,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and diff --git a/google/cloud/managedidentities_v1/services/managed_identities_service/transports/__init__.py b/google/cloud/managedidentities_v1/services/managed_identities_service/transports/__init__.py index df7f634..152cae7 100644 --- a/google/cloud/managedidentities_v1/services/managed_identities_service/transports/__init__.py +++ b/google/cloud/managedidentities_v1/services/managed_identities_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/managedidentities_v1/services/managed_identities_service/transports/base.py b/google/cloud/managedidentities_v1/services/managed_identities_service/transports/base.py index b5cd83e..2879286 100644 --- a/google/cloud/managedidentities_v1/services/managed_identities_service/transports/base.py +++ b/google/cloud/managedidentities_v1/services/managed_identities_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,22 +13,22 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import abc -import typing +from typing import Awaitable, Callable, Dict, Optional, Sequence, Union +import packaging.version import pkg_resources -from google import auth # type: ignore -from google.api_core import exceptions # type: ignore +import google.auth # type: ignore +import google.api_core # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.api_core import operations_v1 # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.cloud.managedidentities_v1.types import managed_identities_service from google.cloud.managedidentities_v1.types import resource -from google.longrunning import operations_pb2 as operations # type: ignore - +from google.longrunning import operations_pb2 # type: ignore try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( @@ -40,27 +39,41 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() +try: + # google.auth.__version__ was added in 1.26.0 + _GOOGLE_AUTH_VERSION = google.auth.__version__ +except AttributeError: + try: # try pkg_resources if it is available + _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version + except pkg_resources.DistributionNotFound: # pragma: NO COVER + _GOOGLE_AUTH_VERSION = None + +_API_CORE_VERSION = google.api_core.__version__ + class ManagedIdentitiesServiceTransport(abc.ABC): """Abstract transport class for ManagedIdentitiesService.""" AUTH_SCOPES = ("https://www.googleapis.com/auth/cloud-platform",) + DEFAULT_HOST: str = "managedidentities.googleapis.com" + def __init__( self, *, - host: str = "managedidentities.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 = { @@ -153,20 +213,20 @@ def operations_client(self) -> operations_v1.OperationsClient: @property def create_microsoft_ad_domain( self, - ) -> typing.Callable[ + ) -> Callable[ [managed_identities_service.CreateMicrosoftAdDomainRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def reset_admin_password( self, - ) -> typing.Callable[ + ) -> Callable[ [managed_identities_service.ResetAdminPasswordRequest], - typing.Union[ + Union[ managed_identities_service.ResetAdminPasswordResponse, - typing.Awaitable[managed_identities_service.ResetAdminPasswordResponse], + Awaitable[managed_identities_service.ResetAdminPasswordResponse], ], ]: raise NotImplementedError() @@ -174,11 +234,11 @@ def reset_admin_password( @property def list_domains( self, - ) -> typing.Callable[ + ) -> Callable[ [managed_identities_service.ListDomainsRequest], - typing.Union[ + Union[ managed_identities_service.ListDomainsResponse, - typing.Awaitable[managed_identities_service.ListDomainsResponse], + Awaitable[managed_identities_service.ListDomainsResponse], ], ]: raise NotImplementedError() @@ -186,63 +246,63 @@ def list_domains( @property def get_domain( self, - ) -> typing.Callable[ + ) -> Callable[ [managed_identities_service.GetDomainRequest], - typing.Union[resource.Domain, typing.Awaitable[resource.Domain]], + Union[resource.Domain, Awaitable[resource.Domain]], ]: raise NotImplementedError() @property def update_domain( self, - ) -> typing.Callable[ + ) -> Callable[ [managed_identities_service.UpdateDomainRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def delete_domain( self, - ) -> typing.Callable[ + ) -> Callable[ [managed_identities_service.DeleteDomainRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def attach_trust( self, - ) -> typing.Callable[ + ) -> Callable[ [managed_identities_service.AttachTrustRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def reconfigure_trust( self, - ) -> typing.Callable[ + ) -> Callable[ [managed_identities_service.ReconfigureTrustRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def detach_trust( self, - ) -> typing.Callable[ + ) -> Callable[ [managed_identities_service.DetachTrustRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def validate_trust( self, - ) -> typing.Callable[ + ) -> Callable[ [managed_identities_service.ValidateTrustRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() diff --git a/google/cloud/managedidentities_v1/services/managed_identities_service/transports/grpc.py b/google/cloud/managedidentities_v1/services/managed_identities_service/transports/grpc.py index 6c42dde..3aa47be 100644 --- a/google/cloud/managedidentities_v1/services/managed_identities_service/transports/grpc.py +++ b/google/cloud/managedidentities_v1/services/managed_identities_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,23 +13,21 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import warnings -from typing import Callable, Dict, Optional, Sequence, Tuple +from typing import Callable, Dict, Optional, Sequence, Tuple, Union from google.api_core import grpc_helpers # type: ignore from google.api_core import operations_v1 # type: ignore from google.api_core import gapic_v1 # type: ignore -from google import auth # type: ignore -from google.auth import credentials # type: ignore +import google.auth # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore import grpc # type: ignore from google.cloud.managedidentities_v1.types import managed_identities_service from google.cloud.managedidentities_v1.types import resource -from google.longrunning import operations_pb2 as operations # type: ignore - +from google.longrunning import operations_pb2 # type: ignore from .base import ManagedIdentitiesServiceTransport, DEFAULT_CLIENT_INFO @@ -87,7 +84,7 @@ def __init__( self, *, host: str = "managedidentities.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: str = None, scopes: Sequence[str] = None, channel: grpc.Channel = None, @@ -101,7 +98,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 @@ -212,7 +210,7 @@ def __init__( def create_channel( cls, host: str = "managedidentities.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, @@ -243,13 +241,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, ) @@ -278,7 +278,7 @@ def create_microsoft_ad_domain( self, ) -> Callable[ [managed_identities_service.CreateMicrosoftAdDomainRequest], - operations.Operation, + operations_pb2.Operation, ]: r"""Return a callable for the create microsoft ad domain method over gRPC. @@ -298,7 +298,7 @@ def create_microsoft_ad_domain( self._stubs["create_microsoft_ad_domain"] = self.grpc_channel.unary_unary( "/google.cloud.managedidentities.v1.ManagedIdentitiesService/CreateMicrosoftAdDomain", request_serializer=managed_identities_service.CreateMicrosoftAdDomainRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["create_microsoft_ad_domain"] @@ -390,7 +390,7 @@ def get_domain( def update_domain( self, ) -> Callable[ - [managed_identities_service.UpdateDomainRequest], operations.Operation + [managed_identities_service.UpdateDomainRequest], operations_pb2.Operation ]: r"""Return a callable for the update domain method over gRPC. @@ -410,7 +410,7 @@ def update_domain( self._stubs["update_domain"] = self.grpc_channel.unary_unary( "/google.cloud.managedidentities.v1.ManagedIdentitiesService/UpdateDomain", request_serializer=managed_identities_service.UpdateDomainRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["update_domain"] @@ -418,7 +418,7 @@ def update_domain( def delete_domain( self, ) -> Callable[ - [managed_identities_service.DeleteDomainRequest], operations.Operation + [managed_identities_service.DeleteDomainRequest], operations_pb2.Operation ]: r"""Return a callable for the delete domain method over gRPC. @@ -438,7 +438,7 @@ def delete_domain( self._stubs["delete_domain"] = self.grpc_channel.unary_unary( "/google.cloud.managedidentities.v1.ManagedIdentitiesService/DeleteDomain", request_serializer=managed_identities_service.DeleteDomainRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["delete_domain"] @@ -446,7 +446,7 @@ def delete_domain( def attach_trust( self, ) -> Callable[ - [managed_identities_service.AttachTrustRequest], operations.Operation + [managed_identities_service.AttachTrustRequest], operations_pb2.Operation ]: r"""Return a callable for the attach trust method over gRPC. @@ -466,7 +466,7 @@ def attach_trust( self._stubs["attach_trust"] = self.grpc_channel.unary_unary( "/google.cloud.managedidentities.v1.ManagedIdentitiesService/AttachTrust", request_serializer=managed_identities_service.AttachTrustRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["attach_trust"] @@ -474,7 +474,7 @@ def attach_trust( def reconfigure_trust( self, ) -> Callable[ - [managed_identities_service.ReconfigureTrustRequest], operations.Operation + [managed_identities_service.ReconfigureTrustRequest], operations_pb2.Operation ]: r"""Return a callable for the reconfigure trust method over gRPC. @@ -494,7 +494,7 @@ def reconfigure_trust( self._stubs["reconfigure_trust"] = self.grpc_channel.unary_unary( "/google.cloud.managedidentities.v1.ManagedIdentitiesService/ReconfigureTrust", request_serializer=managed_identities_service.ReconfigureTrustRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["reconfigure_trust"] @@ -502,7 +502,7 @@ def reconfigure_trust( def detach_trust( self, ) -> Callable[ - [managed_identities_service.DetachTrustRequest], operations.Operation + [managed_identities_service.DetachTrustRequest], operations_pb2.Operation ]: r"""Return a callable for the detach trust method over gRPC. @@ -522,7 +522,7 @@ def detach_trust( self._stubs["detach_trust"] = self.grpc_channel.unary_unary( "/google.cloud.managedidentities.v1.ManagedIdentitiesService/DetachTrust", request_serializer=managed_identities_service.DetachTrustRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["detach_trust"] @@ -530,7 +530,7 @@ def detach_trust( def validate_trust( self, ) -> Callable[ - [managed_identities_service.ValidateTrustRequest], operations.Operation + [managed_identities_service.ValidateTrustRequest], operations_pb2.Operation ]: r"""Return a callable for the validate trust method over gRPC. @@ -552,7 +552,7 @@ def validate_trust( self._stubs["validate_trust"] = self.grpc_channel.unary_unary( "/google.cloud.managedidentities.v1.ManagedIdentitiesService/ValidateTrust", request_serializer=managed_identities_service.ValidateTrustRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["validate_trust"] diff --git a/google/cloud/managedidentities_v1/services/managed_identities_service/transports/grpc_asyncio.py b/google/cloud/managedidentities_v1/services/managed_identities_service/transports/grpc_asyncio.py index 1676ebc..cf8d5d6 100644 --- a/google/cloud/managedidentities_v1/services/managed_identities_service/transports/grpc_asyncio.py +++ b/google/cloud/managedidentities_v1/services/managed_identities_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,24 +13,22 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import warnings -from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple +from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union from google.api_core import gapic_v1 # type: ignore from google.api_core import grpc_helpers_async # type: ignore from google.api_core import operations_v1 # type: ignore -from google import auth # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore from google.cloud.managedidentities_v1.types import managed_identities_service from google.cloud.managedidentities_v1.types import resource -from google.longrunning import operations_pb2 as operations # type: ignore - +from google.longrunning import operations_pb2 # type: ignore from .base import ManagedIdentitiesServiceTransport, DEFAULT_CLIENT_INFO from .grpc import ManagedIdentitiesServiceGrpcTransport @@ -90,7 +87,7 @@ class ManagedIdentitiesServiceGrpcAsyncIOTransport(ManagedIdentitiesServiceTrans def create_channel( cls, host: str = "managedidentities.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, @@ -117,13 +114,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, ) @@ -131,7 +130,7 @@ def __init__( self, *, host: str = "managedidentities.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, @@ -145,7 +144,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 @@ -204,7 +204,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 @@ -284,7 +283,7 @@ def create_microsoft_ad_domain( self, ) -> Callable[ [managed_identities_service.CreateMicrosoftAdDomainRequest], - Awaitable[operations.Operation], + Awaitable[operations_pb2.Operation], ]: r"""Return a callable for the create microsoft ad domain method over gRPC. @@ -304,7 +303,7 @@ def create_microsoft_ad_domain( self._stubs["create_microsoft_ad_domain"] = self.grpc_channel.unary_unary( "/google.cloud.managedidentities.v1.ManagedIdentitiesService/CreateMicrosoftAdDomain", request_serializer=managed_identities_service.CreateMicrosoftAdDomainRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["create_microsoft_ad_domain"] @@ -399,7 +398,7 @@ def update_domain( self, ) -> Callable[ [managed_identities_service.UpdateDomainRequest], - Awaitable[operations.Operation], + Awaitable[operations_pb2.Operation], ]: r"""Return a callable for the update domain method over gRPC. @@ -419,7 +418,7 @@ def update_domain( self._stubs["update_domain"] = self.grpc_channel.unary_unary( "/google.cloud.managedidentities.v1.ManagedIdentitiesService/UpdateDomain", request_serializer=managed_identities_service.UpdateDomainRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["update_domain"] @@ -428,7 +427,7 @@ def delete_domain( self, ) -> Callable[ [managed_identities_service.DeleteDomainRequest], - Awaitable[operations.Operation], + Awaitable[operations_pb2.Operation], ]: r"""Return a callable for the delete domain method over gRPC. @@ -448,7 +447,7 @@ def delete_domain( self._stubs["delete_domain"] = self.grpc_channel.unary_unary( "/google.cloud.managedidentities.v1.ManagedIdentitiesService/DeleteDomain", request_serializer=managed_identities_service.DeleteDomainRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["delete_domain"] @@ -456,7 +455,8 @@ def delete_domain( def attach_trust( self, ) -> Callable[ - [managed_identities_service.AttachTrustRequest], Awaitable[operations.Operation] + [managed_identities_service.AttachTrustRequest], + Awaitable[operations_pb2.Operation], ]: r"""Return a callable for the attach trust method over gRPC. @@ -476,7 +476,7 @@ def attach_trust( self._stubs["attach_trust"] = self.grpc_channel.unary_unary( "/google.cloud.managedidentities.v1.ManagedIdentitiesService/AttachTrust", request_serializer=managed_identities_service.AttachTrustRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["attach_trust"] @@ -485,7 +485,7 @@ def reconfigure_trust( self, ) -> Callable[ [managed_identities_service.ReconfigureTrustRequest], - Awaitable[operations.Operation], + Awaitable[operations_pb2.Operation], ]: r"""Return a callable for the reconfigure trust method over gRPC. @@ -505,7 +505,7 @@ def reconfigure_trust( self._stubs["reconfigure_trust"] = self.grpc_channel.unary_unary( "/google.cloud.managedidentities.v1.ManagedIdentitiesService/ReconfigureTrust", request_serializer=managed_identities_service.ReconfigureTrustRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["reconfigure_trust"] @@ -513,7 +513,8 @@ def reconfigure_trust( def detach_trust( self, ) -> Callable[ - [managed_identities_service.DetachTrustRequest], Awaitable[operations.Operation] + [managed_identities_service.DetachTrustRequest], + Awaitable[operations_pb2.Operation], ]: r"""Return a callable for the detach trust method over gRPC. @@ -533,7 +534,7 @@ def detach_trust( self._stubs["detach_trust"] = self.grpc_channel.unary_unary( "/google.cloud.managedidentities.v1.ManagedIdentitiesService/DetachTrust", request_serializer=managed_identities_service.DetachTrustRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["detach_trust"] @@ -542,7 +543,7 @@ def validate_trust( self, ) -> Callable[ [managed_identities_service.ValidateTrustRequest], - Awaitable[operations.Operation], + Awaitable[operations_pb2.Operation], ]: r"""Return a callable for the validate trust method over gRPC. @@ -564,7 +565,7 @@ def validate_trust( self._stubs["validate_trust"] = self.grpc_channel.unary_unary( "/google.cloud.managedidentities.v1.ManagedIdentitiesService/ValidateTrust", request_serializer=managed_identities_service.ValidateTrustRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["validate_trust"] diff --git a/google/cloud/managedidentities_v1/types/__init__.py b/google/cloud/managedidentities_v1/types/__init__.py index c2a1c1d..0ebcaff 100644 --- a/google/cloud/managedidentities_v1/types/__init__.py +++ b/google/cloud/managedidentities_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 .managed_identities_service import ( AttachTrustRequest, CreateMicrosoftAdDomainRequest, diff --git a/google/cloud/managedidentities_v1/types/managed_identities_service.py b/google/cloud/managedidentities_v1/types/managed_identities_service.py index 5673f00..c79314f 100644 --- a/google/cloud/managedidentities_v1/types/managed_identities_service.py +++ b/google/cloud/managedidentities_v1/types/managed_identities_service.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,13 +13,11 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.managedidentities_v1.types import resource -from google.protobuf import field_mask_pb2 as field_mask # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore __protobuf__ = proto.module( @@ -45,7 +42,6 @@ class OpMetadata(proto.Message): r"""Represents the metadata of the long-running operation. - Attributes: create_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The time the operation was @@ -70,17 +66,12 @@ class OpMetadata(proto.Message): operation. """ - create_time = proto.Field(proto.MESSAGE, number=1, message=timestamp.Timestamp,) - - end_time = proto.Field(proto.MESSAGE, number=2, message=timestamp.Timestamp,) - - target = proto.Field(proto.STRING, number=3) - - verb = proto.Field(proto.STRING, number=4) - - requested_cancellation = proto.Field(proto.BOOL, number=5) - - api_version = proto.Field(proto.STRING, number=6) + create_time = proto.Field(proto.MESSAGE, number=1, message=timestamp_pb2.Timestamp,) + end_time = proto.Field(proto.MESSAGE, number=2, message=timestamp_pb2.Timestamp,) + target = proto.Field(proto.STRING, number=3,) + verb = proto.Field(proto.STRING, number=4,) + requested_cancellation = proto.Field(proto.BOOL, number=5,) + api_version = proto.Field(proto.STRING, number=6,) class CreateMicrosoftAdDomainRequest(proto.Message): @@ -110,10 +101,8 @@ class CreateMicrosoftAdDomainRequest(proto.Message): Required. A Managed Identity domain resource. """ - parent = proto.Field(proto.STRING, number=1) - - domain_name = proto.Field(proto.STRING, number=2) - + parent = proto.Field(proto.STRING, number=1,) + domain_name = proto.Field(proto.STRING, number=2,) domain = proto.Field(proto.MESSAGE, number=3, message=resource.Domain,) @@ -127,7 +116,7 @@ class ResetAdminPasswordRequest(proto.Message): ``projects/{project_id}/locations/global/domains/{domain_name}`` """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class ResetAdminPasswordResponse(proto.Message): @@ -141,7 +130,7 @@ class ResetAdminPasswordResponse(proto.Message): more information. """ - password = proto.Field(proto.STRING, number=1) + password = proto.Field(proto.STRING, number=1,) class ListDomainsRequest(proto.Message): @@ -172,15 +161,11 @@ class ListDomainsRequest(proto.Message): for more information. """ - parent = proto.Field(proto.STRING, number=1) - - page_size = proto.Field(proto.INT32, number=2) - - page_token = proto.Field(proto.STRING, number=3) - - filter = proto.Field(proto.STRING, number=4) - - order_by = proto.Field(proto.STRING, number=5) + parent = proto.Field(proto.STRING, number=1,) + page_size = proto.Field(proto.INT32, number=2,) + page_token = proto.Field(proto.STRING, number=3,) + filter = proto.Field(proto.STRING, number=4,) + order_by = proto.Field(proto.STRING, number=5,) class ListDomainsResponse(proto.Message): @@ -205,10 +190,8 @@ def raw_page(self): return self domains = proto.RepeatedField(proto.MESSAGE, number=1, message=resource.Domain,) - - next_page_token = proto.Field(proto.STRING, number=2) - - unreachable = proto.RepeatedField(proto.STRING, number=3) + next_page_token = proto.Field(proto.STRING, number=2,) + unreachable = proto.RepeatedField(proto.STRING, number=3,) class GetDomainRequest(proto.Message): @@ -221,7 +204,7 @@ class GetDomainRequest(proto.Message): ``projects/{project_id}/locations/global/domains/{domain_name}`` """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class UpdateDomainRequest(proto.Message): @@ -243,8 +226,9 @@ class UpdateDomainRequest(proto.Message): fields specified in update_mask are updated. """ - update_mask = proto.Field(proto.MESSAGE, number=1, message=field_mask.FieldMask,) - + update_mask = proto.Field( + proto.MESSAGE, number=1, message=field_mask_pb2.FieldMask, + ) domain = proto.Field(proto.MESSAGE, number=2, message=resource.Domain,) @@ -258,7 +242,7 @@ class DeleteDomainRequest(proto.Message): ``projects/{project_id}/locations/global/domains/{domain_name}`` """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class AttachTrustRequest(proto.Message): @@ -274,8 +258,7 @@ class AttachTrustRequest(proto.Message): Required. The domain trust resource. """ - name = proto.Field(proto.STRING, number=1) - + name = proto.Field(proto.STRING, number=1,) trust = proto.Field(proto.MESSAGE, number=2, message=resource.Trust,) @@ -297,11 +280,9 @@ class ReconfigureTrustRequest(proto.Message): trust. """ - name = proto.Field(proto.STRING, number=1) - - target_domain_name = proto.Field(proto.STRING, number=2) - - target_dns_ip_addresses = proto.RepeatedField(proto.STRING, number=3) + name = proto.Field(proto.STRING, number=1,) + target_domain_name = proto.Field(proto.STRING, number=2,) + target_dns_ip_addresses = proto.RepeatedField(proto.STRING, number=3,) class DetachTrustRequest(proto.Message): @@ -318,8 +299,7 @@ class DetachTrustRequest(proto.Message): removed. """ - name = proto.Field(proto.STRING, number=1) - + name = proto.Field(proto.STRING, number=1,) trust = proto.Field(proto.MESSAGE, number=2, message=resource.Trust,) @@ -337,8 +317,7 @@ class ValidateTrustRequest(proto.Message): state for. """ - name = proto.Field(proto.STRING, number=1) - + name = proto.Field(proto.STRING, number=1,) trust = proto.Field(proto.MESSAGE, number=2, message=resource.Trust,) diff --git a/google/cloud/managedidentities_v1/types/resource.py b/google/cloud/managedidentities_v1/types/resource.py index 250f9db..338fe7c 100644 --- a/google/cloud/managedidentities_v1/types/resource.py +++ b/google/cloud/managedidentities_v1/types/resource.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,11 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - -from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore __protobuf__ = proto.module( @@ -28,7 +25,6 @@ class Domain(proto.Message): r"""Represents a managed Microsoft Active Directory domain. - Attributes: name (str): Required. The unique name of the domain using the form: @@ -90,28 +86,21 @@ class State(proto.Enum): PERFORMING_MAINTENANCE = 6 UNAVAILABLE = 7 - name = proto.Field(proto.STRING, number=1) - - labels = proto.MapField(proto.STRING, proto.STRING, number=2) - - authorized_networks = proto.RepeatedField(proto.STRING, number=3) - - reserved_ip_range = proto.Field(proto.STRING, number=4) - - locations = proto.RepeatedField(proto.STRING, number=5) - - admin = proto.Field(proto.STRING, number=6) - - fqdn = proto.Field(proto.STRING, number=10) - - create_time = proto.Field(proto.MESSAGE, number=11, message=timestamp.Timestamp,) - - update_time = proto.Field(proto.MESSAGE, number=12, message=timestamp.Timestamp,) - + name = proto.Field(proto.STRING, number=1,) + labels = proto.MapField(proto.STRING, proto.STRING, number=2,) + authorized_networks = proto.RepeatedField(proto.STRING, number=3,) + reserved_ip_range = proto.Field(proto.STRING, number=4,) + locations = proto.RepeatedField(proto.STRING, number=5,) + admin = proto.Field(proto.STRING, number=6,) + fqdn = proto.Field(proto.STRING, number=10,) + create_time = proto.Field( + proto.MESSAGE, number=11, message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, number=12, message=timestamp_pb2.Timestamp, + ) state = proto.Field(proto.ENUM, number=13, enum=State,) - - status_message = proto.Field(proto.STRING, number=14) - + status_message = proto.Field(proto.STRING, number=14,) trusts = proto.RepeatedField(proto.MESSAGE, number=15, message="Trust",) @@ -185,28 +174,18 @@ class TrustDirection(proto.Enum): OUTBOUND = 2 BIDIRECTIONAL = 3 - target_domain_name = proto.Field(proto.STRING, number=1) - + target_domain_name = proto.Field(proto.STRING, number=1,) trust_type = proto.Field(proto.ENUM, number=2, enum=TrustType,) - trust_direction = proto.Field(proto.ENUM, number=3, enum=TrustDirection,) - - selective_authentication = proto.Field(proto.BOOL, number=4) - - target_dns_ip_addresses = proto.RepeatedField(proto.STRING, number=5) - - trust_handshake_secret = proto.Field(proto.STRING, number=6) - - create_time = proto.Field(proto.MESSAGE, number=7, message=timestamp.Timestamp,) - - update_time = proto.Field(proto.MESSAGE, number=8, message=timestamp.Timestamp,) - + selective_authentication = proto.Field(proto.BOOL, number=4,) + target_dns_ip_addresses = proto.RepeatedField(proto.STRING, number=5,) + trust_handshake_secret = proto.Field(proto.STRING, number=6,) + create_time = proto.Field(proto.MESSAGE, number=7, message=timestamp_pb2.Timestamp,) + update_time = proto.Field(proto.MESSAGE, number=8, message=timestamp_pb2.Timestamp,) state = proto.Field(proto.ENUM, number=9, enum=State,) - - state_description = proto.Field(proto.STRING, number=11) - + state_description = proto.Field(proto.STRING, number=11,) last_trust_heartbeat_time = proto.Field( - proto.MESSAGE, number=12, message=timestamp.Timestamp, + proto.MESSAGE, number=12, message=timestamp_pb2.Timestamp, ) diff --git a/scripts/fixup_managedidentities_v1_keywords.py b/scripts/fixup_managedidentities_v1_keywords.py index 288b8fc..bfd6122 100644 --- a/scripts/fixup_managedidentities_v1_keywords.py +++ b/scripts/fixup_managedidentities_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,17 +39,16 @@ def partition( class managedidentitiesCallTransformer(cst.CSTTransformer): CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { - 'attach_trust': ('name', 'trust', ), - 'create_microsoft_ad_domain': ('parent', 'domain_name', 'domain', ), - 'delete_domain': ('name', ), - 'detach_trust': ('name', 'trust', ), - 'get_domain': ('name', ), - 'list_domains': ('parent', 'page_size', 'page_token', 'filter', 'order_by', ), - 'reconfigure_trust': ('name', 'target_domain_name', 'target_dns_ip_addresses', ), - 'reset_admin_password': ('name', ), - 'update_domain': ('update_mask', 'domain', ), - 'validate_trust': ('name', 'trust', ), - + 'attach_trust': ('name', 'trust', ), + 'create_microsoft_ad_domain': ('parent', 'domain_name', 'domain', ), + 'delete_domain': ('name', ), + 'detach_trust': ('name', 'trust', ), + 'get_domain': ('name', ), + 'list_domains': ('parent', 'page_size', 'page_token', 'filter', 'order_by', ), + 'reconfigure_trust': ('name', 'target_domain_name', 'target_dns_ip_addresses', ), + 'reset_admin_password': ('name', ), + 'update_domain': ('update_mask', 'domain', ), + 'validate_trust': ('name', 'trust', ), } def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: @@ -82,7 +79,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/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..4de6597 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py new file mode 100644 index 0000000..4de6597 --- /dev/null +++ b/tests/unit/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/tests/unit/gapic/__init__.py b/tests/unit/gapic/__init__.py new file mode 100644 index 0000000..4de6597 --- /dev/null +++ b/tests/unit/gapic/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/tests/unit/gapic/managedidentities_v1/__init__.py b/tests/unit/gapic/managedidentities_v1/__init__.py index 42ffdf2..4de6597 100644 --- a/tests/unit/gapic/managedidentities_v1/__init__.py +++ b/tests/unit/gapic/managedidentities_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/managedidentities_v1/test_managed_identities_service.py b/tests/unit/gapic/managedidentities_v1/test_managed_identities_service.py index 7572e1a..5547a95 100644 --- a/tests/unit/gapic/managedidentities_v1/test_managed_identities_service.py +++ b/tests/unit/gapic/managedidentities_v1/test_managed_identities_service.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import os import mock +import packaging.version import grpc from grpc.experimental import aio @@ -24,16 +23,16 @@ import pytest from proto.marshal.rules.dates import DurationRule, TimestampRule -from google import auth + from google.api_core import client_options -from google.api_core import exceptions +from google.api_core import exceptions as core_exceptions from google.api_core import future from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 -from google.auth import credentials +from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.managedidentities_v1.services.managed_identities_service import ( ManagedIdentitiesServiceAsyncClient, @@ -45,12 +44,42 @@ from google.cloud.managedidentities_v1.services.managed_identities_service import ( transports, ) +from google.cloud.managedidentities_v1.services.managed_identities_service.transports.base import ( + _API_CORE_VERSION, +) +from google.cloud.managedidentities_v1.services.managed_identities_service.transports.base import ( + _GOOGLE_AUTH_VERSION, +) from google.cloud.managedidentities_v1.types import managed_identities_service from google.cloud.managedidentities_v1.types import resource from google.longrunning import operations_pb2 from google.oauth2 import service_account -from google.protobuf import field_mask_pb2 as field_mask # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_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(): @@ -103,7 +132,7 @@ def test__get_default_mtls_endpoint(): [ManagedIdentitiesServiceClient, ManagedIdentitiesServiceAsyncClient,], ) def test_managed_identities_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: @@ -121,7 +150,7 @@ def test_managed_identities_service_client_from_service_account_info(client_clas [ManagedIdentitiesServiceClient, ManagedIdentitiesServiceAsyncClient,], ) def test_managed_identities_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: @@ -180,7 +209,7 @@ def test_managed_identities_service_client_client_options( with mock.patch.object( ManagedIdentitiesServiceClient, "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() @@ -489,7 +518,7 @@ def test_create_microsoft_ad_domain( request_type=managed_identities_service.CreateMicrosoftAdDomainRequest, ): client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -502,13 +531,11 @@ def test_create_microsoft_ad_domain( ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.create_microsoft_ad_domain(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == managed_identities_service.CreateMicrosoftAdDomainRequest() # Establish that the response is the type that we expect. @@ -523,7 +550,7 @@ def test_create_microsoft_ad_domain_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 = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -533,7 +560,6 @@ def test_create_microsoft_ad_domain_empty_call(): client.create_microsoft_ad_domain() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == managed_identities_service.CreateMicrosoftAdDomainRequest() @@ -543,7 +569,7 @@ async def test_create_microsoft_ad_domain_async( request_type=managed_identities_service.CreateMicrosoftAdDomainRequest, ): client = ManagedIdentitiesServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -558,13 +584,11 @@ async def test_create_microsoft_ad_domain_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.create_microsoft_ad_domain(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == managed_identities_service.CreateMicrosoftAdDomainRequest() # Establish that the response is the type that we expect. @@ -578,12 +602,13 @@ async def test_create_microsoft_ad_domain_async_from_dict(): def test_create_microsoft_ad_domain_field_headers(): client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = managed_identities_service.CreateMicrosoftAdDomainRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -591,7 +616,6 @@ def test_create_microsoft_ad_domain_field_headers(): type(client.transport.create_microsoft_ad_domain), "__call__" ) as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.create_microsoft_ad_domain(request) # Establish that the underlying gRPC stub method was called. @@ -607,12 +631,13 @@ def test_create_microsoft_ad_domain_field_headers(): @pytest.mark.asyncio async def test_create_microsoft_ad_domain_field_headers_async(): client = ManagedIdentitiesServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = managed_identities_service.CreateMicrosoftAdDomainRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -622,7 +647,6 @@ async def test_create_microsoft_ad_domain_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.create_microsoft_ad_domain(request) # Establish that the underlying gRPC stub method was called. @@ -637,7 +661,7 @@ async def test_create_microsoft_ad_domain_field_headers_async(): def test_create_microsoft_ad_domain_flattened(): client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -646,7 +670,6 @@ def test_create_microsoft_ad_domain_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.create_microsoft_ad_domain( @@ -659,17 +682,14 @@ def test_create_microsoft_ad_domain_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].domain_name == "domain_name_value" - assert args[0].domain == resource.Domain(name="name_value") def test_create_microsoft_ad_domain_flattened_error(): client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -686,7 +706,7 @@ def test_create_microsoft_ad_domain_flattened_error(): @pytest.mark.asyncio async def test_create_microsoft_ad_domain_flattened_async(): client = ManagedIdentitiesServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -711,18 +731,15 @@ async def test_create_microsoft_ad_domain_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].domain_name == "domain_name_value" - assert args[0].domain == resource.Domain(name="name_value") @pytest.mark.asyncio async def test_create_microsoft_ad_domain_flattened_error_async(): client = ManagedIdentitiesServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -741,7 +758,7 @@ def test_reset_admin_password( request_type=managed_identities_service.ResetAdminPasswordRequest, ): client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -756,19 +773,15 @@ def test_reset_admin_password( call.return_value = managed_identities_service.ResetAdminPasswordResponse( password="password_value", ) - response = client.reset_admin_password(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == managed_identities_service.ResetAdminPasswordRequest() # Establish that the response is the type that we expect. - assert isinstance(response, managed_identities_service.ResetAdminPasswordResponse) - assert response.password == "password_value" @@ -780,7 +793,7 @@ def test_reset_admin_password_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 = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -790,7 +803,6 @@ def test_reset_admin_password_empty_call(): client.reset_admin_password() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == managed_identities_service.ResetAdminPasswordRequest() @@ -800,7 +812,7 @@ async def test_reset_admin_password_async( request_type=managed_identities_service.ResetAdminPasswordRequest, ): client = ManagedIdentitiesServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -817,18 +829,15 @@ async def test_reset_admin_password_async( password="password_value", ) ) - response = await client.reset_admin_password(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == managed_identities_service.ResetAdminPasswordRequest() # Establish that the response is the type that we expect. assert isinstance(response, managed_identities_service.ResetAdminPasswordResponse) - assert response.password == "password_value" @@ -839,12 +848,13 @@ async def test_reset_admin_password_async_from_dict(): def test_reset_admin_password_field_headers(): client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = managed_identities_service.ResetAdminPasswordRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -852,7 +862,6 @@ def test_reset_admin_password_field_headers(): type(client.transport.reset_admin_password), "__call__" ) as call: call.return_value = managed_identities_service.ResetAdminPasswordResponse() - client.reset_admin_password(request) # Establish that the underlying gRPC stub method was called. @@ -868,12 +877,13 @@ def test_reset_admin_password_field_headers(): @pytest.mark.asyncio async def test_reset_admin_password_field_headers_async(): client = ManagedIdentitiesServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = managed_identities_service.ResetAdminPasswordRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -883,7 +893,6 @@ async def test_reset_admin_password_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( managed_identities_service.ResetAdminPasswordResponse() ) - await client.reset_admin_password(request) # Establish that the underlying gRPC stub method was called. @@ -898,7 +907,7 @@ async def test_reset_admin_password_field_headers_async(): def test_reset_admin_password_flattened(): client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -907,7 +916,6 @@ def test_reset_admin_password_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = managed_identities_service.ResetAdminPasswordResponse() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.reset_admin_password(name="name_value",) @@ -916,13 +924,12 @@ def test_reset_admin_password_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_reset_admin_password_flattened_error(): client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -936,7 +943,7 @@ def test_reset_admin_password_flattened_error(): @pytest.mark.asyncio async def test_reset_admin_password_flattened_async(): client = ManagedIdentitiesServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -957,14 +964,13 @@ async def test_reset_admin_password_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_reset_admin_password_flattened_error_async(): client = ManagedIdentitiesServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -979,7 +985,7 @@ def test_list_domains( transport: str = "grpc", request_type=managed_identities_service.ListDomainsRequest ): client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -992,21 +998,16 @@ def test_list_domains( call.return_value = managed_identities_service.ListDomainsResponse( next_page_token="next_page_token_value", unreachable=["unreachable_value"], ) - response = client.list_domains(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == managed_identities_service.ListDomainsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListDomainsPager) - assert response.next_page_token == "next_page_token_value" - assert response.unreachable == ["unreachable_value"] @@ -1018,7 +1019,7 @@ def test_list_domains_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 = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1026,7 +1027,6 @@ def test_list_domains_empty_call(): client.list_domains() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == managed_identities_service.ListDomainsRequest() @@ -1036,7 +1036,7 @@ async def test_list_domains_async( request_type=managed_identities_service.ListDomainsRequest, ): client = ManagedIdentitiesServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1052,20 +1052,16 @@ async def test_list_domains_async( unreachable=["unreachable_value"], ) ) - response = await client.list_domains(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == managed_identities_service.ListDomainsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListDomainsAsyncPager) - assert response.next_page_token == "next_page_token_value" - assert response.unreachable == ["unreachable_value"] @@ -1076,18 +1072,18 @@ async def test_list_domains_async_from_dict(): def test_list_domains_field_headers(): client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = managed_identities_service.ListDomainsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_domains), "__call__") as call: call.return_value = managed_identities_service.ListDomainsResponse() - client.list_domains(request) # Establish that the underlying gRPC stub method was called. @@ -1103,12 +1099,13 @@ def test_list_domains_field_headers(): @pytest.mark.asyncio async def test_list_domains_field_headers_async(): client = ManagedIdentitiesServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = managed_identities_service.ListDomainsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1116,7 +1113,6 @@ async def test_list_domains_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( managed_identities_service.ListDomainsResponse() ) - await client.list_domains(request) # Establish that the underlying gRPC stub method was called. @@ -1131,14 +1127,13 @@ async def test_list_domains_field_headers_async(): def test_list_domains_flattened(): client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_domains), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = managed_identities_service.ListDomainsResponse() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.list_domains(parent="parent_value",) @@ -1147,13 +1142,12 @@ def test_list_domains_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" def test_list_domains_flattened_error(): client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1167,7 +1161,7 @@ def test_list_domains_flattened_error(): @pytest.mark.asyncio async def test_list_domains_flattened_async(): client = ManagedIdentitiesServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1186,14 +1180,13 @@ async def test_list_domains_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" @pytest.mark.asyncio async def test_list_domains_flattened_error_async(): client = ManagedIdentitiesServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1206,7 +1199,7 @@ async def test_list_domains_flattened_error_async(): def test_list_domains_pager(): client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1244,7 +1237,7 @@ def test_list_domains_pager(): def test_list_domains_pages(): client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1274,7 +1267,7 @@ def test_list_domains_pages(): @pytest.mark.asyncio async def test_list_domains_async_pager(): client = ManagedIdentitiesServiceAsyncClient( - credentials=credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1311,7 +1304,7 @@ async def test_list_domains_async_pager(): @pytest.mark.asyncio async def test_list_domains_async_pages(): client = ManagedIdentitiesServiceAsyncClient( - credentials=credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1346,7 +1339,7 @@ def test_get_domain( transport: str = "grpc", request_type=managed_identities_service.GetDomainRequest ): client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1366,33 +1359,22 @@ def test_get_domain( state=resource.Domain.State.CREATING, status_message="status_message_value", ) - response = client.get_domain(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == managed_identities_service.GetDomainRequest() # Establish that the response is the type that we expect. - assert isinstance(response, resource.Domain) - assert response.name == "name_value" - assert response.authorized_networks == ["authorized_networks_value"] - assert response.reserved_ip_range == "reserved_ip_range_value" - assert response.locations == ["locations_value"] - assert response.admin == "admin_value" - assert response.fqdn == "fqdn_value" - assert response.state == resource.Domain.State.CREATING - assert response.status_message == "status_message_value" @@ -1404,7 +1386,7 @@ def test_get_domain_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 = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1412,7 +1394,6 @@ def test_get_domain_empty_call(): client.get_domain() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == managed_identities_service.GetDomainRequest() @@ -1422,7 +1403,7 @@ async def test_get_domain_async( request_type=managed_identities_service.GetDomainRequest, ): client = ManagedIdentitiesServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1444,32 +1425,22 @@ async def test_get_domain_async( status_message="status_message_value", ) ) - response = await client.get_domain(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == managed_identities_service.GetDomainRequest() # Establish that the response is the type that we expect. assert isinstance(response, resource.Domain) - assert response.name == "name_value" - assert response.authorized_networks == ["authorized_networks_value"] - assert response.reserved_ip_range == "reserved_ip_range_value" - assert response.locations == ["locations_value"] - assert response.admin == "admin_value" - assert response.fqdn == "fqdn_value" - assert response.state == resource.Domain.State.CREATING - assert response.status_message == "status_message_value" @@ -1480,18 +1451,18 @@ async def test_get_domain_async_from_dict(): def test_get_domain_field_headers(): client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = managed_identities_service.GetDomainRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_domain), "__call__") as call: call.return_value = resource.Domain() - client.get_domain(request) # Establish that the underlying gRPC stub method was called. @@ -1507,18 +1478,18 @@ def test_get_domain_field_headers(): @pytest.mark.asyncio async def test_get_domain_field_headers_async(): client = ManagedIdentitiesServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = managed_identities_service.GetDomainRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_domain), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(resource.Domain()) - await client.get_domain(request) # Establish that the underlying gRPC stub method was called. @@ -1533,14 +1504,13 @@ async def test_get_domain_field_headers_async(): def test_get_domain_flattened(): client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_domain), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = resource.Domain() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.get_domain(name="name_value",) @@ -1549,13 +1519,12 @@ def test_get_domain_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_get_domain_flattened_error(): client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1569,7 +1538,7 @@ def test_get_domain_flattened_error(): @pytest.mark.asyncio async def test_get_domain_flattened_async(): client = ManagedIdentitiesServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1586,14 +1555,13 @@ async def test_get_domain_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_domain_flattened_error_async(): client = ManagedIdentitiesServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1608,7 +1576,7 @@ def test_update_domain( transport: str = "grpc", request_type=managed_identities_service.UpdateDomainRequest ): client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1619,13 +1587,11 @@ def test_update_domain( with mock.patch.object(type(client.transport.update_domain), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.update_domain(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == managed_identities_service.UpdateDomainRequest() # Establish that the response is the type that we expect. @@ -1640,7 +1606,7 @@ def test_update_domain_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 = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1648,7 +1614,6 @@ def test_update_domain_empty_call(): client.update_domain() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == managed_identities_service.UpdateDomainRequest() @@ -1658,7 +1623,7 @@ async def test_update_domain_async( request_type=managed_identities_service.UpdateDomainRequest, ): client = ManagedIdentitiesServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1671,13 +1636,11 @@ async def test_update_domain_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.update_domain(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == managed_identities_service.UpdateDomainRequest() # Establish that the response is the type that we expect. @@ -1691,18 +1654,18 @@ async def test_update_domain_async_from_dict(): def test_update_domain_field_headers(): client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = managed_identities_service.UpdateDomainRequest() + request.domain.name = "domain.name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_domain), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.update_domain(request) # Establish that the underlying gRPC stub method was called. @@ -1718,12 +1681,13 @@ def test_update_domain_field_headers(): @pytest.mark.asyncio async def test_update_domain_field_headers_async(): client = ManagedIdentitiesServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = managed_identities_service.UpdateDomainRequest() + request.domain.name = "domain.name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1731,7 +1695,6 @@ async def test_update_domain_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.update_domain(request) # Establish that the underlying gRPC stub method was called. @@ -1746,34 +1709,31 @@ async def test_update_domain_field_headers_async(): def test_update_domain_flattened(): client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_domain), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.update_domain( domain=resource.Domain(name="name_value"), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].domain == resource.Domain(name="name_value") - - assert args[0].update_mask == field_mask.FieldMask(paths=["paths_value"]) + assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) def test_update_domain_flattened_error(): client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1782,14 +1742,14 @@ def test_update_domain_flattened_error(): client.update_domain( managed_identities_service.UpdateDomainRequest(), domain=resource.Domain(name="name_value"), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @pytest.mark.asyncio async def test_update_domain_flattened_async(): client = ManagedIdentitiesServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1804,23 +1764,21 @@ async def test_update_domain_flattened_async(): # using the keyword arguments to the method. response = await client.update_domain( domain=resource.Domain(name="name_value"), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].domain == resource.Domain(name="name_value") - - assert args[0].update_mask == field_mask.FieldMask(paths=["paths_value"]) + assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) @pytest.mark.asyncio async def test_update_domain_flattened_error_async(): client = ManagedIdentitiesServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1829,7 +1787,7 @@ async def test_update_domain_flattened_error_async(): await client.update_domain( managed_identities_service.UpdateDomainRequest(), domain=resource.Domain(name="name_value"), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @@ -1837,7 +1795,7 @@ def test_delete_domain( transport: str = "grpc", request_type=managed_identities_service.DeleteDomainRequest ): client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1848,13 +1806,11 @@ def test_delete_domain( with mock.patch.object(type(client.transport.delete_domain), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.delete_domain(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == managed_identities_service.DeleteDomainRequest() # Establish that the response is the type that we expect. @@ -1869,7 +1825,7 @@ def test_delete_domain_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 = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1877,7 +1833,6 @@ def test_delete_domain_empty_call(): client.delete_domain() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == managed_identities_service.DeleteDomainRequest() @@ -1887,7 +1842,7 @@ async def test_delete_domain_async( request_type=managed_identities_service.DeleteDomainRequest, ): client = ManagedIdentitiesServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1900,13 +1855,11 @@ async def test_delete_domain_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.delete_domain(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == managed_identities_service.DeleteDomainRequest() # Establish that the response is the type that we expect. @@ -1920,18 +1873,18 @@ async def test_delete_domain_async_from_dict(): def test_delete_domain_field_headers(): client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = managed_identities_service.DeleteDomainRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_domain), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.delete_domain(request) # Establish that the underlying gRPC stub method was called. @@ -1947,12 +1900,13 @@ def test_delete_domain_field_headers(): @pytest.mark.asyncio async def test_delete_domain_field_headers_async(): client = ManagedIdentitiesServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = managed_identities_service.DeleteDomainRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1960,7 +1914,6 @@ async def test_delete_domain_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.delete_domain(request) # Establish that the underlying gRPC stub method was called. @@ -1975,14 +1928,13 @@ async def test_delete_domain_field_headers_async(): def test_delete_domain_flattened(): client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_domain), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.delete_domain(name="name_value",) @@ -1991,13 +1943,12 @@ def test_delete_domain_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_delete_domain_flattened_error(): client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -2011,7 +1962,7 @@ def test_delete_domain_flattened_error(): @pytest.mark.asyncio async def test_delete_domain_flattened_async(): client = ManagedIdentitiesServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2030,14 +1981,13 @@ async def test_delete_domain_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_domain_flattened_error_async(): client = ManagedIdentitiesServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -2052,7 +2002,7 @@ def test_attach_trust( transport: str = "grpc", request_type=managed_identities_service.AttachTrustRequest ): client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2063,13 +2013,11 @@ def test_attach_trust( with mock.patch.object(type(client.transport.attach_trust), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.attach_trust(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == managed_identities_service.AttachTrustRequest() # Establish that the response is the type that we expect. @@ -2084,7 +2032,7 @@ def test_attach_trust_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 = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2092,7 +2040,6 @@ def test_attach_trust_empty_call(): client.attach_trust() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == managed_identities_service.AttachTrustRequest() @@ -2102,7 +2049,7 @@ async def test_attach_trust_async( request_type=managed_identities_service.AttachTrustRequest, ): client = ManagedIdentitiesServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2115,13 +2062,11 @@ async def test_attach_trust_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.attach_trust(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == managed_identities_service.AttachTrustRequest() # Establish that the response is the type that we expect. @@ -2135,18 +2080,18 @@ async def test_attach_trust_async_from_dict(): def test_attach_trust_field_headers(): client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = managed_identities_service.AttachTrustRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.attach_trust), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.attach_trust(request) # Establish that the underlying gRPC stub method was called. @@ -2162,12 +2107,13 @@ def test_attach_trust_field_headers(): @pytest.mark.asyncio async def test_attach_trust_field_headers_async(): client = ManagedIdentitiesServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = managed_identities_service.AttachTrustRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2175,7 +2121,6 @@ async def test_attach_trust_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.attach_trust(request) # Establish that the underlying gRPC stub method was called. @@ -2190,14 +2135,13 @@ async def test_attach_trust_field_headers_async(): def test_attach_trust_flattened(): client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.attach_trust), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.attach_trust( @@ -2209,9 +2153,7 @@ def test_attach_trust_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].trust == resource.Trust( target_domain_name="target_domain_name_value" ) @@ -2219,7 +2161,7 @@ def test_attach_trust_flattened(): def test_attach_trust_flattened_error(): client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -2235,7 +2177,7 @@ def test_attach_trust_flattened_error(): @pytest.mark.asyncio async def test_attach_trust_flattened_async(): client = ManagedIdentitiesServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2257,9 +2199,7 @@ async def test_attach_trust_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].trust == resource.Trust( target_domain_name="target_domain_name_value" ) @@ -2268,7 +2208,7 @@ async def test_attach_trust_flattened_async(): @pytest.mark.asyncio async def test_attach_trust_flattened_error_async(): client = ManagedIdentitiesServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -2286,7 +2226,7 @@ def test_reconfigure_trust( request_type=managed_identities_service.ReconfigureTrustRequest, ): client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2299,13 +2239,11 @@ def test_reconfigure_trust( ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.reconfigure_trust(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == managed_identities_service.ReconfigureTrustRequest() # Establish that the response is the type that we expect. @@ -2320,7 +2258,7 @@ def test_reconfigure_trust_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 = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2330,7 +2268,6 @@ def test_reconfigure_trust_empty_call(): client.reconfigure_trust() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == managed_identities_service.ReconfigureTrustRequest() @@ -2340,7 +2277,7 @@ async def test_reconfigure_trust_async( request_type=managed_identities_service.ReconfigureTrustRequest, ): client = ManagedIdentitiesServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2355,13 +2292,11 @@ async def test_reconfigure_trust_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.reconfigure_trust(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == managed_identities_service.ReconfigureTrustRequest() # Establish that the response is the type that we expect. @@ -2375,12 +2310,13 @@ async def test_reconfigure_trust_async_from_dict(): def test_reconfigure_trust_field_headers(): client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = managed_identities_service.ReconfigureTrustRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2388,7 +2324,6 @@ def test_reconfigure_trust_field_headers(): type(client.transport.reconfigure_trust), "__call__" ) as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.reconfigure_trust(request) # Establish that the underlying gRPC stub method was called. @@ -2404,12 +2339,13 @@ def test_reconfigure_trust_field_headers(): @pytest.mark.asyncio async def test_reconfigure_trust_field_headers_async(): client = ManagedIdentitiesServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = managed_identities_service.ReconfigureTrustRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2419,7 +2355,6 @@ async def test_reconfigure_trust_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.reconfigure_trust(request) # Establish that the underlying gRPC stub method was called. @@ -2434,7 +2369,7 @@ async def test_reconfigure_trust_field_headers_async(): def test_reconfigure_trust_flattened(): client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2443,7 +2378,6 @@ def test_reconfigure_trust_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.reconfigure_trust( @@ -2456,17 +2390,14 @@ def test_reconfigure_trust_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].target_domain_name == "target_domain_name_value" - assert args[0].target_dns_ip_addresses == ["target_dns_ip_addresses_value"] def test_reconfigure_trust_flattened_error(): client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -2483,7 +2414,7 @@ def test_reconfigure_trust_flattened_error(): @pytest.mark.asyncio async def test_reconfigure_trust_flattened_async(): client = ManagedIdentitiesServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2508,18 +2439,15 @@ async def test_reconfigure_trust_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].target_domain_name == "target_domain_name_value" - assert args[0].target_dns_ip_addresses == ["target_dns_ip_addresses_value"] @pytest.mark.asyncio async def test_reconfigure_trust_flattened_error_async(): client = ManagedIdentitiesServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -2537,7 +2465,7 @@ def test_detach_trust( transport: str = "grpc", request_type=managed_identities_service.DetachTrustRequest ): client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2548,13 +2476,11 @@ def test_detach_trust( with mock.patch.object(type(client.transport.detach_trust), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.detach_trust(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == managed_identities_service.DetachTrustRequest() # Establish that the response is the type that we expect. @@ -2569,7 +2495,7 @@ def test_detach_trust_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 = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2577,7 +2503,6 @@ def test_detach_trust_empty_call(): client.detach_trust() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == managed_identities_service.DetachTrustRequest() @@ -2587,7 +2512,7 @@ async def test_detach_trust_async( request_type=managed_identities_service.DetachTrustRequest, ): client = ManagedIdentitiesServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2600,13 +2525,11 @@ async def test_detach_trust_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.detach_trust(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == managed_identities_service.DetachTrustRequest() # Establish that the response is the type that we expect. @@ -2620,18 +2543,18 @@ async def test_detach_trust_async_from_dict(): def test_detach_trust_field_headers(): client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = managed_identities_service.DetachTrustRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.detach_trust), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.detach_trust(request) # Establish that the underlying gRPC stub method was called. @@ -2647,12 +2570,13 @@ def test_detach_trust_field_headers(): @pytest.mark.asyncio async def test_detach_trust_field_headers_async(): client = ManagedIdentitiesServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = managed_identities_service.DetachTrustRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2660,7 +2584,6 @@ async def test_detach_trust_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.detach_trust(request) # Establish that the underlying gRPC stub method was called. @@ -2675,14 +2598,13 @@ async def test_detach_trust_field_headers_async(): def test_detach_trust_flattened(): client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.detach_trust), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.detach_trust( @@ -2694,9 +2616,7 @@ def test_detach_trust_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].trust == resource.Trust( target_domain_name="target_domain_name_value" ) @@ -2704,7 +2624,7 @@ def test_detach_trust_flattened(): def test_detach_trust_flattened_error(): client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -2720,7 +2640,7 @@ def test_detach_trust_flattened_error(): @pytest.mark.asyncio async def test_detach_trust_flattened_async(): client = ManagedIdentitiesServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2742,9 +2662,7 @@ async def test_detach_trust_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].trust == resource.Trust( target_domain_name="target_domain_name_value" ) @@ -2753,7 +2671,7 @@ async def test_detach_trust_flattened_async(): @pytest.mark.asyncio async def test_detach_trust_flattened_error_async(): client = ManagedIdentitiesServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -2771,7 +2689,7 @@ def test_validate_trust( request_type=managed_identities_service.ValidateTrustRequest, ): client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2782,13 +2700,11 @@ def test_validate_trust( with mock.patch.object(type(client.transport.validate_trust), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.validate_trust(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == managed_identities_service.ValidateTrustRequest() # Establish that the response is the type that we expect. @@ -2803,7 +2719,7 @@ def test_validate_trust_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 = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2811,7 +2727,6 @@ def test_validate_trust_empty_call(): client.validate_trust() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == managed_identities_service.ValidateTrustRequest() @@ -2821,7 +2736,7 @@ async def test_validate_trust_async( request_type=managed_identities_service.ValidateTrustRequest, ): client = ManagedIdentitiesServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2834,13 +2749,11 @@ async def test_validate_trust_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.validate_trust(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == managed_identities_service.ValidateTrustRequest() # Establish that the response is the type that we expect. @@ -2854,18 +2767,18 @@ async def test_validate_trust_async_from_dict(): def test_validate_trust_field_headers(): client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = managed_identities_service.ValidateTrustRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.validate_trust), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.validate_trust(request) # Establish that the underlying gRPC stub method was called. @@ -2881,12 +2794,13 @@ def test_validate_trust_field_headers(): @pytest.mark.asyncio async def test_validate_trust_field_headers_async(): client = ManagedIdentitiesServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = managed_identities_service.ValidateTrustRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2894,7 +2808,6 @@ async def test_validate_trust_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.validate_trust(request) # Establish that the underlying gRPC stub method was called. @@ -2909,14 +2822,13 @@ async def test_validate_trust_field_headers_async(): def test_validate_trust_flattened(): client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.validate_trust), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.validate_trust( @@ -2928,9 +2840,7 @@ def test_validate_trust_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].trust == resource.Trust( target_domain_name="target_domain_name_value" ) @@ -2938,7 +2848,7 @@ def test_validate_trust_flattened(): def test_validate_trust_flattened_error(): client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -2954,7 +2864,7 @@ def test_validate_trust_flattened_error(): @pytest.mark.asyncio async def test_validate_trust_flattened_async(): client = ManagedIdentitiesServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2976,9 +2886,7 @@ async def test_validate_trust_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].trust == resource.Trust( target_domain_name="target_domain_name_value" ) @@ -2987,7 +2895,7 @@ async def test_validate_trust_flattened_async(): @pytest.mark.asyncio async def test_validate_trust_flattened_error_async(): client = ManagedIdentitiesServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -3003,16 +2911,16 @@ async def test_validate_trust_flattened_error_async(): def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.ManagedIdentitiesServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = ManagedIdentitiesServiceClient( - 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.ManagedIdentitiesServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = ManagedIdentitiesServiceClient( @@ -3022,7 +2930,7 @@ def test_credentials_transport_error(): # It is an error to provide scopes and a transport instance. transport = transports.ManagedIdentitiesServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = ManagedIdentitiesServiceClient( @@ -3033,7 +2941,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.ManagedIdentitiesServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) client = ManagedIdentitiesServiceClient(transport=transport) assert client.transport is transport @@ -3042,13 +2950,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.ManagedIdentitiesServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel transport = transports.ManagedIdentitiesServiceGrpcAsyncIOTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel @@ -3063,8 +2971,8 @@ def test_transport_get_channel(): ) def test_transport_adc(transport_class): # Test default credentials are used if not provided. - with mock.patch.object(auth, "default") as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport_class() adc.assert_called_once() @@ -3072,7 +2980,7 @@ def test_transport_adc(transport_class): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) assert isinstance( client.transport, transports.ManagedIdentitiesServiceGrpcTransport, @@ -3081,9 +2989,9 @@ def test_transport_grpc_default(): def test_managed_identities_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.ManagedIdentitiesServiceTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), credentials_file="credentials.json", ) @@ -3095,7 +3003,7 @@ def test_managed_identities_service_base_transport(): ) as Transport: Transport.return_value = None transport = transports.ManagedIdentitiesServiceTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Every method on the transport should just blindly @@ -3122,15 +3030,37 @@ def test_managed_identities_service_base_transport(): transport.operations_client +@requires_google_auth_gte_1_25_0 def test_managed_identities_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.managedidentities_v1.services.managed_identities_service.transports.ManagedIdentitiesServiceTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.ManagedIdentitiesServiceTransport( + credentials_file="credentials.json", quota_project_id="octopus", + ) + load_creds.assert_called_once_with( + "credentials.json", + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", + ) + + +@requires_google_auth_lt_1_25_0 +def test_managed_identities_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.managedidentities_v1.services.managed_identities_service.transports.ManagedIdentitiesServiceTransport._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.ManagedIdentitiesServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", ) @@ -3143,19 +3073,33 @@ def test_managed_identities_service_base_transport_with_credentials_file(): def test_managed_identities_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.managedidentities_v1.services.managed_identities_service.transports.ManagedIdentitiesServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (credentials.AnonymousCredentials(), None) + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ManagedIdentitiesServiceTransport() adc.assert_called_once() +@requires_google_auth_gte_1_25_0 def test_managed_identities_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) + ManagedIdentitiesServiceClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id=None, + ) + + +@requires_google_auth_lt_1_25_0 +def test_managed_identities_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) ManagedIdentitiesServiceClient() adc.assert_called_once_with( scopes=("https://www.googleapis.com/auth/cloud-platform",), @@ -3163,20 +3107,158 @@ def test_managed_identities_service_auth_adc(): ) -def test_managed_identities_service_transport_auth_adc(): +@pytest.mark.parametrize( + "transport_class", + [ + transports.ManagedIdentitiesServiceGrpcTransport, + transports.ManagedIdentitiesServiceGrpcAsyncIOTransport, + ], +) +@requires_google_auth_gte_1_25_0 +def test_managed_identities_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.ManagedIdentitiesServiceGrpcTransport( - host="squid.clam.whelk", quota_project_id="octopus" + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + adc.assert_called_once_with( + scopes=["1", "2"], + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.ManagedIdentitiesServiceGrpcTransport, + transports.ManagedIdentitiesServiceGrpcAsyncIOTransport, + ], +) +@requires_google_auth_lt_1_25_0 +def test_managed_identities_service_transport_auth_adc_old_google_auth(transport_class): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus") adc.assert_called_once_with( scopes=("https://www.googleapis.com/auth/cloud-platform",), quota_project_id="octopus", ) +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.ManagedIdentitiesServiceGrpcTransport, grpc_helpers), + (transports.ManagedIdentitiesServiceGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_gte_1_26_0 +def test_managed_identities_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( + "managedidentities.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=["1", "2"], + default_host="managedidentities.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.ManagedIdentitiesServiceGrpcTransport, grpc_helpers), + (transports.ManagedIdentitiesServiceGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_managed_identities_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( + "managedidentities.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + scopes=("https://www.googleapis.com/auth/cloud-platform",), + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.ManagedIdentitiesServiceGrpcTransport, grpc_helpers), + (transports.ManagedIdentitiesServiceGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_managed_identities_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( + "managedidentities.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", [ @@ -3187,7 +3269,7 @@ def test_managed_identities_service_transport_auth_adc(): def test_managed_identities_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: @@ -3226,7 +3308,7 @@ def test_managed_identities_service_grpc_transport_client_cert_source_for_mtls( def test_managed_identities_service_host_no_port(): client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="managedidentities.googleapis.com" ), @@ -3236,7 +3318,7 @@ def test_managed_identities_service_host_no_port(): def test_managed_identities_service_host_with_port(): client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="managedidentities.googleapis.com:8000" ), @@ -3292,9 +3374,9 @@ def test_managed_identities_service_transport_channel_mtls_with_client_cert_sour mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = credentials.AnonymousCredentials() + cred = ga_credentials.AnonymousCredentials() with pytest.warns(DeprecationWarning): - with mock.patch.object(auth, "default") as adc: + with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) transport = transport_class( host="squid.clam.whelk", @@ -3370,7 +3452,7 @@ def test_managed_identities_service_transport_channel_mtls_with_adc(transport_cl def test_managed_identities_service_grpc_lro_client(): client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) transport = client.transport @@ -3383,7 +3465,7 @@ def test_managed_identities_service_grpc_lro_client(): def test_managed_identities_service_grpc_lro_async_client(): client = ManagedIdentitiesServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", ) transport = client.transport @@ -3398,7 +3480,6 @@ def test_domain_path(): project = "squid" location = "clam" domain = "whelk" - expected = "projects/{project}/locations/{location}/domains/{domain}".format( project=project, location=location, domain=domain, ) @@ -3421,7 +3502,6 @@ def test_parse_domain_path(): def test_common_billing_account_path(): billing_account = "cuttlefish" - expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -3442,7 +3522,6 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "winkle" - expected = "folders/{folder}".format(folder=folder,) actual = ManagedIdentitiesServiceClient.common_folder_path(folder) assert expected == actual @@ -3461,7 +3540,6 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "scallop" - expected = "organizations/{organization}".format(organization=organization,) actual = ManagedIdentitiesServiceClient.common_organization_path(organization) assert expected == actual @@ -3480,7 +3558,6 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "squid" - expected = "projects/{project}".format(project=project,) actual = ManagedIdentitiesServiceClient.common_project_path(project) assert expected == actual @@ -3500,7 +3577,6 @@ def test_parse_common_project_path(): def test_common_location_path(): project = "whelk" location = "octopus" - expected = "projects/{project}/locations/{location}".format( project=project, location=location, ) @@ -3527,7 +3603,7 @@ def test_client_withDEFAULT_CLIENT_INFO(): transports.ManagedIdentitiesServiceTransport, "_prep_wrapped_messages" ) as prep: client = ManagedIdentitiesServiceClient( - credentials=credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -3536,6 +3612,6 @@ def test_client_withDEFAULT_CLIENT_INFO(): ) as prep: transport_class = ManagedIdentitiesServiceClient.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)