diff --git a/docs/assuredworkloads_v1beta1/assured_workloads_service.rst b/docs/assuredworkloads_v1beta1/assured_workloads_service.rst index 9291a34..bd798cb 100644 --- a/docs/assuredworkloads_v1beta1/assured_workloads_service.rst +++ b/docs/assuredworkloads_v1beta1/assured_workloads_service.rst @@ -5,7 +5,6 @@ AssuredWorkloadsService :members: :inherited-members: - .. automodule:: google.cloud.assuredworkloads_v1beta1.services.assured_workloads_service.pagers :members: :inherited-members: diff --git a/google/cloud/assuredworkloads/__init__.py b/google/cloud/assuredworkloads/__init__.py index 74bd0eb..b362e11 100644 --- a/google/cloud/assuredworkloads/__init__.py +++ b/google/cloud/assuredworkloads/__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.assuredworkloads_v1beta1.services.assured_workloads_service.async_client import ( - AssuredWorkloadsServiceAsyncClient, -) from google.cloud.assuredworkloads_v1beta1.services.assured_workloads_service.client import ( AssuredWorkloadsServiceClient, ) +from google.cloud.assuredworkloads_v1beta1.services.assured_workloads_service.async_client import ( + AssuredWorkloadsServiceAsyncClient, +) + from google.cloud.assuredworkloads_v1beta1.types.assuredworkloads_v1beta1 import ( CreateWorkloadOperationMetadata, ) @@ -47,8 +47,8 @@ ) __all__ = ( - "AssuredWorkloadsServiceAsyncClient", "AssuredWorkloadsServiceClient", + "AssuredWorkloadsServiceAsyncClient", "CreateWorkloadOperationMetadata", "CreateWorkloadRequest", "DeleteWorkloadRequest", diff --git a/google/cloud/assuredworkloads_v1beta1/__init__.py b/google/cloud/assuredworkloads_v1beta1/__init__.py index cd06fba..8c635a0 100644 --- a/google/cloud/assuredworkloads_v1beta1/__init__.py +++ b/google/cloud/assuredworkloads_v1beta1/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,6 +15,8 @@ # from .services.assured_workloads_service import AssuredWorkloadsServiceClient +from .services.assured_workloads_service import AssuredWorkloadsServiceAsyncClient + from .types.assuredworkloads_v1beta1 import CreateWorkloadOperationMetadata from .types.assuredworkloads_v1beta1 import CreateWorkloadRequest from .types.assuredworkloads_v1beta1 import DeleteWorkloadRequest @@ -25,8 +26,9 @@ from .types.assuredworkloads_v1beta1 import UpdateWorkloadRequest from .types.assuredworkloads_v1beta1 import Workload - __all__ = ( + "AssuredWorkloadsServiceAsyncClient", + "AssuredWorkloadsServiceClient", "CreateWorkloadOperationMetadata", "CreateWorkloadRequest", "DeleteWorkloadRequest", @@ -35,5 +37,4 @@ "ListWorkloadsResponse", "UpdateWorkloadRequest", "Workload", - "AssuredWorkloadsServiceClient", ) diff --git a/google/cloud/assuredworkloads_v1beta1/gapic_metadata.json b/google/cloud/assuredworkloads_v1beta1/gapic_metadata.json new file mode 100644 index 0000000..38803a0 --- /dev/null +++ b/google/cloud/assuredworkloads_v1beta1/gapic_metadata.json @@ -0,0 +1,73 @@ + { + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", + "language": "python", + "libraryPackage": "google.cloud.assuredworkloads_v1beta1", + "protoPackage": "google.cloud.assuredworkloads.v1beta1", + "schema": "1.0", + "services": { + "AssuredWorkloadsService": { + "clients": { + "grpc": { + "libraryClient": "AssuredWorkloadsServiceClient", + "rpcs": { + "CreateWorkload": { + "methods": [ + "create_workload" + ] + }, + "DeleteWorkload": { + "methods": [ + "delete_workload" + ] + }, + "GetWorkload": { + "methods": [ + "get_workload" + ] + }, + "ListWorkloads": { + "methods": [ + "list_workloads" + ] + }, + "UpdateWorkload": { + "methods": [ + "update_workload" + ] + } + } + }, + "grpc-async": { + "libraryClient": "AssuredWorkloadsServiceAsyncClient", + "rpcs": { + "CreateWorkload": { + "methods": [ + "create_workload" + ] + }, + "DeleteWorkload": { + "methods": [ + "delete_workload" + ] + }, + "GetWorkload": { + "methods": [ + "get_workload" + ] + }, + "ListWorkloads": { + "methods": [ + "list_workloads" + ] + }, + "UpdateWorkload": { + "methods": [ + "update_workload" + ] + } + } + } + } + } + } +} diff --git a/google/cloud/assuredworkloads_v1beta1/services/__init__.py b/google/cloud/assuredworkloads_v1beta1/services/__init__.py index 42ffdf2..4de6597 100644 --- a/google/cloud/assuredworkloads_v1beta1/services/__init__.py +++ b/google/cloud/assuredworkloads_v1beta1/services/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/__init__.py b/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/__init__.py index 100757c..a88dc7c 100644 --- a/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/__init__.py +++ b/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_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 AssuredWorkloadsServiceClient from .async_client import AssuredWorkloadsServiceAsyncClient diff --git a/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/async_client.py b/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/async_client.py index ca738cc..f91ce0d 100644 --- a/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/async_client.py +++ b/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_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 @@ -34,9 +32,8 @@ pagers, ) from google.cloud.assuredworkloads_v1beta1.types import assuredworkloads_v1beta1 -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 from .transports.base import AssuredWorkloadsServiceTransport, DEFAULT_CLIENT_INFO from .transports.grpc_asyncio import AssuredWorkloadsServiceGrpcAsyncIOTransport from .client import AssuredWorkloadsServiceClient @@ -54,33 +51,28 @@ class AssuredWorkloadsServiceAsyncClient: parse_workload_path = staticmethod( AssuredWorkloadsServiceClient.parse_workload_path ) - common_billing_account_path = staticmethod( AssuredWorkloadsServiceClient.common_billing_account_path ) parse_common_billing_account_path = staticmethod( AssuredWorkloadsServiceClient.parse_common_billing_account_path ) - common_folder_path = staticmethod(AssuredWorkloadsServiceClient.common_folder_path) parse_common_folder_path = staticmethod( AssuredWorkloadsServiceClient.parse_common_folder_path ) - common_organization_path = staticmethod( AssuredWorkloadsServiceClient.common_organization_path ) parse_common_organization_path = staticmethod( AssuredWorkloadsServiceClient.parse_common_organization_path ) - common_project_path = staticmethod( AssuredWorkloadsServiceClient.common_project_path ) parse_common_project_path = staticmethod( AssuredWorkloadsServiceClient.parse_common_project_path ) - common_location_path = staticmethod( AssuredWorkloadsServiceClient.common_location_path ) @@ -90,7 +82,8 @@ class AssuredWorkloadsServiceAsyncClient: @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. @@ -105,7 +98,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 @@ -122,7 +115,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> AssuredWorkloadsServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: AssuredWorkloadsServiceTransport: The transport used by the client instance. @@ -137,12 +130,12 @@ def transport(self) -> AssuredWorkloadsServiceTransport: def __init__( self, *, - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, transport: Union[str, AssuredWorkloadsServiceTransport] = "grpc_asyncio", client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the assured workloads service client. + """Instantiates the assured workloads service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -174,7 +167,6 @@ def __init__( google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport creation failed for any reason. """ - self._client = AssuredWorkloadsServiceClient( credentials=credentials, transport=transport, @@ -210,7 +202,6 @@ async def create_workload( This corresponds to the ``workload`` 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. @@ -239,7 +230,6 @@ async def create_workload( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if workload is not None: @@ -278,7 +268,7 @@ async def update_workload( request: assuredworkloads_v1beta1.UpdateWorkloadRequest = None, *, workload: assuredworkloads_v1beta1.Workload = 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]] = (), @@ -307,7 +297,6 @@ async def update_workload( 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. @@ -335,7 +324,6 @@ async def update_workload( # If we have keyword arguments corresponding to fields on the # request, apply these. - if workload is not None: request.workload = workload if update_mask is not None: @@ -387,7 +375,6 @@ async def delete_workload( 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. @@ -408,7 +395,6 @@ async def delete_workload( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -420,7 +406,9 @@ async def delete_workload( initial=0.2, maximum=30.0, multiplier=1.3, - predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), deadline=60.0, ), default_timeout=60.0, @@ -463,7 +451,6 @@ async def get_workload( 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. @@ -491,7 +478,6 @@ async def get_workload( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -503,7 +489,9 @@ async def get_workload( initial=0.2, maximum=30.0, multiplier=1.3, - predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), deadline=60.0, ), default_timeout=60.0, @@ -545,7 +533,6 @@ async def list_workloads( 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. @@ -574,7 +561,6 @@ async def list_workloads( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -586,7 +572,9 @@ async def list_workloads( initial=0.2, maximum=30.0, multiplier=1.3, - predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), deadline=60.0, ), default_timeout=60.0, diff --git a/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/client.py b/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/client.py index bd9655e..6156a3f 100644 --- a/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/client.py +++ b/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_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 @@ -38,9 +36,8 @@ pagers, ) from google.cloud.assuredworkloads_v1beta1.types import assuredworkloads_v1beta1 -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 from .transports.base import AssuredWorkloadsServiceTransport, DEFAULT_CLIENT_INFO from .transports.grpc import AssuredWorkloadsServiceGrpcTransport from .transports.grpc_asyncio import AssuredWorkloadsServiceGrpcAsyncIOTransport @@ -63,7 +60,7 @@ class AssuredWorkloadsServiceClientMeta(type): def get_transport_class( cls, label: str = None, ) -> Type[AssuredWorkloadsServiceTransport]: - """Return an appropriate transport class. + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -86,7 +83,8 @@ class AssuredWorkloadsServiceClient(metaclass=AssuredWorkloadsServiceClientMeta) @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: @@ -120,7 +118,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. @@ -137,7 +136,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 @@ -156,23 +155,24 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> AssuredWorkloadsServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - AssuredWorkloadsServiceTransport: The transport used by the client instance. + AssuredWorkloadsServiceTransport: The transport used by the client + instance. """ return self._transport @staticmethod def workload_path(organization: str, location: str, workload: str,) -> str: - """Return a fully-qualified workload string.""" + """Returns a fully-qualified workload string.""" return "organizations/{organization}/locations/{location}/workloads/{workload}".format( organization=organization, location=location, workload=workload, ) @staticmethod def parse_workload_path(path: str) -> Dict[str, str]: - """Parse a workload path into its component segments.""" + """Parses a workload path into its component segments.""" m = re.match( r"^organizations/(?P.+?)/locations/(?P.+?)/workloads/(?P.+?)$", path, @@ -181,7 +181,7 @@ def parse_workload_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, ) @@ -194,7 +194,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 @@ -205,7 +205,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 @@ -216,7 +216,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 @@ -227,7 +227,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, ) @@ -241,12 +241,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, AssuredWorkloadsServiceTransport, None] = None, client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the assured workloads service client. + """Instantiates the assured workloads service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -301,9 +301,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: @@ -315,12 +316,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. @@ -335,8 +338,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: @@ -379,7 +382,6 @@ def create_workload( This corresponds to the ``workload`` 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. @@ -410,10 +412,8 @@ def create_workload( # there are no flattened fields. if not isinstance(request, assuredworkloads_v1beta1.CreateWorkloadRequest): request = assuredworkloads_v1beta1.CreateWorkloadRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if workload is not None: @@ -448,7 +448,7 @@ def update_workload( request: assuredworkloads_v1beta1.UpdateWorkloadRequest = None, *, workload: assuredworkloads_v1beta1.Workload = 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]] = (), @@ -477,7 +477,6 @@ def update_workload( 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. @@ -507,10 +506,8 @@ def update_workload( # there are no flattened fields. if not isinstance(request, assuredworkloads_v1beta1.UpdateWorkloadRequest): request = assuredworkloads_v1beta1.UpdateWorkloadRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if workload is not None: request.workload = workload if update_mask is not None: @@ -558,7 +555,6 @@ def delete_workload( 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. @@ -581,10 +577,8 @@ def delete_workload( # there are no flattened fields. if not isinstance(request, assuredworkloads_v1beta1.DeleteWorkloadRequest): request = assuredworkloads_v1beta1.DeleteWorkloadRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -628,7 +622,6 @@ def get_workload( 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. @@ -658,10 +651,8 @@ def get_workload( # there are no flattened fields. if not isinstance(request, assuredworkloads_v1beta1.GetWorkloadRequest): request = assuredworkloads_v1beta1.GetWorkloadRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -704,7 +695,6 @@ def list_workloads( 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. @@ -735,10 +725,8 @@ def list_workloads( # there are no flattened fields. if not isinstance(request, assuredworkloads_v1beta1.ListWorkloadsRequest): request = assuredworkloads_v1beta1.ListWorkloadsRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent diff --git a/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/pagers.py b/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/pagers.py index 5ff263b..061c475 100644 --- a/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/pagers.py +++ b/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_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, @@ -119,7 +117,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/assuredworkloads_v1beta1/services/assured_workloads_service/transports/__init__.py b/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/transports/__init__.py index 7850a2b..d0ed01e 100644 --- a/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/transports/__init__.py +++ b/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_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/assuredworkloads_v1beta1/services/assured_workloads_service/transports/base.py b/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/transports/base.py index a9e8c02..2d48784 100644 --- a/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/transports/base.py +++ b/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_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.assuredworkloads_v1beta1.types import assuredworkloads_v1beta1 -from google.longrunning import operations_pb2 as operations # type: ignore -from google.protobuf import empty_pb2 as empty # type: ignore - +from google.longrunning import operations_pb2 # type: ignore +from google.protobuf import empty_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 AssuredWorkloadsServiceTransport(abc.ABC): """Abstract transport class for AssuredWorkloadsService.""" AUTH_SCOPES = ("https://www.googleapis.com/auth/cloud-platform",) + DEFAULT_HOST: str = "assuredworkloads.googleapis.com" + def __init__( self, *, - host: str = "assuredworkloads.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 = { @@ -121,7 +181,9 @@ def _prep_wrapped_messages(self, client_info): initial=0.2, maximum=30.0, multiplier=1.3, - predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), deadline=60.0, ), default_timeout=60.0, @@ -133,7 +195,9 @@ def _prep_wrapped_messages(self, client_info): initial=0.2, maximum=30.0, multiplier=1.3, - predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), deadline=60.0, ), default_timeout=60.0, @@ -145,7 +209,9 @@ def _prep_wrapped_messages(self, client_info): initial=0.2, maximum=30.0, multiplier=1.3, - predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), deadline=60.0, ), default_timeout=60.0, @@ -161,20 +227,20 @@ def operations_client(self) -> operations_v1.OperationsClient: @property def create_workload( self, - ) -> typing.Callable[ + ) -> Callable[ [assuredworkloads_v1beta1.CreateWorkloadRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def update_workload( self, - ) -> typing.Callable[ + ) -> Callable[ [assuredworkloads_v1beta1.UpdateWorkloadRequest], - typing.Union[ + Union[ assuredworkloads_v1beta1.Workload, - typing.Awaitable[assuredworkloads_v1beta1.Workload], + Awaitable[assuredworkloads_v1beta1.Workload], ], ]: raise NotImplementedError() @@ -182,20 +248,20 @@ def update_workload( @property def delete_workload( self, - ) -> typing.Callable[ + ) -> Callable[ [assuredworkloads_v1beta1.DeleteWorkloadRequest], - typing.Union[empty.Empty, typing.Awaitable[empty.Empty]], + Union[empty_pb2.Empty, Awaitable[empty_pb2.Empty]], ]: raise NotImplementedError() @property def get_workload( self, - ) -> typing.Callable[ + ) -> Callable[ [assuredworkloads_v1beta1.GetWorkloadRequest], - typing.Union[ + Union[ assuredworkloads_v1beta1.Workload, - typing.Awaitable[assuredworkloads_v1beta1.Workload], + Awaitable[assuredworkloads_v1beta1.Workload], ], ]: raise NotImplementedError() @@ -203,11 +269,11 @@ def get_workload( @property def list_workloads( self, - ) -> typing.Callable[ + ) -> Callable[ [assuredworkloads_v1beta1.ListWorkloadsRequest], - typing.Union[ + Union[ assuredworkloads_v1beta1.ListWorkloadsResponse, - typing.Awaitable[assuredworkloads_v1beta1.ListWorkloadsResponse], + Awaitable[assuredworkloads_v1beta1.ListWorkloadsResponse], ], ]: raise NotImplementedError() diff --git a/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/transports/grpc.py b/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/transports/grpc.py index e3f4436..0319f09 100644 --- a/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/transports/grpc.py +++ b/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_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.assuredworkloads_v1beta1.types import assuredworkloads_v1beta1 -from google.longrunning import operations_pb2 as operations # type: ignore -from google.protobuf import empty_pb2 as empty # type: ignore - +from google.longrunning import operations_pb2 # type: ignore +from google.protobuf import empty_pb2 # type: ignore from .base import AssuredWorkloadsServiceTransport, DEFAULT_CLIENT_INFO @@ -53,7 +50,7 @@ def __init__( self, *, host: str = "assuredworkloads.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: str = None, scopes: Sequence[str] = None, channel: grpc.Channel = None, @@ -67,7 +64,8 @@ def __init__( """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -178,7 +176,7 @@ def __init__( def create_channel( cls, host: str = "assuredworkloads.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, @@ -209,13 +207,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, ) @@ -243,7 +243,7 @@ def operations_client(self) -> operations_v1.OperationsClient: def create_workload( self, ) -> Callable[ - [assuredworkloads_v1beta1.CreateWorkloadRequest], operations.Operation + [assuredworkloads_v1beta1.CreateWorkloadRequest], operations_pb2.Operation ]: r"""Return a callable for the create workload method over gRPC. @@ -263,7 +263,7 @@ def create_workload( self._stubs["create_workload"] = self.grpc_channel.unary_unary( "/google.cloud.assuredworkloads.v1beta1.AssuredWorkloadsService/CreateWorkload", request_serializer=assuredworkloads_v1beta1.CreateWorkloadRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["create_workload"] @@ -302,7 +302,7 @@ def update_workload( @property def delete_workload( self, - ) -> Callable[[assuredworkloads_v1beta1.DeleteWorkloadRequest], empty.Empty]: + ) -> Callable[[assuredworkloads_v1beta1.DeleteWorkloadRequest], empty_pb2.Empty]: r"""Return a callable for the delete workload method over gRPC. Deletes the workload. Make sure that workload's direct children @@ -323,7 +323,7 @@ def delete_workload( self._stubs["delete_workload"] = self.grpc_channel.unary_unary( "/google.cloud.assuredworkloads.v1beta1.AssuredWorkloadsService/DeleteWorkload", request_serializer=assuredworkloads_v1beta1.DeleteWorkloadRequest.serialize, - response_deserializer=empty.Empty.FromString, + response_deserializer=empty_pb2.Empty.FromString, ) return self._stubs["delete_workload"] diff --git a/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/transports/grpc_asyncio.py b/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/transports/grpc_asyncio.py index 30e1060..fcef1cc 100644 --- a/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/transports/grpc_asyncio.py +++ b/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_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.assuredworkloads_v1beta1.types import assuredworkloads_v1beta1 -from google.longrunning import operations_pb2 as operations # type: ignore -from google.protobuf import empty_pb2 as empty # type: ignore - +from google.longrunning import operations_pb2 # type: ignore +from google.protobuf import empty_pb2 # type: ignore from .base import AssuredWorkloadsServiceTransport, DEFAULT_CLIENT_INFO from .grpc import AssuredWorkloadsServiceGrpcTransport @@ -56,7 +53,7 @@ class AssuredWorkloadsServiceGrpcAsyncIOTransport(AssuredWorkloadsServiceTranspo def create_channel( cls, host: str = "assuredworkloads.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, @@ -83,13 +80,15 @@ def create_channel( Returns: aio.Channel: A gRPC AsyncIO channel object. """ - scopes = scopes or cls.AUTH_SCOPES + + self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) + return grpc_helpers_async.create_channel( host, credentials=credentials, credentials_file=credentials_file, - scopes=scopes, quota_project_id=quota_project_id, + **self_signed_jwt_kwargs, **kwargs, ) @@ -97,7 +96,7 @@ def __init__( self, *, host: str = "assuredworkloads.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, channel: aio.Channel = None, @@ -111,7 +110,8 @@ def __init__( """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -170,7 +170,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 @@ -250,7 +249,7 @@ def create_workload( self, ) -> Callable[ [assuredworkloads_v1beta1.CreateWorkloadRequest], - Awaitable[operations.Operation], + Awaitable[operations_pb2.Operation], ]: r"""Return a callable for the create workload method over gRPC. @@ -270,7 +269,7 @@ def create_workload( self._stubs["create_workload"] = self.grpc_channel.unary_unary( "/google.cloud.assuredworkloads.v1beta1.AssuredWorkloadsService/CreateWorkload", request_serializer=assuredworkloads_v1beta1.CreateWorkloadRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["create_workload"] @@ -310,7 +309,7 @@ def update_workload( def delete_workload( self, ) -> Callable[ - [assuredworkloads_v1beta1.DeleteWorkloadRequest], Awaitable[empty.Empty] + [assuredworkloads_v1beta1.DeleteWorkloadRequest], Awaitable[empty_pb2.Empty] ]: r"""Return a callable for the delete workload method over gRPC. @@ -332,7 +331,7 @@ def delete_workload( self._stubs["delete_workload"] = self.grpc_channel.unary_unary( "/google.cloud.assuredworkloads.v1beta1.AssuredWorkloadsService/DeleteWorkload", request_serializer=assuredworkloads_v1beta1.DeleteWorkloadRequest.serialize, - response_deserializer=empty.Empty.FromString, + response_deserializer=empty_pb2.Empty.FromString, ) return self._stubs["delete_workload"] diff --git a/google/cloud/assuredworkloads_v1beta1/types/__init__.py b/google/cloud/assuredworkloads_v1beta1/types/__init__.py index 5adf85b..76da280 100644 --- a/google/cloud/assuredworkloads_v1beta1/types/__init__.py +++ b/google/cloud/assuredworkloads_v1beta1/types/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from .assuredworkloads_v1beta1 import ( CreateWorkloadOperationMetadata, CreateWorkloadRequest, diff --git a/google/cloud/assuredworkloads_v1beta1/types/assuredworkloads_v1beta1.py b/google/cloud/assuredworkloads_v1beta1/types/assuredworkloads_v1beta1.py index 96b42e2..e489500 100644 --- a/google/cloud/assuredworkloads_v1beta1/types/assuredworkloads_v1beta1.py +++ b/google/cloud/assuredworkloads_v1beta1/types/assuredworkloads_v1beta1.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,13 +13,11 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - -from google.protobuf import duration_pb2 as duration # 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 duration_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore __protobuf__ = proto.module( @@ -40,7 +37,6 @@ class CreateWorkloadRequest(proto.Message): r"""Request for creating a workload. - Attributes: parent (str): Required. The resource name of the new Workload's parent. @@ -57,16 +53,13 @@ class CreateWorkloadRequest(proto.Message): projects with the identifier as the value. """ - parent = proto.Field(proto.STRING, number=1) - + parent = proto.Field(proto.STRING, number=1,) workload = proto.Field(proto.MESSAGE, number=2, message="Workload",) - - external_id = proto.Field(proto.STRING, number=3) + external_id = proto.Field(proto.STRING, number=3,) class UpdateWorkloadRequest(proto.Message): r"""Request for Updating a workload. - Attributes: workload (google.cloud.assuredworkloads_v1beta1.types.Workload): Required. The workload to update. The workload’s ``name`` @@ -78,13 +71,13 @@ class UpdateWorkloadRequest(proto.Message): """ workload = proto.Field(proto.MESSAGE, number=1, message="Workload",) - - update_mask = proto.Field(proto.MESSAGE, number=2, message=field_mask.FieldMask,) + update_mask = proto.Field( + proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask, + ) class DeleteWorkloadRequest(proto.Message): r"""Request for deleting a Workload. - Attributes: name (str): Required. The ``name`` field is used to identify the @@ -96,14 +89,12 @@ class DeleteWorkloadRequest(proto.Message): etag. """ - name = proto.Field(proto.STRING, number=1) - - etag = proto.Field(proto.STRING, number=2) + name = proto.Field(proto.STRING, number=1,) + etag = proto.Field(proto.STRING, number=2,) class GetWorkloadRequest(proto.Message): r"""Request for fetching a workload. - Attributes: name (str): Required. The resource name of the Workload to fetch. This @@ -113,12 +104,11 @@ class GetWorkloadRequest(proto.Message): "organizations/123/locations/us-east1/workloads/assured-workload-1". """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class ListWorkloadsRequest(proto.Message): r"""Request for fetching workloads in an organization. - Attributes: parent (str): Required. Parent Resource to list workloads from. Must be of @@ -136,18 +126,14 @@ class ListWorkloadsRequest(proto.Message): labels is supported. """ - 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) + 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,) class ListWorkloadsResponse(proto.Message): r"""Response of ListWorkloads endpoint. - Attributes: workloads (Sequence[google.cloud.assuredworkloads_v1beta1.types.Workload]): List of Workloads under a given parent. @@ -161,8 +147,7 @@ def raw_page(self): return self workloads = proto.RepeatedField(proto.MESSAGE, number=1, message="Workload",) - - next_page_token = proto.Field(proto.STRING, number=2) + next_page_token = proto.Field(proto.STRING, number=2,) class Workload(proto.Message): @@ -257,7 +242,6 @@ class ComplianceRegime(proto.Enum): class ResourceInfo(proto.Message): r"""Represent the resources that are children of this Workload. - Attributes: resource_id (int): Resource identifier. For a project this represents @@ -272,15 +256,13 @@ class ResourceType(proto.Enum): CONSUMER_PROJECT = 1 ENCRYPTION_KEYS_PROJECT = 2 - resource_id = proto.Field(proto.INT64, number=1) - + resource_id = proto.Field(proto.INT64, number=1,) resource_type = proto.Field( proto.ENUM, number=2, enum="Workload.ResourceInfo.ResourceType", ) class KMSSettings(proto.Message): r"""Settings specific to the Key Management Service. - Attributes: next_rotation_time (google.protobuf.timestamp_pb2.Timestamp): Required. Input only. Immutable. The time at @@ -295,16 +277,14 @@ class KMSSettings(proto.Message): """ next_rotation_time = proto.Field( - proto.MESSAGE, number=1, message=timestamp.Timestamp, + proto.MESSAGE, number=1, message=timestamp_pb2.Timestamp, ) - rotation_period = proto.Field( - proto.MESSAGE, number=2, message=duration.Duration, + proto.MESSAGE, number=2, message=duration_pb2.Duration, ) class IL4Settings(proto.Message): r"""Settings specific to resources needed for IL4. - Attributes: kms_settings (google.cloud.assuredworkloads_v1beta1.types.Workload.KMSSettings): Required. Input only. Immutable. Settings @@ -317,7 +297,6 @@ class IL4Settings(proto.Message): class CJISSettings(proto.Message): r"""Settings specific to resources needed for CJIS. - Attributes: kms_settings (google.cloud.assuredworkloads_v1beta1.types.Workload.KMSSettings): Required. Input only. Immutable. Settings @@ -330,7 +309,6 @@ class CJISSettings(proto.Message): class FedrampHighSettings(proto.Message): r"""Settings specific to resources needed for FedRAMP High. - Attributes: kms_settings (google.cloud.assuredworkloads_v1beta1.types.Workload.KMSSettings): Required. Input only. Immutable. Settings @@ -343,7 +321,6 @@ class FedrampHighSettings(proto.Message): class FedrampModerateSettings(proto.Message): r"""Settings specific to resources needed for FedRAMP Moderate. - Attributes: kms_settings (google.cloud.assuredworkloads_v1beta1.types.Workload.KMSSettings): Required. Input only. Immutable. Settings @@ -369,60 +346,45 @@ class ResourceSettings(proto.Message): (CONSUMER_PROJECT or ENCRYPTION_KEYS_PROJECT) """ - resource_id = proto.Field(proto.STRING, number=1) - + resource_id = proto.Field(proto.STRING, number=1,) resource_type = proto.Field( proto.ENUM, number=2, enum="Workload.ResourceInfo.ResourceType", ) - name = proto.Field(proto.STRING, number=1) - - display_name = proto.Field(proto.STRING, number=2) - + name = proto.Field(proto.STRING, number=1,) + display_name = proto.Field(proto.STRING, number=2,) resources = proto.RepeatedField(proto.MESSAGE, number=3, message=ResourceInfo,) - compliance_regime = proto.Field(proto.ENUM, number=4, enum=ComplianceRegime,) - - create_time = proto.Field(proto.MESSAGE, number=5, message=timestamp.Timestamp,) - - billing_account = proto.Field(proto.STRING, number=6) - + create_time = proto.Field(proto.MESSAGE, number=5, message=timestamp_pb2.Timestamp,) + billing_account = proto.Field(proto.STRING, number=6,) il4_settings = proto.Field( proto.MESSAGE, number=7, oneof="compliance_regime_settings", message=IL4Settings, ) - cjis_settings = proto.Field( proto.MESSAGE, number=8, oneof="compliance_regime_settings", message=CJISSettings, ) - fedramp_high_settings = proto.Field( proto.MESSAGE, number=11, oneof="compliance_regime_settings", message=FedrampHighSettings, ) - fedramp_moderate_settings = proto.Field( proto.MESSAGE, number=12, oneof="compliance_regime_settings", message=FedrampModerateSettings, ) - - etag = proto.Field(proto.STRING, number=9) - - labels = proto.MapField(proto.STRING, proto.STRING, number=10) - - provisioned_resources_parent = proto.Field(proto.STRING, number=13) - + etag = proto.Field(proto.STRING, number=9,) + labels = proto.MapField(proto.STRING, proto.STRING, number=10,) + provisioned_resources_parent = proto.Field(proto.STRING, number=13,) kms_settings = proto.Field(proto.MESSAGE, number=14, message=KMSSettings,) - resource_settings = proto.RepeatedField( proto.MESSAGE, number=15, message=ResourceSettings, ) @@ -430,7 +392,6 @@ class ResourceSettings(proto.Message): class CreateWorkloadOperationMetadata(proto.Message): r"""Operation metadata to give request details of CreateWorkload. - Attributes: create_time (google.protobuf.timestamp_pb2.Timestamp): Optional. Time when the operation was @@ -445,12 +406,9 @@ class CreateWorkloadOperationMetadata(proto.Message): workload. """ - create_time = proto.Field(proto.MESSAGE, number=1, message=timestamp.Timestamp,) - - display_name = proto.Field(proto.STRING, number=2) - - parent = proto.Field(proto.STRING, number=3) - + create_time = proto.Field(proto.MESSAGE, number=1, message=timestamp_pb2.Timestamp,) + display_name = proto.Field(proto.STRING, number=2,) + parent = proto.Field(proto.STRING, number=3,) compliance_regime = proto.Field( proto.ENUM, number=4, enum="Workload.ComplianceRegime", ) 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/assuredworkloads_v1beta1/__init__.py b/tests/unit/gapic/assuredworkloads_v1beta1/__init__.py index 42ffdf2..4de6597 100644 --- a/tests/unit/gapic/assuredworkloads_v1beta1/__init__.py +++ b/tests/unit/gapic/assuredworkloads_v1beta1/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/unit/gapic/assuredworkloads_v1beta1/test_assured_workloads_service.py b/tests/unit/gapic/assuredworkloads_v1beta1/test_assured_workloads_service.py index 46f3435..9dde81a 100644 --- a/tests/unit/gapic/assuredworkloads_v1beta1/test_assured_workloads_service.py +++ b/tests/unit/gapic/assuredworkloads_v1beta1/test_assured_workloads_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.assuredworkloads_v1beta1.services.assured_workloads_service import ( AssuredWorkloadsServiceAsyncClient, @@ -47,12 +46,42 @@ from google.cloud.assuredworkloads_v1beta1.services.assured_workloads_service import ( transports, ) +from google.cloud.assuredworkloads_v1beta1.services.assured_workloads_service.transports.base import ( + _API_CORE_VERSION, +) +from google.cloud.assuredworkloads_v1beta1.services.assured_workloads_service.transports.base import ( + _GOOGLE_AUTH_VERSION, +) from google.cloud.assuredworkloads_v1beta1.types import assuredworkloads_v1beta1 from google.longrunning import operations_pb2 from google.oauth2 import service_account -from google.protobuf import duration_pb2 as duration # 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 duration_pb2 # 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(): @@ -104,7 +133,7 @@ def test__get_default_mtls_endpoint(): "client_class", [AssuredWorkloadsServiceClient, AssuredWorkloadsServiceAsyncClient,] ) def test_assured_workloads_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_assured_workloads_service_client_from_service_account_info(client_class "client_class", [AssuredWorkloadsServiceClient, AssuredWorkloadsServiceAsyncClient,] ) def test_assured_workloads_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: @@ -178,7 +207,7 @@ def test_assured_workloads_service_client_client_options( ): # Check that if channel is provided we won't create a new one. with mock.patch.object(AssuredWorkloadsServiceClient, "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() @@ -484,7 +513,7 @@ def test_create_workload( transport: str = "grpc", request_type=assuredworkloads_v1beta1.CreateWorkloadRequest ): client = AssuredWorkloadsServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -495,13 +524,11 @@ def test_create_workload( with mock.patch.object(type(client.transport.create_workload), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.create_workload(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == assuredworkloads_v1beta1.CreateWorkloadRequest() # Establish that the response is the type that we expect. @@ -516,7 +543,7 @@ def test_create_workload_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 = AssuredWorkloadsServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -524,7 +551,6 @@ def test_create_workload_empty_call(): client.create_workload() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == assuredworkloads_v1beta1.CreateWorkloadRequest() @@ -534,7 +560,7 @@ async def test_create_workload_async( request_type=assuredworkloads_v1beta1.CreateWorkloadRequest, ): client = AssuredWorkloadsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -547,13 +573,11 @@ async def test_create_workload_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.create_workload(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == assuredworkloads_v1beta1.CreateWorkloadRequest() # Establish that the response is the type that we expect. @@ -567,18 +591,18 @@ async def test_create_workload_async_from_dict(): def test_create_workload_field_headers(): client = AssuredWorkloadsServiceClient( - 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 = assuredworkloads_v1beta1.CreateWorkloadRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_workload), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.create_workload(request) # Establish that the underlying gRPC stub method was called. @@ -594,12 +618,13 @@ def test_create_workload_field_headers(): @pytest.mark.asyncio async def test_create_workload_field_headers_async(): client = AssuredWorkloadsServiceAsyncClient( - 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 = assuredworkloads_v1beta1.CreateWorkloadRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -607,7 +632,6 @@ async def test_create_workload_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.create_workload(request) # Establish that the underlying gRPC stub method was called. @@ -622,14 +646,13 @@ async def test_create_workload_field_headers_async(): def test_create_workload_flattened(): client = AssuredWorkloadsServiceClient( - 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.create_workload), "__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.create_workload( @@ -641,15 +664,13 @@ def test_create_workload_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].workload == assuredworkloads_v1beta1.Workload(name="name_value") def test_create_workload_flattened_error(): client = AssuredWorkloadsServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -665,7 +686,7 @@ def test_create_workload_flattened_error(): @pytest.mark.asyncio async def test_create_workload_flattened_async(): client = AssuredWorkloadsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -687,16 +708,14 @@ async def test_create_workload_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].workload == assuredworkloads_v1beta1.Workload(name="name_value") @pytest.mark.asyncio async def test_create_workload_flattened_error_async(): client = AssuredWorkloadsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -713,7 +732,7 @@ def test_update_workload( transport: str = "grpc", request_type=assuredworkloads_v1beta1.UpdateWorkloadRequest ): client = AssuredWorkloadsServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -732,36 +751,27 @@ def test_update_workload( provisioned_resources_parent="provisioned_resources_parent_value", il4_settings=assuredworkloads_v1beta1.Workload.IL4Settings( kms_settings=assuredworkloads_v1beta1.Workload.KMSSettings( - next_rotation_time=timestamp.Timestamp(seconds=751) + next_rotation_time=timestamp_pb2.Timestamp(seconds=751) ) ), ) - response = client.update_workload(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == assuredworkloads_v1beta1.UpdateWorkloadRequest() # Establish that the response is the type that we expect. - assert isinstance(response, assuredworkloads_v1beta1.Workload) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert ( response.compliance_regime == assuredworkloads_v1beta1.Workload.ComplianceRegime.IL4 ) - assert response.billing_account == "billing_account_value" - assert response.etag == "etag_value" - assert response.provisioned_resources_parent == "provisioned_resources_parent_value" @@ -773,7 +783,7 @@ def test_update_workload_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 = AssuredWorkloadsServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -781,7 +791,6 @@ def test_update_workload_empty_call(): client.update_workload() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == assuredworkloads_v1beta1.UpdateWorkloadRequest() @@ -791,7 +800,7 @@ async def test_update_workload_async( request_type=assuredworkloads_v1beta1.UpdateWorkloadRequest, ): client = AssuredWorkloadsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -811,31 +820,23 @@ async def test_update_workload_async( provisioned_resources_parent="provisioned_resources_parent_value", ) ) - response = await client.update_workload(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == assuredworkloads_v1beta1.UpdateWorkloadRequest() # Establish that the response is the type that we expect. assert isinstance(response, assuredworkloads_v1beta1.Workload) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert ( response.compliance_regime == assuredworkloads_v1beta1.Workload.ComplianceRegime.IL4 ) - assert response.billing_account == "billing_account_value" - assert response.etag == "etag_value" - assert response.provisioned_resources_parent == "provisioned_resources_parent_value" @@ -846,18 +847,18 @@ async def test_update_workload_async_from_dict(): def test_update_workload_field_headers(): client = AssuredWorkloadsServiceClient( - 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 = assuredworkloads_v1beta1.UpdateWorkloadRequest() + request.workload.name = "workload.name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_workload), "__call__") as call: call.return_value = assuredworkloads_v1beta1.Workload() - client.update_workload(request) # Establish that the underlying gRPC stub method was called. @@ -875,12 +876,13 @@ def test_update_workload_field_headers(): @pytest.mark.asyncio async def test_update_workload_field_headers_async(): client = AssuredWorkloadsServiceAsyncClient( - 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 = assuredworkloads_v1beta1.UpdateWorkloadRequest() + request.workload.name = "workload.name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -888,7 +890,6 @@ async def test_update_workload_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( assuredworkloads_v1beta1.Workload() ) - await client.update_workload(request) # Establish that the underlying gRPC stub method was called. @@ -905,34 +906,31 @@ async def test_update_workload_field_headers_async(): def test_update_workload_flattened(): client = AssuredWorkloadsServiceClient( - 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_workload), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = assuredworkloads_v1beta1.Workload() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.update_workload( workload=assuredworkloads_v1beta1.Workload(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].workload == assuredworkloads_v1beta1.Workload(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_workload_flattened_error(): client = AssuredWorkloadsServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -941,14 +939,14 @@ def test_update_workload_flattened_error(): client.update_workload( assuredworkloads_v1beta1.UpdateWorkloadRequest(), workload=assuredworkloads_v1beta1.Workload(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_workload_flattened_async(): client = AssuredWorkloadsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -963,23 +961,21 @@ async def test_update_workload_flattened_async(): # using the keyword arguments to the method. response = await client.update_workload( workload=assuredworkloads_v1beta1.Workload(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].workload == assuredworkloads_v1beta1.Workload(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_workload_flattened_error_async(): client = AssuredWorkloadsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -988,7 +984,7 @@ async def test_update_workload_flattened_error_async(): await client.update_workload( assuredworkloads_v1beta1.UpdateWorkloadRequest(), workload=assuredworkloads_v1beta1.Workload(name="name_value"), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @@ -996,7 +992,7 @@ def test_delete_workload( transport: str = "grpc", request_type=assuredworkloads_v1beta1.DeleteWorkloadRequest ): client = AssuredWorkloadsServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1007,13 +1003,11 @@ def test_delete_workload( with mock.patch.object(type(client.transport.delete_workload), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None - response = client.delete_workload(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == assuredworkloads_v1beta1.DeleteWorkloadRequest() # Establish that the response is the type that we expect. @@ -1028,7 +1022,7 @@ def test_delete_workload_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 = AssuredWorkloadsServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1036,7 +1030,6 @@ def test_delete_workload_empty_call(): client.delete_workload() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == assuredworkloads_v1beta1.DeleteWorkloadRequest() @@ -1046,7 +1039,7 @@ async def test_delete_workload_async( request_type=assuredworkloads_v1beta1.DeleteWorkloadRequest, ): client = AssuredWorkloadsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1057,13 +1050,11 @@ async def test_delete_workload_async( with mock.patch.object(type(client.transport.delete_workload), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - response = await client.delete_workload(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == assuredworkloads_v1beta1.DeleteWorkloadRequest() # Establish that the response is the type that we expect. @@ -1077,18 +1068,18 @@ async def test_delete_workload_async_from_dict(): def test_delete_workload_field_headers(): client = AssuredWorkloadsServiceClient( - 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 = assuredworkloads_v1beta1.DeleteWorkloadRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_workload), "__call__") as call: call.return_value = None - client.delete_workload(request) # Establish that the underlying gRPC stub method was called. @@ -1104,18 +1095,18 @@ def test_delete_workload_field_headers(): @pytest.mark.asyncio async def test_delete_workload_field_headers_async(): client = AssuredWorkloadsServiceAsyncClient( - 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 = assuredworkloads_v1beta1.DeleteWorkloadRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_workload), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - await client.delete_workload(request) # Establish that the underlying gRPC stub method was called. @@ -1130,14 +1121,13 @@ async def test_delete_workload_field_headers_async(): def test_delete_workload_flattened(): client = AssuredWorkloadsServiceClient( - 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_workload), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.delete_workload(name="name_value",) @@ -1146,13 +1136,12 @@ def test_delete_workload_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_delete_workload_flattened_error(): client = AssuredWorkloadsServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1166,7 +1155,7 @@ def test_delete_workload_flattened_error(): @pytest.mark.asyncio async def test_delete_workload_flattened_async(): client = AssuredWorkloadsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1183,14 +1172,13 @@ async def test_delete_workload_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_workload_flattened_error_async(): client = AssuredWorkloadsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1205,7 +1193,7 @@ def test_get_workload( transport: str = "grpc", request_type=assuredworkloads_v1beta1.GetWorkloadRequest ): client = AssuredWorkloadsServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1224,36 +1212,27 @@ def test_get_workload( provisioned_resources_parent="provisioned_resources_parent_value", il4_settings=assuredworkloads_v1beta1.Workload.IL4Settings( kms_settings=assuredworkloads_v1beta1.Workload.KMSSettings( - next_rotation_time=timestamp.Timestamp(seconds=751) + next_rotation_time=timestamp_pb2.Timestamp(seconds=751) ) ), ) - response = client.get_workload(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == assuredworkloads_v1beta1.GetWorkloadRequest() # Establish that the response is the type that we expect. - assert isinstance(response, assuredworkloads_v1beta1.Workload) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert ( response.compliance_regime == assuredworkloads_v1beta1.Workload.ComplianceRegime.IL4 ) - assert response.billing_account == "billing_account_value" - assert response.etag == "etag_value" - assert response.provisioned_resources_parent == "provisioned_resources_parent_value" @@ -1265,7 +1244,7 @@ def test_get_workload_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 = AssuredWorkloadsServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1273,7 +1252,6 @@ def test_get_workload_empty_call(): client.get_workload() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == assuredworkloads_v1beta1.GetWorkloadRequest() @@ -1283,7 +1261,7 @@ async def test_get_workload_async( request_type=assuredworkloads_v1beta1.GetWorkloadRequest, ): client = AssuredWorkloadsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1303,31 +1281,23 @@ async def test_get_workload_async( provisioned_resources_parent="provisioned_resources_parent_value", ) ) - response = await client.get_workload(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == assuredworkloads_v1beta1.GetWorkloadRequest() # Establish that the response is the type that we expect. assert isinstance(response, assuredworkloads_v1beta1.Workload) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert ( response.compliance_regime == assuredworkloads_v1beta1.Workload.ComplianceRegime.IL4 ) - assert response.billing_account == "billing_account_value" - assert response.etag == "etag_value" - assert response.provisioned_resources_parent == "provisioned_resources_parent_value" @@ -1338,18 +1308,18 @@ async def test_get_workload_async_from_dict(): def test_get_workload_field_headers(): client = AssuredWorkloadsServiceClient( - 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 = assuredworkloads_v1beta1.GetWorkloadRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_workload), "__call__") as call: call.return_value = assuredworkloads_v1beta1.Workload() - client.get_workload(request) # Establish that the underlying gRPC stub method was called. @@ -1365,12 +1335,13 @@ def test_get_workload_field_headers(): @pytest.mark.asyncio async def test_get_workload_field_headers_async(): client = AssuredWorkloadsServiceAsyncClient( - 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 = assuredworkloads_v1beta1.GetWorkloadRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1378,7 +1349,6 @@ async def test_get_workload_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( assuredworkloads_v1beta1.Workload() ) - await client.get_workload(request) # Establish that the underlying gRPC stub method was called. @@ -1393,14 +1363,13 @@ async def test_get_workload_field_headers_async(): def test_get_workload_flattened(): client = AssuredWorkloadsServiceClient( - 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_workload), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = assuredworkloads_v1beta1.Workload() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.get_workload(name="name_value",) @@ -1409,13 +1378,12 @@ def test_get_workload_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_get_workload_flattened_error(): client = AssuredWorkloadsServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1429,7 +1397,7 @@ def test_get_workload_flattened_error(): @pytest.mark.asyncio async def test_get_workload_flattened_async(): client = AssuredWorkloadsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1448,14 +1416,13 @@ async def test_get_workload_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_workload_flattened_error_async(): client = AssuredWorkloadsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1470,7 +1437,7 @@ def test_list_workloads( transport: str = "grpc", request_type=assuredworkloads_v1beta1.ListWorkloadsRequest ): client = AssuredWorkloadsServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1483,19 +1450,15 @@ def test_list_workloads( call.return_value = assuredworkloads_v1beta1.ListWorkloadsResponse( next_page_token="next_page_token_value", ) - response = client.list_workloads(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == assuredworkloads_v1beta1.ListWorkloadsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListWorkloadsPager) - assert response.next_page_token == "next_page_token_value" @@ -1507,7 +1470,7 @@ def test_list_workloads_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 = AssuredWorkloadsServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1515,7 +1478,6 @@ def test_list_workloads_empty_call(): client.list_workloads() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == assuredworkloads_v1beta1.ListWorkloadsRequest() @@ -1525,7 +1487,7 @@ async def test_list_workloads_async( request_type=assuredworkloads_v1beta1.ListWorkloadsRequest, ): client = AssuredWorkloadsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1540,18 +1502,15 @@ async def test_list_workloads_async( next_page_token="next_page_token_value", ) ) - response = await client.list_workloads(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == assuredworkloads_v1beta1.ListWorkloadsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListWorkloadsAsyncPager) - assert response.next_page_token == "next_page_token_value" @@ -1562,18 +1521,18 @@ async def test_list_workloads_async_from_dict(): def test_list_workloads_field_headers(): client = AssuredWorkloadsServiceClient( - 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 = assuredworkloads_v1beta1.ListWorkloadsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_workloads), "__call__") as call: call.return_value = assuredworkloads_v1beta1.ListWorkloadsResponse() - client.list_workloads(request) # Establish that the underlying gRPC stub method was called. @@ -1589,12 +1548,13 @@ def test_list_workloads_field_headers(): @pytest.mark.asyncio async def test_list_workloads_field_headers_async(): client = AssuredWorkloadsServiceAsyncClient( - 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 = assuredworkloads_v1beta1.ListWorkloadsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1602,7 +1562,6 @@ async def test_list_workloads_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( assuredworkloads_v1beta1.ListWorkloadsResponse() ) - await client.list_workloads(request) # Establish that the underlying gRPC stub method was called. @@ -1617,14 +1576,13 @@ async def test_list_workloads_field_headers_async(): def test_list_workloads_flattened(): client = AssuredWorkloadsServiceClient( - 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_workloads), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = assuredworkloads_v1beta1.ListWorkloadsResponse() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.list_workloads(parent="parent_value",) @@ -1633,13 +1591,12 @@ def test_list_workloads_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" def test_list_workloads_flattened_error(): client = AssuredWorkloadsServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1653,7 +1610,7 @@ def test_list_workloads_flattened_error(): @pytest.mark.asyncio async def test_list_workloads_flattened_async(): client = AssuredWorkloadsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1672,14 +1629,13 @@ async def test_list_workloads_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_workloads_flattened_error_async(): client = AssuredWorkloadsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1692,7 +1648,7 @@ async def test_list_workloads_flattened_error_async(): def test_list_workloads_pager(): client = AssuredWorkloadsServiceClient( - credentials=credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1737,7 +1693,7 @@ def test_list_workloads_pager(): def test_list_workloads_pages(): client = AssuredWorkloadsServiceClient( - credentials=credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1774,7 +1730,7 @@ def test_list_workloads_pages(): @pytest.mark.asyncio async def test_list_workloads_async_pager(): client = AssuredWorkloadsServiceAsyncClient( - credentials=credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1818,7 +1774,7 @@ async def test_list_workloads_async_pager(): @pytest.mark.asyncio async def test_list_workloads_async_pages(): client = AssuredWorkloadsServiceAsyncClient( - credentials=credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1859,16 +1815,16 @@ async def test_list_workloads_async_pages(): def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.AssuredWorkloadsServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = AssuredWorkloadsServiceClient( - 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.AssuredWorkloadsServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = AssuredWorkloadsServiceClient( @@ -1878,7 +1834,7 @@ def test_credentials_transport_error(): # It is an error to provide scopes and a transport instance. transport = transports.AssuredWorkloadsServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = AssuredWorkloadsServiceClient( @@ -1889,7 +1845,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.AssuredWorkloadsServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) client = AssuredWorkloadsServiceClient(transport=transport) assert client.transport is transport @@ -1898,13 +1854,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.AssuredWorkloadsServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel transport = transports.AssuredWorkloadsServiceGrpcAsyncIOTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel @@ -1919,8 +1875,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() @@ -1928,7 +1884,7 @@ def test_transport_adc(transport_class): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = AssuredWorkloadsServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) assert isinstance( client.transport, transports.AssuredWorkloadsServiceGrpcTransport, @@ -1937,9 +1893,9 @@ def test_transport_grpc_default(): def test_assured_workloads_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.AssuredWorkloadsServiceTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), credentials_file="credentials.json", ) @@ -1951,7 +1907,7 @@ def test_assured_workloads_service_base_transport(): ) as Transport: Transport.return_value = None transport = transports.AssuredWorkloadsServiceTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Every method on the transport should just blindly @@ -1973,15 +1929,37 @@ def test_assured_workloads_service_base_transport(): transport.operations_client +@requires_google_auth_gte_1_25_0 def test_assured_workloads_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.assuredworkloads_v1beta1.services.assured_workloads_service.transports.AssuredWorkloadsServiceTransport._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.AssuredWorkloadsServiceTransport( + 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_assured_workloads_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.assuredworkloads_v1beta1.services.assured_workloads_service.transports.AssuredWorkloadsServiceTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AssuredWorkloadsServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", ) @@ -1994,19 +1972,33 @@ def test_assured_workloads_service_base_transport_with_credentials_file(): def test_assured_workloads_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.assuredworkloads_v1beta1.services.assured_workloads_service.transports.AssuredWorkloadsServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (credentials.AnonymousCredentials(), None) + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AssuredWorkloadsServiceTransport() adc.assert_called_once() +@requires_google_auth_gte_1_25_0 def test_assured_workloads_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) + AssuredWorkloadsServiceClient() + 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_assured_workloads_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) AssuredWorkloadsServiceClient() adc.assert_called_once_with( scopes=("https://www.googleapis.com/auth/cloud-platform",), @@ -2014,20 +2006,158 @@ def test_assured_workloads_service_auth_adc(): ) -def test_assured_workloads_service_transport_auth_adc(): +@pytest.mark.parametrize( + "transport_class", + [ + transports.AssuredWorkloadsServiceGrpcTransport, + transports.AssuredWorkloadsServiceGrpcAsyncIOTransport, + ], +) +@requires_google_auth_gte_1_25_0 +def test_assured_workloads_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.AssuredWorkloadsServiceGrpcTransport( - 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.AssuredWorkloadsServiceGrpcTransport, + transports.AssuredWorkloadsServiceGrpcAsyncIOTransport, + ], +) +@requires_google_auth_lt_1_25_0 +def test_assured_workloads_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.AssuredWorkloadsServiceGrpcTransport, grpc_helpers), + (transports.AssuredWorkloadsServiceGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_gte_1_26_0 +def test_assured_workloads_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( + "assuredworkloads.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="assuredworkloads.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.AssuredWorkloadsServiceGrpcTransport, grpc_helpers), + (transports.AssuredWorkloadsServiceGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_assured_workloads_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( + "assuredworkloads.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.AssuredWorkloadsServiceGrpcTransport, grpc_helpers), + (transports.AssuredWorkloadsServiceGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_assured_workloads_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( + "assuredworkloads.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", [ @@ -2038,7 +2168,7 @@ def test_assured_workloads_service_transport_auth_adc(): def test_assured_workloads_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: @@ -2077,7 +2207,7 @@ def test_assured_workloads_service_grpc_transport_client_cert_source_for_mtls( def test_assured_workloads_service_host_no_port(): client = AssuredWorkloadsServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="assuredworkloads.googleapis.com" ), @@ -2087,7 +2217,7 @@ def test_assured_workloads_service_host_no_port(): def test_assured_workloads_service_host_with_port(): client = AssuredWorkloadsServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="assuredworkloads.googleapis.com:8000" ), @@ -2143,9 +2273,9 @@ def test_assured_workloads_service_transport_channel_mtls_with_client_cert_sourc 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", @@ -2221,7 +2351,7 @@ def test_assured_workloads_service_transport_channel_mtls_with_adc(transport_cla def test_assured_workloads_service_grpc_lro_client(): client = AssuredWorkloadsServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) transport = client.transport @@ -2234,7 +2364,7 @@ def test_assured_workloads_service_grpc_lro_client(): def test_assured_workloads_service_grpc_lro_async_client(): client = AssuredWorkloadsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", ) transport = client.transport @@ -2249,7 +2379,6 @@ def test_workload_path(): organization = "squid" location = "clam" workload = "whelk" - expected = "organizations/{organization}/locations/{location}/workloads/{workload}".format( organization=organization, location=location, workload=workload, ) @@ -2274,7 +2403,6 @@ def test_parse_workload_path(): def test_common_billing_account_path(): billing_account = "cuttlefish" - expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -2295,7 +2423,6 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "winkle" - expected = "folders/{folder}".format(folder=folder,) actual = AssuredWorkloadsServiceClient.common_folder_path(folder) assert expected == actual @@ -2314,7 +2441,6 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "scallop" - expected = "organizations/{organization}".format(organization=organization,) actual = AssuredWorkloadsServiceClient.common_organization_path(organization) assert expected == actual @@ -2333,7 +2459,6 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "squid" - expected = "projects/{project}".format(project=project,) actual = AssuredWorkloadsServiceClient.common_project_path(project) assert expected == actual @@ -2353,7 +2478,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, ) @@ -2380,7 +2504,7 @@ def test_client_withDEFAULT_CLIENT_INFO(): transports.AssuredWorkloadsServiceTransport, "_prep_wrapped_messages" ) as prep: client = AssuredWorkloadsServiceClient( - credentials=credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -2389,6 +2513,6 @@ def test_client_withDEFAULT_CLIENT_INFO(): ) as prep: transport_class = AssuredWorkloadsServiceClient.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)