diff --git a/docs/functions_v1/cloud_functions_service.rst b/docs/functions_v1/cloud_functions_service.rst index e20b86c..36d0114 100644 --- a/docs/functions_v1/cloud_functions_service.rst +++ b/docs/functions_v1/cloud_functions_service.rst @@ -5,7 +5,6 @@ CloudFunctionsService :members: :inherited-members: - .. automodule:: google.cloud.functions_v1.services.cloud_functions_service.pagers :members: :inherited-members: diff --git a/google/cloud/functions/__init__.py b/google/cloud/functions/__init__.py index 316e6f2..beaf702 100644 --- a/google/cloud/functions/__init__.py +++ b/google/cloud/functions/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,16 +14,16 @@ # limitations under the License. # -from google.cloud.functions_v1.services.cloud_functions_service.async_client import ( - CloudFunctionsServiceAsyncClient, -) from google.cloud.functions_v1.services.cloud_functions_service.client import ( CloudFunctionsServiceClient, ) +from google.cloud.functions_v1.services.cloud_functions_service.async_client import ( + CloudFunctionsServiceAsyncClient, +) + from google.cloud.functions_v1.types.functions import CallFunctionRequest from google.cloud.functions_v1.types.functions import CallFunctionResponse from google.cloud.functions_v1.types.functions import CloudFunction -from google.cloud.functions_v1.types.functions import CloudFunctionStatus from google.cloud.functions_v1.types.functions import CreateFunctionRequest from google.cloud.functions_v1.types.functions import DeleteFunctionRequest from google.cloud.functions_v1.types.functions import EventTrigger @@ -39,16 +38,16 @@ from google.cloud.functions_v1.types.functions import ListFunctionsResponse from google.cloud.functions_v1.types.functions import SourceRepository from google.cloud.functions_v1.types.functions import UpdateFunctionRequest +from google.cloud.functions_v1.types.functions import CloudFunctionStatus from google.cloud.functions_v1.types.operations import OperationMetadataV1 from google.cloud.functions_v1.types.operations import OperationType __all__ = ( + "CloudFunctionsServiceClient", + "CloudFunctionsServiceAsyncClient", "CallFunctionRequest", "CallFunctionResponse", "CloudFunction", - "CloudFunctionStatus", - "CloudFunctionsServiceAsyncClient", - "CloudFunctionsServiceClient", "CreateFunctionRequest", "DeleteFunctionRequest", "EventTrigger", @@ -61,8 +60,9 @@ "HttpsTrigger", "ListFunctionsRequest", "ListFunctionsResponse", - "OperationMetadataV1", - "OperationType", "SourceRepository", "UpdateFunctionRequest", + "CloudFunctionStatus", + "OperationMetadataV1", + "OperationType", ) diff --git a/google/cloud/functions_v1/__init__.py b/google/cloud/functions_v1/__init__.py index fc6b6ee..dfa8c79 100644 --- a/google/cloud/functions_v1/__init__.py +++ b/google/cloud/functions_v1/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,10 +15,11 @@ # from .services.cloud_functions_service import CloudFunctionsServiceClient +from .services.cloud_functions_service import CloudFunctionsServiceAsyncClient + from .types.functions import CallFunctionRequest from .types.functions import CallFunctionResponse from .types.functions import CloudFunction -from .types.functions import CloudFunctionStatus from .types.functions import CreateFunctionRequest from .types.functions import DeleteFunctionRequest from .types.functions import EventTrigger @@ -34,15 +34,17 @@ from .types.functions import ListFunctionsResponse from .types.functions import SourceRepository from .types.functions import UpdateFunctionRequest +from .types.functions import CloudFunctionStatus from .types.operations import OperationMetadataV1 from .types.operations import OperationType - __all__ = ( + "CloudFunctionsServiceAsyncClient", "CallFunctionRequest", "CallFunctionResponse", "CloudFunction", "CloudFunctionStatus", + "CloudFunctionsServiceClient", "CreateFunctionRequest", "DeleteFunctionRequest", "EventTrigger", @@ -59,5 +61,4 @@ "OperationType", "SourceRepository", "UpdateFunctionRequest", - "CloudFunctionsServiceClient", ) diff --git a/google/cloud/functions_v1/gapic_metadata.json b/google/cloud/functions_v1/gapic_metadata.json new file mode 100644 index 0000000..5745d05 --- /dev/null +++ b/google/cloud/functions_v1/gapic_metadata.json @@ -0,0 +1,133 @@ + { + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", + "language": "python", + "libraryPackage": "google.cloud.functions_v1", + "protoPackage": "google.cloud.functions.v1", + "schema": "1.0", + "services": { + "CloudFunctionsService": { + "clients": { + "grpc": { + "libraryClient": "CloudFunctionsServiceClient", + "rpcs": { + "CallFunction": { + "methods": [ + "call_function" + ] + }, + "CreateFunction": { + "methods": [ + "create_function" + ] + }, + "DeleteFunction": { + "methods": [ + "delete_function" + ] + }, + "GenerateDownloadUrl": { + "methods": [ + "generate_download_url" + ] + }, + "GenerateUploadUrl": { + "methods": [ + "generate_upload_url" + ] + }, + "GetFunction": { + "methods": [ + "get_function" + ] + }, + "GetIamPolicy": { + "methods": [ + "get_iam_policy" + ] + }, + "ListFunctions": { + "methods": [ + "list_functions" + ] + }, + "SetIamPolicy": { + "methods": [ + "set_iam_policy" + ] + }, + "TestIamPermissions": { + "methods": [ + "test_iam_permissions" + ] + }, + "UpdateFunction": { + "methods": [ + "update_function" + ] + } + } + }, + "grpc-async": { + "libraryClient": "CloudFunctionsServiceAsyncClient", + "rpcs": { + "CallFunction": { + "methods": [ + "call_function" + ] + }, + "CreateFunction": { + "methods": [ + "create_function" + ] + }, + "DeleteFunction": { + "methods": [ + "delete_function" + ] + }, + "GenerateDownloadUrl": { + "methods": [ + "generate_download_url" + ] + }, + "GenerateUploadUrl": { + "methods": [ + "generate_upload_url" + ] + }, + "GetFunction": { + "methods": [ + "get_function" + ] + }, + "GetIamPolicy": { + "methods": [ + "get_iam_policy" + ] + }, + "ListFunctions": { + "methods": [ + "list_functions" + ] + }, + "SetIamPolicy": { + "methods": [ + "set_iam_policy" + ] + }, + "TestIamPermissions": { + "methods": [ + "test_iam_permissions" + ] + }, + "UpdateFunction": { + "methods": [ + "update_function" + ] + } + } + } + } + } + } +} diff --git a/google/cloud/functions_v1/services/__init__.py b/google/cloud/functions_v1/services/__init__.py index 42ffdf2..4de6597 100644 --- a/google/cloud/functions_v1/services/__init__.py +++ b/google/cloud/functions_v1/services/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/google/cloud/functions_v1/services/cloud_functions_service/__init__.py b/google/cloud/functions_v1/services/cloud_functions_service/__init__.py index b0bc399..c85657e 100644 --- a/google/cloud/functions_v1/services/cloud_functions_service/__init__.py +++ b/google/cloud/functions_v1/services/cloud_functions_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 CloudFunctionsServiceClient from .async_client import CloudFunctionsServiceAsyncClient diff --git a/google/cloud/functions_v1/services/cloud_functions_service/async_client.py b/google/cloud/functions_v1/services/cloud_functions_service/async_client.py index 5e05ca3..8933008 100644 --- a/google/cloud/functions_v1/services/cloud_functions_service/async_client.py +++ b/google/cloud/functions_v1/services/cloud_functions_service/async_client.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict import functools import re @@ -22,10 +20,10 @@ import pkg_resources import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore from google.api_core import operation # type: ignore @@ -33,12 +31,11 @@ from google.cloud.functions_v1.services.cloud_functions_service import pagers from google.cloud.functions_v1.types import functions from google.cloud.functions_v1.types import operations -from google.iam.v1 import iam_policy_pb2 as iam_policy # type: ignore -from google.iam.v1 import policy_pb2 as policy # type: ignore -from google.protobuf import duration_pb2 as duration # type: ignore -from google.protobuf import empty_pb2 as empty # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore - +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.protobuf import duration_pb2 # type: ignore +from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore from .transports.base import CloudFunctionsServiceTransport, DEFAULT_CLIENT_INFO from .transports.grpc_asyncio import CloudFunctionsServiceGrpcAsyncIOTransport from .client import CloudFunctionsServiceClient @@ -58,31 +55,26 @@ class CloudFunctionsServiceAsyncClient: parse_cloud_function_path = staticmethod( CloudFunctionsServiceClient.parse_cloud_function_path ) - common_billing_account_path = staticmethod( CloudFunctionsServiceClient.common_billing_account_path ) parse_common_billing_account_path = staticmethod( CloudFunctionsServiceClient.parse_common_billing_account_path ) - common_folder_path = staticmethod(CloudFunctionsServiceClient.common_folder_path) parse_common_folder_path = staticmethod( CloudFunctionsServiceClient.parse_common_folder_path ) - common_organization_path = staticmethod( CloudFunctionsServiceClient.common_organization_path ) parse_common_organization_path = staticmethod( CloudFunctionsServiceClient.parse_common_organization_path ) - common_project_path = staticmethod(CloudFunctionsServiceClient.common_project_path) parse_common_project_path = staticmethod( CloudFunctionsServiceClient.parse_common_project_path ) - common_location_path = staticmethod( CloudFunctionsServiceClient.common_location_path ) @@ -92,7 +84,8 @@ class CloudFunctionsServiceAsyncClient: @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. @@ -107,7 +100,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 @@ -124,7 +117,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> CloudFunctionsServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: CloudFunctionsServiceTransport: The transport used by the client instance. @@ -139,12 +132,12 @@ def transport(self) -> CloudFunctionsServiceTransport: def __init__( self, *, - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, transport: Union[str, CloudFunctionsServiceTransport] = "grpc_asyncio", client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the cloud functions service client. + """Instantiates the cloud functions service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -176,7 +169,6 @@ def __init__( google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport creation failed for any reason. """ - self._client = CloudFunctionsServiceClient( credentials=credentials, transport=transport, @@ -199,7 +191,6 @@ async def list_functions( request (:class:`google.cloud.functions_v1.types.ListFunctionsRequest`): The request object. Request for the `ListFunctions` method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -215,7 +206,6 @@ async def list_functions( """ # Create or coerce a protobuf request object. - request = functions.ListFunctionsRequest(request) # Wrap the RPC method; this adds retry and timeout information, @@ -227,7 +217,8 @@ async def list_functions( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -276,7 +267,6 @@ async def get_function( 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. @@ -305,7 +295,6 @@ async def get_function( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -318,7 +307,8 @@ async def get_function( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -369,7 +359,6 @@ async def create_function( This corresponds to the ``function`` 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. @@ -399,7 +388,6 @@ async def create_function( # If we have keyword arguments corresponding to fields on the # request, apply these. - if location is not None: request.location = location if function is not None: @@ -455,7 +443,6 @@ async def update_function( This corresponds to the ``function`` 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. @@ -485,7 +472,6 @@ async def update_function( # If we have keyword arguments corresponding to fields on the # request, apply these. - if function is not None: request.function = function @@ -498,7 +484,8 @@ async def update_function( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -553,7 +540,6 @@ async def delete_function( 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. @@ -593,7 +579,6 @@ async def delete_function( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -606,7 +591,8 @@ async def delete_function( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -627,7 +613,7 @@ async def delete_function( response = operation_async.from_gapic( response, self._client._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=operations.OperationMetadataV1, ) @@ -667,7 +653,6 @@ async def call_function( This corresponds to the ``data`` 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. @@ -692,7 +677,6 @@ async def call_function( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if data is not None: @@ -759,7 +743,6 @@ async def generate_upload_url( request (:class:`google.cloud.functions_v1.types.GenerateUploadUrlRequest`): The request object. Request of `GenerateSourceUploadUrl` method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -771,7 +754,6 @@ async def generate_upload_url( Response of GenerateSourceUploadUrl method. """ # Create or coerce a protobuf request object. - request = functions.GenerateUploadUrlRequest(request) # Wrap the RPC method; this adds retry and timeout information, @@ -814,7 +796,6 @@ async def generate_download_url( request (:class:`google.cloud.functions_v1.types.GenerateDownloadUrlRequest`): The request object. Request of `GenerateDownloadUrl` method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -826,7 +807,6 @@ async def generate_download_url( Response of GenerateDownloadUrl method. """ # Create or coerce a protobuf request object. - request = functions.GenerateDownloadUrlRequest(request) # Wrap the RPC method; this adds retry and timeout information, @@ -851,12 +831,12 @@ async def generate_download_url( async def set_iam_policy( self, - request: iam_policy.SetIamPolicyRequest = None, + request: iam_policy_pb2.SetIamPolicyRequest = None, *, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> policy.Policy: + ) -> policy_pb2.Policy: r"""Sets the IAM access control policy on the specified function. Replaces any existing policy. @@ -864,7 +844,6 @@ async def set_iam_policy( request (:class:`google.iam.v1.iam_policy_pb2.SetIamPolicyRequest`): The request object. Request message for `SetIamPolicy` method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -931,11 +910,10 @@ async def set_iam_policy( """ # Create or coerce a protobuf request object. - # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if isinstance(request, dict): - request = iam_policy.SetIamPolicyRequest(**request) + request = iam_policy_pb2.SetIamPolicyRequest(**request) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -959,12 +937,12 @@ async def set_iam_policy( async def get_iam_policy( self, - request: iam_policy.GetIamPolicyRequest = None, + request: iam_policy_pb2.GetIamPolicyRequest = None, *, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> policy.Policy: + ) -> policy_pb2.Policy: r"""Gets the IAM access control policy for a function. Returns an empty policy if the function exists and does not have a policy set. @@ -973,7 +951,6 @@ async def get_iam_policy( request (:class:`google.iam.v1.iam_policy_pb2.GetIamPolicyRequest`): The request object. Request message for `GetIamPolicy` method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1040,11 +1017,10 @@ async def get_iam_policy( """ # Create or coerce a protobuf request object. - # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if isinstance(request, dict): - request = iam_policy.GetIamPolicyRequest(**request) + request = iam_policy_pb2.GetIamPolicyRequest(**request) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1068,12 +1044,12 @@ async def get_iam_policy( async def test_iam_permissions( self, - request: iam_policy.TestIamPermissionsRequest = None, + request: iam_policy_pb2.TestIamPermissionsRequest = None, *, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> iam_policy.TestIamPermissionsResponse: + ) -> iam_policy_pb2.TestIamPermissionsResponse: r"""Tests the specified permissions against the IAM access control policy for a function. If the function does not exist, this will return an empty set of permissions, not a NOT_FOUND error. @@ -1082,7 +1058,6 @@ async def test_iam_permissions( request (:class:`google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest`): The request object. Request message for `TestIamPermissions` method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1094,11 +1069,10 @@ async def test_iam_permissions( Response message for TestIamPermissions method. """ # Create or coerce a protobuf request object. - # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if isinstance(request, dict): - request = iam_policy.TestIamPermissionsRequest(**request) + request = iam_policy_pb2.TestIamPermissionsRequest(**request) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. diff --git a/google/cloud/functions_v1/services/cloud_functions_service/client.py b/google/cloud/functions_v1/services/cloud_functions_service/client.py index 3202d24..b5e6156 100644 --- a/google/cloud/functions_v1/services/cloud_functions_service/client.py +++ b/google/cloud/functions_v1/services/cloud_functions_service/client.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict from distutils import util import os @@ -23,10 +21,10 @@ import pkg_resources from google.api_core import client_options as client_options_lib # type: ignore -from google.api_core import exceptions # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport import mtls # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.auth.exceptions import MutualTLSChannelError # type: ignore @@ -37,12 +35,11 @@ from google.cloud.functions_v1.services.cloud_functions_service import pagers from google.cloud.functions_v1.types import functions from google.cloud.functions_v1.types import operations -from google.iam.v1 import iam_policy_pb2 as iam_policy # type: ignore -from google.iam.v1 import policy_pb2 as policy # type: ignore -from google.protobuf import duration_pb2 as duration # type: ignore -from google.protobuf import empty_pb2 as empty # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore - +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.protobuf import duration_pb2 # type: ignore +from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore from .transports.base import CloudFunctionsServiceTransport, DEFAULT_CLIENT_INFO from .transports.grpc import CloudFunctionsServiceGrpcTransport from .transports.grpc_asyncio import CloudFunctionsServiceGrpcAsyncIOTransport @@ -65,7 +62,7 @@ class CloudFunctionsServiceClientMeta(type): def get_transport_class( cls, label: str = None, ) -> Type[CloudFunctionsServiceTransport]: - """Return an appropriate transport class. + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -90,7 +87,8 @@ class CloudFunctionsServiceClient(metaclass=CloudFunctionsServiceClientMeta): @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: @@ -124,7 +122,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. @@ -141,7 +140,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 @@ -160,23 +159,24 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> CloudFunctionsServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - CloudFunctionsServiceTransport: The transport used by the client instance. + CloudFunctionsServiceTransport: The transport used by the client + instance. """ return self._transport @staticmethod def cloud_function_path(project: str, location: str, function: str,) -> str: - """Return a fully-qualified cloud_function string.""" + """Returns a fully-qualified cloud_function string.""" return "projects/{project}/locations/{location}/functions/{function}".format( project=project, location=location, function=function, ) @staticmethod def parse_cloud_function_path(path: str) -> Dict[str, str]: - """Parse a cloud_function path into its component segments.""" + """Parses a cloud_function path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/functions/(?P.+?)$", path, @@ -185,7 +185,7 @@ def parse_cloud_function_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, ) @@ -198,7 +198,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 @@ -209,7 +209,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 @@ -220,7 +220,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 @@ -231,7 +231,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, ) @@ -245,12 +245,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, CloudFunctionsServiceTransport, None] = None, client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the cloud functions service client. + """Instantiates the cloud functions service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -305,9 +305,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: @@ -319,12 +320,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. @@ -339,8 +342,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: @@ -370,7 +373,6 @@ def list_functions( request (google.cloud.functions_v1.types.ListFunctionsRequest): The request object. Request for the `ListFunctions` method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -386,7 +388,6 @@ def list_functions( """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes # in a functions.ListFunctionsRequest. # There's no risk of modifying the input as we've already verified @@ -439,7 +440,6 @@ def get_function( 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. @@ -470,10 +470,8 @@ def get_function( # there are no flattened fields. if not isinstance(request, functions.GetFunctionRequest): request = functions.GetFunctionRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -524,7 +522,6 @@ def create_function( This corresponds to the ``function`` 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. @@ -556,10 +553,8 @@ def create_function( # there are no flattened fields. if not isinstance(request, functions.CreateFunctionRequest): request = functions.CreateFunctionRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if location is not None: request.location = location if function is not None: @@ -611,7 +606,6 @@ def update_function( This corresponds to the ``function`` 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. @@ -643,10 +637,8 @@ def update_function( # there are no flattened fields. if not isinstance(request, functions.UpdateFunctionRequest): request = functions.UpdateFunctionRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if function is not None: request.function = function @@ -701,7 +693,6 @@ def delete_function( 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. @@ -743,10 +734,8 @@ def delete_function( # there are no flattened fields. if not isinstance(request, functions.DeleteFunctionRequest): request = functions.DeleteFunctionRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -767,7 +756,7 @@ def delete_function( response = operation.from_gapic( response, self._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=operations.OperationMetadataV1, ) @@ -807,7 +796,6 @@ def call_function( This corresponds to the ``data`` 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. @@ -834,10 +822,8 @@ def call_function( # there are no flattened fields. if not isinstance(request, functions.CallFunctionRequest): request = functions.CallFunctionRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if data is not None: @@ -900,7 +886,6 @@ def generate_upload_url( request (google.cloud.functions_v1.types.GenerateUploadUrlRequest): The request object. Request of `GenerateSourceUploadUrl` method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -912,7 +897,6 @@ def generate_upload_url( Response of GenerateSourceUploadUrl method. """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes # in a functions.GenerateUploadUrlRequest. # There's no risk of modifying the input as we've already verified @@ -956,7 +940,6 @@ def generate_download_url( request (google.cloud.functions_v1.types.GenerateDownloadUrlRequest): The request object. Request of `GenerateDownloadUrl` method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -968,7 +951,6 @@ def generate_download_url( Response of GenerateDownloadUrl method. """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes # in a functions.GenerateDownloadUrlRequest. # There's no risk of modifying the input as we've already verified @@ -994,12 +976,12 @@ def generate_download_url( def set_iam_policy( self, - request: iam_policy.SetIamPolicyRequest = None, + request: iam_policy_pb2.SetIamPolicyRequest = None, *, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> policy.Policy: + ) -> policy_pb2.Policy: r"""Sets the IAM access control policy on the specified function. Replaces any existing policy. @@ -1007,7 +989,6 @@ def set_iam_policy( request (google.iam.v1.iam_policy_pb2.SetIamPolicyRequest): The request object. Request message for `SetIamPolicy` method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1074,14 +1055,13 @@ def set_iam_policy( """ # Create or coerce a protobuf request object. - if isinstance(request, dict): # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - request = iam_policy.SetIamPolicyRequest(**request) + request = iam_policy_pb2.SetIamPolicyRequest(**request) elif not request: # Null request, just make one. - request = iam_policy.SetIamPolicyRequest() + request = iam_policy_pb2.SetIamPolicyRequest() # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1101,12 +1081,12 @@ def set_iam_policy( def get_iam_policy( self, - request: iam_policy.GetIamPolicyRequest = None, + request: iam_policy_pb2.GetIamPolicyRequest = None, *, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> policy.Policy: + ) -> policy_pb2.Policy: r"""Gets the IAM access control policy for a function. Returns an empty policy if the function exists and does not have a policy set. @@ -1115,7 +1095,6 @@ def get_iam_policy( request (google.iam.v1.iam_policy_pb2.GetIamPolicyRequest): The request object. Request message for `GetIamPolicy` method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1182,14 +1161,13 @@ def get_iam_policy( """ # Create or coerce a protobuf request object. - if isinstance(request, dict): # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - request = iam_policy.GetIamPolicyRequest(**request) + request = iam_policy_pb2.GetIamPolicyRequest(**request) elif not request: # Null request, just make one. - request = iam_policy.GetIamPolicyRequest() + request = iam_policy_pb2.GetIamPolicyRequest() # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1209,12 +1187,12 @@ def get_iam_policy( def test_iam_permissions( self, - request: iam_policy.TestIamPermissionsRequest = None, + request: iam_policy_pb2.TestIamPermissionsRequest = None, *, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> iam_policy.TestIamPermissionsResponse: + ) -> iam_policy_pb2.TestIamPermissionsResponse: r"""Tests the specified permissions against the IAM access control policy for a function. If the function does not exist, this will return an empty set of permissions, not a NOT_FOUND error. @@ -1223,7 +1201,6 @@ def test_iam_permissions( request (google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest): The request object. Request message for `TestIamPermissions` method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1235,14 +1212,13 @@ def test_iam_permissions( Response message for TestIamPermissions method. """ # Create or coerce a protobuf request object. - if isinstance(request, dict): # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - request = iam_policy.TestIamPermissionsRequest(**request) + request = iam_policy_pb2.TestIamPermissionsRequest(**request) elif not request: # Null request, just make one. - request = iam_policy.TestIamPermissionsRequest() + request = iam_policy_pb2.TestIamPermissionsRequest() # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. diff --git a/google/cloud/functions_v1/services/cloud_functions_service/pagers.py b/google/cloud/functions_v1/services/cloud_functions_service/pagers.py index 272d877..c836a87 100644 --- a/google/cloud/functions_v1/services/cloud_functions_service/pagers.py +++ b/google/cloud/functions_v1/services/cloud_functions_service/pagers.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from typing import ( Any, AsyncIterable, @@ -117,7 +115,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and diff --git a/google/cloud/functions_v1/services/cloud_functions_service/transports/__init__.py b/google/cloud/functions_v1/services/cloud_functions_service/transports/__init__.py index 90fe312..208b24a 100644 --- a/google/cloud/functions_v1/services/cloud_functions_service/transports/__init__.py +++ b/google/cloud/functions_v1/services/cloud_functions_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/functions_v1/services/cloud_functions_service/transports/base.py b/google/cloud/functions_v1/services/cloud_functions_service/transports/base.py index eb6c359..9696a29 100644 --- a/google/cloud/functions_v1/services/cloud_functions_service/transports/base.py +++ b/google/cloud/functions_v1/services/cloud_functions_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,23 +13,23 @@ # 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.functions_v1.types import functions -from google.iam.v1 import iam_policy_pb2 as iam_policy # type: ignore -from google.iam.v1 import policy_pb2 as policy # type: ignore -from google.longrunning import operations_pb2 as operations # type: ignore - +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 # type: ignore try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( @@ -39,27 +38,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 CloudFunctionsServiceTransport(abc.ABC): """Abstract transport class for CloudFunctionsService.""" AUTH_SCOPES = ("https://www.googleapis.com/auth/cloud-platform",) + DEFAULT_HOST: str = "cloudfunctions.googleapis.com" + def __init__( self, *, - host: str = "cloudfunctions.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 @@ -68,7 +81,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): @@ -82,29 +95,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 = { @@ -115,7 +175,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -129,7 +190,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -146,7 +208,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -160,7 +223,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -199,11 +263,10 @@ def operations_client(self) -> operations_v1.OperationsClient: @property def list_functions( self, - ) -> typing.Callable[ + ) -> Callable[ [functions.ListFunctionsRequest], - typing.Union[ - functions.ListFunctionsResponse, - typing.Awaitable[functions.ListFunctionsResponse], + Union[ + functions.ListFunctionsResponse, Awaitable[functions.ListFunctionsResponse] ], ]: raise NotImplementedError() @@ -211,49 +274,46 @@ def list_functions( @property def get_function( self, - ) -> typing.Callable[ + ) -> Callable[ [functions.GetFunctionRequest], - typing.Union[ - functions.CloudFunction, typing.Awaitable[functions.CloudFunction] - ], + Union[functions.CloudFunction, Awaitable[functions.CloudFunction]], ]: raise NotImplementedError() @property def create_function( self, - ) -> typing.Callable[ + ) -> Callable[ [functions.CreateFunctionRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def update_function( self, - ) -> typing.Callable[ + ) -> Callable[ [functions.UpdateFunctionRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def delete_function( self, - ) -> typing.Callable[ + ) -> Callable[ [functions.DeleteFunctionRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def call_function( self, - ) -> typing.Callable[ + ) -> Callable[ [functions.CallFunctionRequest], - typing.Union[ - functions.CallFunctionResponse, - typing.Awaitable[functions.CallFunctionResponse], + Union[ + functions.CallFunctionResponse, Awaitable[functions.CallFunctionResponse] ], ]: raise NotImplementedError() @@ -261,11 +321,11 @@ def call_function( @property def generate_upload_url( self, - ) -> typing.Callable[ + ) -> Callable[ [functions.GenerateUploadUrlRequest], - typing.Union[ + Union[ functions.GenerateUploadUrlResponse, - typing.Awaitable[functions.GenerateUploadUrlResponse], + Awaitable[functions.GenerateUploadUrlResponse], ], ]: raise NotImplementedError() @@ -273,11 +333,11 @@ def generate_upload_url( @property def generate_download_url( self, - ) -> typing.Callable[ + ) -> Callable[ [functions.GenerateDownloadUrlRequest], - typing.Union[ + Union[ functions.GenerateDownloadUrlResponse, - typing.Awaitable[functions.GenerateDownloadUrlResponse], + Awaitable[functions.GenerateDownloadUrlResponse], ], ]: raise NotImplementedError() @@ -285,29 +345,29 @@ def generate_download_url( @property def set_iam_policy( self, - ) -> typing.Callable[ - [iam_policy.SetIamPolicyRequest], - typing.Union[policy.Policy, typing.Awaitable[policy.Policy]], + ) -> Callable[ + [iam_policy_pb2.SetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], ]: raise NotImplementedError() @property def get_iam_policy( self, - ) -> typing.Callable[ - [iam_policy.GetIamPolicyRequest], - typing.Union[policy.Policy, typing.Awaitable[policy.Policy]], + ) -> Callable[ + [iam_policy_pb2.GetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], ]: raise NotImplementedError() @property def test_iam_permissions( self, - ) -> typing.Callable[ - [iam_policy.TestIamPermissionsRequest], - typing.Union[ - iam_policy.TestIamPermissionsResponse, - typing.Awaitable[iam_policy.TestIamPermissionsResponse], + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + Union[ + iam_policy_pb2.TestIamPermissionsResponse, + Awaitable[iam_policy_pb2.TestIamPermissionsResponse], ], ]: raise NotImplementedError() diff --git a/google/cloud/functions_v1/services/cloud_functions_service/transports/grpc.py b/google/cloud/functions_v1/services/cloud_functions_service/transports/grpc.py index c299fcb..3e67709 100644 --- a/google/cloud/functions_v1/services/cloud_functions_service/transports/grpc.py +++ b/google/cloud/functions_v1/services/cloud_functions_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,24 +13,22 @@ # 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.functions_v1.types import functions -from google.iam.v1 import iam_policy_pb2 as iam_policy # type: ignore -from google.iam.v1 import policy_pb2 as policy # type: ignore -from google.longrunning import operations_pb2 as operations # type: ignore - +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 # type: ignore from .base import CloudFunctionsServiceTransport, DEFAULT_CLIENT_INFO @@ -55,7 +52,7 @@ def __init__( self, *, host: str = "cloudfunctions.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: str = None, scopes: Sequence[str] = None, channel: grpc.Channel = None, @@ -69,7 +66,8 @@ def __init__( """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -180,7 +178,7 @@ def __init__( def create_channel( cls, host: str = "cloudfunctions.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, @@ -211,13 +209,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, ) @@ -298,7 +298,7 @@ def get_function( @property def create_function( self, - ) -> Callable[[functions.CreateFunctionRequest], operations.Operation]: + ) -> Callable[[functions.CreateFunctionRequest], operations_pb2.Operation]: r"""Return a callable for the create function method over gRPC. Creates a new function. If a function with the given name @@ -319,14 +319,14 @@ def create_function( self._stubs["create_function"] = self.grpc_channel.unary_unary( "/google.cloud.functions.v1.CloudFunctionsService/CreateFunction", request_serializer=functions.CreateFunctionRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["create_function"] @property def update_function( self, - ) -> Callable[[functions.UpdateFunctionRequest], operations.Operation]: + ) -> Callable[[functions.UpdateFunctionRequest], operations_pb2.Operation]: r"""Return a callable for the update function method over gRPC. Updates existing function. @@ -345,14 +345,14 @@ def update_function( self._stubs["update_function"] = self.grpc_channel.unary_unary( "/google.cloud.functions.v1.CloudFunctionsService/UpdateFunction", request_serializer=functions.UpdateFunctionRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["update_function"] @property def delete_function( self, - ) -> Callable[[functions.DeleteFunctionRequest], operations.Operation]: + ) -> Callable[[functions.DeleteFunctionRequest], operations_pb2.Operation]: r"""Return a callable for the delete function method over gRPC. Deletes a function with the given name from the @@ -374,7 +374,7 @@ def delete_function( self._stubs["delete_function"] = self.grpc_channel.unary_unary( "/google.cloud.functions.v1.CloudFunctionsService/DeleteFunction", request_serializer=functions.DeleteFunctionRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["delete_function"] @@ -499,7 +499,7 @@ def generate_download_url( @property def set_iam_policy( self, - ) -> Callable[[iam_policy.SetIamPolicyRequest], policy.Policy]: + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: r"""Return a callable for the set iam policy method over gRPC. Sets the IAM access control policy on the specified @@ -518,15 +518,15 @@ def set_iam_policy( if "set_iam_policy" not in self._stubs: self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( "/google.cloud.functions.v1.CloudFunctionsService/SetIamPolicy", - request_serializer=iam_policy.SetIamPolicyRequest.SerializeToString, - response_deserializer=policy.Policy.FromString, + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, ) return self._stubs["set_iam_policy"] @property def get_iam_policy( self, - ) -> Callable[[iam_policy.GetIamPolicyRequest], policy.Policy]: + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: r"""Return a callable for the get iam policy method over gRPC. Gets the IAM access control policy for a function. @@ -546,8 +546,8 @@ def get_iam_policy( if "get_iam_policy" not in self._stubs: self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( "/google.cloud.functions.v1.CloudFunctionsService/GetIamPolicy", - request_serializer=iam_policy.GetIamPolicyRequest.SerializeToString, - response_deserializer=policy.Policy.FromString, + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, ) return self._stubs["get_iam_policy"] @@ -555,7 +555,8 @@ def get_iam_policy( def test_iam_permissions( self, ) -> Callable[ - [iam_policy.TestIamPermissionsRequest], iam_policy.TestIamPermissionsResponse + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, ]: r"""Return a callable for the test iam permissions method over gRPC. @@ -576,8 +577,8 @@ def test_iam_permissions( if "test_iam_permissions" not in self._stubs: self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( "/google.cloud.functions.v1.CloudFunctionsService/TestIamPermissions", - request_serializer=iam_policy.TestIamPermissionsRequest.SerializeToString, - response_deserializer=iam_policy.TestIamPermissionsResponse.FromString, + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, ) return self._stubs["test_iam_permissions"] diff --git a/google/cloud/functions_v1/services/cloud_functions_service/transports/grpc_asyncio.py b/google/cloud/functions_v1/services/cloud_functions_service/transports/grpc_asyncio.py index 28ddfae..4398c28 100644 --- a/google/cloud/functions_v1/services/cloud_functions_service/transports/grpc_asyncio.py +++ b/google/cloud/functions_v1/services/cloud_functions_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,25 +13,23 @@ # 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.functions_v1.types import functions -from google.iam.v1 import iam_policy_pb2 as iam_policy # type: ignore -from google.iam.v1 import policy_pb2 as policy # type: ignore -from google.longrunning import operations_pb2 as operations # type: ignore - +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 # type: ignore from .base import CloudFunctionsServiceTransport, DEFAULT_CLIENT_INFO from .grpc import CloudFunctionsServiceGrpcTransport @@ -58,7 +55,7 @@ class CloudFunctionsServiceGrpcAsyncIOTransport(CloudFunctionsServiceTransport): def create_channel( cls, host: str = "cloudfunctions.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, @@ -85,13 +82,15 @@ def create_channel( Returns: aio.Channel: A gRPC AsyncIO channel object. """ - scopes = scopes or cls.AUTH_SCOPES + + self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) + return grpc_helpers_async.create_channel( host, credentials=credentials, credentials_file=credentials_file, - scopes=scopes, quota_project_id=quota_project_id, + **self_signed_jwt_kwargs, **kwargs, ) @@ -99,7 +98,7 @@ def __init__( self, *, host: str = "cloudfunctions.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, channel: aio.Channel = None, @@ -113,7 +112,8 @@ def __init__( """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -172,7 +172,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 @@ -306,7 +305,9 @@ def get_function( @property def create_function( self, - ) -> Callable[[functions.CreateFunctionRequest], Awaitable[operations.Operation]]: + ) -> Callable[ + [functions.CreateFunctionRequest], Awaitable[operations_pb2.Operation] + ]: r"""Return a callable for the create function method over gRPC. Creates a new function. If a function with the given name @@ -327,14 +328,16 @@ def create_function( self._stubs["create_function"] = self.grpc_channel.unary_unary( "/google.cloud.functions.v1.CloudFunctionsService/CreateFunction", request_serializer=functions.CreateFunctionRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["create_function"] @property def update_function( self, - ) -> Callable[[functions.UpdateFunctionRequest], Awaitable[operations.Operation]]: + ) -> Callable[ + [functions.UpdateFunctionRequest], Awaitable[operations_pb2.Operation] + ]: r"""Return a callable for the update function method over gRPC. Updates existing function. @@ -353,14 +356,16 @@ def update_function( self._stubs["update_function"] = self.grpc_channel.unary_unary( "/google.cloud.functions.v1.CloudFunctionsService/UpdateFunction", request_serializer=functions.UpdateFunctionRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["update_function"] @property def delete_function( self, - ) -> Callable[[functions.DeleteFunctionRequest], Awaitable[operations.Operation]]: + ) -> Callable[ + [functions.DeleteFunctionRequest], Awaitable[operations_pb2.Operation] + ]: r"""Return a callable for the delete function method over gRPC. Deletes a function with the given name from the @@ -382,7 +387,7 @@ def delete_function( self._stubs["delete_function"] = self.grpc_channel.unary_unary( "/google.cloud.functions.v1.CloudFunctionsService/DeleteFunction", request_serializer=functions.DeleteFunctionRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["delete_function"] @@ -511,7 +516,7 @@ def generate_download_url( @property def set_iam_policy( self, - ) -> Callable[[iam_policy.SetIamPolicyRequest], Awaitable[policy.Policy]]: + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], Awaitable[policy_pb2.Policy]]: r"""Return a callable for the set iam policy method over gRPC. Sets the IAM access control policy on the specified @@ -530,15 +535,15 @@ def set_iam_policy( if "set_iam_policy" not in self._stubs: self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( "/google.cloud.functions.v1.CloudFunctionsService/SetIamPolicy", - request_serializer=iam_policy.SetIamPolicyRequest.SerializeToString, - response_deserializer=policy.Policy.FromString, + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, ) return self._stubs["set_iam_policy"] @property def get_iam_policy( self, - ) -> Callable[[iam_policy.GetIamPolicyRequest], Awaitable[policy.Policy]]: + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], Awaitable[policy_pb2.Policy]]: r"""Return a callable for the get iam policy method over gRPC. Gets the IAM access control policy for a function. @@ -558,8 +563,8 @@ def get_iam_policy( if "get_iam_policy" not in self._stubs: self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( "/google.cloud.functions.v1.CloudFunctionsService/GetIamPolicy", - request_serializer=iam_policy.GetIamPolicyRequest.SerializeToString, - response_deserializer=policy.Policy.FromString, + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, ) return self._stubs["get_iam_policy"] @@ -567,8 +572,8 @@ def get_iam_policy( def test_iam_permissions( self, ) -> Callable[ - [iam_policy.TestIamPermissionsRequest], - Awaitable[iam_policy.TestIamPermissionsResponse], + [iam_policy_pb2.TestIamPermissionsRequest], + Awaitable[iam_policy_pb2.TestIamPermissionsResponse], ]: r"""Return a callable for the test iam permissions method over gRPC. @@ -589,8 +594,8 @@ def test_iam_permissions( if "test_iam_permissions" not in self._stubs: self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( "/google.cloud.functions.v1.CloudFunctionsService/TestIamPermissions", - request_serializer=iam_policy.TestIamPermissionsRequest.SerializeToString, - response_deserializer=iam_policy.TestIamPermissionsResponse.FromString, + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, ) return self._stubs["test_iam_permissions"] diff --git a/google/cloud/functions_v1/types/__init__.py b/google/cloud/functions_v1/types/__init__.py index 62b2f9b..057540b 100644 --- a/google/cloud/functions_v1/types/__init__.py +++ b/google/cloud/functions_v1/types/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from .functions import ( CallFunctionRequest, CallFunctionResponse, diff --git a/google/cloud/functions_v1/types/functions.py b/google/cloud/functions_v1/types/functions.py index e5c3ee7..6dae135 100644 --- a/google/cloud/functions_v1/types/functions.py +++ b/google/cloud/functions_v1/types/functions.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( @@ -194,59 +191,39 @@ class IngressSettings(proto.Enum): ALLOW_INTERNAL_ONLY = 2 ALLOW_INTERNAL_AND_GCLB = 3 - name = proto.Field(proto.STRING, number=1) - - description = proto.Field(proto.STRING, number=2) - - source_archive_url = proto.Field(proto.STRING, number=3, oneof="source_code") - + name = proto.Field(proto.STRING, number=1,) + description = proto.Field(proto.STRING, number=2,) + source_archive_url = proto.Field(proto.STRING, number=3, oneof="source_code",) source_repository = proto.Field( proto.MESSAGE, number=4, oneof="source_code", message="SourceRepository", ) - - source_upload_url = proto.Field(proto.STRING, number=16, oneof="source_code") - + source_upload_url = proto.Field(proto.STRING, number=16, oneof="source_code",) https_trigger = proto.Field( proto.MESSAGE, number=5, oneof="trigger", message="HttpsTrigger", ) - event_trigger = proto.Field( proto.MESSAGE, number=6, oneof="trigger", message="EventTrigger", ) - status = proto.Field(proto.ENUM, number=7, enum="CloudFunctionStatus",) - - entry_point = proto.Field(proto.STRING, number=8) - - runtime = proto.Field(proto.STRING, number=19) - - timeout = proto.Field(proto.MESSAGE, number=9, message=duration.Duration,) - - available_memory_mb = proto.Field(proto.INT32, number=10) - - service_account_email = proto.Field(proto.STRING, number=11) - - update_time = proto.Field(proto.MESSAGE, number=12, message=timestamp.Timestamp,) - - version_id = proto.Field(proto.INT64, number=14) - - labels = proto.MapField(proto.STRING, proto.STRING, number=15) - - environment_variables = proto.MapField(proto.STRING, proto.STRING, number=17) - - network = proto.Field(proto.STRING, number=18) - - max_instances = proto.Field(proto.INT32, number=20) - - vpc_connector = proto.Field(proto.STRING, number=22) - + entry_point = proto.Field(proto.STRING, number=8,) + runtime = proto.Field(proto.STRING, number=19,) + timeout = proto.Field(proto.MESSAGE, number=9, message=duration_pb2.Duration,) + available_memory_mb = proto.Field(proto.INT32, number=10,) + service_account_email = proto.Field(proto.STRING, number=11,) + update_time = proto.Field( + proto.MESSAGE, number=12, message=timestamp_pb2.Timestamp, + ) + version_id = proto.Field(proto.INT64, number=14,) + labels = proto.MapField(proto.STRING, proto.STRING, number=15,) + environment_variables = proto.MapField(proto.STRING, proto.STRING, number=17,) + network = proto.Field(proto.STRING, number=18,) + max_instances = proto.Field(proto.INT32, number=20,) + vpc_connector = proto.Field(proto.STRING, number=22,) vpc_connector_egress_settings = proto.Field( proto.ENUM, number=23, enum=VpcConnectorEgressSettings, ) - ingress_settings = proto.Field(proto.ENUM, number=24, enum=IngressSettings,) - - build_id = proto.Field(proto.STRING, number=27) + build_id = proto.Field(proto.STRING, number=27,) class SourceRepository(proto.Message): @@ -276,9 +253,8 @@ class SourceRepository(proto.Message): specific commit in the format described above. """ - url = proto.Field(proto.STRING, number=1) - - deployed_url = proto.Field(proto.STRING, number=2) + url = proto.Field(proto.STRING, number=1,) + deployed_url = proto.Field(proto.STRING, number=2,) class HttpsTrigger(proto.Message): @@ -291,7 +267,7 @@ class HttpsTrigger(proto.Message): function. """ - url = proto.Field(proto.STRING, number=1) + url = proto.Field(proto.STRING, number=1,) class EventTrigger(proto.Message): @@ -347,12 +323,9 @@ class EventTrigger(proto.Message): Specifies policy for failed executions. """ - event_type = proto.Field(proto.STRING, number=1) - - resource = proto.Field(proto.STRING, number=2) - - service = proto.Field(proto.STRING, number=3) - + event_type = proto.Field(proto.STRING, number=1,) + resource = proto.Field(proto.STRING, number=2,) + service = proto.Field(proto.STRING, number=3,) failure_policy = proto.Field(proto.MESSAGE, number=5, message="FailurePolicy",) @@ -373,14 +346,13 @@ class Retry(proto.Message): failed execution will be retried up to 7 days with an exponential backoff (capped at 10 seconds). Retried execution is charged as any other execution. - """ + """ retry = proto.Field(proto.MESSAGE, number=1, oneof="action", message=Retry,) class CreateFunctionRequest(proto.Message): r"""Request for the ``CreateFunction`` method. - Attributes: location (str): Required. The project and location in which the function @@ -390,14 +362,12 @@ class CreateFunctionRequest(proto.Message): Required. Function to be created. """ - location = proto.Field(proto.STRING, number=1) - + location = proto.Field(proto.STRING, number=1,) function = proto.Field(proto.MESSAGE, number=2, message="CloudFunction",) class UpdateFunctionRequest(proto.Message): r"""Request for the ``UpdateFunction`` method. - Attributes: function (google.cloud.functions_v1.types.CloudFunction): Required. New version of the function. @@ -407,25 +377,24 @@ class UpdateFunctionRequest(proto.Message): """ function = proto.Field(proto.MESSAGE, number=1, message="CloudFunction",) - - 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 GetFunctionRequest(proto.Message): r"""Request for the ``GetFunction`` method. - Attributes: name (str): Required. The name of the function which details should be obtained. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class ListFunctionsRequest(proto.Message): r"""Request for the ``ListFunctions`` method. - Attributes: parent (str): The project and location from which the function should be @@ -445,16 +414,13 @@ class ListFunctionsRequest(proto.Message): the next page of data. """ - parent = proto.Field(proto.STRING, number=1) - - page_size = proto.Field(proto.INT32, number=2) - - page_token = proto.Field(proto.STRING, number=3) + parent = proto.Field(proto.STRING, number=1,) + page_size = proto.Field(proto.INT32, number=2,) + page_token = proto.Field(proto.STRING, number=3,) class ListFunctionsResponse(proto.Message): r"""Response for the ``ListFunctions`` method. - Attributes: functions (Sequence[google.cloud.functions_v1.types.CloudFunction]): The functions that match the request. @@ -474,27 +440,23 @@ def raw_page(self): return self functions = proto.RepeatedField(proto.MESSAGE, number=1, message="CloudFunction",) - - next_page_token = proto.Field(proto.STRING, number=2) - - unreachable = proto.RepeatedField(proto.STRING, number=3) + next_page_token = proto.Field(proto.STRING, number=2,) + unreachable = proto.RepeatedField(proto.STRING, number=3,) class DeleteFunctionRequest(proto.Message): r"""Request for the ``DeleteFunction`` method. - Attributes: name (str): Required. The name of the function which should be deleted. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class CallFunctionRequest(proto.Message): r"""Request for the ``CallFunction`` method. - Attributes: name (str): Required. The name of the function to be @@ -503,14 +465,12 @@ class CallFunctionRequest(proto.Message): Required. Input to be passed to the function. """ - name = proto.Field(proto.STRING, number=1) - - data = proto.Field(proto.STRING, number=2) + name = proto.Field(proto.STRING, number=1,) + data = proto.Field(proto.STRING, number=2,) class CallFunctionResponse(proto.Message): r"""Response of ``CallFunction`` method. - Attributes: execution_id (str): Execution id of function invocation. @@ -524,16 +484,13 @@ class CallFunctionResponse(proto.Message): error. Set if execution was not successful. """ - execution_id = proto.Field(proto.STRING, number=1) - - result = proto.Field(proto.STRING, number=2) - - error = proto.Field(proto.STRING, number=3) + execution_id = proto.Field(proto.STRING, number=1,) + result = proto.Field(proto.STRING, number=2,) + error = proto.Field(proto.STRING, number=3,) class GenerateUploadUrlRequest(proto.Message): r"""Request of ``GenerateSourceUploadUrl`` method. - Attributes: parent (str): The project and location in which the Google Cloud Storage @@ -541,12 +498,11 @@ class GenerateUploadUrlRequest(proto.Message): ``projects/*/locations/*``. """ - parent = proto.Field(proto.STRING, number=1) + parent = proto.Field(proto.STRING, number=1,) class GenerateUploadUrlResponse(proto.Message): r"""Response of ``GenerateSourceUploadUrl`` method. - Attributes: upload_url (str): The generated Google Cloud Storage signed URL @@ -555,12 +511,11 @@ class GenerateUploadUrlResponse(proto.Message): archive which contains a function. """ - upload_url = proto.Field(proto.STRING, number=1) + upload_url = proto.Field(proto.STRING, number=1,) class GenerateDownloadUrlRequest(proto.Message): r"""Request of ``GenerateDownloadUrl`` method. - Attributes: name (str): The name of function for which source code @@ -571,14 +526,12 @@ class GenerateDownloadUrlRequest(proto.Message): default, current version is used. """ - name = proto.Field(proto.STRING, number=1) - - version_id = proto.Field(proto.UINT64, number=2) + name = proto.Field(proto.STRING, number=1,) + version_id = proto.Field(proto.UINT64, number=2,) class GenerateDownloadUrlResponse(proto.Message): r"""Response of ``GenerateDownloadUrl`` method. - Attributes: download_url (str): The generated Google Cloud Storage signed URL @@ -586,7 +539,7 @@ class GenerateDownloadUrlResponse(proto.Message): download. """ - download_url = proto.Field(proto.STRING, number=1) + download_url = proto.Field(proto.STRING, number=1,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/functions_v1/types/operations.py b/google/cloud/functions_v1/types/operations.py index 5a452e1..49b85fb 100644 --- a/google/cloud/functions_v1/types/operations.py +++ b/google/cloud/functions_v1/types/operations.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,12 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - -from google.protobuf import any_pb2 as gp_any # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.protobuf import any_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore __protobuf__ = proto.module( @@ -38,7 +35,6 @@ class OperationType(proto.Enum): class OperationMetadataV1(proto.Message): r"""Metadata describing an [Operation][google.longrunning.Operation] - Attributes: target (str): Target of the operation - for example @@ -60,17 +56,12 @@ class OperationMetadataV1(proto.Message): populated for Create and Update operations. """ - target = proto.Field(proto.STRING, number=1) - + target = proto.Field(proto.STRING, number=1,) type_ = proto.Field(proto.ENUM, number=2, enum="OperationType",) - - request = proto.Field(proto.MESSAGE, number=3, message=gp_any.Any,) - - version_id = proto.Field(proto.INT64, number=4) - - update_time = proto.Field(proto.MESSAGE, number=5, message=timestamp.Timestamp,) - - build_id = proto.Field(proto.STRING, number=6) + request = proto.Field(proto.MESSAGE, number=3, message=any_pb2.Any,) + version_id = proto.Field(proto.INT64, number=4,) + update_time = proto.Field(proto.MESSAGE, number=5, message=timestamp_pb2.Timestamp,) + build_id = proto.Field(proto.STRING, number=6,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/scripts/fixup_functions_v1_keywords.py b/scripts/fixup_functions_v1_keywords.py index 78b0502..5d0c9b2 100644 --- a/scripts/fixup_functions_v1_keywords.py +++ b/scripts/fixup_functions_v1_keywords.py @@ -1,6 +1,5 @@ #! /usr/bin/env python3 # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,7 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import argparse import os import libcst as cst @@ -41,18 +39,17 @@ def partition( class functionsCallTransformer(cst.CSTTransformer): CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { - 'call_function': ('name', 'data', ), - 'create_function': ('location', 'function', ), - 'delete_function': ('name', ), - 'generate_download_url': ('name', 'version_id', ), - 'generate_upload_url': ('parent', ), - 'get_function': ('name', ), - 'get_iam_policy': ('resource', 'options', ), - 'list_functions': ('parent', 'page_size', 'page_token', ), - 'set_iam_policy': ('resource', 'policy', ), - 'test_iam_permissions': ('resource', 'permissions', ), - 'update_function': ('function', 'update_mask', ), - + 'call_function': ('name', 'data', ), + 'create_function': ('location', 'function', ), + 'delete_function': ('name', ), + 'generate_download_url': ('name', 'version_id', ), + 'generate_upload_url': ('parent', ), + 'get_function': ('name', ), + 'get_iam_policy': ('resource', 'options', ), + 'list_functions': ('parent', 'page_size', 'page_token', ), + 'set_iam_policy': ('resource', 'policy', ), + 'test_iam_permissions': ('resource', 'permissions', ), + 'update_function': ('function', 'update_mask', ), } def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: @@ -83,7 +80,7 @@ def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: value=cst.Dict([ cst.DictElement( cst.SimpleString("'{}'".format(name)), - cst.Element(value=arg.value) +cst.Element(value=arg.value) ) # Note: the args + kwargs looks silly, but keep in mind that # the control parameters had to be stripped out, and that diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..4de6597 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py new file mode 100644 index 0000000..4de6597 --- /dev/null +++ b/tests/unit/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/tests/unit/gapic/__init__.py b/tests/unit/gapic/__init__.py new file mode 100644 index 0000000..4de6597 --- /dev/null +++ b/tests/unit/gapic/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/tests/unit/gapic/functions_v1/__init__.py b/tests/unit/gapic/functions_v1/__init__.py index 42ffdf2..4de6597 100644 --- a/tests/unit/gapic/functions_v1/__init__.py +++ b/tests/unit/gapic/functions_v1/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/unit/gapic/functions_v1/test_cloud_functions_service.py b/tests/unit/gapic/functions_v1/test_cloud_functions_service.py index d328a0e..26ca1ec 100644 --- a/tests/unit/gapic/functions_v1/test_cloud_functions_service.py +++ b/tests/unit/gapic/functions_v1/test_cloud_functions_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.functions_v1.services.cloud_functions_service import ( CloudFunctionsServiceAsyncClient, @@ -43,17 +42,47 @@ ) from google.cloud.functions_v1.services.cloud_functions_service import pagers from google.cloud.functions_v1.services.cloud_functions_service import transports +from google.cloud.functions_v1.services.cloud_functions_service.transports.base import ( + _API_CORE_VERSION, +) +from google.cloud.functions_v1.services.cloud_functions_service.transports.base import ( + _GOOGLE_AUTH_VERSION, +) from google.cloud.functions_v1.types import functions from google.cloud.functions_v1.types import operations -from google.iam.v1 import iam_policy_pb2 as iam_policy # type: ignore -from google.iam.v1 import options_pb2 as options # type: ignore -from google.iam.v1 import policy_pb2 as policy # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import options_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore 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.type import expr_pb2 as expr # 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 +from google.type import expr_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(): @@ -105,7 +134,7 @@ def test__get_default_mtls_endpoint(): "client_class", [CloudFunctionsServiceClient, CloudFunctionsServiceAsyncClient,] ) def test_cloud_functions_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: @@ -122,7 +151,7 @@ def test_cloud_functions_service_client_from_service_account_info(client_class): "client_class", [CloudFunctionsServiceClient, CloudFunctionsServiceAsyncClient,] ) def test_cloud_functions_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: @@ -179,7 +208,7 @@ def test_cloud_functions_service_client_client_options( ): # Check that if channel is provided we won't create a new one. with mock.patch.object(CloudFunctionsServiceClient, "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() @@ -485,7 +514,7 @@ def test_list_functions( transport: str = "grpc", request_type=functions.ListFunctionsRequest ): client = CloudFunctionsServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -498,21 +527,16 @@ def test_list_functions( call.return_value = functions.ListFunctionsResponse( next_page_token="next_page_token_value", unreachable=["unreachable_value"], ) - response = client.list_functions(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == functions.ListFunctionsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListFunctionsPager) - assert response.next_page_token == "next_page_token_value" - assert response.unreachable == ["unreachable_value"] @@ -524,7 +548,7 @@ def test_list_functions_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 = CloudFunctionsServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -532,7 +556,6 @@ def test_list_functions_empty_call(): client.list_functions() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == functions.ListFunctionsRequest() @@ -541,7 +564,7 @@ async def test_list_functions_async( transport: str = "grpc_asyncio", request_type=functions.ListFunctionsRequest ): client = CloudFunctionsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -557,20 +580,16 @@ async def test_list_functions_async( unreachable=["unreachable_value"], ) ) - response = await client.list_functions(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == functions.ListFunctionsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListFunctionsAsyncPager) - assert response.next_page_token == "next_page_token_value" - assert response.unreachable == ["unreachable_value"] @@ -581,18 +600,18 @@ async def test_list_functions_async_from_dict(): def test_list_functions_field_headers(): client = CloudFunctionsServiceClient( - 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 = functions.ListFunctionsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_functions), "__call__") as call: call.return_value = functions.ListFunctionsResponse() - client.list_functions(request) # Establish that the underlying gRPC stub method was called. @@ -608,12 +627,13 @@ def test_list_functions_field_headers(): @pytest.mark.asyncio async def test_list_functions_field_headers_async(): client = CloudFunctionsServiceAsyncClient( - 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 = functions.ListFunctionsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -621,7 +641,6 @@ async def test_list_functions_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( functions.ListFunctionsResponse() ) - await client.list_functions(request) # Establish that the underlying gRPC stub method was called. @@ -635,7 +654,9 @@ async def test_list_functions_field_headers_async(): def test_list_functions_pager(): - client = CloudFunctionsServiceClient(credentials=credentials.AnonymousCredentials,) + client = CloudFunctionsServiceClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_functions), "__call__") as call: @@ -673,7 +694,9 @@ def test_list_functions_pager(): def test_list_functions_pages(): - client = CloudFunctionsServiceClient(credentials=credentials.AnonymousCredentials,) + client = CloudFunctionsServiceClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_functions), "__call__") as call: @@ -704,7 +727,7 @@ def test_list_functions_pages(): @pytest.mark.asyncio async def test_list_functions_async_pager(): client = CloudFunctionsServiceAsyncClient( - credentials=credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -743,7 +766,7 @@ async def test_list_functions_async_pager(): @pytest.mark.asyncio async def test_list_functions_async_pages(): client = CloudFunctionsServiceAsyncClient( - credentials=credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -780,7 +803,7 @@ def test_get_function( transport: str = "grpc", request_type=functions.GetFunctionRequest ): client = CloudFunctionsServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -808,50 +831,33 @@ def test_get_function( source_archive_url="source_archive_url_value", https_trigger=functions.HttpsTrigger(url="url_value"), ) - response = client.get_function(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == functions.GetFunctionRequest() # Establish that the response is the type that we expect. - assert isinstance(response, functions.CloudFunction) - assert response.name == "name_value" - assert response.description == "description_value" - assert response.status == functions.CloudFunctionStatus.ACTIVE - assert response.entry_point == "entry_point_value" - assert response.runtime == "runtime_value" - assert response.available_memory_mb == 1991 - assert response.service_account_email == "service_account_email_value" - assert response.version_id == 1074 - assert response.network == "network_value" - assert response.max_instances == 1389 - assert response.vpc_connector == "vpc_connector_value" - assert ( response.vpc_connector_egress_settings == functions.CloudFunction.VpcConnectorEgressSettings.PRIVATE_RANGES_ONLY ) - assert ( response.ingress_settings == functions.CloudFunction.IngressSettings.ALLOW_ALL ) - assert response.build_id == "build_id_value" @@ -863,7 +869,7 @@ def test_get_function_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 = CloudFunctionsServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -871,7 +877,6 @@ def test_get_function_empty_call(): client.get_function() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == functions.GetFunctionRequest() @@ -880,7 +885,7 @@ async def test_get_function_async( transport: str = "grpc_asyncio", request_type=functions.GetFunctionRequest ): client = CloudFunctionsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -908,49 +913,33 @@ async def test_get_function_async( build_id="build_id_value", ) ) - response = await client.get_function(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == functions.GetFunctionRequest() # Establish that the response is the type that we expect. assert isinstance(response, functions.CloudFunction) - assert response.name == "name_value" - assert response.description == "description_value" - assert response.status == functions.CloudFunctionStatus.ACTIVE - assert response.entry_point == "entry_point_value" - assert response.runtime == "runtime_value" - assert response.available_memory_mb == 1991 - assert response.service_account_email == "service_account_email_value" - assert response.version_id == 1074 - assert response.network == "network_value" - assert response.max_instances == 1389 - assert response.vpc_connector == "vpc_connector_value" - assert ( response.vpc_connector_egress_settings == functions.CloudFunction.VpcConnectorEgressSettings.PRIVATE_RANGES_ONLY ) - assert ( response.ingress_settings == functions.CloudFunction.IngressSettings.ALLOW_ALL ) - assert response.build_id == "build_id_value" @@ -961,18 +950,18 @@ async def test_get_function_async_from_dict(): def test_get_function_field_headers(): client = CloudFunctionsServiceClient( - 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 = functions.GetFunctionRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_function), "__call__") as call: call.return_value = functions.CloudFunction() - client.get_function(request) # Establish that the underlying gRPC stub method was called. @@ -988,12 +977,13 @@ def test_get_function_field_headers(): @pytest.mark.asyncio async def test_get_function_field_headers_async(): client = CloudFunctionsServiceAsyncClient( - 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 = functions.GetFunctionRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1001,7 +991,6 @@ async def test_get_function_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( functions.CloudFunction() ) - await client.get_function(request) # Establish that the underlying gRPC stub method was called. @@ -1016,14 +1005,13 @@ async def test_get_function_field_headers_async(): def test_get_function_flattened(): client = CloudFunctionsServiceClient( - 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_function), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = functions.CloudFunction() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.get_function(name="name_value",) @@ -1032,13 +1020,12 @@ def test_get_function_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_get_function_flattened_error(): client = CloudFunctionsServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1052,7 +1039,7 @@ def test_get_function_flattened_error(): @pytest.mark.asyncio async def test_get_function_flattened_async(): client = CloudFunctionsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1071,14 +1058,13 @@ async def test_get_function_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_function_flattened_error_async(): client = CloudFunctionsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1093,7 +1079,7 @@ def test_create_function( transport: str = "grpc", request_type=functions.CreateFunctionRequest ): client = CloudFunctionsServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1104,13 +1090,11 @@ def test_create_function( with mock.patch.object(type(client.transport.create_function), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.create_function(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == functions.CreateFunctionRequest() # Establish that the response is the type that we expect. @@ -1125,7 +1109,7 @@ def test_create_function_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 = CloudFunctionsServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1133,7 +1117,6 @@ def test_create_function_empty_call(): client.create_function() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == functions.CreateFunctionRequest() @@ -1142,7 +1125,7 @@ async def test_create_function_async( transport: str = "grpc_asyncio", request_type=functions.CreateFunctionRequest ): client = CloudFunctionsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1155,13 +1138,11 @@ async def test_create_function_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.create_function(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == functions.CreateFunctionRequest() # Establish that the response is the type that we expect. @@ -1175,18 +1156,18 @@ async def test_create_function_async_from_dict(): def test_create_function_field_headers(): client = CloudFunctionsServiceClient( - 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 = functions.CreateFunctionRequest() + request.location = "location/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_function), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.create_function(request) # Establish that the underlying gRPC stub method was called. @@ -1202,12 +1183,13 @@ def test_create_function_field_headers(): @pytest.mark.asyncio async def test_create_function_field_headers_async(): client = CloudFunctionsServiceAsyncClient( - 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 = functions.CreateFunctionRequest() + request.location = "location/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1215,7 +1197,6 @@ async def test_create_function_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.create_function(request) # Establish that the underlying gRPC stub method was called. @@ -1230,14 +1211,13 @@ async def test_create_function_field_headers_async(): def test_create_function_flattened(): client = CloudFunctionsServiceClient( - 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_function), "__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_function( @@ -1249,15 +1229,13 @@ def test_create_function_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].location == "location_value" - assert args[0].function == functions.CloudFunction(name="name_value") def test_create_function_flattened_error(): client = CloudFunctionsServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1273,7 +1251,7 @@ def test_create_function_flattened_error(): @pytest.mark.asyncio async def test_create_function_flattened_async(): client = CloudFunctionsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1295,16 +1273,14 @@ async def test_create_function_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].location == "location_value" - assert args[0].function == functions.CloudFunction(name="name_value") @pytest.mark.asyncio async def test_create_function_flattened_error_async(): client = CloudFunctionsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1321,7 +1297,7 @@ def test_update_function( transport: str = "grpc", request_type=functions.UpdateFunctionRequest ): client = CloudFunctionsServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1332,13 +1308,11 @@ def test_update_function( with mock.patch.object(type(client.transport.update_function), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.update_function(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == functions.UpdateFunctionRequest() # Establish that the response is the type that we expect. @@ -1353,7 +1327,7 @@ def test_update_function_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 = CloudFunctionsServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1361,7 +1335,6 @@ def test_update_function_empty_call(): client.update_function() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == functions.UpdateFunctionRequest() @@ -1370,7 +1343,7 @@ async def test_update_function_async( transport: str = "grpc_asyncio", request_type=functions.UpdateFunctionRequest ): client = CloudFunctionsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1383,13 +1356,11 @@ async def test_update_function_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.update_function(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == functions.UpdateFunctionRequest() # Establish that the response is the type that we expect. @@ -1403,18 +1374,18 @@ async def test_update_function_async_from_dict(): def test_update_function_field_headers(): client = CloudFunctionsServiceClient( - 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 = functions.UpdateFunctionRequest() + request.function.name = "function.name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_function), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.update_function(request) # Establish that the underlying gRPC stub method was called. @@ -1432,12 +1403,13 @@ def test_update_function_field_headers(): @pytest.mark.asyncio async def test_update_function_field_headers_async(): client = CloudFunctionsServiceAsyncClient( - 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 = functions.UpdateFunctionRequest() + request.function.name = "function.name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1445,7 +1417,6 @@ async def test_update_function_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.update_function(request) # Establish that the underlying gRPC stub method was called. @@ -1462,14 +1433,13 @@ async def test_update_function_field_headers_async(): def test_update_function_flattened(): client = CloudFunctionsServiceClient( - 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_function), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.update_function(function=functions.CloudFunction(name="name_value"),) @@ -1478,13 +1448,12 @@ def test_update_function_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].function == functions.CloudFunction(name="name_value") def test_update_function_flattened_error(): client = CloudFunctionsServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1499,7 +1468,7 @@ def test_update_function_flattened_error(): @pytest.mark.asyncio async def test_update_function_flattened_async(): client = CloudFunctionsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1520,14 +1489,13 @@ async def test_update_function_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].function == functions.CloudFunction(name="name_value") @pytest.mark.asyncio async def test_update_function_flattened_error_async(): client = CloudFunctionsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1543,7 +1511,7 @@ def test_delete_function( transport: str = "grpc", request_type=functions.DeleteFunctionRequest ): client = CloudFunctionsServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1554,13 +1522,11 @@ def test_delete_function( with mock.patch.object(type(client.transport.delete_function), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.delete_function(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == functions.DeleteFunctionRequest() # Establish that the response is the type that we expect. @@ -1575,7 +1541,7 @@ def test_delete_function_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 = CloudFunctionsServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1583,7 +1549,6 @@ def test_delete_function_empty_call(): client.delete_function() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == functions.DeleteFunctionRequest() @@ -1592,7 +1557,7 @@ async def test_delete_function_async( transport: str = "grpc_asyncio", request_type=functions.DeleteFunctionRequest ): client = CloudFunctionsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1605,13 +1570,11 @@ async def test_delete_function_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.delete_function(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == functions.DeleteFunctionRequest() # Establish that the response is the type that we expect. @@ -1625,18 +1588,18 @@ async def test_delete_function_async_from_dict(): def test_delete_function_field_headers(): client = CloudFunctionsServiceClient( - 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 = functions.DeleteFunctionRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_function), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.delete_function(request) # Establish that the underlying gRPC stub method was called. @@ -1652,12 +1615,13 @@ def test_delete_function_field_headers(): @pytest.mark.asyncio async def test_delete_function_field_headers_async(): client = CloudFunctionsServiceAsyncClient( - 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 = functions.DeleteFunctionRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1665,7 +1629,6 @@ async def test_delete_function_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.delete_function(request) # Establish that the underlying gRPC stub method was called. @@ -1680,14 +1643,13 @@ async def test_delete_function_field_headers_async(): def test_delete_function_flattened(): client = CloudFunctionsServiceClient( - 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_function), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.delete_function(name="name_value",) @@ -1696,13 +1658,12 @@ def test_delete_function_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_delete_function_flattened_error(): client = CloudFunctionsServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1716,7 +1677,7 @@ def test_delete_function_flattened_error(): @pytest.mark.asyncio async def test_delete_function_flattened_async(): client = CloudFunctionsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1735,14 +1696,13 @@ async def test_delete_function_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_function_flattened_error_async(): client = CloudFunctionsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1757,7 +1717,7 @@ def test_call_function( transport: str = "grpc", request_type=functions.CallFunctionRequest ): client = CloudFunctionsServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1772,23 +1732,17 @@ def test_call_function( result="result_value", error="error_value", ) - response = client.call_function(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == functions.CallFunctionRequest() # Establish that the response is the type that we expect. - assert isinstance(response, functions.CallFunctionResponse) - assert response.execution_id == "execution_id_value" - assert response.result == "result_value" - assert response.error == "error_value" @@ -1800,7 +1754,7 @@ def test_call_function_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 = CloudFunctionsServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1808,7 +1762,6 @@ def test_call_function_empty_call(): client.call_function() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == functions.CallFunctionRequest() @@ -1817,7 +1770,7 @@ async def test_call_function_async( transport: str = "grpc_asyncio", request_type=functions.CallFunctionRequest ): client = CloudFunctionsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1834,22 +1787,17 @@ async def test_call_function_async( error="error_value", ) ) - response = await client.call_function(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == functions.CallFunctionRequest() # Establish that the response is the type that we expect. assert isinstance(response, functions.CallFunctionResponse) - assert response.execution_id == "execution_id_value" - assert response.result == "result_value" - assert response.error == "error_value" @@ -1860,18 +1808,18 @@ async def test_call_function_async_from_dict(): def test_call_function_field_headers(): client = CloudFunctionsServiceClient( - 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 = functions.CallFunctionRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.call_function), "__call__") as call: call.return_value = functions.CallFunctionResponse() - client.call_function(request) # Establish that the underlying gRPC stub method was called. @@ -1887,12 +1835,13 @@ def test_call_function_field_headers(): @pytest.mark.asyncio async def test_call_function_field_headers_async(): client = CloudFunctionsServiceAsyncClient( - 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 = functions.CallFunctionRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1900,7 +1849,6 @@ async def test_call_function_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( functions.CallFunctionResponse() ) - await client.call_function(request) # Establish that the underlying gRPC stub method was called. @@ -1915,14 +1863,13 @@ async def test_call_function_field_headers_async(): def test_call_function_flattened(): client = CloudFunctionsServiceClient( - 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.call_function), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = functions.CallFunctionResponse() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.call_function( @@ -1933,15 +1880,13 @@ def test_call_function_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].data == "data_value" def test_call_function_flattened_error(): client = CloudFunctionsServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1955,7 +1900,7 @@ def test_call_function_flattened_error(): @pytest.mark.asyncio async def test_call_function_flattened_async(): client = CloudFunctionsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1974,16 +1919,14 @@ async def test_call_function_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].data == "data_value" @pytest.mark.asyncio async def test_call_function_flattened_error_async(): client = CloudFunctionsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1998,7 +1941,7 @@ def test_generate_upload_url( transport: str = "grpc", request_type=functions.GenerateUploadUrlRequest ): client = CloudFunctionsServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2013,19 +1956,15 @@ def test_generate_upload_url( call.return_value = functions.GenerateUploadUrlResponse( upload_url="upload_url_value", ) - response = client.generate_upload_url(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == functions.GenerateUploadUrlRequest() # Establish that the response is the type that we expect. - assert isinstance(response, functions.GenerateUploadUrlResponse) - assert response.upload_url == "upload_url_value" @@ -2037,7 +1976,7 @@ def test_generate_upload_url_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 = CloudFunctionsServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2047,7 +1986,6 @@ def test_generate_upload_url_empty_call(): client.generate_upload_url() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == functions.GenerateUploadUrlRequest() @@ -2056,7 +1994,7 @@ async def test_generate_upload_url_async( transport: str = "grpc_asyncio", request_type=functions.GenerateUploadUrlRequest ): client = CloudFunctionsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2071,18 +2009,15 @@ async def test_generate_upload_url_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( functions.GenerateUploadUrlResponse(upload_url="upload_url_value",) ) - response = await client.generate_upload_url(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == functions.GenerateUploadUrlRequest() # Establish that the response is the type that we expect. assert isinstance(response, functions.GenerateUploadUrlResponse) - assert response.upload_url == "upload_url_value" @@ -2093,12 +2028,13 @@ async def test_generate_upload_url_async_from_dict(): def test_generate_upload_url_field_headers(): client = CloudFunctionsServiceClient( - 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 = functions.GenerateUploadUrlRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2106,7 +2042,6 @@ def test_generate_upload_url_field_headers(): type(client.transport.generate_upload_url), "__call__" ) as call: call.return_value = functions.GenerateUploadUrlResponse() - client.generate_upload_url(request) # Establish that the underlying gRPC stub method was called. @@ -2122,12 +2057,13 @@ def test_generate_upload_url_field_headers(): @pytest.mark.asyncio async def test_generate_upload_url_field_headers_async(): client = CloudFunctionsServiceAsyncClient( - 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 = functions.GenerateUploadUrlRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2137,7 +2073,6 @@ async def test_generate_upload_url_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( functions.GenerateUploadUrlResponse() ) - await client.generate_upload_url(request) # Establish that the underlying gRPC stub method was called. @@ -2154,7 +2089,7 @@ def test_generate_download_url( transport: str = "grpc", request_type=functions.GenerateDownloadUrlRequest ): client = CloudFunctionsServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2169,19 +2104,15 @@ def test_generate_download_url( call.return_value = functions.GenerateDownloadUrlResponse( download_url="download_url_value", ) - response = client.generate_download_url(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == functions.GenerateDownloadUrlRequest() # Establish that the response is the type that we expect. - assert isinstance(response, functions.GenerateDownloadUrlResponse) - assert response.download_url == "download_url_value" @@ -2193,7 +2124,7 @@ def test_generate_download_url_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 = CloudFunctionsServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2203,7 +2134,6 @@ def test_generate_download_url_empty_call(): client.generate_download_url() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == functions.GenerateDownloadUrlRequest() @@ -2212,7 +2142,7 @@ async def test_generate_download_url_async( transport: str = "grpc_asyncio", request_type=functions.GenerateDownloadUrlRequest ): client = CloudFunctionsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2227,18 +2157,15 @@ async def test_generate_download_url_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( functions.GenerateDownloadUrlResponse(download_url="download_url_value",) ) - response = await client.generate_download_url(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == functions.GenerateDownloadUrlRequest() # Establish that the response is the type that we expect. assert isinstance(response, functions.GenerateDownloadUrlResponse) - assert response.download_url == "download_url_value" @@ -2249,12 +2176,13 @@ async def test_generate_download_url_async_from_dict(): def test_generate_download_url_field_headers(): client = CloudFunctionsServiceClient( - 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 = functions.GenerateDownloadUrlRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2262,7 +2190,6 @@ def test_generate_download_url_field_headers(): type(client.transport.generate_download_url), "__call__" ) as call: call.return_value = functions.GenerateDownloadUrlResponse() - client.generate_download_url(request) # Establish that the underlying gRPC stub method was called. @@ -2278,12 +2205,13 @@ def test_generate_download_url_field_headers(): @pytest.mark.asyncio async def test_generate_download_url_field_headers_async(): client = CloudFunctionsServiceAsyncClient( - 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 = functions.GenerateDownloadUrlRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2293,7 +2221,6 @@ async def test_generate_download_url_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( functions.GenerateDownloadUrlResponse() ) - await client.generate_download_url(request) # Establish that the underlying gRPC stub method was called. @@ -2307,10 +2234,10 @@ async def test_generate_download_url_field_headers_async(): def test_set_iam_policy( - transport: str = "grpc", request_type=iam_policy.SetIamPolicyRequest + transport: str = "grpc", request_type=iam_policy_pb2.SetIamPolicyRequest ): client = CloudFunctionsServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2320,22 +2247,17 @@ def test_set_iam_policy( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = policy.Policy(version=774, etag=b"etag_blob",) - + call.return_value = policy_pb2.Policy(version=774, etag=b"etag_blob",) response = client.set_iam_policy(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - - assert args[0] == iam_policy.SetIamPolicyRequest() + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() # Establish that the response is the type that we expect. - - assert isinstance(response, policy.Policy) - + assert isinstance(response, policy_pb2.Policy) assert response.version == 774 - assert response.etag == b"etag_blob" @@ -2347,7 +2269,7 @@ def test_set_iam_policy_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 = CloudFunctionsServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2355,16 +2277,15 @@ def test_set_iam_policy_empty_call(): client.set_iam_policy() call.assert_called() _, args, _ = call.mock_calls[0] - - assert args[0] == iam_policy.SetIamPolicyRequest() + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() @pytest.mark.asyncio async def test_set_iam_policy_async( - transport: str = "grpc_asyncio", request_type=iam_policy.SetIamPolicyRequest + transport: str = "grpc_asyncio", request_type=iam_policy_pb2.SetIamPolicyRequest ): client = CloudFunctionsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2375,22 +2296,18 @@ async def test_set_iam_policy_async( with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - policy.Policy(version=774, etag=b"etag_blob",) + policy_pb2.Policy(version=774, etag=b"etag_blob",) ) - response = await client.set_iam_policy(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - - assert args[0] == iam_policy.SetIamPolicyRequest() + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() # Establish that the response is the type that we expect. - assert isinstance(response, policy.Policy) - + assert isinstance(response, policy_pb2.Policy) assert response.version == 774 - assert response.etag == b"etag_blob" @@ -2401,18 +2318,18 @@ async def test_set_iam_policy_async_from_dict(): def test_set_iam_policy_field_headers(): client = CloudFunctionsServiceClient( - 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 = iam_policy.SetIamPolicyRequest() + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: - call.return_value = policy.Policy() - + call.return_value = policy_pb2.Policy() client.set_iam_policy(request) # Establish that the underlying gRPC stub method was called. @@ -2428,18 +2345,18 @@ def test_set_iam_policy_field_headers(): @pytest.mark.asyncio async def test_set_iam_policy_field_headers_async(): client = CloudFunctionsServiceAsyncClient( - 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 = iam_policy.SetIamPolicyRequest() + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy.Policy()) - + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) await client.set_iam_policy(request) # Establish that the underlying gRPC stub method was called. @@ -2454,27 +2371,26 @@ async def test_set_iam_policy_field_headers_async(): def test_set_iam_policy_from_dict_foreign(): client = CloudFunctionsServiceClient( - 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.set_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = policy.Policy() - + call.return_value = policy_pb2.Policy() response = client.set_iam_policy( request={ "resource": "resource_value", - "policy": policy.Policy(version=774), + "policy": policy_pb2.Policy(version=774), } ) call.assert_called() def test_get_iam_policy( - transport: str = "grpc", request_type=iam_policy.GetIamPolicyRequest + transport: str = "grpc", request_type=iam_policy_pb2.GetIamPolicyRequest ): client = CloudFunctionsServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2484,22 +2400,17 @@ def test_get_iam_policy( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = policy.Policy(version=774, etag=b"etag_blob",) - + call.return_value = policy_pb2.Policy(version=774, etag=b"etag_blob",) response = client.get_iam_policy(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - - assert args[0] == iam_policy.GetIamPolicyRequest() + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() # Establish that the response is the type that we expect. - - assert isinstance(response, policy.Policy) - + assert isinstance(response, policy_pb2.Policy) assert response.version == 774 - assert response.etag == b"etag_blob" @@ -2511,7 +2422,7 @@ def test_get_iam_policy_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 = CloudFunctionsServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2519,16 +2430,15 @@ def test_get_iam_policy_empty_call(): client.get_iam_policy() call.assert_called() _, args, _ = call.mock_calls[0] - - assert args[0] == iam_policy.GetIamPolicyRequest() + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() @pytest.mark.asyncio async def test_get_iam_policy_async( - transport: str = "grpc_asyncio", request_type=iam_policy.GetIamPolicyRequest + transport: str = "grpc_asyncio", request_type=iam_policy_pb2.GetIamPolicyRequest ): client = CloudFunctionsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2539,22 +2449,18 @@ async def test_get_iam_policy_async( with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - policy.Policy(version=774, etag=b"etag_blob",) + policy_pb2.Policy(version=774, etag=b"etag_blob",) ) - response = await client.get_iam_policy(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - - assert args[0] == iam_policy.GetIamPolicyRequest() + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() # Establish that the response is the type that we expect. - assert isinstance(response, policy.Policy) - + assert isinstance(response, policy_pb2.Policy) assert response.version == 774 - assert response.etag == b"etag_blob" @@ -2565,18 +2471,18 @@ async def test_get_iam_policy_async_from_dict(): def test_get_iam_policy_field_headers(): client = CloudFunctionsServiceClient( - 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 = iam_policy.GetIamPolicyRequest() + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: - call.return_value = policy.Policy() - + call.return_value = policy_pb2.Policy() client.get_iam_policy(request) # Establish that the underlying gRPC stub method was called. @@ -2592,18 +2498,18 @@ def test_get_iam_policy_field_headers(): @pytest.mark.asyncio async def test_get_iam_policy_field_headers_async(): client = CloudFunctionsServiceAsyncClient( - 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 = iam_policy.GetIamPolicyRequest() + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy.Policy()) - + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) await client.get_iam_policy(request) # Establish that the underlying gRPC stub method was called. @@ -2618,27 +2524,26 @@ async def test_get_iam_policy_field_headers_async(): def test_get_iam_policy_from_dict_foreign(): client = CloudFunctionsServiceClient( - 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_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = policy.Policy() - + call.return_value = policy_pb2.Policy() response = client.get_iam_policy( request={ "resource": "resource_value", - "options": options.GetPolicyOptions(requested_policy_version=2598), + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), } ) call.assert_called() def test_test_iam_permissions( - transport: str = "grpc", request_type=iam_policy.TestIamPermissionsRequest + transport: str = "grpc", request_type=iam_policy_pb2.TestIamPermissionsRequest ): client = CloudFunctionsServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2650,22 +2555,18 @@ def test_test_iam_permissions( type(client.transport.test_iam_permissions), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = iam_policy.TestIamPermissionsResponse( + call.return_value = iam_policy_pb2.TestIamPermissionsResponse( permissions=["permissions_value"], ) - response = client.test_iam_permissions(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - - assert args[0] == iam_policy.TestIamPermissionsRequest() + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() # Establish that the response is the type that we expect. - - assert isinstance(response, iam_policy.TestIamPermissionsResponse) - + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) assert response.permissions == ["permissions_value"] @@ -2677,7 +2578,7 @@ def test_test_iam_permissions_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 = CloudFunctionsServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2687,16 +2588,16 @@ def test_test_iam_permissions_empty_call(): client.test_iam_permissions() call.assert_called() _, args, _ = call.mock_calls[0] - - assert args[0] == iam_policy.TestIamPermissionsRequest() + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() @pytest.mark.asyncio async def test_test_iam_permissions_async( - transport: str = "grpc_asyncio", request_type=iam_policy.TestIamPermissionsRequest + transport: str = "grpc_asyncio", + request_type=iam_policy_pb2.TestIamPermissionsRequest, ): client = CloudFunctionsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2709,20 +2610,19 @@ async def test_test_iam_permissions_async( ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - iam_policy.TestIamPermissionsResponse(permissions=["permissions_value"],) + iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) ) - response = await client.test_iam_permissions(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - - assert args[0] == iam_policy.TestIamPermissionsRequest() + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, iam_policy.TestIamPermissionsResponse) - + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) assert response.permissions == ["permissions_value"] @@ -2733,20 +2633,20 @@ async def test_test_iam_permissions_async_from_dict(): def test_test_iam_permissions_field_headers(): client = CloudFunctionsServiceClient( - 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 = iam_policy.TestIamPermissionsRequest() + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( type(client.transport.test_iam_permissions), "__call__" ) as call: - call.return_value = iam_policy.TestIamPermissionsResponse() - + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() client.test_iam_permissions(request) # Establish that the underlying gRPC stub method was called. @@ -2762,12 +2662,13 @@ def test_test_iam_permissions_field_headers(): @pytest.mark.asyncio async def test_test_iam_permissions_field_headers_async(): client = CloudFunctionsServiceAsyncClient( - 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 = iam_policy.TestIamPermissionsRequest() + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2775,9 +2676,8 @@ async def test_test_iam_permissions_field_headers_async(): type(client.transport.test_iam_permissions), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - iam_policy.TestIamPermissionsResponse() + iam_policy_pb2.TestIamPermissionsResponse() ) - await client.test_iam_permissions(request) # Establish that the underlying gRPC stub method was called. @@ -2792,15 +2692,14 @@ async def test_test_iam_permissions_field_headers_async(): def test_test_iam_permissions_from_dict_foreign(): client = CloudFunctionsServiceClient( - 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.test_iam_permissions), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = iam_policy.TestIamPermissionsResponse() - + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() response = client.test_iam_permissions( request={ "resource": "resource_value", @@ -2813,16 +2712,16 @@ def test_test_iam_permissions_from_dict_foreign(): def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.CloudFunctionsServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = CloudFunctionsServiceClient( - 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.CloudFunctionsServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = CloudFunctionsServiceClient( @@ -2832,7 +2731,7 @@ def test_credentials_transport_error(): # It is an error to provide scopes and a transport instance. transport = transports.CloudFunctionsServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = CloudFunctionsServiceClient( @@ -2843,7 +2742,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.CloudFunctionsServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) client = CloudFunctionsServiceClient(transport=transport) assert client.transport is transport @@ -2852,13 +2751,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.CloudFunctionsServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel transport = transports.CloudFunctionsServiceGrpcAsyncIOTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel @@ -2873,8 +2772,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() @@ -2882,16 +2781,16 @@ def test_transport_adc(transport_class): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = CloudFunctionsServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) assert isinstance(client.transport, transports.CloudFunctionsServiceGrpcTransport,) def test_cloud_functions_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.CloudFunctionsServiceTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), credentials_file="credentials.json", ) @@ -2903,7 +2802,7 @@ def test_cloud_functions_service_base_transport(): ) as Transport: Transport.return_value = None transport = transports.CloudFunctionsServiceTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Every method on the transport should just blindly @@ -2931,15 +2830,37 @@ def test_cloud_functions_service_base_transport(): transport.operations_client +@requires_google_auth_gte_1_25_0 def test_cloud_functions_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.functions_v1.services.cloud_functions_service.transports.CloudFunctionsServiceTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.CloudFunctionsServiceTransport( + 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_cloud_functions_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.functions_v1.services.cloud_functions_service.transports.CloudFunctionsServiceTransport._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.CloudFunctionsServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", ) @@ -2952,19 +2873,33 @@ def test_cloud_functions_service_base_transport_with_credentials_file(): def test_cloud_functions_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.functions_v1.services.cloud_functions_service.transports.CloudFunctionsServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (credentials.AnonymousCredentials(), None) + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CloudFunctionsServiceTransport() adc.assert_called_once() +@requires_google_auth_gte_1_25_0 def test_cloud_functions_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) + CloudFunctionsServiceClient() + 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_cloud_functions_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) CloudFunctionsServiceClient() adc.assert_called_once_with( scopes=("https://www.googleapis.com/auth/cloud-platform",), @@ -2972,20 +2907,158 @@ def test_cloud_functions_service_auth_adc(): ) -def test_cloud_functions_service_transport_auth_adc(): +@pytest.mark.parametrize( + "transport_class", + [ + transports.CloudFunctionsServiceGrpcTransport, + transports.CloudFunctionsServiceGrpcAsyncIOTransport, + ], +) +@requires_google_auth_gte_1_25_0 +def test_cloud_functions_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.CloudFunctionsServiceGrpcTransport( - 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.CloudFunctionsServiceGrpcTransport, + transports.CloudFunctionsServiceGrpcAsyncIOTransport, + ], +) +@requires_google_auth_lt_1_25_0 +def test_cloud_functions_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.CloudFunctionsServiceGrpcTransport, grpc_helpers), + (transports.CloudFunctionsServiceGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_gte_1_26_0 +def test_cloud_functions_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( + "cloudfunctions.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="cloudfunctions.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.CloudFunctionsServiceGrpcTransport, grpc_helpers), + (transports.CloudFunctionsServiceGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_cloud_functions_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( + "cloudfunctions.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.CloudFunctionsServiceGrpcTransport, grpc_helpers), + (transports.CloudFunctionsServiceGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_cloud_functions_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( + "cloudfunctions.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", [ @@ -2996,7 +3069,7 @@ def test_cloud_functions_service_transport_auth_adc(): def test_cloud_functions_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: @@ -3035,7 +3108,7 @@ def test_cloud_functions_service_grpc_transport_client_cert_source_for_mtls( def test_cloud_functions_service_host_no_port(): client = CloudFunctionsServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="cloudfunctions.googleapis.com" ), @@ -3045,7 +3118,7 @@ def test_cloud_functions_service_host_no_port(): def test_cloud_functions_service_host_with_port(): client = CloudFunctionsServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="cloudfunctions.googleapis.com:8000" ), @@ -3101,9 +3174,9 @@ def test_cloud_functions_service_transport_channel_mtls_with_client_cert_source( mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = credentials.AnonymousCredentials() + cred = ga_credentials.AnonymousCredentials() with pytest.warns(DeprecationWarning): - with mock.patch.object(auth, "default") as adc: + with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) transport = transport_class( host="squid.clam.whelk", @@ -3179,7 +3252,7 @@ def test_cloud_functions_service_transport_channel_mtls_with_adc(transport_class def test_cloud_functions_service_grpc_lro_client(): client = CloudFunctionsServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) transport = client.transport @@ -3192,7 +3265,7 @@ def test_cloud_functions_service_grpc_lro_client(): def test_cloud_functions_service_grpc_lro_async_client(): client = CloudFunctionsServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", ) transport = client.transport @@ -3207,7 +3280,6 @@ def test_cloud_function_path(): project = "squid" location = "clam" function = "whelk" - expected = "projects/{project}/locations/{location}/functions/{function}".format( project=project, location=location, function=function, ) @@ -3232,7 +3304,6 @@ def test_parse_cloud_function_path(): def test_common_billing_account_path(): billing_account = "cuttlefish" - expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -3253,7 +3324,6 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "winkle" - expected = "folders/{folder}".format(folder=folder,) actual = CloudFunctionsServiceClient.common_folder_path(folder) assert expected == actual @@ -3272,7 +3342,6 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "scallop" - expected = "organizations/{organization}".format(organization=organization,) actual = CloudFunctionsServiceClient.common_organization_path(organization) assert expected == actual @@ -3291,7 +3360,6 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "squid" - expected = "projects/{project}".format(project=project,) actual = CloudFunctionsServiceClient.common_project_path(project) assert expected == actual @@ -3311,7 +3379,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, ) @@ -3338,7 +3405,7 @@ def test_client_withDEFAULT_CLIENT_INFO(): transports.CloudFunctionsServiceTransport, "_prep_wrapped_messages" ) as prep: client = CloudFunctionsServiceClient( - credentials=credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -3347,6 +3414,6 @@ def test_client_withDEFAULT_CLIENT_INFO(): ) as prep: transport_class = CloudFunctionsServiceClient.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)