diff --git a/.github/.OwlBot.yaml b/.github/.OwlBot.yaml index 111d785..e20d763 100644 --- a/.github/.OwlBot.yaml +++ b/.github/.OwlBot.yaml @@ -22,7 +22,7 @@ deep-copy-regex: - source: /google/cloud/workflows/executions/(v.*)/.*-py/(.*) dest: /owl-bot-staging/executions/$1/$2 - source: /google/cloud/workflows/(v.*)/.*-py/(.*) - dest: /owl-bot-staging/$1/$2 + dest: /owl-bot-staging/workflows/$1/$2 begin-after-commit-hash: acb4b773a6df45f9303067ffcb21387a7b6ad40d diff --git a/docs/executions_v1/executions.rst b/docs/executions_v1/executions.rst index cf374ec..4bae72f 100644 --- a/docs/executions_v1/executions.rst +++ b/docs/executions_v1/executions.rst @@ -5,7 +5,6 @@ Executions :members: :inherited-members: - .. automodule:: google.cloud.workflows.executions_v1.services.executions.pagers :members: :inherited-members: diff --git a/docs/executions_v1beta/executions.rst b/docs/executions_v1beta/executions.rst index d591170..8e18a7f 100644 --- a/docs/executions_v1beta/executions.rst +++ b/docs/executions_v1beta/executions.rst @@ -5,7 +5,6 @@ Executions :members: :inherited-members: - .. automodule:: google.cloud.workflows.executions_v1beta.services.executions.pagers :members: :inherited-members: diff --git a/docs/workflows_v1/workflows.rst b/docs/workflows_v1/workflows.rst index 66dfaa6..3c91658 100644 --- a/docs/workflows_v1/workflows.rst +++ b/docs/workflows_v1/workflows.rst @@ -5,7 +5,6 @@ Workflows :members: :inherited-members: - .. automodule:: google.cloud.workflows_v1.services.workflows.pagers :members: :inherited-members: diff --git a/docs/workflows_v1beta/workflows.rst b/docs/workflows_v1beta/workflows.rst index 381d505..ac0a1b0 100644 --- a/docs/workflows_v1beta/workflows.rst +++ b/docs/workflows_v1beta/workflows.rst @@ -5,7 +5,6 @@ Workflows :members: :inherited-members: - .. automodule:: google.cloud.workflows_v1beta.services.workflows.pagers :members: :inherited-members: diff --git a/google/cloud/workflows/__init__.py b/google/cloud/workflows/__init__.py index 3929d77..0db35b2 100644 --- a/google/cloud/workflows/__init__.py +++ b/google/cloud/workflows/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,10 +14,11 @@ # limitations under the License. # +from google.cloud.workflows_v1.services.workflows.client import WorkflowsClient from google.cloud.workflows_v1.services.workflows.async_client import ( WorkflowsAsyncClient, ) -from google.cloud.workflows_v1.services.workflows.client import WorkflowsClient + from google.cloud.workflows_v1.types.workflows import CreateWorkflowRequest from google.cloud.workflows_v1.types.workflows import DeleteWorkflowRequest from google.cloud.workflows_v1.types.workflows import GetWorkflowRequest @@ -29,6 +29,8 @@ from google.cloud.workflows_v1.types.workflows import Workflow __all__ = ( + "WorkflowsClient", + "WorkflowsAsyncClient", "CreateWorkflowRequest", "DeleteWorkflowRequest", "GetWorkflowRequest", @@ -37,6 +39,4 @@ "OperationMetadata", "UpdateWorkflowRequest", "Workflow", - "WorkflowsAsyncClient", - "WorkflowsClient", ) diff --git a/google/cloud/workflows/executions/__init__.py b/google/cloud/workflows/executions/__init__.py index 4d74157..b031779 100644 --- a/google/cloud/workflows/executions/__init__.py +++ b/google/cloud/workflows/executions/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,28 +14,29 @@ # limitations under the License. # -from google.cloud.workflows.executions_v1.services.executions.async_client import ( - ExecutionsAsyncClient, -) from google.cloud.workflows.executions_v1.services.executions.client import ( ExecutionsClient, ) +from google.cloud.workflows.executions_v1.services.executions.async_client import ( + ExecutionsAsyncClient, +) + from google.cloud.workflows.executions_v1.types.executions import CancelExecutionRequest from google.cloud.workflows.executions_v1.types.executions import CreateExecutionRequest from google.cloud.workflows.executions_v1.types.executions import Execution -from google.cloud.workflows.executions_v1.types.executions import ExecutionView from google.cloud.workflows.executions_v1.types.executions import GetExecutionRequest from google.cloud.workflows.executions_v1.types.executions import ListExecutionsRequest from google.cloud.workflows.executions_v1.types.executions import ListExecutionsResponse +from google.cloud.workflows.executions_v1.types.executions import ExecutionView __all__ = ( + "ExecutionsClient", + "ExecutionsAsyncClient", "CancelExecutionRequest", "CreateExecutionRequest", "Execution", - "ExecutionView", - "ExecutionsAsyncClient", - "ExecutionsClient", "GetExecutionRequest", "ListExecutionsRequest", "ListExecutionsResponse", + "ExecutionView", ) diff --git a/google/cloud/workflows/executions_v1/__init__.py b/google/cloud/workflows/executions_v1/__init__.py index 65343af..a5d6d71 100644 --- a/google/cloud/workflows/executions_v1/__init__.py +++ b/google/cloud/workflows/executions_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,22 +15,24 @@ # from .services.executions import ExecutionsClient +from .services.executions import ExecutionsAsyncClient + from .types.executions import CancelExecutionRequest from .types.executions import CreateExecutionRequest from .types.executions import Execution -from .types.executions import ExecutionView from .types.executions import GetExecutionRequest from .types.executions import ListExecutionsRequest from .types.executions import ListExecutionsResponse - +from .types.executions import ExecutionView __all__ = ( + "ExecutionsAsyncClient", "CancelExecutionRequest", "CreateExecutionRequest", "Execution", "ExecutionView", + "ExecutionsClient", "GetExecutionRequest", "ListExecutionsRequest", "ListExecutionsResponse", - "ExecutionsClient", ) diff --git a/google/cloud/workflows/executions_v1/gapic_metadata.json b/google/cloud/workflows/executions_v1/gapic_metadata.json new file mode 100644 index 0000000..f17943a --- /dev/null +++ b/google/cloud/workflows/executions_v1/gapic_metadata.json @@ -0,0 +1,63 @@ + { + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", + "language": "python", + "libraryPackage": "google.cloud.workflows.executions_v1", + "protoPackage": "google.cloud.workflows.executions.v1", + "schema": "1.0", + "services": { + "Executions": { + "clients": { + "grpc": { + "libraryClient": "ExecutionsClient", + "rpcs": { + "CancelExecution": { + "methods": [ + "cancel_execution" + ] + }, + "CreateExecution": { + "methods": [ + "create_execution" + ] + }, + "GetExecution": { + "methods": [ + "get_execution" + ] + }, + "ListExecutions": { + "methods": [ + "list_executions" + ] + } + } + }, + "grpc-async": { + "libraryClient": "ExecutionsAsyncClient", + "rpcs": { + "CancelExecution": { + "methods": [ + "cancel_execution" + ] + }, + "CreateExecution": { + "methods": [ + "create_execution" + ] + }, + "GetExecution": { + "methods": [ + "get_execution" + ] + }, + "ListExecutions": { + "methods": [ + "list_executions" + ] + } + } + } + } + } + } +} diff --git a/google/cloud/workflows/executions_v1/services/__init__.py b/google/cloud/workflows/executions_v1/services/__init__.py index 42ffdf2..4de6597 100644 --- a/google/cloud/workflows/executions_v1/services/__init__.py +++ b/google/cloud/workflows/executions_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/workflows/executions_v1/services/executions/__init__.py b/google/cloud/workflows/executions_v1/services/executions/__init__.py index 2a778e1..6c2372c 100644 --- a/google/cloud/workflows/executions_v1/services/executions/__init__.py +++ b/google/cloud/workflows/executions_v1/services/executions/__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 ExecutionsClient from .async_client import ExecutionsAsyncClient diff --git a/google/cloud/workflows/executions_v1/services/executions/async_client.py b/google/cloud/workflows/executions_v1/services/executions/async_client.py index 40e5b73..af280fa 100644 --- a/google/cloud/workflows/executions_v1/services/executions/async_client.py +++ b/google/cloud/workflows/executions_v1/services/executions/async_client.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict import functools import re @@ -22,16 +20,15 @@ import pkg_resources import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore from google.cloud.workflows.executions_v1.services.executions import pagers from google.cloud.workflows.executions_v1.types import executions -from google.protobuf import timestamp_pb2 as timestamp # type: ignore - +from google.protobuf import timestamp_pb2 # type: ignore from .transports.base import ExecutionsTransport, DEFAULT_CLIENT_INFO from .transports.grpc_asyncio import ExecutionsGrpcAsyncIOTransport from .client import ExecutionsClient @@ -51,25 +48,20 @@ class ExecutionsAsyncClient: parse_execution_path = staticmethod(ExecutionsClient.parse_execution_path) workflow_path = staticmethod(ExecutionsClient.workflow_path) parse_workflow_path = staticmethod(ExecutionsClient.parse_workflow_path) - common_billing_account_path = staticmethod( ExecutionsClient.common_billing_account_path ) parse_common_billing_account_path = staticmethod( ExecutionsClient.parse_common_billing_account_path ) - common_folder_path = staticmethod(ExecutionsClient.common_folder_path) parse_common_folder_path = staticmethod(ExecutionsClient.parse_common_folder_path) - common_organization_path = staticmethod(ExecutionsClient.common_organization_path) parse_common_organization_path = staticmethod( ExecutionsClient.parse_common_organization_path ) - common_project_path = staticmethod(ExecutionsClient.common_project_path) parse_common_project_path = staticmethod(ExecutionsClient.parse_common_project_path) - common_location_path = staticmethod(ExecutionsClient.common_location_path) parse_common_location_path = staticmethod( ExecutionsClient.parse_common_location_path @@ -77,7 +69,8 @@ class ExecutionsAsyncClient: @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. @@ -92,7 +85,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 @@ -109,7 +102,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> ExecutionsTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: ExecutionsTransport: The transport used by the client instance. @@ -123,12 +116,12 @@ def transport(self) -> ExecutionsTransport: def __init__( self, *, - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, transport: Union[str, ExecutionsTransport] = "grpc_asyncio", client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the executions client. + """Instantiates the executions client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -160,7 +153,6 @@ def __init__( google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport creation failed for any reason. """ - self._client = ExecutionsClient( credentials=credentials, transport=transport, @@ -197,7 +189,6 @@ async def list_executions( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -228,7 +219,6 @@ async def list_executions( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -292,7 +282,6 @@ async def create_execution( This corresponds to the ``execution`` 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. @@ -319,7 +308,6 @@ async def create_execution( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if execution is not None: @@ -369,7 +357,6 @@ async def get_execution( 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. @@ -396,7 +383,6 @@ async def get_execution( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -444,7 +430,6 @@ async def cancel_execution( 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. @@ -471,7 +456,6 @@ async def cancel_execution( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name diff --git a/google/cloud/workflows/executions_v1/services/executions/client.py b/google/cloud/workflows/executions_v1/services/executions/client.py index 00bc655..477898f 100644 --- a/google/cloud/workflows/executions_v1/services/executions/client.py +++ b/google/cloud/workflows/executions_v1/services/executions/client.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict from distutils import util import os @@ -23,10 +21,10 @@ import pkg_resources from google.api_core import client_options as client_options_lib # type: ignore -from google.api_core import exceptions # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport import mtls # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.auth.exceptions import MutualTLSChannelError # type: ignore @@ -34,8 +32,7 @@ from google.cloud.workflows.executions_v1.services.executions import pagers from google.cloud.workflows.executions_v1.types import executions -from google.protobuf import timestamp_pb2 as timestamp # type: ignore - +from google.protobuf import timestamp_pb2 # type: ignore from .transports.base import ExecutionsTransport, DEFAULT_CLIENT_INFO from .transports.grpc import ExecutionsGrpcTransport from .transports.grpc_asyncio import ExecutionsGrpcAsyncIOTransport @@ -54,7 +51,7 @@ class ExecutionsClientMeta(type): _transport_registry["grpc_asyncio"] = ExecutionsGrpcAsyncIOTransport def get_transport_class(cls, label: str = None,) -> Type[ExecutionsTransport]: - """Return an appropriate transport class. + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -79,7 +76,8 @@ class ExecutionsClient(metaclass=ExecutionsClientMeta): @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: @@ -113,7 +111,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. @@ -130,7 +129,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 @@ -149,10 +148,11 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> ExecutionsTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - ExecutionsTransport: The transport used by the client instance. + ExecutionsTransport: The transport used by the client + instance. """ return self._transport @@ -160,14 +160,14 @@ def transport(self) -> ExecutionsTransport: def execution_path( project: str, location: str, workflow: str, execution: str, ) -> str: - """Return a fully-qualified execution string.""" + """Returns a fully-qualified execution string.""" return "projects/{project}/locations/{location}/workflows/{workflow}/executions/{execution}".format( project=project, location=location, workflow=workflow, execution=execution, ) @staticmethod def parse_execution_path(path: str) -> Dict[str, str]: - """Parse a execution path into its component segments.""" + """Parses a execution path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/workflows/(?P.+?)/executions/(?P.+?)$", path, @@ -176,14 +176,14 @@ def parse_execution_path(path: str) -> Dict[str, str]: @staticmethod def workflow_path(project: str, location: str, workflow: str,) -> str: - """Return a fully-qualified workflow string.""" + """Returns a fully-qualified workflow string.""" return "projects/{project}/locations/{location}/workflows/{workflow}".format( project=project, location=location, workflow=workflow, ) @staticmethod def parse_workflow_path(path: str) -> Dict[str, str]: - """Parse a workflow path into its component segments.""" + """Parses a workflow path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/workflows/(?P.+?)$", path, @@ -192,7 +192,7 @@ def parse_workflow_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, ) @@ -205,7 +205,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 @@ -216,7 +216,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 @@ -227,7 +227,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 @@ -238,7 +238,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, ) @@ -252,12 +252,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, ExecutionsTransport, None] = None, client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the executions client. + """Instantiates the executions client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -312,9 +312,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: @@ -326,12 +327,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. @@ -346,8 +349,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: @@ -391,7 +394,6 @@ def list_executions( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -424,10 +426,8 @@ def list_executions( # there are no flattened fields. if not isinstance(request, executions.ListExecutionsRequest): request = executions.ListExecutionsRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -487,7 +487,6 @@ def create_execution( This corresponds to the ``execution`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -516,10 +515,8 @@ def create_execution( # there are no flattened fields. if not isinstance(request, executions.CreateExecutionRequest): request = executions.CreateExecutionRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if execution is not None: @@ -565,7 +562,6 @@ def get_execution( 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. @@ -594,10 +590,8 @@ def get_execution( # there are no flattened fields. if not isinstance(request, executions.GetExecutionRequest): request = executions.GetExecutionRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -641,7 +635,6 @@ def cancel_execution( 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. @@ -670,10 +663,8 @@ def cancel_execution( # there are no flattened fields. if not isinstance(request, executions.CancelExecutionRequest): request = executions.CancelExecutionRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name diff --git a/google/cloud/workflows/executions_v1/services/executions/pagers.py b/google/cloud/workflows/executions_v1/services/executions/pagers.py index fd31ddd..3bc2c0b 100644 --- a/google/cloud/workflows/executions_v1/services/executions/pagers.py +++ b/google/cloud/workflows/executions_v1/services/executions/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/workflows/executions_v1/services/executions/transports/__init__.py b/google/cloud/workflows/executions_v1/services/executions/transports/__init__.py index abab840..6c60cd3 100644 --- a/google/cloud/workflows/executions_v1/services/executions/transports/__init__.py +++ b/google/cloud/workflows/executions_v1/services/executions/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/workflows/executions_v1/services/executions/transports/base.py b/google/cloud/workflows/executions_v1/services/executions/transports/base.py index 5cf9562..deef0d6 100644 --- a/google/cloud/workflows/executions_v1/services/executions/transports/base.py +++ b/google/cloud/workflows/executions_v1/services/executions/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,20 +13,20 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import abc -import typing +from typing import Awaitable, Callable, Dict, Optional, Sequence, Union +import packaging.version import pkg_resources -from google import auth # type: ignore -from google.api_core import exceptions # type: ignore +import google.auth # type: ignore +import google.api_core # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.cloud.workflows.executions_v1.types import executions - try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=pkg_resources.get_distribution("google-cloud-workflow",).version, @@ -35,27 +34,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 ExecutionsTransport(abc.ABC): """Abstract transport class for Executions.""" AUTH_SCOPES = ("https://www.googleapis.com/auth/cloud-platform",) + DEFAULT_HOST: str = "workflowexecutions.googleapis.com" + def __init__( self, *, - host: str = "workflowexecutions.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 @@ -64,7 +77,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): @@ -78,29 +91,76 @@ def __init__( host += ":443" self._host = host + scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + # Save the scopes. self._scopes = scopes or self.AUTH_SCOPES # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: - raise exceptions.DuplicateCredentialArgs( + raise core_exceptions.DuplicateCredentialArgs( "'credentials_file' and 'credentials' are mutually exclusive" ) if credentials_file is not None: - credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=self._scopes, quota_project_id=quota_project_id + credentials, _ = google.auth.load_credentials_from_file( + credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) elif credentials is None: - credentials, _ = auth.default( - scopes=self._scopes, quota_project_id=quota_project_id + credentials, _ = google.auth.default( + **scopes_kwargs, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials + # TODO(busunkim): These two class methods are in the base transport + # to avoid duplicating code across the transport classes. These functions + # should be deleted once the minimum required versions of google-api-core + # and google-auth are increased. + + # TODO: Remove this function once google-auth >= 1.25.0 is required + @classmethod + def _get_scopes_kwargs( + cls, host: str, scopes: Optional[Sequence[str]] + ) -> Dict[str, Optional[Sequence[str]]]: + """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" + + scopes_kwargs = {} + + if _GOOGLE_AUTH_VERSION and ( + packaging.version.parse(_GOOGLE_AUTH_VERSION) + >= packaging.version.parse("1.25.0") + ): + scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} + else: + scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} + + return scopes_kwargs + + # TODO: Remove this function once google-api-core >= 1.26.0 is required + @classmethod + def _get_self_signed_jwt_kwargs( + cls, host: str, scopes: Optional[Sequence[str]] + ) -> Dict[str, Union[Optional[Sequence[str]], str]]: + """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" + + self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} + + if _API_CORE_VERSION and ( + packaging.version.parse(_API_CORE_VERSION) + >= packaging.version.parse("1.26.0") + ): + self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES + self_signed_jwt_kwargs["scopes"] = scopes + self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST + else: + self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES + + return self_signed_jwt_kwargs + def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { @@ -121,11 +181,11 @@ def _prep_wrapped_messages(self, client_info): @property def list_executions( self, - ) -> typing.Callable[ + ) -> Callable[ [executions.ListExecutionsRequest], - typing.Union[ + Union[ executions.ListExecutionsResponse, - typing.Awaitable[executions.ListExecutionsResponse], + Awaitable[executions.ListExecutionsResponse], ], ]: raise NotImplementedError() @@ -133,27 +193,27 @@ def list_executions( @property def create_execution( self, - ) -> typing.Callable[ + ) -> Callable[ [executions.CreateExecutionRequest], - typing.Union[executions.Execution, typing.Awaitable[executions.Execution]], + Union[executions.Execution, Awaitable[executions.Execution]], ]: raise NotImplementedError() @property def get_execution( self, - ) -> typing.Callable[ + ) -> Callable[ [executions.GetExecutionRequest], - typing.Union[executions.Execution, typing.Awaitable[executions.Execution]], + Union[executions.Execution, Awaitable[executions.Execution]], ]: raise NotImplementedError() @property def cancel_execution( self, - ) -> typing.Callable[ + ) -> Callable[ [executions.CancelExecutionRequest], - typing.Union[executions.Execution, typing.Awaitable[executions.Execution]], + Union[executions.Execution, Awaitable[executions.Execution]], ]: raise NotImplementedError() diff --git a/google/cloud/workflows/executions_v1/services/executions/transports/grpc.py b/google/cloud/workflows/executions_v1/services/executions/transports/grpc.py index 205e953..e41472f 100644 --- a/google/cloud/workflows/executions_v1/services/executions/transports/grpc.py +++ b/google/cloud/workflows/executions_v1/services/executions/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,20 +13,18 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import warnings -from typing import Callable, Dict, Optional, Sequence, Tuple +from typing import Callable, Dict, Optional, Sequence, Tuple, Union from google.api_core import grpc_helpers # type: ignore from google.api_core import gapic_v1 # type: ignore -from google import auth # type: ignore -from google.auth import credentials # type: ignore +import google.auth # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore import grpc # type: ignore from google.cloud.workflows.executions_v1.types import executions - from .base import ExecutionsTransport, DEFAULT_CLIENT_INFO @@ -51,7 +48,7 @@ def __init__( self, *, host: str = "workflowexecutions.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: str = None, scopes: Sequence[str] = None, channel: grpc.Channel = None, @@ -65,7 +62,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 @@ -175,7 +173,7 @@ def __init__( def create_channel( cls, host: str = "workflowexecutions.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, @@ -206,13 +204,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, ) diff --git a/google/cloud/workflows/executions_v1/services/executions/transports/grpc_asyncio.py b/google/cloud/workflows/executions_v1/services/executions/transports/grpc_asyncio.py index 930a549..0142cc0 100644 --- a/google/cloud/workflows/executions_v1/services/executions/transports/grpc_asyncio.py +++ b/google/cloud/workflows/executions_v1/services/executions/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,21 +13,19 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import warnings -from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple +from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union from google.api_core import gapic_v1 # type: ignore from google.api_core import grpc_helpers_async # type: ignore -from google import auth # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore from google.cloud.workflows.executions_v1.types import executions - from .base import ExecutionsTransport, DEFAULT_CLIENT_INFO from .grpc import ExecutionsGrpcTransport @@ -54,7 +51,7 @@ class ExecutionsGrpcAsyncIOTransport(ExecutionsTransport): def create_channel( cls, host: str = "workflowexecutions.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, @@ -81,13 +78,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, ) @@ -95,7 +94,7 @@ def __init__( self, *, host: str = "workflowexecutions.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, @@ -109,7 +108,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 @@ -167,7 +167,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 diff --git a/google/cloud/workflows/executions_v1/types/__init__.py b/google/cloud/workflows/executions_v1/types/__init__.py index 3ea6e8b..45de544 100644 --- a/google/cloud/workflows/executions_v1/types/__init__.py +++ b/google/cloud/workflows/executions_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 .executions import ( CancelExecutionRequest, CreateExecutionRequest, diff --git a/google/cloud/workflows/executions_v1/types/executions.py b/google/cloud/workflows/executions_v1/types/executions.py index d0ca7a1..c421fc3 100644 --- a/google/cloud/workflows/executions_v1/types/executions.py +++ b/google/cloud/workflows/executions_v1/types/executions.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,11 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - -from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore __protobuf__ = proto.module( @@ -87,7 +84,6 @@ class State(proto.Enum): class Error(proto.Message): r"""Error describes why the execution was abnormally terminated. - Attributes: payload (str): Error payload returned by the execution, @@ -97,30 +93,21 @@ class Error(proto.Message): debugging purposes. """ - payload = proto.Field(proto.STRING, number=1) - - context = proto.Field(proto.STRING, number=2) - - name = proto.Field(proto.STRING, number=1) - - start_time = proto.Field(proto.MESSAGE, number=2, message=timestamp.Timestamp,) - - end_time = proto.Field(proto.MESSAGE, number=3, message=timestamp.Timestamp,) + payload = proto.Field(proto.STRING, number=1,) + context = proto.Field(proto.STRING, number=2,) + name = proto.Field(proto.STRING, number=1,) + start_time = proto.Field(proto.MESSAGE, number=2, message=timestamp_pb2.Timestamp,) + end_time = proto.Field(proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp,) state = proto.Field(proto.ENUM, number=4, enum=State,) - - argument = proto.Field(proto.STRING, number=5) - - result = proto.Field(proto.STRING, number=6) - + argument = proto.Field(proto.STRING, number=5,) + result = proto.Field(proto.STRING, number=6,) error = proto.Field(proto.MESSAGE, number=7, message=Error,) - - workflow_revision_id = proto.Field(proto.STRING, number=8) + workflow_revision_id = proto.Field(proto.STRING, number=8,) class ListExecutionsRequest(proto.Message): r"""Request for the [ListExecutions][] method. - Attributes: parent (str): Required. Name of the workflow for which the @@ -147,12 +134,9 @@ class ListExecutionsRequest(proto.Message): will default to the BASIC view. """ - 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,) view = proto.Field(proto.ENUM, number=4, enum="ExecutionView",) @@ -175,8 +159,7 @@ def raw_page(self): return self executions = proto.RepeatedField(proto.MESSAGE, number=1, message="Execution",) - - next_page_token = proto.Field(proto.STRING, number=2) + next_page_token = proto.Field(proto.STRING, number=2,) class CreateExecutionRequest(proto.Message): @@ -195,8 +178,7 @@ class CreateExecutionRequest(proto.Message): Required. Execution to be created. """ - parent = proto.Field(proto.STRING, number=1) - + parent = proto.Field(proto.STRING, number=1,) execution = proto.Field(proto.MESSAGE, number=2, message="Execution",) @@ -216,8 +198,7 @@ class GetExecutionRequest(proto.Message): will default to the FULL view. """ - name = proto.Field(proto.STRING, number=1) - + name = proto.Field(proto.STRING, number=1,) view = proto.Field(proto.ENUM, number=2, enum="ExecutionView",) @@ -233,7 +214,7 @@ class CancelExecutionRequest(proto.Message): projects/{project}/locations/{location}/workflows/{workflow}/executions/{execution} """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/workflows/executions_v1beta/__init__.py b/google/cloud/workflows/executions_v1beta/__init__.py index 65343af..a5d6d71 100644 --- a/google/cloud/workflows/executions_v1beta/__init__.py +++ b/google/cloud/workflows/executions_v1beta/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,22 +15,24 @@ # from .services.executions import ExecutionsClient +from .services.executions import ExecutionsAsyncClient + from .types.executions import CancelExecutionRequest from .types.executions import CreateExecutionRequest from .types.executions import Execution -from .types.executions import ExecutionView from .types.executions import GetExecutionRequest from .types.executions import ListExecutionsRequest from .types.executions import ListExecutionsResponse - +from .types.executions import ExecutionView __all__ = ( + "ExecutionsAsyncClient", "CancelExecutionRequest", "CreateExecutionRequest", "Execution", "ExecutionView", + "ExecutionsClient", "GetExecutionRequest", "ListExecutionsRequest", "ListExecutionsResponse", - "ExecutionsClient", ) diff --git a/google/cloud/workflows/executions_v1beta/gapic_metadata.json b/google/cloud/workflows/executions_v1beta/gapic_metadata.json new file mode 100644 index 0000000..dec2db0 --- /dev/null +++ b/google/cloud/workflows/executions_v1beta/gapic_metadata.json @@ -0,0 +1,63 @@ + { + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", + "language": "python", + "libraryPackage": "google.cloud.workflows.executions_v1beta", + "protoPackage": "google.cloud.workflows.executions.v1beta", + "schema": "1.0", + "services": { + "Executions": { + "clients": { + "grpc": { + "libraryClient": "ExecutionsClient", + "rpcs": { + "CancelExecution": { + "methods": [ + "cancel_execution" + ] + }, + "CreateExecution": { + "methods": [ + "create_execution" + ] + }, + "GetExecution": { + "methods": [ + "get_execution" + ] + }, + "ListExecutions": { + "methods": [ + "list_executions" + ] + } + } + }, + "grpc-async": { + "libraryClient": "ExecutionsAsyncClient", + "rpcs": { + "CancelExecution": { + "methods": [ + "cancel_execution" + ] + }, + "CreateExecution": { + "methods": [ + "create_execution" + ] + }, + "GetExecution": { + "methods": [ + "get_execution" + ] + }, + "ListExecutions": { + "methods": [ + "list_executions" + ] + } + } + } + } + } + } +} diff --git a/google/cloud/workflows/executions_v1beta/services/__init__.py b/google/cloud/workflows/executions_v1beta/services/__init__.py index 42ffdf2..4de6597 100644 --- a/google/cloud/workflows/executions_v1beta/services/__init__.py +++ b/google/cloud/workflows/executions_v1beta/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/workflows/executions_v1beta/services/executions/__init__.py b/google/cloud/workflows/executions_v1beta/services/executions/__init__.py index 2a778e1..6c2372c 100644 --- a/google/cloud/workflows/executions_v1beta/services/executions/__init__.py +++ b/google/cloud/workflows/executions_v1beta/services/executions/__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 ExecutionsClient from .async_client import ExecutionsAsyncClient diff --git a/google/cloud/workflows/executions_v1beta/services/executions/async_client.py b/google/cloud/workflows/executions_v1beta/services/executions/async_client.py index dca7088..ccc7e4b 100644 --- a/google/cloud/workflows/executions_v1beta/services/executions/async_client.py +++ b/google/cloud/workflows/executions_v1beta/services/executions/async_client.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict import functools import re @@ -22,16 +20,15 @@ import pkg_resources import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore from google.cloud.workflows.executions_v1beta.services.executions import pagers from google.cloud.workflows.executions_v1beta.types import executions -from google.protobuf import timestamp_pb2 as timestamp # type: ignore - +from google.protobuf import timestamp_pb2 # type: ignore from .transports.base import ExecutionsTransport, DEFAULT_CLIENT_INFO from .transports.grpc_asyncio import ExecutionsGrpcAsyncIOTransport from .client import ExecutionsClient @@ -52,25 +49,20 @@ class ExecutionsAsyncClient: parse_execution_path = staticmethod(ExecutionsClient.parse_execution_path) workflow_path = staticmethod(ExecutionsClient.workflow_path) parse_workflow_path = staticmethod(ExecutionsClient.parse_workflow_path) - common_billing_account_path = staticmethod( ExecutionsClient.common_billing_account_path ) parse_common_billing_account_path = staticmethod( ExecutionsClient.parse_common_billing_account_path ) - common_folder_path = staticmethod(ExecutionsClient.common_folder_path) parse_common_folder_path = staticmethod(ExecutionsClient.parse_common_folder_path) - common_organization_path = staticmethod(ExecutionsClient.common_organization_path) parse_common_organization_path = staticmethod( ExecutionsClient.parse_common_organization_path ) - common_project_path = staticmethod(ExecutionsClient.common_project_path) parse_common_project_path = staticmethod(ExecutionsClient.parse_common_project_path) - common_location_path = staticmethod(ExecutionsClient.common_location_path) parse_common_location_path = staticmethod( ExecutionsClient.parse_common_location_path @@ -78,7 +70,8 @@ class ExecutionsAsyncClient: @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. @@ -93,7 +86,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 @@ -110,7 +103,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> ExecutionsTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: ExecutionsTransport: The transport used by the client instance. @@ -124,12 +117,12 @@ def transport(self) -> ExecutionsTransport: def __init__( self, *, - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, transport: Union[str, ExecutionsTransport] = "grpc_asyncio", client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the executions client. + """Instantiates the executions client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -161,7 +154,6 @@ def __init__( google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport creation failed for any reason. """ - self._client = ExecutionsClient( credentials=credentials, transport=transport, @@ -198,7 +190,6 @@ async def list_executions( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -229,7 +220,6 @@ async def list_executions( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -293,7 +283,6 @@ async def create_execution( This corresponds to the ``execution`` 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. @@ -320,7 +309,6 @@ async def create_execution( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if execution is not None: @@ -370,7 +358,6 @@ async def get_execution( 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. @@ -397,7 +384,6 @@ async def get_execution( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -445,7 +431,6 @@ async def cancel_execution( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -472,7 +457,6 @@ async def cancel_execution( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name diff --git a/google/cloud/workflows/executions_v1beta/services/executions/client.py b/google/cloud/workflows/executions_v1beta/services/executions/client.py index 2c4f7df..47be016 100644 --- a/google/cloud/workflows/executions_v1beta/services/executions/client.py +++ b/google/cloud/workflows/executions_v1beta/services/executions/client.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict from distutils import util import os @@ -23,10 +21,10 @@ import pkg_resources from google.api_core import client_options as client_options_lib # type: ignore -from google.api_core import exceptions # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport import mtls # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.auth.exceptions import MutualTLSChannelError # type: ignore @@ -34,8 +32,7 @@ from google.cloud.workflows.executions_v1beta.services.executions import pagers from google.cloud.workflows.executions_v1beta.types import executions -from google.protobuf import timestamp_pb2 as timestamp # type: ignore - +from google.protobuf import timestamp_pb2 # type: ignore from .transports.base import ExecutionsTransport, DEFAULT_CLIENT_INFO from .transports.grpc import ExecutionsGrpcTransport from .transports.grpc_asyncio import ExecutionsGrpcAsyncIOTransport @@ -54,7 +51,7 @@ class ExecutionsClientMeta(type): _transport_registry["grpc_asyncio"] = ExecutionsGrpcAsyncIOTransport def get_transport_class(cls, label: str = None,) -> Type[ExecutionsTransport]: - """Return an appropriate transport class. + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -80,7 +77,8 @@ class ExecutionsClient(metaclass=ExecutionsClientMeta): @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: @@ -114,7 +112,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. @@ -131,7 +130,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 @@ -150,10 +149,11 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> ExecutionsTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - ExecutionsTransport: The transport used by the client instance. + ExecutionsTransport: The transport used by the client + instance. """ return self._transport @@ -161,14 +161,14 @@ def transport(self) -> ExecutionsTransport: def execution_path( project: str, location: str, workflow: str, execution: str, ) -> str: - """Return a fully-qualified execution string.""" + """Returns a fully-qualified execution string.""" return "projects/{project}/locations/{location}/workflows/{workflow}/executions/{execution}".format( project=project, location=location, workflow=workflow, execution=execution, ) @staticmethod def parse_execution_path(path: str) -> Dict[str, str]: - """Parse a execution path into its component segments.""" + """Parses a execution path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/workflows/(?P.+?)/executions/(?P.+?)$", path, @@ -177,14 +177,14 @@ def parse_execution_path(path: str) -> Dict[str, str]: @staticmethod def workflow_path(project: str, location: str, workflow: str,) -> str: - """Return a fully-qualified workflow string.""" + """Returns a fully-qualified workflow string.""" return "projects/{project}/locations/{location}/workflows/{workflow}".format( project=project, location=location, workflow=workflow, ) @staticmethod def parse_workflow_path(path: str) -> Dict[str, str]: - """Parse a workflow path into its component segments.""" + """Parses a workflow path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/workflows/(?P.+?)$", path, @@ -193,7 +193,7 @@ def parse_workflow_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, ) @@ -206,7 +206,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 @@ -217,7 +217,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 @@ -228,7 +228,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 @@ -239,7 +239,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, ) @@ -253,12 +253,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, ExecutionsTransport, None] = None, client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the executions client. + """Instantiates the executions client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -313,9 +313,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: @@ -327,12 +328,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. @@ -347,8 +350,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: @@ -392,7 +395,6 @@ def list_executions( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -425,10 +427,8 @@ def list_executions( # there are no flattened fields. if not isinstance(request, executions.ListExecutionsRequest): request = executions.ListExecutionsRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -488,7 +488,6 @@ def create_execution( This corresponds to the ``execution`` 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. @@ -517,10 +516,8 @@ def create_execution( # there are no flattened fields. if not isinstance(request, executions.CreateExecutionRequest): request = executions.CreateExecutionRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if execution is not None: @@ -566,7 +563,6 @@ def get_execution( 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. @@ -595,10 +591,8 @@ def get_execution( # there are no flattened fields. if not isinstance(request, executions.GetExecutionRequest): request = executions.GetExecutionRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -642,7 +636,6 @@ def cancel_execution( 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. @@ -671,10 +664,8 @@ def cancel_execution( # there are no flattened fields. if not isinstance(request, executions.CancelExecutionRequest): request = executions.CancelExecutionRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name diff --git a/google/cloud/workflows/executions_v1beta/services/executions/pagers.py b/google/cloud/workflows/executions_v1beta/services/executions/pagers.py index 4a6e5c6..96c0ade 100644 --- a/google/cloud/workflows/executions_v1beta/services/executions/pagers.py +++ b/google/cloud/workflows/executions_v1beta/services/executions/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/workflows/executions_v1beta/services/executions/transports/__init__.py b/google/cloud/workflows/executions_v1beta/services/executions/transports/__init__.py index abab840..6c60cd3 100644 --- a/google/cloud/workflows/executions_v1beta/services/executions/transports/__init__.py +++ b/google/cloud/workflows/executions_v1beta/services/executions/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/workflows/executions_v1beta/services/executions/transports/base.py b/google/cloud/workflows/executions_v1beta/services/executions/transports/base.py index dca9e01..9ad4d10 100644 --- a/google/cloud/workflows/executions_v1beta/services/executions/transports/base.py +++ b/google/cloud/workflows/executions_v1beta/services/executions/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,20 +13,20 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import abc -import typing +from typing import Awaitable, Callable, Dict, Optional, Sequence, Union +import packaging.version import pkg_resources -from google import auth # type: ignore -from google.api_core import exceptions # type: ignore +import google.auth # type: ignore +import google.api_core # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.cloud.workflows.executions_v1beta.types import executions - try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=pkg_resources.get_distribution("google-cloud-workflow",).version, @@ -35,27 +34,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 ExecutionsTransport(abc.ABC): """Abstract transport class for Executions.""" AUTH_SCOPES = ("https://www.googleapis.com/auth/cloud-platform",) + DEFAULT_HOST: str = "workflowexecutions.googleapis.com" + def __init__( self, *, - host: str = "workflowexecutions.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 @@ -64,7 +77,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): @@ -78,29 +91,76 @@ def __init__( host += ":443" self._host = host + scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + # Save the scopes. self._scopes = scopes or self.AUTH_SCOPES # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: - raise exceptions.DuplicateCredentialArgs( + raise core_exceptions.DuplicateCredentialArgs( "'credentials_file' and 'credentials' are mutually exclusive" ) if credentials_file is not None: - credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=self._scopes, quota_project_id=quota_project_id + credentials, _ = google.auth.load_credentials_from_file( + credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) elif credentials is None: - credentials, _ = auth.default( - scopes=self._scopes, quota_project_id=quota_project_id + credentials, _ = google.auth.default( + **scopes_kwargs, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials + # TODO(busunkim): These two class methods are in the base transport + # to avoid duplicating code across the transport classes. These functions + # should be deleted once the minimum required versions of google-api-core + # and google-auth are increased. + + # TODO: Remove this function once google-auth >= 1.25.0 is required + @classmethod + def _get_scopes_kwargs( + cls, host: str, scopes: Optional[Sequence[str]] + ) -> Dict[str, Optional[Sequence[str]]]: + """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" + + scopes_kwargs = {} + + if _GOOGLE_AUTH_VERSION and ( + packaging.version.parse(_GOOGLE_AUTH_VERSION) + >= packaging.version.parse("1.25.0") + ): + scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} + else: + scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} + + return scopes_kwargs + + # TODO: Remove this function once google-api-core >= 1.26.0 is required + @classmethod + def _get_self_signed_jwt_kwargs( + cls, host: str, scopes: Optional[Sequence[str]] + ) -> Dict[str, Union[Optional[Sequence[str]], str]]: + """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" + + self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} + + if _API_CORE_VERSION and ( + packaging.version.parse(_API_CORE_VERSION) + >= packaging.version.parse("1.26.0") + ): + self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES + self_signed_jwt_kwargs["scopes"] = scopes + self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST + else: + self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES + + return self_signed_jwt_kwargs + def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { @@ -121,11 +181,11 @@ def _prep_wrapped_messages(self, client_info): @property def list_executions( self, - ) -> typing.Callable[ + ) -> Callable[ [executions.ListExecutionsRequest], - typing.Union[ + Union[ executions.ListExecutionsResponse, - typing.Awaitable[executions.ListExecutionsResponse], + Awaitable[executions.ListExecutionsResponse], ], ]: raise NotImplementedError() @@ -133,27 +193,27 @@ def list_executions( @property def create_execution( self, - ) -> typing.Callable[ + ) -> Callable[ [executions.CreateExecutionRequest], - typing.Union[executions.Execution, typing.Awaitable[executions.Execution]], + Union[executions.Execution, Awaitable[executions.Execution]], ]: raise NotImplementedError() @property def get_execution( self, - ) -> typing.Callable[ + ) -> Callable[ [executions.GetExecutionRequest], - typing.Union[executions.Execution, typing.Awaitable[executions.Execution]], + Union[executions.Execution, Awaitable[executions.Execution]], ]: raise NotImplementedError() @property def cancel_execution( self, - ) -> typing.Callable[ + ) -> Callable[ [executions.CancelExecutionRequest], - typing.Union[executions.Execution, typing.Awaitable[executions.Execution]], + Union[executions.Execution, Awaitable[executions.Execution]], ]: raise NotImplementedError() diff --git a/google/cloud/workflows/executions_v1beta/services/executions/transports/grpc.py b/google/cloud/workflows/executions_v1beta/services/executions/transports/grpc.py index 94cbdf8..fe71352 100644 --- a/google/cloud/workflows/executions_v1beta/services/executions/transports/grpc.py +++ b/google/cloud/workflows/executions_v1beta/services/executions/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,20 +13,18 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import warnings -from typing import Callable, Dict, Optional, Sequence, Tuple +from typing import Callable, Dict, Optional, Sequence, Tuple, Union from google.api_core import grpc_helpers # type: ignore from google.api_core import gapic_v1 # type: ignore -from google import auth # type: ignore -from google.auth import credentials # type: ignore +import google.auth # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore import grpc # type: ignore from google.cloud.workflows.executions_v1beta.types import executions - from .base import ExecutionsTransport, DEFAULT_CLIENT_INFO @@ -52,7 +49,7 @@ def __init__( self, *, host: str = "workflowexecutions.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: str = None, scopes: Sequence[str] = None, channel: grpc.Channel = None, @@ -66,7 +63,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 @@ -176,7 +174,7 @@ def __init__( def create_channel( cls, host: str = "workflowexecutions.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, @@ -207,13 +205,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, ) diff --git a/google/cloud/workflows/executions_v1beta/services/executions/transports/grpc_asyncio.py b/google/cloud/workflows/executions_v1beta/services/executions/transports/grpc_asyncio.py index 6580883..956ec43 100644 --- a/google/cloud/workflows/executions_v1beta/services/executions/transports/grpc_asyncio.py +++ b/google/cloud/workflows/executions_v1beta/services/executions/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,21 +13,19 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import warnings -from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple +from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union from google.api_core import gapic_v1 # type: ignore from google.api_core import grpc_helpers_async # type: ignore -from google import auth # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore from google.cloud.workflows.executions_v1beta.types import executions - from .base import ExecutionsTransport, DEFAULT_CLIENT_INFO from .grpc import ExecutionsGrpcTransport @@ -55,7 +52,7 @@ class ExecutionsGrpcAsyncIOTransport(ExecutionsTransport): def create_channel( cls, host: str = "workflowexecutions.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, @@ -82,13 +79,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, ) @@ -96,7 +95,7 @@ def __init__( self, *, host: str = "workflowexecutions.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, @@ -110,7 +109,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 @@ -168,7 +168,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 diff --git a/google/cloud/workflows/executions_v1beta/types/__init__.py b/google/cloud/workflows/executions_v1beta/types/__init__.py index 3ea6e8b..45de544 100644 --- a/google/cloud/workflows/executions_v1beta/types/__init__.py +++ b/google/cloud/workflows/executions_v1beta/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 .executions import ( CancelExecutionRequest, CreateExecutionRequest, diff --git a/google/cloud/workflows/executions_v1beta/types/executions.py b/google/cloud/workflows/executions_v1beta/types/executions.py index a69e778..863466a 100644 --- a/google/cloud/workflows/executions_v1beta/types/executions.py +++ b/google/cloud/workflows/executions_v1beta/types/executions.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,11 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - -from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore __protobuf__ = proto.module( @@ -87,7 +84,6 @@ class State(proto.Enum): class Error(proto.Message): r"""Error describes why the execution was abnormally terminated. - Attributes: payload (str): Error payload returned by the execution, @@ -97,25 +93,17 @@ class Error(proto.Message): debugging purposes. """ - payload = proto.Field(proto.STRING, number=1) - - context = proto.Field(proto.STRING, number=2) - - name = proto.Field(proto.STRING, number=1) - - start_time = proto.Field(proto.MESSAGE, number=2, message=timestamp.Timestamp,) - - end_time = proto.Field(proto.MESSAGE, number=3, message=timestamp.Timestamp,) + payload = proto.Field(proto.STRING, number=1,) + context = proto.Field(proto.STRING, number=2,) + name = proto.Field(proto.STRING, number=1,) + start_time = proto.Field(proto.MESSAGE, number=2, message=timestamp_pb2.Timestamp,) + end_time = proto.Field(proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp,) state = proto.Field(proto.ENUM, number=4, enum=State,) - - argument = proto.Field(proto.STRING, number=5) - - result = proto.Field(proto.STRING, number=6) - + argument = proto.Field(proto.STRING, number=5,) + result = proto.Field(proto.STRING, number=6,) error = proto.Field(proto.MESSAGE, number=7, message=Error,) - - workflow_revision_id = proto.Field(proto.STRING, number=8) + workflow_revision_id = proto.Field(proto.STRING, number=8,) class ListExecutionsRequest(proto.Message): @@ -149,12 +137,9 @@ class ListExecutionsRequest(proto.Message): will default to the BASIC view. """ - 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,) view = proto.Field(proto.ENUM, number=4, enum="ExecutionView",) @@ -177,8 +162,7 @@ def raw_page(self): return self executions = proto.RepeatedField(proto.MESSAGE, number=1, message="Execution",) - - next_page_token = proto.Field(proto.STRING, number=2) + next_page_token = proto.Field(proto.STRING, number=2,) class CreateExecutionRequest(proto.Message): @@ -197,8 +181,7 @@ class CreateExecutionRequest(proto.Message): Required. Execution to be created. """ - parent = proto.Field(proto.STRING, number=1) - + parent = proto.Field(proto.STRING, number=1,) execution = proto.Field(proto.MESSAGE, number=2, message="Execution",) @@ -218,8 +201,7 @@ class GetExecutionRequest(proto.Message): will default to the FULL view. """ - name = proto.Field(proto.STRING, number=1) - + name = proto.Field(proto.STRING, number=1,) view = proto.Field(proto.ENUM, number=2, enum="ExecutionView",) @@ -235,7 +217,7 @@ class CancelExecutionRequest(proto.Message): projects/{project}/locations/{location}/workflows/{workflow}/executions/{execution} """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/workflows_v1/__init__.py b/google/cloud/workflows_v1/__init__.py index 91f1cc1..e80a3bd 100644 --- a/google/cloud/workflows_v1/__init__.py +++ b/google/cloud/workflows_v1/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,6 +15,8 @@ # from .services.workflows import WorkflowsClient +from .services.workflows import WorkflowsAsyncClient + from .types.workflows import CreateWorkflowRequest from .types.workflows import DeleteWorkflowRequest from .types.workflows import GetWorkflowRequest @@ -25,8 +26,8 @@ from .types.workflows import UpdateWorkflowRequest from .types.workflows import Workflow - __all__ = ( + "WorkflowsAsyncClient", "CreateWorkflowRequest", "DeleteWorkflowRequest", "GetWorkflowRequest", diff --git a/google/cloud/workflows_v1/gapic_metadata.json b/google/cloud/workflows_v1/gapic_metadata.json new file mode 100644 index 0000000..60ac0dc --- /dev/null +++ b/google/cloud/workflows_v1/gapic_metadata.json @@ -0,0 +1,73 @@ + { + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", + "language": "python", + "libraryPackage": "google.cloud.workflows_v1", + "protoPackage": "google.cloud.workflows.v1", + "schema": "1.0", + "services": { + "Workflows": { + "clients": { + "grpc": { + "libraryClient": "WorkflowsClient", + "rpcs": { + "CreateWorkflow": { + "methods": [ + "create_workflow" + ] + }, + "DeleteWorkflow": { + "methods": [ + "delete_workflow" + ] + }, + "GetWorkflow": { + "methods": [ + "get_workflow" + ] + }, + "ListWorkflows": { + "methods": [ + "list_workflows" + ] + }, + "UpdateWorkflow": { + "methods": [ + "update_workflow" + ] + } + } + }, + "grpc-async": { + "libraryClient": "WorkflowsAsyncClient", + "rpcs": { + "CreateWorkflow": { + "methods": [ + "create_workflow" + ] + }, + "DeleteWorkflow": { + "methods": [ + "delete_workflow" + ] + }, + "GetWorkflow": { + "methods": [ + "get_workflow" + ] + }, + "ListWorkflows": { + "methods": [ + "list_workflows" + ] + }, + "UpdateWorkflow": { + "methods": [ + "update_workflow" + ] + } + } + } + } + } + } +} diff --git a/google/cloud/workflows_v1/services/__init__.py b/google/cloud/workflows_v1/services/__init__.py index 42ffdf2..4de6597 100644 --- a/google/cloud/workflows_v1/services/__init__.py +++ b/google/cloud/workflows_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/workflows_v1/services/workflows/__init__.py b/google/cloud/workflows_v1/services/workflows/__init__.py index 3afd340..b08649c 100644 --- a/google/cloud/workflows_v1/services/workflows/__init__.py +++ b/google/cloud/workflows_v1/services/workflows/__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 WorkflowsClient from .async_client import WorkflowsAsyncClient diff --git a/google/cloud/workflows_v1/services/workflows/async_client.py b/google/cloud/workflows_v1/services/workflows/async_client.py index 778f6c5..77fefc1 100644 --- a/google/cloud/workflows_v1/services/workflows/async_client.py +++ b/google/cloud/workflows_v1/services/workflows/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,20 +20,19 @@ import pkg_resources import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.workflows_v1.services.workflows import pagers from google.cloud.workflows_v1.types import workflows -from google.protobuf import empty_pb2 as empty # type: ignore -from google.protobuf import field_mask_pb2 as field_mask # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore - +from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore from .transports.base import WorkflowsTransport, DEFAULT_CLIENT_INFO from .transports.grpc_asyncio import WorkflowsGrpcAsyncIOTransport from .client import WorkflowsClient @@ -54,25 +51,20 @@ class WorkflowsAsyncClient: workflow_path = staticmethod(WorkflowsClient.workflow_path) parse_workflow_path = staticmethod(WorkflowsClient.parse_workflow_path) - common_billing_account_path = staticmethod( WorkflowsClient.common_billing_account_path ) parse_common_billing_account_path = staticmethod( WorkflowsClient.parse_common_billing_account_path ) - common_folder_path = staticmethod(WorkflowsClient.common_folder_path) parse_common_folder_path = staticmethod(WorkflowsClient.parse_common_folder_path) - common_organization_path = staticmethod(WorkflowsClient.common_organization_path) parse_common_organization_path = staticmethod( WorkflowsClient.parse_common_organization_path ) - common_project_path = staticmethod(WorkflowsClient.common_project_path) parse_common_project_path = staticmethod(WorkflowsClient.parse_common_project_path) - common_location_path = staticmethod(WorkflowsClient.common_location_path) parse_common_location_path = staticmethod( WorkflowsClient.parse_common_location_path @@ -80,7 +72,8 @@ class WorkflowsAsyncClient: @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. @@ -95,7 +88,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 @@ -112,7 +105,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> WorkflowsTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: WorkflowsTransport: The transport used by the client instance. @@ -126,12 +119,12 @@ def transport(self) -> WorkflowsTransport: def __init__( self, *, - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, transport: Union[str, WorkflowsTransport] = "grpc_asyncio", client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the workflows client. + """Instantiates the workflows client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -163,7 +156,6 @@ def __init__( google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport creation failed for any reason. """ - self._client = WorkflowsClient( credentials=credentials, transport=transport, @@ -197,7 +189,6 @@ async def list_workflows( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -228,7 +219,6 @@ async def list_workflows( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -282,7 +272,6 @@ async def get_workflow( 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. @@ -309,7 +298,6 @@ async def get_workflow( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -383,7 +371,6 @@ async def create_workflow( This corresponds to the ``workflow_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -413,7 +400,6 @@ async def create_workflow( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if workflow is not None: @@ -475,7 +461,6 @@ async def delete_workflow( 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. @@ -515,7 +500,6 @@ async def delete_workflow( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -540,7 +524,7 @@ async def delete_workflow( response = operation_async.from_gapic( response, self._client._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=workflows.OperationMetadata, ) @@ -552,7 +536,7 @@ async def update_workflow( request: workflows.UpdateWorkflowRequest = None, *, workflow: workflows.Workflow = None, - update_mask: field_mask.FieldMask = None, + update_mask: field_mask_pb2.FieldMask = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), @@ -582,7 +566,6 @@ async def update_workflow( This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -612,7 +595,6 @@ async def update_workflow( # If we have keyword arguments corresponding to fields on the # request, apply these. - if workflow is not None: request.workflow = workflow if update_mask is not None: diff --git a/google/cloud/workflows_v1/services/workflows/client.py b/google/cloud/workflows_v1/services/workflows/client.py index aab2e48..603482c 100644 --- a/google/cloud/workflows_v1/services/workflows/client.py +++ b/google/cloud/workflows_v1/services/workflows/client.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict from distutils import util import os @@ -23,10 +21,10 @@ import pkg_resources from google.api_core import client_options as client_options_lib # type: ignore -from google.api_core import exceptions # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport import mtls # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.auth.exceptions import MutualTLSChannelError # type: ignore @@ -36,10 +34,9 @@ from google.api_core import operation_async # type: ignore from google.cloud.workflows_v1.services.workflows import pagers from google.cloud.workflows_v1.types import workflows -from google.protobuf import empty_pb2 as empty # type: ignore -from google.protobuf import field_mask_pb2 as field_mask # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore - +from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore from .transports.base import WorkflowsTransport, DEFAULT_CLIENT_INFO from .transports.grpc import WorkflowsGrpcTransport from .transports.grpc_asyncio import WorkflowsGrpcAsyncIOTransport @@ -58,7 +55,7 @@ class WorkflowsClientMeta(type): _transport_registry["grpc_asyncio"] = WorkflowsGrpcAsyncIOTransport def get_transport_class(cls, label: str = None,) -> Type[WorkflowsTransport]: - """Return an appropriate transport class. + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -84,7 +81,8 @@ class WorkflowsClient(metaclass=WorkflowsClientMeta): @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: @@ -118,7 +116,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. @@ -135,7 +134,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 @@ -154,23 +153,24 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> WorkflowsTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - WorkflowsTransport: The transport used by the client instance. + WorkflowsTransport: The transport used by the client + instance. """ return self._transport @staticmethod def workflow_path(project: str, location: str, workflow: str,) -> str: - """Return a fully-qualified workflow string.""" + """Returns a fully-qualified workflow string.""" return "projects/{project}/locations/{location}/workflows/{workflow}".format( project=project, location=location, workflow=workflow, ) @staticmethod def parse_workflow_path(path: str) -> Dict[str, str]: - """Parse a workflow path into its component segments.""" + """Parses a workflow path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/workflows/(?P.+?)$", path, @@ -179,7 +179,7 @@ def parse_workflow_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, ) @@ -192,7 +192,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 @@ -203,7 +203,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 @@ -214,7 +214,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 @@ -225,7 +225,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, ) @@ -239,12 +239,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, WorkflowsTransport, None] = None, client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the workflows client. + """Instantiates the workflows client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -299,9 +299,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: @@ -313,12 +314,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. @@ -333,8 +336,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: @@ -375,7 +378,6 @@ def list_workflows( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -408,10 +410,8 @@ def list_workflows( # there are no flattened fields. if not isinstance(request, workflows.ListWorkflowsRequest): request = workflows.ListWorkflowsRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -461,7 +461,6 @@ def get_workflow( 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. @@ -490,10 +489,8 @@ def get_workflow( # there are no flattened fields. if not isinstance(request, workflows.GetWorkflowRequest): request = workflows.GetWorkflowRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -563,7 +560,6 @@ def create_workflow( This corresponds to the ``workflow_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -595,10 +591,8 @@ def create_workflow( # there are no flattened fields. if not isinstance(request, workflows.CreateWorkflowRequest): request = workflows.CreateWorkflowRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if workflow is not None: @@ -656,7 +650,6 @@ def delete_workflow( 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. @@ -698,10 +691,8 @@ def delete_workflow( # there are no flattened fields. if not isinstance(request, workflows.DeleteWorkflowRequest): request = workflows.DeleteWorkflowRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -722,7 +713,7 @@ def delete_workflow( response = operation.from_gapic( response, self._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=workflows.OperationMetadata, ) @@ -734,7 +725,7 @@ def update_workflow( request: workflows.UpdateWorkflowRequest = None, *, workflow: workflows.Workflow = None, - update_mask: field_mask.FieldMask = None, + update_mask: field_mask_pb2.FieldMask = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), @@ -764,7 +755,6 @@ def update_workflow( This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -796,10 +786,8 @@ def update_workflow( # there are no flattened fields. if not isinstance(request, workflows.UpdateWorkflowRequest): request = workflows.UpdateWorkflowRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if workflow is not None: request.workflow = workflow if update_mask is not None: diff --git a/google/cloud/workflows_v1/services/workflows/pagers.py b/google/cloud/workflows_v1/services/workflows/pagers.py index bff7b2c..b42af59 100644 --- a/google/cloud/workflows_v1/services/workflows/pagers.py +++ b/google/cloud/workflows_v1/services/workflows/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/workflows_v1/services/workflows/transports/__init__.py b/google/cloud/workflows_v1/services/workflows/transports/__init__.py index ceeb985..83dfa01 100644 --- a/google/cloud/workflows_v1/services/workflows/transports/__init__.py +++ b/google/cloud/workflows_v1/services/workflows/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/workflows_v1/services/workflows/transports/base.py b/google/cloud/workflows_v1/services/workflows/transports/base.py index 2b54f1c..9b4a9be 100644 --- a/google/cloud/workflows_v1/services/workflows/transports/base.py +++ b/google/cloud/workflows_v1/services/workflows/transports/base.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,21 +13,21 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import abc -import typing +from typing import Awaitable, Callable, Dict, Optional, Sequence, Union +import packaging.version import pkg_resources -from google import auth # type: ignore -from google.api_core import exceptions # type: ignore +import google.auth # type: ignore +import google.api_core # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.api_core import operations_v1 # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.cloud.workflows_v1.types import workflows -from google.longrunning import operations_pb2 as operations # type: ignore - +from google.longrunning import operations_pb2 # type: ignore try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( @@ -37,27 +36,41 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() +try: + # google.auth.__version__ was added in 1.26.0 + _GOOGLE_AUTH_VERSION = google.auth.__version__ +except AttributeError: + try: # try pkg_resources if it is available + _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version + except pkg_resources.DistributionNotFound: # pragma: NO COVER + _GOOGLE_AUTH_VERSION = None + +_API_CORE_VERSION = google.api_core.__version__ + class WorkflowsTransport(abc.ABC): """Abstract transport class for Workflows.""" AUTH_SCOPES = ("https://www.googleapis.com/auth/cloud-platform",) + DEFAULT_HOST: str = "workflows.googleapis.com" + def __init__( self, *, - host: str = "workflows.googleapis.com", - credentials: credentials.Credentials = None, - credentials_file: typing.Optional[str] = None, - scopes: typing.Optional[typing.Sequence[str]] = AUTH_SCOPES, - quota_project_id: typing.Optional[str] = None, + host: str = DEFAULT_HOST, + credentials: ga_credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, **kwargs, ) -> None: """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -66,7 +79,7 @@ def __init__( credentials_file (Optional[str]): A file with credentials that can be loaded with :func:`google.auth.load_credentials_from_file`. This argument is mutually exclusive with credentials. - scope (Optional[Sequence[str]]): A list of scopes. + scopes (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -80,29 +93,76 @@ def __init__( host += ":443" self._host = host + scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + # Save the scopes. self._scopes = scopes or self.AUTH_SCOPES # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: - raise exceptions.DuplicateCredentialArgs( + raise core_exceptions.DuplicateCredentialArgs( "'credentials_file' and 'credentials' are mutually exclusive" ) if credentials_file is not None: - credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=self._scopes, quota_project_id=quota_project_id + credentials, _ = google.auth.load_credentials_from_file( + credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) elif credentials is None: - credentials, _ = auth.default( - scopes=self._scopes, quota_project_id=quota_project_id + credentials, _ = google.auth.default( + **scopes_kwargs, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials + # TODO(busunkim): These two class methods are in the base transport + # to avoid duplicating code across the transport classes. These functions + # should be deleted once the minimum required versions of google-api-core + # and google-auth are increased. + + # TODO: Remove this function once google-auth >= 1.25.0 is required + @classmethod + def _get_scopes_kwargs( + cls, host: str, scopes: Optional[Sequence[str]] + ) -> Dict[str, Optional[Sequence[str]]]: + """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" + + scopes_kwargs = {} + + if _GOOGLE_AUTH_VERSION and ( + packaging.version.parse(_GOOGLE_AUTH_VERSION) + >= packaging.version.parse("1.25.0") + ): + scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} + else: + scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} + + return scopes_kwargs + + # TODO: Remove this function once google-api-core >= 1.26.0 is required + @classmethod + def _get_self_signed_jwt_kwargs( + cls, host: str, scopes: Optional[Sequence[str]] + ) -> Dict[str, Union[Optional[Sequence[str]], str]]: + """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" + + self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} + + if _API_CORE_VERSION and ( + packaging.version.parse(_API_CORE_VERSION) + >= packaging.version.parse("1.26.0") + ): + self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES + self_signed_jwt_kwargs["scopes"] = scopes + self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST + else: + self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES + + return self_signed_jwt_kwargs + def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { @@ -131,11 +191,10 @@ def operations_client(self) -> operations_v1.OperationsClient: @property def list_workflows( self, - ) -> typing.Callable[ + ) -> Callable[ [workflows.ListWorkflowsRequest], - typing.Union[ - workflows.ListWorkflowsResponse, - typing.Awaitable[workflows.ListWorkflowsResponse], + Union[ + workflows.ListWorkflowsResponse, Awaitable[workflows.ListWorkflowsResponse] ], ]: raise NotImplementedError() @@ -143,36 +202,36 @@ def list_workflows( @property def get_workflow( self, - ) -> typing.Callable[ + ) -> Callable[ [workflows.GetWorkflowRequest], - typing.Union[workflows.Workflow, typing.Awaitable[workflows.Workflow]], + Union[workflows.Workflow, Awaitable[workflows.Workflow]], ]: raise NotImplementedError() @property def create_workflow( self, - ) -> typing.Callable[ + ) -> Callable[ [workflows.CreateWorkflowRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def delete_workflow( self, - ) -> typing.Callable[ + ) -> Callable[ [workflows.DeleteWorkflowRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def update_workflow( self, - ) -> typing.Callable[ + ) -> Callable[ [workflows.UpdateWorkflowRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() diff --git a/google/cloud/workflows_v1/services/workflows/transports/grpc.py b/google/cloud/workflows_v1/services/workflows/transports/grpc.py index 8bf1104..d559c68 100644 --- a/google/cloud/workflows_v1/services/workflows/transports/grpc.py +++ b/google/cloud/workflows_v1/services/workflows/transports/grpc.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,22 +13,20 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import warnings -from typing import Callable, Dict, Optional, Sequence, Tuple +from typing import Callable, Dict, Optional, Sequence, Tuple, Union from google.api_core import grpc_helpers # type: ignore from google.api_core import operations_v1 # type: ignore from google.api_core import gapic_v1 # type: ignore -from google import auth # type: ignore -from google.auth import credentials # type: ignore +import google.auth # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore import grpc # type: ignore from google.cloud.workflows_v1.types import workflows -from google.longrunning import operations_pb2 as operations # type: ignore - +from google.longrunning import operations_pb2 # type: ignore from .base import WorkflowsTransport, DEFAULT_CLIENT_INFO @@ -54,7 +51,7 @@ def __init__( self, *, host: str = "workflows.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: str = None, scopes: Sequence[str] = None, channel: grpc.Channel = None, @@ -68,7 +65,8 @@ def __init__( """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -179,7 +177,7 @@ def __init__( def create_channel( cls, host: str = "workflows.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: str = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, @@ -210,13 +208,15 @@ def create_channel( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ - scopes = scopes or cls.AUTH_SCOPES + + self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) + return grpc_helpers.create_channel( host, credentials=credentials, credentials_file=credentials_file, - scopes=scopes, quota_project_id=quota_project_id, + **self_signed_jwt_kwargs, **kwargs, ) @@ -296,7 +296,7 @@ def get_workflow( @property def create_workflow( self, - ) -> Callable[[workflows.CreateWorkflowRequest], operations.Operation]: + ) -> Callable[[workflows.CreateWorkflowRequest], operations_pb2.Operation]: r"""Return a callable for the create workflow method over gRPC. Creates a new workflow. If a workflow with the specified name @@ -318,14 +318,14 @@ def create_workflow( self._stubs["create_workflow"] = self.grpc_channel.unary_unary( "/google.cloud.workflows.v1.Workflows/CreateWorkflow", request_serializer=workflows.CreateWorkflowRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["create_workflow"] @property def delete_workflow( self, - ) -> Callable[[workflows.DeleteWorkflowRequest], operations.Operation]: + ) -> Callable[[workflows.DeleteWorkflowRequest], operations_pb2.Operation]: r"""Return a callable for the delete workflow method over gRPC. Deletes a workflow with the specified name. @@ -346,14 +346,14 @@ def delete_workflow( self._stubs["delete_workflow"] = self.grpc_channel.unary_unary( "/google.cloud.workflows.v1.Workflows/DeleteWorkflow", request_serializer=workflows.DeleteWorkflowRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["delete_workflow"] @property def update_workflow( self, - ) -> Callable[[workflows.UpdateWorkflowRequest], operations.Operation]: + ) -> Callable[[workflows.UpdateWorkflowRequest], operations_pb2.Operation]: r"""Return a callable for the update workflow method over gRPC. Updates an existing workflow. @@ -377,7 +377,7 @@ def update_workflow( self._stubs["update_workflow"] = self.grpc_channel.unary_unary( "/google.cloud.workflows.v1.Workflows/UpdateWorkflow", request_serializer=workflows.UpdateWorkflowRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["update_workflow"] diff --git a/google/cloud/workflows_v1/services/workflows/transports/grpc_asyncio.py b/google/cloud/workflows_v1/services/workflows/transports/grpc_asyncio.py index 61c0792..dc1aae8 100644 --- a/google/cloud/workflows_v1/services/workflows/transports/grpc_asyncio.py +++ b/google/cloud/workflows_v1/services/workflows/transports/grpc_asyncio.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,23 +13,21 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import warnings -from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple +from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union from google.api_core import gapic_v1 # type: ignore from google.api_core import grpc_helpers_async # type: ignore from google.api_core import operations_v1 # type: ignore -from google import auth # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore from google.cloud.workflows_v1.types import workflows -from google.longrunning import operations_pb2 as operations # type: ignore - +from google.longrunning import operations_pb2 # type: ignore from .base import WorkflowsTransport, DEFAULT_CLIENT_INFO from .grpc import WorkflowsGrpcTransport @@ -57,7 +54,7 @@ class WorkflowsGrpcAsyncIOTransport(WorkflowsTransport): def create_channel( cls, host: str = "workflows.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, @@ -84,13 +81,15 @@ def create_channel( Returns: aio.Channel: A gRPC AsyncIO channel object. """ - scopes = scopes or cls.AUTH_SCOPES + + self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) + return grpc_helpers_async.create_channel( host, credentials=credentials, credentials_file=credentials_file, - scopes=scopes, quota_project_id=quota_project_id, + **self_signed_jwt_kwargs, **kwargs, ) @@ -98,7 +97,7 @@ def __init__( self, *, host: str = "workflows.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, channel: aio.Channel = None, @@ -112,7 +111,8 @@ def __init__( """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -171,7 +171,6 @@ def __init__( # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - else: if api_mtls_endpoint: host = api_mtls_endpoint @@ -304,7 +303,9 @@ def get_workflow( @property def create_workflow( self, - ) -> Callable[[workflows.CreateWorkflowRequest], Awaitable[operations.Operation]]: + ) -> Callable[ + [workflows.CreateWorkflowRequest], Awaitable[operations_pb2.Operation] + ]: r"""Return a callable for the create workflow method over gRPC. Creates a new workflow. If a workflow with the specified name @@ -326,14 +327,16 @@ def create_workflow( self._stubs["create_workflow"] = self.grpc_channel.unary_unary( "/google.cloud.workflows.v1.Workflows/CreateWorkflow", request_serializer=workflows.CreateWorkflowRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["create_workflow"] @property def delete_workflow( self, - ) -> Callable[[workflows.DeleteWorkflowRequest], Awaitable[operations.Operation]]: + ) -> Callable[ + [workflows.DeleteWorkflowRequest], Awaitable[operations_pb2.Operation] + ]: r"""Return a callable for the delete workflow method over gRPC. Deletes a workflow with the specified name. @@ -354,14 +357,16 @@ def delete_workflow( self._stubs["delete_workflow"] = self.grpc_channel.unary_unary( "/google.cloud.workflows.v1.Workflows/DeleteWorkflow", request_serializer=workflows.DeleteWorkflowRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["delete_workflow"] @property def update_workflow( self, - ) -> Callable[[workflows.UpdateWorkflowRequest], Awaitable[operations.Operation]]: + ) -> Callable[ + [workflows.UpdateWorkflowRequest], Awaitable[operations_pb2.Operation] + ]: r"""Return a callable for the update workflow method over gRPC. Updates an existing workflow. @@ -385,7 +390,7 @@ def update_workflow( self._stubs["update_workflow"] = self.grpc_channel.unary_unary( "/google.cloud.workflows.v1.Workflows/UpdateWorkflow", request_serializer=workflows.UpdateWorkflowRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["update_workflow"] diff --git a/google/cloud/workflows_v1/types/__init__.py b/google/cloud/workflows_v1/types/__init__.py index b3730e6..de29da5 100644 --- a/google/cloud/workflows_v1/types/__init__.py +++ b/google/cloud/workflows_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 .workflows import ( CreateWorkflowRequest, DeleteWorkflowRequest, diff --git a/google/cloud/workflows_v1/types/workflows.py b/google/cloud/workflows_v1/types/workflows.py index 26fd9e4..e7c8324 100644 --- a/google/cloud/workflows_v1/types/workflows.py +++ b/google/cloud/workflows_v1/types/workflows.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 field_mask_pb2 as field_mask # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore __protobuf__ = proto.module( @@ -39,7 +36,6 @@ class Workflow(proto.Message): r"""Workflow program to be executed by Workflows. - Attributes: name (str): The resource name of the workflow. @@ -106,27 +102,18 @@ class State(proto.Enum): STATE_UNSPECIFIED = 0 ACTIVE = 1 - name = proto.Field(proto.STRING, number=1) - - description = proto.Field(proto.STRING, number=2) - + name = proto.Field(proto.STRING, number=1,) + description = proto.Field(proto.STRING, number=2,) state = proto.Field(proto.ENUM, number=3, enum=State,) - - revision_id = proto.Field(proto.STRING, number=4) - - create_time = proto.Field(proto.MESSAGE, number=5, message=timestamp.Timestamp,) - - update_time = proto.Field(proto.MESSAGE, number=6, message=timestamp.Timestamp,) - + revision_id = proto.Field(proto.STRING, number=4,) + create_time = proto.Field(proto.MESSAGE, number=5, message=timestamp_pb2.Timestamp,) + update_time = proto.Field(proto.MESSAGE, number=6, message=timestamp_pb2.Timestamp,) revision_create_time = proto.Field( - proto.MESSAGE, number=7, message=timestamp.Timestamp, + proto.MESSAGE, number=7, message=timestamp_pb2.Timestamp, ) - - labels = proto.MapField(proto.STRING, proto.STRING, number=8) - - service_account = proto.Field(proto.STRING, number=9) - - source_contents = proto.Field(proto.STRING, number=10, oneof="source_code") + labels = proto.MapField(proto.STRING, proto.STRING, number=8,) + service_account = proto.Field(proto.STRING, number=9,) + source_contents = proto.Field(proto.STRING, number=10, oneof="source_code",) class ListWorkflowsRequest(proto.Message): @@ -166,15 +153,11 @@ class ListWorkflowsRequest(proto.Message): in an unspecified order. """ - parent = proto.Field(proto.STRING, number=1) - - page_size = proto.Field(proto.INT32, number=2) - - page_token = proto.Field(proto.STRING, number=3) - - filter = proto.Field(proto.STRING, number=4) - - order_by = proto.Field(proto.STRING, number=5) + parent = proto.Field(proto.STRING, number=1,) + page_size = proto.Field(proto.INT32, number=2,) + page_token = proto.Field(proto.STRING, number=3,) + filter = proto.Field(proto.STRING, number=4,) + order_by = proto.Field(proto.STRING, number=5,) class ListWorkflowsResponse(proto.Message): @@ -198,10 +181,8 @@ def raw_page(self): return self workflows = proto.RepeatedField(proto.MESSAGE, number=1, message="Workflow",) - - 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 GetWorkflowRequest(proto.Message): @@ -216,7 +197,7 @@ class GetWorkflowRequest(proto.Message): projects/{project}/locations/{location}/workflows/{workflow} """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class CreateWorkflowRequest(proto.Message): @@ -243,11 +224,9 @@ class CreateWorkflowRequest(proto.Message): - Must be unique within the customer project and location. """ - parent = proto.Field(proto.STRING, number=1) - + parent = proto.Field(proto.STRING, number=1,) workflow = proto.Field(proto.MESSAGE, number=2, message="Workflow",) - - workflow_id = proto.Field(proto.STRING, number=3) + workflow_id = proto.Field(proto.STRING, number=3,) class DeleteWorkflowRequest(proto.Message): @@ -262,7 +241,7 @@ class DeleteWorkflowRequest(proto.Message): projects/{project}/locations/{location}/workflows/{workflow} """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class UpdateWorkflowRequest(proto.Message): @@ -279,13 +258,13 @@ class UpdateWorkflowRequest(proto.Message): """ workflow = proto.Field(proto.MESSAGE, number=1, message="Workflow",) - - 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 OperationMetadata(proto.Message): r"""Represents the metadata of the long-running operation. - Attributes: create_time (google.protobuf.timestamp_pb2.Timestamp): The time the operation was created. @@ -300,15 +279,11 @@ class OperationMetadata(proto.Message): API version used to start the operation. """ - create_time = proto.Field(proto.MESSAGE, number=1, message=timestamp.Timestamp,) - - end_time = proto.Field(proto.MESSAGE, number=2, message=timestamp.Timestamp,) - - target = proto.Field(proto.STRING, number=3) - - verb = proto.Field(proto.STRING, number=4) - - api_version = proto.Field(proto.STRING, number=5) + create_time = proto.Field(proto.MESSAGE, number=1, message=timestamp_pb2.Timestamp,) + end_time = proto.Field(proto.MESSAGE, number=2, message=timestamp_pb2.Timestamp,) + target = proto.Field(proto.STRING, number=3,) + verb = proto.Field(proto.STRING, number=4,) + api_version = proto.Field(proto.STRING, number=5,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/workflows_v1beta/__init__.py b/google/cloud/workflows_v1beta/__init__.py index 91f1cc1..e80a3bd 100644 --- a/google/cloud/workflows_v1beta/__init__.py +++ b/google/cloud/workflows_v1beta/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,6 +15,8 @@ # from .services.workflows import WorkflowsClient +from .services.workflows import WorkflowsAsyncClient + from .types.workflows import CreateWorkflowRequest from .types.workflows import DeleteWorkflowRequest from .types.workflows import GetWorkflowRequest @@ -25,8 +26,8 @@ from .types.workflows import UpdateWorkflowRequest from .types.workflows import Workflow - __all__ = ( + "WorkflowsAsyncClient", "CreateWorkflowRequest", "DeleteWorkflowRequest", "GetWorkflowRequest", diff --git a/google/cloud/workflows_v1beta/gapic_metadata.json b/google/cloud/workflows_v1beta/gapic_metadata.json new file mode 100644 index 0000000..f56aae9 --- /dev/null +++ b/google/cloud/workflows_v1beta/gapic_metadata.json @@ -0,0 +1,73 @@ + { + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", + "language": "python", + "libraryPackage": "google.cloud.workflows_v1beta", + "protoPackage": "google.cloud.workflows.v1beta", + "schema": "1.0", + "services": { + "Workflows": { + "clients": { + "grpc": { + "libraryClient": "WorkflowsClient", + "rpcs": { + "CreateWorkflow": { + "methods": [ + "create_workflow" + ] + }, + "DeleteWorkflow": { + "methods": [ + "delete_workflow" + ] + }, + "GetWorkflow": { + "methods": [ + "get_workflow" + ] + }, + "ListWorkflows": { + "methods": [ + "list_workflows" + ] + }, + "UpdateWorkflow": { + "methods": [ + "update_workflow" + ] + } + } + }, + "grpc-async": { + "libraryClient": "WorkflowsAsyncClient", + "rpcs": { + "CreateWorkflow": { + "methods": [ + "create_workflow" + ] + }, + "DeleteWorkflow": { + "methods": [ + "delete_workflow" + ] + }, + "GetWorkflow": { + "methods": [ + "get_workflow" + ] + }, + "ListWorkflows": { + "methods": [ + "list_workflows" + ] + }, + "UpdateWorkflow": { + "methods": [ + "update_workflow" + ] + } + } + } + } + } + } +} diff --git a/google/cloud/workflows_v1beta/services/__init__.py b/google/cloud/workflows_v1beta/services/__init__.py index 42ffdf2..4de6597 100644 --- a/google/cloud/workflows_v1beta/services/__init__.py +++ b/google/cloud/workflows_v1beta/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/workflows_v1beta/services/workflows/__init__.py b/google/cloud/workflows_v1beta/services/workflows/__init__.py index 3afd340..b08649c 100644 --- a/google/cloud/workflows_v1beta/services/workflows/__init__.py +++ b/google/cloud/workflows_v1beta/services/workflows/__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 WorkflowsClient from .async_client import WorkflowsAsyncClient diff --git a/google/cloud/workflows_v1beta/services/workflows/async_client.py b/google/cloud/workflows_v1beta/services/workflows/async_client.py index ba757c5..fb27813 100644 --- a/google/cloud/workflows_v1beta/services/workflows/async_client.py +++ b/google/cloud/workflows_v1beta/services/workflows/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,20 +20,19 @@ import pkg_resources import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.workflows_v1beta.services.workflows import pagers from google.cloud.workflows_v1beta.types import workflows -from google.protobuf import empty_pb2 as empty # type: ignore -from google.protobuf import field_mask_pb2 as field_mask # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore - +from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore from .transports.base import WorkflowsTransport, DEFAULT_CLIENT_INFO from .transports.grpc_asyncio import WorkflowsGrpcAsyncIOTransport from .client import WorkflowsClient @@ -54,25 +51,20 @@ class WorkflowsAsyncClient: workflow_path = staticmethod(WorkflowsClient.workflow_path) parse_workflow_path = staticmethod(WorkflowsClient.parse_workflow_path) - common_billing_account_path = staticmethod( WorkflowsClient.common_billing_account_path ) parse_common_billing_account_path = staticmethod( WorkflowsClient.parse_common_billing_account_path ) - common_folder_path = staticmethod(WorkflowsClient.common_folder_path) parse_common_folder_path = staticmethod(WorkflowsClient.parse_common_folder_path) - common_organization_path = staticmethod(WorkflowsClient.common_organization_path) parse_common_organization_path = staticmethod( WorkflowsClient.parse_common_organization_path ) - common_project_path = staticmethod(WorkflowsClient.common_project_path) parse_common_project_path = staticmethod(WorkflowsClient.parse_common_project_path) - common_location_path = staticmethod(WorkflowsClient.common_location_path) parse_common_location_path = staticmethod( WorkflowsClient.parse_common_location_path @@ -80,7 +72,8 @@ class WorkflowsAsyncClient: @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. @@ -95,7 +88,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 @@ -112,7 +105,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> WorkflowsTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: WorkflowsTransport: The transport used by the client instance. @@ -126,12 +119,12 @@ def transport(self) -> WorkflowsTransport: def __init__( self, *, - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, transport: Union[str, WorkflowsTransport] = "grpc_asyncio", client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the workflows client. + """Instantiates the workflows client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -163,7 +156,6 @@ def __init__( google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport creation failed for any reason. """ - self._client = WorkflowsClient( credentials=credentials, transport=transport, @@ -197,7 +189,6 @@ async def list_workflows( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -228,7 +219,6 @@ async def list_workflows( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -282,7 +272,6 @@ async def get_workflow( 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. @@ -309,7 +298,6 @@ async def get_workflow( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -383,7 +371,6 @@ async def create_workflow( This corresponds to the ``workflow_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -413,7 +400,6 @@ async def create_workflow( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if workflow is not None: @@ -475,7 +461,6 @@ async def delete_workflow( 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. @@ -515,7 +500,6 @@ async def delete_workflow( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -540,7 +524,7 @@ async def delete_workflow( response = operation_async.from_gapic( response, self._client._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=workflows.OperationMetadata, ) @@ -552,7 +536,7 @@ async def update_workflow( request: workflows.UpdateWorkflowRequest = None, *, workflow: workflows.Workflow = None, - update_mask: field_mask.FieldMask = None, + update_mask: field_mask_pb2.FieldMask = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), @@ -582,7 +566,6 @@ async def update_workflow( This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -612,7 +595,6 @@ async def update_workflow( # If we have keyword arguments corresponding to fields on the # request, apply these. - if workflow is not None: request.workflow = workflow if update_mask is not None: diff --git a/google/cloud/workflows_v1beta/services/workflows/client.py b/google/cloud/workflows_v1beta/services/workflows/client.py index 4610a56..c9b0d31 100644 --- a/google/cloud/workflows_v1beta/services/workflows/client.py +++ b/google/cloud/workflows_v1beta/services/workflows/client.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict from distutils import util import os @@ -23,10 +21,10 @@ import pkg_resources from google.api_core import client_options as client_options_lib # type: ignore -from google.api_core import exceptions # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport import mtls # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.auth.exceptions import MutualTLSChannelError # type: ignore @@ -36,10 +34,9 @@ from google.api_core import operation_async # type: ignore from google.cloud.workflows_v1beta.services.workflows import pagers from google.cloud.workflows_v1beta.types import workflows -from google.protobuf import empty_pb2 as empty # type: ignore -from google.protobuf import field_mask_pb2 as field_mask # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore - +from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore from .transports.base import WorkflowsTransport, DEFAULT_CLIENT_INFO from .transports.grpc import WorkflowsGrpcTransport from .transports.grpc_asyncio import WorkflowsGrpcAsyncIOTransport @@ -58,7 +55,7 @@ class WorkflowsClientMeta(type): _transport_registry["grpc_asyncio"] = WorkflowsGrpcAsyncIOTransport def get_transport_class(cls, label: str = None,) -> Type[WorkflowsTransport]: - """Return an appropriate transport class. + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -84,7 +81,8 @@ class WorkflowsClient(metaclass=WorkflowsClientMeta): @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: @@ -118,7 +116,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. @@ -135,7 +134,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 @@ -154,23 +153,24 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> WorkflowsTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - WorkflowsTransport: The transport used by the client instance. + WorkflowsTransport: The transport used by the client + instance. """ return self._transport @staticmethod def workflow_path(project: str, location: str, workflow: str,) -> str: - """Return a fully-qualified workflow string.""" + """Returns a fully-qualified workflow string.""" return "projects/{project}/locations/{location}/workflows/{workflow}".format( project=project, location=location, workflow=workflow, ) @staticmethod def parse_workflow_path(path: str) -> Dict[str, str]: - """Parse a workflow path into its component segments.""" + """Parses a workflow path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/workflows/(?P.+?)$", path, @@ -179,7 +179,7 @@ def parse_workflow_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, ) @@ -192,7 +192,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 @@ -203,7 +203,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 @@ -214,7 +214,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 @@ -225,7 +225,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, ) @@ -239,12 +239,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, WorkflowsTransport, None] = None, client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the workflows client. + """Instantiates the workflows client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -299,9 +299,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: @@ -313,12 +314,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. @@ -333,8 +336,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: @@ -375,7 +378,6 @@ def list_workflows( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -408,10 +410,8 @@ def list_workflows( # there are no flattened fields. if not isinstance(request, workflows.ListWorkflowsRequest): request = workflows.ListWorkflowsRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -461,7 +461,6 @@ def get_workflow( 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. @@ -490,10 +489,8 @@ def get_workflow( # there are no flattened fields. if not isinstance(request, workflows.GetWorkflowRequest): request = workflows.GetWorkflowRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -563,7 +560,6 @@ def create_workflow( This corresponds to the ``workflow_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -595,10 +591,8 @@ def create_workflow( # there are no flattened fields. if not isinstance(request, workflows.CreateWorkflowRequest): request = workflows.CreateWorkflowRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if workflow is not None: @@ -656,7 +650,6 @@ def delete_workflow( 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. @@ -698,10 +691,8 @@ def delete_workflow( # there are no flattened fields. if not isinstance(request, workflows.DeleteWorkflowRequest): request = workflows.DeleteWorkflowRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -722,7 +713,7 @@ def delete_workflow( response = operation.from_gapic( response, self._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=workflows.OperationMetadata, ) @@ -734,7 +725,7 @@ def update_workflow( request: workflows.UpdateWorkflowRequest = None, *, workflow: workflows.Workflow = None, - update_mask: field_mask.FieldMask = None, + update_mask: field_mask_pb2.FieldMask = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), @@ -764,7 +755,6 @@ def update_workflow( This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -796,10 +786,8 @@ def update_workflow( # there are no flattened fields. if not isinstance(request, workflows.UpdateWorkflowRequest): request = workflows.UpdateWorkflowRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if workflow is not None: request.workflow = workflow if update_mask is not None: diff --git a/google/cloud/workflows_v1beta/services/workflows/pagers.py b/google/cloud/workflows_v1beta/services/workflows/pagers.py index 9ca8cba..032da4c 100644 --- a/google/cloud/workflows_v1beta/services/workflows/pagers.py +++ b/google/cloud/workflows_v1beta/services/workflows/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/workflows_v1beta/services/workflows/transports/__init__.py b/google/cloud/workflows_v1beta/services/workflows/transports/__init__.py index ceeb985..83dfa01 100644 --- a/google/cloud/workflows_v1beta/services/workflows/transports/__init__.py +++ b/google/cloud/workflows_v1beta/services/workflows/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/workflows_v1beta/services/workflows/transports/base.py b/google/cloud/workflows_v1beta/services/workflows/transports/base.py index bb51618..0eab1c5 100644 --- a/google/cloud/workflows_v1beta/services/workflows/transports/base.py +++ b/google/cloud/workflows_v1beta/services/workflows/transports/base.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,21 +13,21 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import abc -import typing +from typing import Awaitable, Callable, Dict, Optional, Sequence, Union +import packaging.version import pkg_resources -from google import auth # type: ignore -from google.api_core import exceptions # type: ignore +import google.auth # type: ignore +import google.api_core # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.api_core import operations_v1 # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.cloud.workflows_v1beta.types import workflows -from google.longrunning import operations_pb2 as operations # type: ignore - +from google.longrunning import operations_pb2 # type: ignore try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( @@ -37,27 +36,41 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() +try: + # google.auth.__version__ was added in 1.26.0 + _GOOGLE_AUTH_VERSION = google.auth.__version__ +except AttributeError: + try: # try pkg_resources if it is available + _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version + except pkg_resources.DistributionNotFound: # pragma: NO COVER + _GOOGLE_AUTH_VERSION = None + +_API_CORE_VERSION = google.api_core.__version__ + class WorkflowsTransport(abc.ABC): """Abstract transport class for Workflows.""" AUTH_SCOPES = ("https://www.googleapis.com/auth/cloud-platform",) + DEFAULT_HOST: str = "workflows.googleapis.com" + def __init__( self, *, - host: str = "workflows.googleapis.com", - credentials: credentials.Credentials = None, - credentials_file: typing.Optional[str] = None, - scopes: typing.Optional[typing.Sequence[str]] = AUTH_SCOPES, - quota_project_id: typing.Optional[str] = None, + host: str = DEFAULT_HOST, + credentials: ga_credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, **kwargs, ) -> None: """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -66,7 +79,7 @@ def __init__( credentials_file (Optional[str]): A file with credentials that can be loaded with :func:`google.auth.load_credentials_from_file`. This argument is mutually exclusive with credentials. - scope (Optional[Sequence[str]]): A list of scopes. + scopes (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -80,29 +93,76 @@ def __init__( host += ":443" self._host = host + scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + # Save the scopes. self._scopes = scopes or self.AUTH_SCOPES # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: - raise exceptions.DuplicateCredentialArgs( + raise core_exceptions.DuplicateCredentialArgs( "'credentials_file' and 'credentials' are mutually exclusive" ) if credentials_file is not None: - credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=self._scopes, quota_project_id=quota_project_id + credentials, _ = google.auth.load_credentials_from_file( + credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) elif credentials is None: - credentials, _ = auth.default( - scopes=self._scopes, quota_project_id=quota_project_id + credentials, _ = google.auth.default( + **scopes_kwargs, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials + # TODO(busunkim): These two class methods are in the base transport + # to avoid duplicating code across the transport classes. These functions + # should be deleted once the minimum required versions of google-api-core + # and google-auth are increased. + + # TODO: Remove this function once google-auth >= 1.25.0 is required + @classmethod + def _get_scopes_kwargs( + cls, host: str, scopes: Optional[Sequence[str]] + ) -> Dict[str, Optional[Sequence[str]]]: + """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" + + scopes_kwargs = {} + + if _GOOGLE_AUTH_VERSION and ( + packaging.version.parse(_GOOGLE_AUTH_VERSION) + >= packaging.version.parse("1.25.0") + ): + scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} + else: + scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} + + return scopes_kwargs + + # TODO: Remove this function once google-api-core >= 1.26.0 is required + @classmethod + def _get_self_signed_jwt_kwargs( + cls, host: str, scopes: Optional[Sequence[str]] + ) -> Dict[str, Union[Optional[Sequence[str]], str]]: + """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" + + self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} + + if _API_CORE_VERSION and ( + packaging.version.parse(_API_CORE_VERSION) + >= packaging.version.parse("1.26.0") + ): + self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES + self_signed_jwt_kwargs["scopes"] = scopes + self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST + else: + self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES + + return self_signed_jwt_kwargs + def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { @@ -131,11 +191,10 @@ def operations_client(self) -> operations_v1.OperationsClient: @property def list_workflows( self, - ) -> typing.Callable[ + ) -> Callable[ [workflows.ListWorkflowsRequest], - typing.Union[ - workflows.ListWorkflowsResponse, - typing.Awaitable[workflows.ListWorkflowsResponse], + Union[ + workflows.ListWorkflowsResponse, Awaitable[workflows.ListWorkflowsResponse] ], ]: raise NotImplementedError() @@ -143,36 +202,36 @@ def list_workflows( @property def get_workflow( self, - ) -> typing.Callable[ + ) -> Callable[ [workflows.GetWorkflowRequest], - typing.Union[workflows.Workflow, typing.Awaitable[workflows.Workflow]], + Union[workflows.Workflow, Awaitable[workflows.Workflow]], ]: raise NotImplementedError() @property def create_workflow( self, - ) -> typing.Callable[ + ) -> Callable[ [workflows.CreateWorkflowRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def delete_workflow( self, - ) -> typing.Callable[ + ) -> Callable[ [workflows.DeleteWorkflowRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def update_workflow( self, - ) -> typing.Callable[ + ) -> Callable[ [workflows.UpdateWorkflowRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() diff --git a/google/cloud/workflows_v1beta/services/workflows/transports/grpc.py b/google/cloud/workflows_v1beta/services/workflows/transports/grpc.py index ee55e23..1dbb6d6 100644 --- a/google/cloud/workflows_v1beta/services/workflows/transports/grpc.py +++ b/google/cloud/workflows_v1beta/services/workflows/transports/grpc.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,22 +13,20 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import warnings -from typing import Callable, Dict, Optional, Sequence, Tuple +from typing import Callable, Dict, Optional, Sequence, Tuple, Union from google.api_core import grpc_helpers # type: ignore from google.api_core import operations_v1 # type: ignore from google.api_core import gapic_v1 # type: ignore -from google import auth # type: ignore -from google.auth import credentials # type: ignore +import google.auth # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore import grpc # type: ignore from google.cloud.workflows_v1beta.types import workflows -from google.longrunning import operations_pb2 as operations # type: ignore - +from google.longrunning import operations_pb2 # type: ignore from .base import WorkflowsTransport, DEFAULT_CLIENT_INFO @@ -54,7 +51,7 @@ def __init__( self, *, host: str = "workflows.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: str = None, scopes: Sequence[str] = None, channel: grpc.Channel = None, @@ -68,7 +65,8 @@ def __init__( """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -179,7 +177,7 @@ def __init__( def create_channel( cls, host: str = "workflows.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: str = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, @@ -210,13 +208,15 @@ def create_channel( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ - scopes = scopes or cls.AUTH_SCOPES + + self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) + return grpc_helpers.create_channel( host, credentials=credentials, credentials_file=credentials_file, - scopes=scopes, quota_project_id=quota_project_id, + **self_signed_jwt_kwargs, **kwargs, ) @@ -296,7 +296,7 @@ def get_workflow( @property def create_workflow( self, - ) -> Callable[[workflows.CreateWorkflowRequest], operations.Operation]: + ) -> Callable[[workflows.CreateWorkflowRequest], operations_pb2.Operation]: r"""Return a callable for the create workflow method over gRPC. Creates a new workflow. If a workflow with the specified name @@ -318,14 +318,14 @@ def create_workflow( self._stubs["create_workflow"] = self.grpc_channel.unary_unary( "/google.cloud.workflows.v1beta.Workflows/CreateWorkflow", request_serializer=workflows.CreateWorkflowRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["create_workflow"] @property def delete_workflow( self, - ) -> Callable[[workflows.DeleteWorkflowRequest], operations.Operation]: + ) -> Callable[[workflows.DeleteWorkflowRequest], operations_pb2.Operation]: r"""Return a callable for the delete workflow method over gRPC. Deletes a workflow with the specified name. @@ -346,14 +346,14 @@ def delete_workflow( self._stubs["delete_workflow"] = self.grpc_channel.unary_unary( "/google.cloud.workflows.v1beta.Workflows/DeleteWorkflow", request_serializer=workflows.DeleteWorkflowRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["delete_workflow"] @property def update_workflow( self, - ) -> Callable[[workflows.UpdateWorkflowRequest], operations.Operation]: + ) -> Callable[[workflows.UpdateWorkflowRequest], operations_pb2.Operation]: r"""Return a callable for the update workflow method over gRPC. Updates an existing workflow. @@ -377,7 +377,7 @@ def update_workflow( self._stubs["update_workflow"] = self.grpc_channel.unary_unary( "/google.cloud.workflows.v1beta.Workflows/UpdateWorkflow", request_serializer=workflows.UpdateWorkflowRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["update_workflow"] diff --git a/google/cloud/workflows_v1beta/services/workflows/transports/grpc_asyncio.py b/google/cloud/workflows_v1beta/services/workflows/transports/grpc_asyncio.py index 11d85c5..ce9c8ab 100644 --- a/google/cloud/workflows_v1beta/services/workflows/transports/grpc_asyncio.py +++ b/google/cloud/workflows_v1beta/services/workflows/transports/grpc_asyncio.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,23 +13,21 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import warnings -from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple +from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union from google.api_core import gapic_v1 # type: ignore from google.api_core import grpc_helpers_async # type: ignore from google.api_core import operations_v1 # type: ignore -from google import auth # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore from google.cloud.workflows_v1beta.types import workflows -from google.longrunning import operations_pb2 as operations # type: ignore - +from google.longrunning import operations_pb2 # type: ignore from .base import WorkflowsTransport, DEFAULT_CLIENT_INFO from .grpc import WorkflowsGrpcTransport @@ -57,7 +54,7 @@ class WorkflowsGrpcAsyncIOTransport(WorkflowsTransport): def create_channel( cls, host: str = "workflows.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, @@ -84,13 +81,15 @@ def create_channel( Returns: aio.Channel: A gRPC AsyncIO channel object. """ - scopes = scopes or cls.AUTH_SCOPES + + self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) + return grpc_helpers_async.create_channel( host, credentials=credentials, credentials_file=credentials_file, - scopes=scopes, quota_project_id=quota_project_id, + **self_signed_jwt_kwargs, **kwargs, ) @@ -98,7 +97,7 @@ def __init__( self, *, host: str = "workflows.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, channel: aio.Channel = None, @@ -112,7 +111,8 @@ def __init__( """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -171,7 +171,6 @@ def __init__( # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - else: if api_mtls_endpoint: host = api_mtls_endpoint @@ -304,7 +303,9 @@ def get_workflow( @property def create_workflow( self, - ) -> Callable[[workflows.CreateWorkflowRequest], Awaitable[operations.Operation]]: + ) -> Callable[ + [workflows.CreateWorkflowRequest], Awaitable[operations_pb2.Operation] + ]: r"""Return a callable for the create workflow method over gRPC. Creates a new workflow. If a workflow with the specified name @@ -326,14 +327,16 @@ def create_workflow( self._stubs["create_workflow"] = self.grpc_channel.unary_unary( "/google.cloud.workflows.v1beta.Workflows/CreateWorkflow", request_serializer=workflows.CreateWorkflowRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["create_workflow"] @property def delete_workflow( self, - ) -> Callable[[workflows.DeleteWorkflowRequest], Awaitable[operations.Operation]]: + ) -> Callable[ + [workflows.DeleteWorkflowRequest], Awaitable[operations_pb2.Operation] + ]: r"""Return a callable for the delete workflow method over gRPC. Deletes a workflow with the specified name. @@ -354,14 +357,16 @@ def delete_workflow( self._stubs["delete_workflow"] = self.grpc_channel.unary_unary( "/google.cloud.workflows.v1beta.Workflows/DeleteWorkflow", request_serializer=workflows.DeleteWorkflowRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["delete_workflow"] @property def update_workflow( self, - ) -> Callable[[workflows.UpdateWorkflowRequest], Awaitable[operations.Operation]]: + ) -> Callable[ + [workflows.UpdateWorkflowRequest], Awaitable[operations_pb2.Operation] + ]: r"""Return a callable for the update workflow method over gRPC. Updates an existing workflow. @@ -385,7 +390,7 @@ def update_workflow( self._stubs["update_workflow"] = self.grpc_channel.unary_unary( "/google.cloud.workflows.v1beta.Workflows/UpdateWorkflow", request_serializer=workflows.UpdateWorkflowRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["update_workflow"] diff --git a/google/cloud/workflows_v1beta/types/__init__.py b/google/cloud/workflows_v1beta/types/__init__.py index b3730e6..de29da5 100644 --- a/google/cloud/workflows_v1beta/types/__init__.py +++ b/google/cloud/workflows_v1beta/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 .workflows import ( CreateWorkflowRequest, DeleteWorkflowRequest, diff --git a/google/cloud/workflows_v1beta/types/workflows.py b/google/cloud/workflows_v1beta/types/workflows.py index e49a90e..a49f234 100644 --- a/google/cloud/workflows_v1beta/types/workflows.py +++ b/google/cloud/workflows_v1beta/types/workflows.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 field_mask_pb2 as field_mask # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore __protobuf__ = proto.module( @@ -39,7 +36,6 @@ class Workflow(proto.Message): r"""Workflow program to be executed by Workflows. - Attributes: name (str): The resource name of the workflow. @@ -106,27 +102,18 @@ class State(proto.Enum): STATE_UNSPECIFIED = 0 ACTIVE = 1 - name = proto.Field(proto.STRING, number=1) - - description = proto.Field(proto.STRING, number=2) - + name = proto.Field(proto.STRING, number=1,) + description = proto.Field(proto.STRING, number=2,) state = proto.Field(proto.ENUM, number=3, enum=State,) - - revision_id = proto.Field(proto.STRING, number=4) - - create_time = proto.Field(proto.MESSAGE, number=5, message=timestamp.Timestamp,) - - update_time = proto.Field(proto.MESSAGE, number=6, message=timestamp.Timestamp,) - + revision_id = proto.Field(proto.STRING, number=4,) + create_time = proto.Field(proto.MESSAGE, number=5, message=timestamp_pb2.Timestamp,) + update_time = proto.Field(proto.MESSAGE, number=6, message=timestamp_pb2.Timestamp,) revision_create_time = proto.Field( - proto.MESSAGE, number=7, message=timestamp.Timestamp, + proto.MESSAGE, number=7, message=timestamp_pb2.Timestamp, ) - - labels = proto.MapField(proto.STRING, proto.STRING, number=8) - - service_account = proto.Field(proto.STRING, number=9) - - source_contents = proto.Field(proto.STRING, number=10, oneof="source_code") + labels = proto.MapField(proto.STRING, proto.STRING, number=8,) + service_account = proto.Field(proto.STRING, number=9,) + source_contents = proto.Field(proto.STRING, number=10, oneof="source_code",) class ListWorkflowsRequest(proto.Message): @@ -166,15 +153,11 @@ class ListWorkflowsRequest(proto.Message): in an unspecified order. """ - parent = proto.Field(proto.STRING, number=1) - - page_size = proto.Field(proto.INT32, number=2) - - page_token = proto.Field(proto.STRING, number=3) - - filter = proto.Field(proto.STRING, number=4) - - order_by = proto.Field(proto.STRING, number=5) + parent = proto.Field(proto.STRING, number=1,) + page_size = proto.Field(proto.INT32, number=2,) + page_token = proto.Field(proto.STRING, number=3,) + filter = proto.Field(proto.STRING, number=4,) + order_by = proto.Field(proto.STRING, number=5,) class ListWorkflowsResponse(proto.Message): @@ -198,10 +181,8 @@ def raw_page(self): return self workflows = proto.RepeatedField(proto.MESSAGE, number=1, message="Workflow",) - - 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 GetWorkflowRequest(proto.Message): @@ -216,7 +197,7 @@ class GetWorkflowRequest(proto.Message): projects/{project}/locations/{location}/workflows/{workflow} """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class CreateWorkflowRequest(proto.Message): @@ -243,11 +224,9 @@ class CreateWorkflowRequest(proto.Message): - Must be unique within the customer project and location. """ - parent = proto.Field(proto.STRING, number=1) - + parent = proto.Field(proto.STRING, number=1,) workflow = proto.Field(proto.MESSAGE, number=2, message="Workflow",) - - workflow_id = proto.Field(proto.STRING, number=3) + workflow_id = proto.Field(proto.STRING, number=3,) class DeleteWorkflowRequest(proto.Message): @@ -262,7 +241,7 @@ class DeleteWorkflowRequest(proto.Message): projects/{project}/locations/{location}/workflows/{workflow} """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class UpdateWorkflowRequest(proto.Message): @@ -279,13 +258,13 @@ class UpdateWorkflowRequest(proto.Message): """ workflow = proto.Field(proto.MESSAGE, number=1, message="Workflow",) - - 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 OperationMetadata(proto.Message): r"""Represents the metadata of the long-running operation. - Attributes: create_time (google.protobuf.timestamp_pb2.Timestamp): The time the operation was created. @@ -300,15 +279,11 @@ class OperationMetadata(proto.Message): API version used to start the operation. """ - create_time = proto.Field(proto.MESSAGE, number=1, message=timestamp.Timestamp,) - - end_time = proto.Field(proto.MESSAGE, number=2, message=timestamp.Timestamp,) - - target = proto.Field(proto.STRING, number=3) - - verb = proto.Field(proto.STRING, number=4) - - api_version = proto.Field(proto.STRING, number=5) + create_time = proto.Field(proto.MESSAGE, number=1, message=timestamp_pb2.Timestamp,) + end_time = proto.Field(proto.MESSAGE, number=2, message=timestamp_pb2.Timestamp,) + target = proto.Field(proto.STRING, number=3,) + verb = proto.Field(proto.STRING, number=4,) + api_version = proto.Field(proto.STRING, number=5,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owlbot.py b/owlbot.py index d676e60..7b35f3d 100644 --- a/owlbot.py +++ b/owlbot.py @@ -13,7 +13,8 @@ # limitations under the License. """This script is used to synthesize generated parts of this library.""" -import os +from pathlib import Path +from typing import List, Optional import synthtool as s import synthtool.gcp as gcp @@ -21,40 +22,78 @@ common = gcp.CommonTemplates() +# This is a customized version of the s.get_staging_dirs() function from synthtool to +# cater for copying 2 different folders from googleapis-gen +# which are workflows and workflows/executions +# Source https://github.com/googleapis/synthtool/blob/master/synthtool/transforms.py#L280 +def get_staging_dirs( + default_version: Optional[str] = None, sub_directory: Optional[str] = None +) -> List[Path]: + """Returns the list of directories, one per version, copied from + https://github.com/googleapis/googleapis-gen. Will return in lexical sorting + order with the exception of the default_version which will be last (if specified). + + Args: + default_version (str): the default version of the API. The directory for this version + will be the last item in the returned list if specified. + sub_directory (str): if a `sub_directory` is provided, only the directories within the + specified `sub_directory` will be returned. + + Returns: the empty list if no file were copied. + """ + + staging = Path("owl-bot-staging") + + if sub_directory: + staging /= sub_directory + + if staging.is_dir(): + # Collect the subdirectories of the staging directory. + versions = [v.name for v in staging.iterdir() if v.is_dir()] + # Reorder the versions so the default version always comes last. + versions = [v for v in versions if v != default_version] + versions.sort() + if default_version is not None: + versions += [default_version] + dirs = [staging / v for v in versions] + for dir in dirs: + s._tracked_paths.add(dir) + return dirs + else: + return [] + # This library ships clients for two different APIs, # Workflows and Workflows Executions workflows_default_version = "v1" workflows_executions_default_version = "v1" -for library in s.get_staging_dirs(workflows_executions_default_version): - if library.parent.absolute() == 'executions': - # Make sure this library is named 'google-cloud-workflows' - s.replace( - library / "google/**/*.py", "google-cloud-workflows-executions", "google-cloud-workflow" - ) - - s.move( - library, - excludes=[ - "setup.py", - "README.rst", - "docs/index.rst", - f"scripts/fixup_executions_{library.name}_keywords.py", - ], - ) +for library in get_staging_dirs(workflows_executions_default_version, "executions"): + # Make sure this library is named 'google-cloud-workflows' + s.replace( + library / "google/**/*.py", "google-cloud-workflows-executions", "google-cloud-workflow" + ) + + s.move( + library, + excludes=[ + "setup.py", + "README.rst", + "docs/index.rst", + f"scripts/fixup_executions_{library.name}_keywords.py", + ], + ) # move workflows after executions, since we want to use "workflows" for the name -for library in s.get_staging_dirs(workflows_default_version): - if library.parent.absolute() == 'workflows': - s.move( - library, - excludes=[ - "setup.py", - "README.rst", - "docs/index.rst", - f"scripts/fixup_workflows_{library.name}_keywords.py", - ], - ) +for library in get_staging_dirs(workflows_default_version, "workflows"): + s.move( + library, + excludes=[ + "setup.py", + "README.rst", + "docs/index.rst", + f"scripts/fixup_workflows_{library.name}_keywords.py", + ], + ) s.remove_staging_dirs() diff --git a/setup.py b/setup.py index 0d3edfe..4a8c576 100644 --- a/setup.py +++ b/setup.py @@ -43,6 +43,7 @@ "google-api-core[grpc] >= 1.22.2, < 2.0.0dev", "libcst >= 0.2.5", "proto-plus >= 1.4.0", + "packaging >= 14.3", ), python_requires=">=3.6", classifiers=[ diff --git a/testing/constraints-3.6.txt b/testing/constraints-3.6.txt index c933887..33059b8 100644 --- a/testing/constraints-3.6.txt +++ b/testing/constraints-3.6.txt @@ -7,4 +7,6 @@ # Then this file should have foo==1.14.0 google-api-core==1.22.2 libcst==0.2.5 -proto-plus==1.4.0 \ No newline at end of file +proto-plus==1.4.0 +packaging==14.3 +google-auth==1.24.0 # TODO: remove when google-auth>=1.25.0 is required through google-api-core 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/executions_v1/__init__.py b/tests/unit/gapic/executions_v1/__init__.py index 42ffdf2..4de6597 100644 --- a/tests/unit/gapic/executions_v1/__init__.py +++ b/tests/unit/gapic/executions_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/executions_v1/test_executions.py b/tests/unit/gapic/executions_v1/test_executions.py index 10ca798..41c0a90 100644 --- a/tests/unit/gapic/executions_v1/test_executions.py +++ b/tests/unit/gapic/executions_v1/test_executions.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,13 +23,13 @@ import pytest from proto.marshal.rules.dates import DurationRule, TimestampRule -from google import auth + from google.api_core import client_options -from google.api_core import exceptions +from google.api_core import exceptions as core_exceptions from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async -from google.auth import credentials +from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.workflows.executions_v1.services.executions import ( ExecutionsAsyncClient, @@ -38,9 +37,39 @@ from google.cloud.workflows.executions_v1.services.executions import ExecutionsClient from google.cloud.workflows.executions_v1.services.executions import pagers from google.cloud.workflows.executions_v1.services.executions import transports +from google.cloud.workflows.executions_v1.services.executions.transports.base import ( + _API_CORE_VERSION, +) +from google.cloud.workflows.executions_v1.services.executions.transports.base import ( + _GOOGLE_AUTH_VERSION, +) from google.cloud.workflows.executions_v1.types import executions from google.oauth2 import service_account -from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +import google.auth + + +# TODO(busunkim): Once google-api-core >= 1.26.0 is required: +# - Delete all the api-core and auth "less than" test cases +# - Delete these pytest markers (Make the "greater than or equal to" tests the default). +requires_google_auth_lt_1_25_0 = pytest.mark.skipif( + packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), + reason="This test requires google-auth < 1.25.0", +) +requires_google_auth_gte_1_25_0 = pytest.mark.skipif( + packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), + reason="This test requires google-auth >= 1.25.0", +) + +requires_api_core_lt_1_26_0 = pytest.mark.skipif( + packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), + reason="This test requires google-api-core < 1.26.0", +) + +requires_api_core_gte_1_26_0 = pytest.mark.skipif( + packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), + reason="This test requires google-api-core >= 1.26.0", +) def client_cert_source_callback(): @@ -86,7 +115,7 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize("client_class", [ExecutionsClient, ExecutionsAsyncClient,]) def test_executions_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: @@ -101,7 +130,7 @@ def test_executions_client_from_service_account_info(client_class): @pytest.mark.parametrize("client_class", [ExecutionsClient, ExecutionsAsyncClient,]) def test_executions_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: @@ -152,7 +181,7 @@ def test_executions_client_client_options( ): # Check that if channel is provided we won't create a new one. with mock.patch.object(ExecutionsClient, "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() @@ -436,7 +465,7 @@ def test_list_executions( transport: str = "grpc", request_type=executions.ListExecutionsRequest ): client = ExecutionsClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -449,19 +478,15 @@ def test_list_executions( call.return_value = executions.ListExecutionsResponse( next_page_token="next_page_token_value", ) - response = client.list_executions(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == executions.ListExecutionsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListExecutionsPager) - assert response.next_page_token == "next_page_token_value" @@ -473,7 +498,7 @@ def test_list_executions_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 = ExecutionsClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -481,7 +506,6 @@ def test_list_executions_empty_call(): client.list_executions() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == executions.ListExecutionsRequest() @@ -490,7 +514,7 @@ async def test_list_executions_async( transport: str = "grpc_asyncio", request_type=executions.ListExecutionsRequest ): client = ExecutionsAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -503,18 +527,15 @@ async def test_list_executions_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( executions.ListExecutionsResponse(next_page_token="next_page_token_value",) ) - response = await client.list_executions(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == executions.ListExecutionsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListExecutionsAsyncPager) - assert response.next_page_token == "next_page_token_value" @@ -524,17 +545,17 @@ async def test_list_executions_async_from_dict(): def test_list_executions_field_headers(): - client = ExecutionsClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsClient(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 = executions.ListExecutionsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_executions), "__call__") as call: call.return_value = executions.ListExecutionsResponse() - client.list_executions(request) # Establish that the underlying gRPC stub method was called. @@ -549,11 +570,12 @@ def test_list_executions_field_headers(): @pytest.mark.asyncio async def test_list_executions_field_headers_async(): - client = ExecutionsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsAsyncClient(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 = executions.ListExecutionsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -561,7 +583,6 @@ async def test_list_executions_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( executions.ListExecutionsResponse() ) - await client.list_executions(request) # Establish that the underlying gRPC stub method was called. @@ -575,13 +596,12 @@ async def test_list_executions_field_headers_async(): def test_list_executions_flattened(): - client = ExecutionsClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_executions), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = executions.ListExecutionsResponse() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.list_executions(parent="parent_value",) @@ -590,12 +610,11 @@ def test_list_executions_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" def test_list_executions_flattened_error(): - client = ExecutionsClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -607,7 +626,7 @@ def test_list_executions_flattened_error(): @pytest.mark.asyncio async def test_list_executions_flattened_async(): - client = ExecutionsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_executions), "__call__") as call: @@ -625,13 +644,12 @@ async def test_list_executions_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" @pytest.mark.asyncio async def test_list_executions_flattened_error_async(): - client = ExecutionsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -642,7 +660,7 @@ async def test_list_executions_flattened_error_async(): def test_list_executions_pager(): - client = ExecutionsClient(credentials=credentials.AnonymousCredentials,) + client = ExecutionsClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_executions), "__call__") as call: @@ -680,7 +698,7 @@ def test_list_executions_pager(): def test_list_executions_pages(): - client = ExecutionsClient(credentials=credentials.AnonymousCredentials,) + client = ExecutionsClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_executions), "__call__") as call: @@ -710,7 +728,7 @@ def test_list_executions_pages(): @pytest.mark.asyncio async def test_list_executions_async_pager(): - client = ExecutionsAsyncClient(credentials=credentials.AnonymousCredentials,) + client = ExecutionsAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -747,7 +765,7 @@ async def test_list_executions_async_pager(): @pytest.mark.asyncio async def test_list_executions_async_pages(): - client = ExecutionsAsyncClient(credentials=credentials.AnonymousCredentials,) + client = ExecutionsAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -783,7 +801,7 @@ def test_create_execution( transport: str = "grpc", request_type=executions.CreateExecutionRequest ): client = ExecutionsClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -800,27 +818,19 @@ def test_create_execution( result="result_value", workflow_revision_id="workflow_revision_id_value", ) - response = client.create_execution(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == executions.CreateExecutionRequest() # Establish that the response is the type that we expect. - assert isinstance(response, executions.Execution) - assert response.name == "name_value" - assert response.state == executions.Execution.State.ACTIVE - assert response.argument == "argument_value" - assert response.result == "result_value" - assert response.workflow_revision_id == "workflow_revision_id_value" @@ -832,7 +842,7 @@ def test_create_execution_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 = ExecutionsClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -840,7 +850,6 @@ def test_create_execution_empty_call(): client.create_execution() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == executions.CreateExecutionRequest() @@ -849,7 +858,7 @@ async def test_create_execution_async( transport: str = "grpc_asyncio", request_type=executions.CreateExecutionRequest ): client = ExecutionsAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -868,26 +877,19 @@ async def test_create_execution_async( workflow_revision_id="workflow_revision_id_value", ) ) - response = await client.create_execution(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == executions.CreateExecutionRequest() # Establish that the response is the type that we expect. assert isinstance(response, executions.Execution) - assert response.name == "name_value" - assert response.state == executions.Execution.State.ACTIVE - assert response.argument == "argument_value" - assert response.result == "result_value" - assert response.workflow_revision_id == "workflow_revision_id_value" @@ -897,17 +899,17 @@ async def test_create_execution_async_from_dict(): def test_create_execution_field_headers(): - client = ExecutionsClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsClient(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 = executions.CreateExecutionRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_execution), "__call__") as call: call.return_value = executions.Execution() - client.create_execution(request) # Establish that the underlying gRPC stub method was called. @@ -922,11 +924,12 @@ def test_create_execution_field_headers(): @pytest.mark.asyncio async def test_create_execution_field_headers_async(): - client = ExecutionsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsAsyncClient(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 = executions.CreateExecutionRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -934,7 +937,6 @@ async def test_create_execution_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( executions.Execution() ) - await client.create_execution(request) # Establish that the underlying gRPC stub method was called. @@ -948,13 +950,12 @@ async def test_create_execution_field_headers_async(): def test_create_execution_flattened(): - client = ExecutionsClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_execution), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = executions.Execution() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.create_execution( @@ -965,14 +966,12 @@ def test_create_execution_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].execution == executions.Execution(name="name_value") def test_create_execution_flattened_error(): - client = ExecutionsClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -986,7 +985,7 @@ def test_create_execution_flattened_error(): @pytest.mark.asyncio async def test_create_execution_flattened_async(): - client = ExecutionsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_execution), "__call__") as call: @@ -1006,15 +1005,13 @@ async def test_create_execution_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].execution == executions.Execution(name="name_value") @pytest.mark.asyncio async def test_create_execution_flattened_error_async(): - client = ExecutionsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1030,7 +1027,7 @@ def test_get_execution( transport: str = "grpc", request_type=executions.GetExecutionRequest ): client = ExecutionsClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1047,27 +1044,19 @@ def test_get_execution( result="result_value", workflow_revision_id="workflow_revision_id_value", ) - response = client.get_execution(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == executions.GetExecutionRequest() # Establish that the response is the type that we expect. - assert isinstance(response, executions.Execution) - assert response.name == "name_value" - assert response.state == executions.Execution.State.ACTIVE - assert response.argument == "argument_value" - assert response.result == "result_value" - assert response.workflow_revision_id == "workflow_revision_id_value" @@ -1079,7 +1068,7 @@ def test_get_execution_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 = ExecutionsClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1087,7 +1076,6 @@ def test_get_execution_empty_call(): client.get_execution() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == executions.GetExecutionRequest() @@ -1096,7 +1084,7 @@ async def test_get_execution_async( transport: str = "grpc_asyncio", request_type=executions.GetExecutionRequest ): client = ExecutionsAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1115,26 +1103,19 @@ async def test_get_execution_async( workflow_revision_id="workflow_revision_id_value", ) ) - response = await client.get_execution(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == executions.GetExecutionRequest() # Establish that the response is the type that we expect. assert isinstance(response, executions.Execution) - assert response.name == "name_value" - assert response.state == executions.Execution.State.ACTIVE - assert response.argument == "argument_value" - assert response.result == "result_value" - assert response.workflow_revision_id == "workflow_revision_id_value" @@ -1144,17 +1125,17 @@ async def test_get_execution_async_from_dict(): def test_get_execution_field_headers(): - client = ExecutionsClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsClient(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 = executions.GetExecutionRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_execution), "__call__") as call: call.return_value = executions.Execution() - client.get_execution(request) # Establish that the underlying gRPC stub method was called. @@ -1169,11 +1150,12 @@ def test_get_execution_field_headers(): @pytest.mark.asyncio async def test_get_execution_field_headers_async(): - client = ExecutionsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsAsyncClient(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 = executions.GetExecutionRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1181,7 +1163,6 @@ async def test_get_execution_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( executions.Execution() ) - await client.get_execution(request) # Establish that the underlying gRPC stub method was called. @@ -1195,13 +1176,12 @@ async def test_get_execution_field_headers_async(): def test_get_execution_flattened(): - client = ExecutionsClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_execution), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = executions.Execution() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.get_execution(name="name_value",) @@ -1210,12 +1190,11 @@ def test_get_execution_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_get_execution_flattened_error(): - client = ExecutionsClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1227,7 +1206,7 @@ def test_get_execution_flattened_error(): @pytest.mark.asyncio async def test_get_execution_flattened_async(): - client = ExecutionsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_execution), "__call__") as call: @@ -1245,13 +1224,12 @@ async def test_get_execution_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_execution_flattened_error_async(): - client = ExecutionsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1265,7 +1243,7 @@ def test_cancel_execution( transport: str = "grpc", request_type=executions.CancelExecutionRequest ): client = ExecutionsClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1282,27 +1260,19 @@ def test_cancel_execution( result="result_value", workflow_revision_id="workflow_revision_id_value", ) - response = client.cancel_execution(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == executions.CancelExecutionRequest() # Establish that the response is the type that we expect. - assert isinstance(response, executions.Execution) - assert response.name == "name_value" - assert response.state == executions.Execution.State.ACTIVE - assert response.argument == "argument_value" - assert response.result == "result_value" - assert response.workflow_revision_id == "workflow_revision_id_value" @@ -1314,7 +1284,7 @@ def test_cancel_execution_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 = ExecutionsClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1322,7 +1292,6 @@ def test_cancel_execution_empty_call(): client.cancel_execution() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == executions.CancelExecutionRequest() @@ -1331,7 +1300,7 @@ async def test_cancel_execution_async( transport: str = "grpc_asyncio", request_type=executions.CancelExecutionRequest ): client = ExecutionsAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1350,26 +1319,19 @@ async def test_cancel_execution_async( workflow_revision_id="workflow_revision_id_value", ) ) - response = await client.cancel_execution(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == executions.CancelExecutionRequest() # Establish that the response is the type that we expect. assert isinstance(response, executions.Execution) - assert response.name == "name_value" - assert response.state == executions.Execution.State.ACTIVE - assert response.argument == "argument_value" - assert response.result == "result_value" - assert response.workflow_revision_id == "workflow_revision_id_value" @@ -1379,17 +1341,17 @@ async def test_cancel_execution_async_from_dict(): def test_cancel_execution_field_headers(): - client = ExecutionsClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsClient(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 = executions.CancelExecutionRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_execution), "__call__") as call: call.return_value = executions.Execution() - client.cancel_execution(request) # Establish that the underlying gRPC stub method was called. @@ -1404,11 +1366,12 @@ def test_cancel_execution_field_headers(): @pytest.mark.asyncio async def test_cancel_execution_field_headers_async(): - client = ExecutionsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsAsyncClient(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 = executions.CancelExecutionRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1416,7 +1379,6 @@ async def test_cancel_execution_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( executions.Execution() ) - await client.cancel_execution(request) # Establish that the underlying gRPC stub method was called. @@ -1430,13 +1392,12 @@ async def test_cancel_execution_field_headers_async(): def test_cancel_execution_flattened(): - client = ExecutionsClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_execution), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = executions.Execution() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.cancel_execution(name="name_value",) @@ -1445,12 +1406,11 @@ def test_cancel_execution_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_cancel_execution_flattened_error(): - client = ExecutionsClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1462,7 +1422,7 @@ def test_cancel_execution_flattened_error(): @pytest.mark.asyncio async def test_cancel_execution_flattened_async(): - client = ExecutionsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_execution), "__call__") as call: @@ -1480,13 +1440,12 @@ async def test_cancel_execution_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_cancel_execution_flattened_error_async(): - client = ExecutionsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1499,16 +1458,16 @@ async def test_cancel_execution_flattened_error_async(): def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.ExecutionsGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = ExecutionsClient( - 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.ExecutionsGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = ExecutionsClient( @@ -1518,7 +1477,7 @@ def test_credentials_transport_error(): # It is an error to provide scopes and a transport instance. transport = transports.ExecutionsGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = ExecutionsClient( @@ -1529,7 +1488,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.ExecutionsGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) client = ExecutionsClient(transport=transport) assert client.transport is transport @@ -1538,13 +1497,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.ExecutionsGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel transport = transports.ExecutionsGrpcAsyncIOTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel @@ -1556,23 +1515,23 @@ def test_transport_get_channel(): ) def test_transport_adc(transport_class): # Test default credentials are used if not provided. - with mock.patch.object(auth, "default") as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport_class() adc.assert_called_once() def test_transport_grpc_default(): # A client should use the gRPC transport by default. - client = ExecutionsClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsClient(credentials=ga_credentials.AnonymousCredentials(),) assert isinstance(client.transport, transports.ExecutionsGrpcTransport,) def test_executions_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.ExecutionsTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), credentials_file="credentials.json", ) @@ -1584,7 +1543,7 @@ def test_executions_base_transport(): ) as Transport: Transport.return_value = None transport = transports.ExecutionsTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Every method on the transport should just blindly @@ -1600,15 +1559,37 @@ def test_executions_base_transport(): getattr(transport, method)(request=object()) +@requires_google_auth_gte_1_25_0 def test_executions_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.workflows.executions_v1.services.executions.transports.ExecutionsTransport._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.ExecutionsTransport( + 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_executions_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.workflows.executions_v1.services.executions.transports.ExecutionsTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ExecutionsTransport( credentials_file="credentials.json", quota_project_id="octopus", ) @@ -1621,19 +1602,33 @@ def test_executions_base_transport_with_credentials_file(): def test_executions_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.workflows.executions_v1.services.executions.transports.ExecutionsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (credentials.AnonymousCredentials(), None) + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ExecutionsTransport() adc.assert_called_once() +@requires_google_auth_gte_1_25_0 def test_executions_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) + ExecutionsClient() + 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_executions_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) ExecutionsClient() adc.assert_called_once_with( scopes=("https://www.googleapis.com/auth/cloud-platform",), @@ -1641,26 +1636,154 @@ def test_executions_auth_adc(): ) -def test_executions_transport_auth_adc(): +@pytest.mark.parametrize( + "transport_class", + [transports.ExecutionsGrpcTransport, transports.ExecutionsGrpcAsyncIOTransport,], +) +@requires_google_auth_gte_1_25_0 +def test_executions_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.ExecutionsGrpcTransport( - 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.ExecutionsGrpcTransport, transports.ExecutionsGrpcAsyncIOTransport,], +) +@requires_google_auth_lt_1_25_0 +def test_executions_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.ExecutionsGrpcTransport, grpc_helpers), + (transports.ExecutionsGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_gte_1_26_0 +def test_executions_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( + "workflowexecutions.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="workflowexecutions.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.ExecutionsGrpcTransport, grpc_helpers), + (transports.ExecutionsGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_executions_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( + "workflowexecutions.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.ExecutionsGrpcTransport, grpc_helpers), + (transports.ExecutionsGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_executions_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( + "workflowexecutions.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", [transports.ExecutionsGrpcTransport, transports.ExecutionsGrpcAsyncIOTransport], ) def test_executions_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: @@ -1699,7 +1822,7 @@ def test_executions_grpc_transport_client_cert_source_for_mtls(transport_class): def test_executions_host_no_port(): client = ExecutionsClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="workflowexecutions.googleapis.com" ), @@ -1709,7 +1832,7 @@ def test_executions_host_no_port(): def test_executions_host_with_port(): client = ExecutionsClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="workflowexecutions.googleapis.com:8000" ), @@ -1760,9 +1883,9 @@ def test_executions_transport_channel_mtls_with_client_cert_source(transport_cla 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", @@ -1838,7 +1961,6 @@ def test_execution_path(): location = "clam" workflow = "whelk" execution = "octopus" - expected = "projects/{project}/locations/{location}/workflows/{workflow}/executions/{execution}".format( project=project, location=location, workflow=workflow, execution=execution, ) @@ -1864,7 +1986,6 @@ def test_workflow_path(): project = "winkle" location = "nautilus" workflow = "scallop" - expected = "projects/{project}/locations/{location}/workflows/{workflow}".format( project=project, location=location, workflow=workflow, ) @@ -1887,7 +2008,6 @@ def test_parse_workflow_path(): def test_common_billing_account_path(): billing_account = "whelk" - expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -1908,7 +2028,6 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "oyster" - expected = "folders/{folder}".format(folder=folder,) actual = ExecutionsClient.common_folder_path(folder) assert expected == actual @@ -1927,7 +2046,6 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "cuttlefish" - expected = "organizations/{organization}".format(organization=organization,) actual = ExecutionsClient.common_organization_path(organization) assert expected == actual @@ -1946,7 +2064,6 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "winkle" - expected = "projects/{project}".format(project=project,) actual = ExecutionsClient.common_project_path(project) assert expected == actual @@ -1966,7 +2083,6 @@ def test_parse_common_project_path(): def test_common_location_path(): project = "scallop" location = "abalone" - expected = "projects/{project}/locations/{location}".format( project=project, location=location, ) @@ -1993,7 +2109,7 @@ def test_client_withDEFAULT_CLIENT_INFO(): transports.ExecutionsTransport, "_prep_wrapped_messages" ) as prep: client = ExecutionsClient( - credentials=credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -2002,6 +2118,6 @@ def test_client_withDEFAULT_CLIENT_INFO(): ) as prep: transport_class = ExecutionsClient.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) diff --git a/tests/unit/gapic/executions_v1beta/__init__.py b/tests/unit/gapic/executions_v1beta/__init__.py index 42ffdf2..4de6597 100644 --- a/tests/unit/gapic/executions_v1beta/__init__.py +++ b/tests/unit/gapic/executions_v1beta/__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/executions_v1beta/test_executions.py b/tests/unit/gapic/executions_v1beta/test_executions.py index 1c8642a..345cb2a 100644 --- a/tests/unit/gapic/executions_v1beta/test_executions.py +++ b/tests/unit/gapic/executions_v1beta/test_executions.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,13 +23,13 @@ import pytest from proto.marshal.rules.dates import DurationRule, TimestampRule -from google import auth + from google.api_core import client_options -from google.api_core import exceptions +from google.api_core import exceptions as core_exceptions from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async -from google.auth import credentials +from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.workflows.executions_v1beta.services.executions import ( ExecutionsAsyncClient, @@ -40,9 +39,39 @@ ) from google.cloud.workflows.executions_v1beta.services.executions import pagers from google.cloud.workflows.executions_v1beta.services.executions import transports +from google.cloud.workflows.executions_v1beta.services.executions.transports.base import ( + _API_CORE_VERSION, +) +from google.cloud.workflows.executions_v1beta.services.executions.transports.base import ( + _GOOGLE_AUTH_VERSION, +) from google.cloud.workflows.executions_v1beta.types import executions from google.oauth2 import service_account -from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +import google.auth + + +# TODO(busunkim): Once google-api-core >= 1.26.0 is required: +# - Delete all the api-core and auth "less than" test cases +# - Delete these pytest markers (Make the "greater than or equal to" tests the default). +requires_google_auth_lt_1_25_0 = pytest.mark.skipif( + packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), + reason="This test requires google-auth < 1.25.0", +) +requires_google_auth_gte_1_25_0 = pytest.mark.skipif( + packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), + reason="This test requires google-auth >= 1.25.0", +) + +requires_api_core_lt_1_26_0 = pytest.mark.skipif( + packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), + reason="This test requires google-api-core < 1.26.0", +) + +requires_api_core_gte_1_26_0 = pytest.mark.skipif( + packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), + reason="This test requires google-api-core >= 1.26.0", +) def client_cert_source_callback(): @@ -88,7 +117,7 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize("client_class", [ExecutionsClient, ExecutionsAsyncClient,]) def test_executions_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: @@ -103,7 +132,7 @@ def test_executions_client_from_service_account_info(client_class): @pytest.mark.parametrize("client_class", [ExecutionsClient, ExecutionsAsyncClient,]) def test_executions_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: @@ -154,7 +183,7 @@ def test_executions_client_client_options( ): # Check that if channel is provided we won't create a new one. with mock.patch.object(ExecutionsClient, "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() @@ -438,7 +467,7 @@ def test_list_executions( transport: str = "grpc", request_type=executions.ListExecutionsRequest ): client = ExecutionsClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -451,19 +480,15 @@ def test_list_executions( call.return_value = executions.ListExecutionsResponse( next_page_token="next_page_token_value", ) - response = client.list_executions(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == executions.ListExecutionsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListExecutionsPager) - assert response.next_page_token == "next_page_token_value" @@ -475,7 +500,7 @@ def test_list_executions_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 = ExecutionsClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -483,7 +508,6 @@ def test_list_executions_empty_call(): client.list_executions() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == executions.ListExecutionsRequest() @@ -492,7 +516,7 @@ async def test_list_executions_async( transport: str = "grpc_asyncio", request_type=executions.ListExecutionsRequest ): client = ExecutionsAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -505,18 +529,15 @@ async def test_list_executions_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( executions.ListExecutionsResponse(next_page_token="next_page_token_value",) ) - response = await client.list_executions(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == executions.ListExecutionsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListExecutionsAsyncPager) - assert response.next_page_token == "next_page_token_value" @@ -526,17 +547,17 @@ async def test_list_executions_async_from_dict(): def test_list_executions_field_headers(): - client = ExecutionsClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsClient(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 = executions.ListExecutionsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_executions), "__call__") as call: call.return_value = executions.ListExecutionsResponse() - client.list_executions(request) # Establish that the underlying gRPC stub method was called. @@ -551,11 +572,12 @@ def test_list_executions_field_headers(): @pytest.mark.asyncio async def test_list_executions_field_headers_async(): - client = ExecutionsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsAsyncClient(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 = executions.ListExecutionsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -563,7 +585,6 @@ async def test_list_executions_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( executions.ListExecutionsResponse() ) - await client.list_executions(request) # Establish that the underlying gRPC stub method was called. @@ -577,13 +598,12 @@ async def test_list_executions_field_headers_async(): def test_list_executions_flattened(): - client = ExecutionsClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_executions), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = executions.ListExecutionsResponse() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.list_executions(parent="parent_value",) @@ -592,12 +612,11 @@ def test_list_executions_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" def test_list_executions_flattened_error(): - client = ExecutionsClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -609,7 +628,7 @@ def test_list_executions_flattened_error(): @pytest.mark.asyncio async def test_list_executions_flattened_async(): - client = ExecutionsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_executions), "__call__") as call: @@ -627,13 +646,12 @@ async def test_list_executions_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" @pytest.mark.asyncio async def test_list_executions_flattened_error_async(): - client = ExecutionsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -644,7 +662,7 @@ async def test_list_executions_flattened_error_async(): def test_list_executions_pager(): - client = ExecutionsClient(credentials=credentials.AnonymousCredentials,) + client = ExecutionsClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_executions), "__call__") as call: @@ -682,7 +700,7 @@ def test_list_executions_pager(): def test_list_executions_pages(): - client = ExecutionsClient(credentials=credentials.AnonymousCredentials,) + client = ExecutionsClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_executions), "__call__") as call: @@ -712,7 +730,7 @@ def test_list_executions_pages(): @pytest.mark.asyncio async def test_list_executions_async_pager(): - client = ExecutionsAsyncClient(credentials=credentials.AnonymousCredentials,) + client = ExecutionsAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -749,7 +767,7 @@ async def test_list_executions_async_pager(): @pytest.mark.asyncio async def test_list_executions_async_pages(): - client = ExecutionsAsyncClient(credentials=credentials.AnonymousCredentials,) + client = ExecutionsAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -785,7 +803,7 @@ def test_create_execution( transport: str = "grpc", request_type=executions.CreateExecutionRequest ): client = ExecutionsClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -802,27 +820,19 @@ def test_create_execution( result="result_value", workflow_revision_id="workflow_revision_id_value", ) - response = client.create_execution(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == executions.CreateExecutionRequest() # Establish that the response is the type that we expect. - assert isinstance(response, executions.Execution) - assert response.name == "name_value" - assert response.state == executions.Execution.State.ACTIVE - assert response.argument == "argument_value" - assert response.result == "result_value" - assert response.workflow_revision_id == "workflow_revision_id_value" @@ -834,7 +844,7 @@ def test_create_execution_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 = ExecutionsClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -842,7 +852,6 @@ def test_create_execution_empty_call(): client.create_execution() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == executions.CreateExecutionRequest() @@ -851,7 +860,7 @@ async def test_create_execution_async( transport: str = "grpc_asyncio", request_type=executions.CreateExecutionRequest ): client = ExecutionsAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -870,26 +879,19 @@ async def test_create_execution_async( workflow_revision_id="workflow_revision_id_value", ) ) - response = await client.create_execution(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == executions.CreateExecutionRequest() # Establish that the response is the type that we expect. assert isinstance(response, executions.Execution) - assert response.name == "name_value" - assert response.state == executions.Execution.State.ACTIVE - assert response.argument == "argument_value" - assert response.result == "result_value" - assert response.workflow_revision_id == "workflow_revision_id_value" @@ -899,17 +901,17 @@ async def test_create_execution_async_from_dict(): def test_create_execution_field_headers(): - client = ExecutionsClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsClient(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 = executions.CreateExecutionRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_execution), "__call__") as call: call.return_value = executions.Execution() - client.create_execution(request) # Establish that the underlying gRPC stub method was called. @@ -924,11 +926,12 @@ def test_create_execution_field_headers(): @pytest.mark.asyncio async def test_create_execution_field_headers_async(): - client = ExecutionsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsAsyncClient(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 = executions.CreateExecutionRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -936,7 +939,6 @@ async def test_create_execution_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( executions.Execution() ) - await client.create_execution(request) # Establish that the underlying gRPC stub method was called. @@ -950,13 +952,12 @@ async def test_create_execution_field_headers_async(): def test_create_execution_flattened(): - client = ExecutionsClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_execution), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = executions.Execution() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.create_execution( @@ -967,14 +968,12 @@ def test_create_execution_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].execution == executions.Execution(name="name_value") def test_create_execution_flattened_error(): - client = ExecutionsClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -988,7 +987,7 @@ def test_create_execution_flattened_error(): @pytest.mark.asyncio async def test_create_execution_flattened_async(): - client = ExecutionsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_execution), "__call__") as call: @@ -1008,15 +1007,13 @@ async def test_create_execution_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].execution == executions.Execution(name="name_value") @pytest.mark.asyncio async def test_create_execution_flattened_error_async(): - client = ExecutionsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1032,7 +1029,7 @@ def test_get_execution( transport: str = "grpc", request_type=executions.GetExecutionRequest ): client = ExecutionsClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1049,27 +1046,19 @@ def test_get_execution( result="result_value", workflow_revision_id="workflow_revision_id_value", ) - response = client.get_execution(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == executions.GetExecutionRequest() # Establish that the response is the type that we expect. - assert isinstance(response, executions.Execution) - assert response.name == "name_value" - assert response.state == executions.Execution.State.ACTIVE - assert response.argument == "argument_value" - assert response.result == "result_value" - assert response.workflow_revision_id == "workflow_revision_id_value" @@ -1081,7 +1070,7 @@ def test_get_execution_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 = ExecutionsClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1089,7 +1078,6 @@ def test_get_execution_empty_call(): client.get_execution() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == executions.GetExecutionRequest() @@ -1098,7 +1086,7 @@ async def test_get_execution_async( transport: str = "grpc_asyncio", request_type=executions.GetExecutionRequest ): client = ExecutionsAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1117,26 +1105,19 @@ async def test_get_execution_async( workflow_revision_id="workflow_revision_id_value", ) ) - response = await client.get_execution(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == executions.GetExecutionRequest() # Establish that the response is the type that we expect. assert isinstance(response, executions.Execution) - assert response.name == "name_value" - assert response.state == executions.Execution.State.ACTIVE - assert response.argument == "argument_value" - assert response.result == "result_value" - assert response.workflow_revision_id == "workflow_revision_id_value" @@ -1146,17 +1127,17 @@ async def test_get_execution_async_from_dict(): def test_get_execution_field_headers(): - client = ExecutionsClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsClient(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 = executions.GetExecutionRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_execution), "__call__") as call: call.return_value = executions.Execution() - client.get_execution(request) # Establish that the underlying gRPC stub method was called. @@ -1171,11 +1152,12 @@ def test_get_execution_field_headers(): @pytest.mark.asyncio async def test_get_execution_field_headers_async(): - client = ExecutionsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsAsyncClient(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 = executions.GetExecutionRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1183,7 +1165,6 @@ async def test_get_execution_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( executions.Execution() ) - await client.get_execution(request) # Establish that the underlying gRPC stub method was called. @@ -1197,13 +1178,12 @@ async def test_get_execution_field_headers_async(): def test_get_execution_flattened(): - client = ExecutionsClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_execution), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = executions.Execution() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.get_execution(name="name_value",) @@ -1212,12 +1192,11 @@ def test_get_execution_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_get_execution_flattened_error(): - client = ExecutionsClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1229,7 +1208,7 @@ def test_get_execution_flattened_error(): @pytest.mark.asyncio async def test_get_execution_flattened_async(): - client = ExecutionsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_execution), "__call__") as call: @@ -1247,13 +1226,12 @@ async def test_get_execution_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_execution_flattened_error_async(): - client = ExecutionsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1267,7 +1245,7 @@ def test_cancel_execution( transport: str = "grpc", request_type=executions.CancelExecutionRequest ): client = ExecutionsClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1284,27 +1262,19 @@ def test_cancel_execution( result="result_value", workflow_revision_id="workflow_revision_id_value", ) - response = client.cancel_execution(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == executions.CancelExecutionRequest() # Establish that the response is the type that we expect. - assert isinstance(response, executions.Execution) - assert response.name == "name_value" - assert response.state == executions.Execution.State.ACTIVE - assert response.argument == "argument_value" - assert response.result == "result_value" - assert response.workflow_revision_id == "workflow_revision_id_value" @@ -1316,7 +1286,7 @@ def test_cancel_execution_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 = ExecutionsClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1324,7 +1294,6 @@ def test_cancel_execution_empty_call(): client.cancel_execution() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == executions.CancelExecutionRequest() @@ -1333,7 +1302,7 @@ async def test_cancel_execution_async( transport: str = "grpc_asyncio", request_type=executions.CancelExecutionRequest ): client = ExecutionsAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1352,26 +1321,19 @@ async def test_cancel_execution_async( workflow_revision_id="workflow_revision_id_value", ) ) - response = await client.cancel_execution(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == executions.CancelExecutionRequest() # Establish that the response is the type that we expect. assert isinstance(response, executions.Execution) - assert response.name == "name_value" - assert response.state == executions.Execution.State.ACTIVE - assert response.argument == "argument_value" - assert response.result == "result_value" - assert response.workflow_revision_id == "workflow_revision_id_value" @@ -1381,17 +1343,17 @@ async def test_cancel_execution_async_from_dict(): def test_cancel_execution_field_headers(): - client = ExecutionsClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsClient(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 = executions.CancelExecutionRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_execution), "__call__") as call: call.return_value = executions.Execution() - client.cancel_execution(request) # Establish that the underlying gRPC stub method was called. @@ -1406,11 +1368,12 @@ def test_cancel_execution_field_headers(): @pytest.mark.asyncio async def test_cancel_execution_field_headers_async(): - client = ExecutionsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsAsyncClient(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 = executions.CancelExecutionRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1418,7 +1381,6 @@ async def test_cancel_execution_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( executions.Execution() ) - await client.cancel_execution(request) # Establish that the underlying gRPC stub method was called. @@ -1432,13 +1394,12 @@ async def test_cancel_execution_field_headers_async(): def test_cancel_execution_flattened(): - client = ExecutionsClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_execution), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = executions.Execution() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.cancel_execution(name="name_value",) @@ -1447,12 +1408,11 @@ def test_cancel_execution_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_cancel_execution_flattened_error(): - client = ExecutionsClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1464,7 +1424,7 @@ def test_cancel_execution_flattened_error(): @pytest.mark.asyncio async def test_cancel_execution_flattened_async(): - client = ExecutionsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_execution), "__call__") as call: @@ -1482,13 +1442,12 @@ async def test_cancel_execution_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_cancel_execution_flattened_error_async(): - client = ExecutionsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1501,16 +1460,16 @@ async def test_cancel_execution_flattened_error_async(): def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.ExecutionsGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = ExecutionsClient( - 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.ExecutionsGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = ExecutionsClient( @@ -1520,7 +1479,7 @@ def test_credentials_transport_error(): # It is an error to provide scopes and a transport instance. transport = transports.ExecutionsGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = ExecutionsClient( @@ -1531,7 +1490,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.ExecutionsGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) client = ExecutionsClient(transport=transport) assert client.transport is transport @@ -1540,13 +1499,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.ExecutionsGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel transport = transports.ExecutionsGrpcAsyncIOTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel @@ -1558,23 +1517,23 @@ def test_transport_get_channel(): ) def test_transport_adc(transport_class): # Test default credentials are used if not provided. - with mock.patch.object(auth, "default") as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport_class() adc.assert_called_once() def test_transport_grpc_default(): # A client should use the gRPC transport by default. - client = ExecutionsClient(credentials=credentials.AnonymousCredentials(),) + client = ExecutionsClient(credentials=ga_credentials.AnonymousCredentials(),) assert isinstance(client.transport, transports.ExecutionsGrpcTransport,) def test_executions_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.ExecutionsTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), credentials_file="credentials.json", ) @@ -1586,7 +1545,7 @@ def test_executions_base_transport(): ) as Transport: Transport.return_value = None transport = transports.ExecutionsTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Every method on the transport should just blindly @@ -1602,15 +1561,37 @@ def test_executions_base_transport(): getattr(transport, method)(request=object()) +@requires_google_auth_gte_1_25_0 def test_executions_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.workflows.executions_v1beta.services.executions.transports.ExecutionsTransport._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.ExecutionsTransport( + 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_executions_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.workflows.executions_v1beta.services.executions.transports.ExecutionsTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ExecutionsTransport( credentials_file="credentials.json", quota_project_id="octopus", ) @@ -1623,19 +1604,33 @@ def test_executions_base_transport_with_credentials_file(): def test_executions_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.workflows.executions_v1beta.services.executions.transports.ExecutionsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (credentials.AnonymousCredentials(), None) + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ExecutionsTransport() adc.assert_called_once() +@requires_google_auth_gte_1_25_0 def test_executions_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) + ExecutionsClient() + 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_executions_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) ExecutionsClient() adc.assert_called_once_with( scopes=("https://www.googleapis.com/auth/cloud-platform",), @@ -1643,26 +1638,154 @@ def test_executions_auth_adc(): ) -def test_executions_transport_auth_adc(): +@pytest.mark.parametrize( + "transport_class", + [transports.ExecutionsGrpcTransport, transports.ExecutionsGrpcAsyncIOTransport,], +) +@requires_google_auth_gte_1_25_0 +def test_executions_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.ExecutionsGrpcTransport( - 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.ExecutionsGrpcTransport, transports.ExecutionsGrpcAsyncIOTransport,], +) +@requires_google_auth_lt_1_25_0 +def test_executions_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.ExecutionsGrpcTransport, grpc_helpers), + (transports.ExecutionsGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_gte_1_26_0 +def test_executions_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( + "workflowexecutions.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="workflowexecutions.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.ExecutionsGrpcTransport, grpc_helpers), + (transports.ExecutionsGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_executions_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( + "workflowexecutions.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.ExecutionsGrpcTransport, grpc_helpers), + (transports.ExecutionsGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_executions_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( + "workflowexecutions.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", [transports.ExecutionsGrpcTransport, transports.ExecutionsGrpcAsyncIOTransport], ) def test_executions_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: @@ -1701,7 +1824,7 @@ def test_executions_grpc_transport_client_cert_source_for_mtls(transport_class): def test_executions_host_no_port(): client = ExecutionsClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="workflowexecutions.googleapis.com" ), @@ -1711,7 +1834,7 @@ def test_executions_host_no_port(): def test_executions_host_with_port(): client = ExecutionsClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="workflowexecutions.googleapis.com:8000" ), @@ -1762,9 +1885,9 @@ def test_executions_transport_channel_mtls_with_client_cert_source(transport_cla 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", @@ -1840,7 +1963,6 @@ def test_execution_path(): location = "clam" workflow = "whelk" execution = "octopus" - expected = "projects/{project}/locations/{location}/workflows/{workflow}/executions/{execution}".format( project=project, location=location, workflow=workflow, execution=execution, ) @@ -1866,7 +1988,6 @@ def test_workflow_path(): project = "winkle" location = "nautilus" workflow = "scallop" - expected = "projects/{project}/locations/{location}/workflows/{workflow}".format( project=project, location=location, workflow=workflow, ) @@ -1889,7 +2010,6 @@ def test_parse_workflow_path(): def test_common_billing_account_path(): billing_account = "whelk" - expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -1910,7 +2030,6 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "oyster" - expected = "folders/{folder}".format(folder=folder,) actual = ExecutionsClient.common_folder_path(folder) assert expected == actual @@ -1929,7 +2048,6 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "cuttlefish" - expected = "organizations/{organization}".format(organization=organization,) actual = ExecutionsClient.common_organization_path(organization) assert expected == actual @@ -1948,7 +2066,6 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "winkle" - expected = "projects/{project}".format(project=project,) actual = ExecutionsClient.common_project_path(project) assert expected == actual @@ -1968,7 +2085,6 @@ def test_parse_common_project_path(): def test_common_location_path(): project = "scallop" location = "abalone" - expected = "projects/{project}/locations/{location}".format( project=project, location=location, ) @@ -1995,7 +2111,7 @@ def test_client_withDEFAULT_CLIENT_INFO(): transports.ExecutionsTransport, "_prep_wrapped_messages" ) as prep: client = ExecutionsClient( - credentials=credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -2004,6 +2120,6 @@ def test_client_withDEFAULT_CLIENT_INFO(): ) as prep: transport_class = ExecutionsClient.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) diff --git a/tests/unit/gapic/workflows_v1/__init__.py b/tests/unit/gapic/workflows_v1/__init__.py index 42ffdf2..4de6597 100644 --- a/tests/unit/gapic/workflows_v1/__init__.py +++ b/tests/unit/gapic/workflows_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/workflows_v1/test_workflows.py b/tests/unit/gapic/workflows_v1/test_workflows.py index 671b713..81940d5 100644 --- a/tests/unit/gapic/workflows_v1/test_workflows.py +++ b/tests/unit/gapic/workflows_v1/test_workflows.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,26 +23,56 @@ 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.workflows_v1.services.workflows import WorkflowsAsyncClient from google.cloud.workflows_v1.services.workflows import WorkflowsClient from google.cloud.workflows_v1.services.workflows import pagers from google.cloud.workflows_v1.services.workflows import transports +from google.cloud.workflows_v1.services.workflows.transports.base import ( + _API_CORE_VERSION, +) +from google.cloud.workflows_v1.services.workflows.transports.base import ( + _GOOGLE_AUTH_VERSION, +) from google.cloud.workflows_v1.types import workflows from google.longrunning import operations_pb2 from google.oauth2 import service_account -from google.protobuf import field_mask_pb2 as field_mask # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +import google.auth + + +# TODO(busunkim): Once google-api-core >= 1.26.0 is required: +# - Delete all the api-core and auth "less than" test cases +# - Delete these pytest markers (Make the "greater than or equal to" tests the default). +requires_google_auth_lt_1_25_0 = pytest.mark.skipif( + packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), + reason="This test requires google-auth < 1.25.0", +) +requires_google_auth_gte_1_25_0 = pytest.mark.skipif( + packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), + reason="This test requires google-auth >= 1.25.0", +) + +requires_api_core_lt_1_26_0 = pytest.mark.skipif( + packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), + reason="This test requires google-api-core < 1.26.0", +) + +requires_api_core_gte_1_26_0 = pytest.mark.skipif( + packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), + reason="This test requires google-api-core >= 1.26.0", +) def client_cert_source_callback(): @@ -87,7 +116,7 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize("client_class", [WorkflowsClient, WorkflowsAsyncClient,]) def test_workflows_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: @@ -102,7 +131,7 @@ def test_workflows_client_from_service_account_info(client_class): @pytest.mark.parametrize("client_class", [WorkflowsClient, WorkflowsAsyncClient,]) def test_workflows_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: @@ -151,7 +180,7 @@ def test_workflows_client_get_transport_class(): def test_workflows_client_client_options(client_class, transport_class, transport_name): # Check that if channel is provided we won't create a new one. with mock.patch.object(WorkflowsClient, "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() @@ -435,7 +464,7 @@ def test_list_workflows( transport: str = "grpc", request_type=workflows.ListWorkflowsRequest ): client = WorkflowsClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -448,21 +477,16 @@ def test_list_workflows( call.return_value = workflows.ListWorkflowsResponse( next_page_token="next_page_token_value", unreachable=["unreachable_value"], ) - response = client.list_workflows(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == workflows.ListWorkflowsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListWorkflowsPager) - assert response.next_page_token == "next_page_token_value" - assert response.unreachable == ["unreachable_value"] @@ -474,7 +498,7 @@ def test_list_workflows_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 = WorkflowsClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -482,7 +506,6 @@ def test_list_workflows_empty_call(): client.list_workflows() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == workflows.ListWorkflowsRequest() @@ -491,7 +514,7 @@ async def test_list_workflows_async( transport: str = "grpc_asyncio", request_type=workflows.ListWorkflowsRequest ): client = WorkflowsAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -507,20 +530,16 @@ async def test_list_workflows_async( unreachable=["unreachable_value"], ) ) - response = await client.list_workflows(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == workflows.ListWorkflowsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListWorkflowsAsyncPager) - assert response.next_page_token == "next_page_token_value" - assert response.unreachable == ["unreachable_value"] @@ -530,17 +549,17 @@ async def test_list_workflows_async_from_dict(): def test_list_workflows_field_headers(): - client = WorkflowsClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsClient(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 = workflows.ListWorkflowsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_workflows), "__call__") as call: call.return_value = workflows.ListWorkflowsResponse() - client.list_workflows(request) # Establish that the underlying gRPC stub method was called. @@ -555,11 +574,12 @@ def test_list_workflows_field_headers(): @pytest.mark.asyncio async def test_list_workflows_field_headers_async(): - client = WorkflowsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsAsyncClient(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 = workflows.ListWorkflowsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -567,7 +587,6 @@ async def test_list_workflows_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( workflows.ListWorkflowsResponse() ) - await client.list_workflows(request) # Establish that the underlying gRPC stub method was called. @@ -581,13 +600,12 @@ async def test_list_workflows_field_headers_async(): def test_list_workflows_flattened(): - client = WorkflowsClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_workflows), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = workflows.ListWorkflowsResponse() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.list_workflows(parent="parent_value",) @@ -596,12 +614,11 @@ def test_list_workflows_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" def test_list_workflows_flattened_error(): - client = WorkflowsClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -613,7 +630,7 @@ def test_list_workflows_flattened_error(): @pytest.mark.asyncio async def test_list_workflows_flattened_async(): - client = WorkflowsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_workflows), "__call__") as call: @@ -631,13 +648,12 @@ async def test_list_workflows_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" @pytest.mark.asyncio async def test_list_workflows_flattened_error_async(): - client = WorkflowsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -648,7 +664,7 @@ async def test_list_workflows_flattened_error_async(): def test_list_workflows_pager(): - client = WorkflowsClient(credentials=credentials.AnonymousCredentials,) + client = WorkflowsClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_workflows), "__call__") as call: @@ -686,7 +702,7 @@ def test_list_workflows_pager(): def test_list_workflows_pages(): - client = WorkflowsClient(credentials=credentials.AnonymousCredentials,) + client = WorkflowsClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_workflows), "__call__") as call: @@ -716,7 +732,7 @@ def test_list_workflows_pages(): @pytest.mark.asyncio async def test_list_workflows_async_pager(): - client = WorkflowsAsyncClient(credentials=credentials.AnonymousCredentials,) + client = WorkflowsAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -753,7 +769,7 @@ async def test_list_workflows_async_pager(): @pytest.mark.asyncio async def test_list_workflows_async_pages(): - client = WorkflowsAsyncClient(credentials=credentials.AnonymousCredentials,) + client = WorkflowsAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -789,7 +805,7 @@ def test_get_workflow( transport: str = "grpc", request_type=workflows.GetWorkflowRequest ): client = WorkflowsClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -807,27 +823,19 @@ def test_get_workflow( service_account="service_account_value", source_contents="source_contents_value", ) - response = client.get_workflow(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == workflows.GetWorkflowRequest() # Establish that the response is the type that we expect. - assert isinstance(response, workflows.Workflow) - assert response.name == "name_value" - assert response.description == "description_value" - assert response.state == workflows.Workflow.State.ACTIVE - assert response.revision_id == "revision_id_value" - assert response.service_account == "service_account_value" @@ -839,7 +847,7 @@ def test_get_workflow_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 = WorkflowsClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -847,7 +855,6 @@ def test_get_workflow_empty_call(): client.get_workflow() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == workflows.GetWorkflowRequest() @@ -856,7 +863,7 @@ async def test_get_workflow_async( transport: str = "grpc_asyncio", request_type=workflows.GetWorkflowRequest ): client = WorkflowsAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -875,26 +882,19 @@ async def test_get_workflow_async( service_account="service_account_value", ) ) - response = await client.get_workflow(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == workflows.GetWorkflowRequest() # Establish that the response is the type that we expect. assert isinstance(response, workflows.Workflow) - assert response.name == "name_value" - assert response.description == "description_value" - assert response.state == workflows.Workflow.State.ACTIVE - assert response.revision_id == "revision_id_value" - assert response.service_account == "service_account_value" @@ -904,17 +904,17 @@ async def test_get_workflow_async_from_dict(): def test_get_workflow_field_headers(): - client = WorkflowsClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsClient(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 = workflows.GetWorkflowRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_workflow), "__call__") as call: call.return_value = workflows.Workflow() - client.get_workflow(request) # Establish that the underlying gRPC stub method was called. @@ -929,17 +929,17 @@ def test_get_workflow_field_headers(): @pytest.mark.asyncio async def test_get_workflow_field_headers_async(): - client = WorkflowsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsAsyncClient(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 = workflows.GetWorkflowRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_workflow), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(workflows.Workflow()) - await client.get_workflow(request) # Establish that the underlying gRPC stub method was called. @@ -953,13 +953,12 @@ async def test_get_workflow_field_headers_async(): def test_get_workflow_flattened(): - client = WorkflowsClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_workflow), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = workflows.Workflow() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.get_workflow(name="name_value",) @@ -968,12 +967,11 @@ def test_get_workflow_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_get_workflow_flattened_error(): - client = WorkflowsClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -985,7 +983,7 @@ def test_get_workflow_flattened_error(): @pytest.mark.asyncio async def test_get_workflow_flattened_async(): - client = WorkflowsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_workflow), "__call__") as call: @@ -1001,13 +999,12 @@ async def test_get_workflow_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_workflow_flattened_error_async(): - client = WorkflowsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1021,7 +1018,7 @@ def test_create_workflow( transport: str = "grpc", request_type=workflows.CreateWorkflowRequest ): client = WorkflowsClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1032,13 +1029,11 @@ def test_create_workflow( with mock.patch.object(type(client.transport.create_workflow), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.create_workflow(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == workflows.CreateWorkflowRequest() # Establish that the response is the type that we expect. @@ -1053,7 +1048,7 @@ def test_create_workflow_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 = WorkflowsClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1061,7 +1056,6 @@ def test_create_workflow_empty_call(): client.create_workflow() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == workflows.CreateWorkflowRequest() @@ -1070,7 +1064,7 @@ async def test_create_workflow_async( transport: str = "grpc_asyncio", request_type=workflows.CreateWorkflowRequest ): client = WorkflowsAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1083,13 +1077,11 @@ async def test_create_workflow_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.create_workflow(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == workflows.CreateWorkflowRequest() # Establish that the response is the type that we expect. @@ -1102,17 +1094,17 @@ async def test_create_workflow_async_from_dict(): def test_create_workflow_field_headers(): - client = WorkflowsClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsClient(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 = workflows.CreateWorkflowRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_workflow), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.create_workflow(request) # Establish that the underlying gRPC stub method was called. @@ -1127,11 +1119,12 @@ def test_create_workflow_field_headers(): @pytest.mark.asyncio async def test_create_workflow_field_headers_async(): - client = WorkflowsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsAsyncClient(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 = workflows.CreateWorkflowRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1139,7 +1132,6 @@ async def test_create_workflow_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.create_workflow(request) # Establish that the underlying gRPC stub method was called. @@ -1153,13 +1145,12 @@ async def test_create_workflow_field_headers_async(): def test_create_workflow_flattened(): - client = WorkflowsClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_workflow), "__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_workflow( @@ -1172,16 +1163,13 @@ def test_create_workflow_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].workflow == workflows.Workflow(name="name_value") - assert args[0].workflow_id == "workflow_id_value" def test_create_workflow_flattened_error(): - client = WorkflowsClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1196,7 +1184,7 @@ def test_create_workflow_flattened_error(): @pytest.mark.asyncio async def test_create_workflow_flattened_async(): - client = WorkflowsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_workflow), "__call__") as call: @@ -1218,17 +1206,14 @@ async def test_create_workflow_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].workflow == workflows.Workflow(name="name_value") - assert args[0].workflow_id == "workflow_id_value" @pytest.mark.asyncio async def test_create_workflow_flattened_error_async(): - client = WorkflowsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1245,7 +1230,7 @@ def test_delete_workflow( transport: str = "grpc", request_type=workflows.DeleteWorkflowRequest ): client = WorkflowsClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1256,13 +1241,11 @@ def test_delete_workflow( with mock.patch.object(type(client.transport.delete_workflow), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.delete_workflow(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == workflows.DeleteWorkflowRequest() # Establish that the response is the type that we expect. @@ -1277,7 +1260,7 @@ def test_delete_workflow_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 = WorkflowsClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1285,7 +1268,6 @@ def test_delete_workflow_empty_call(): client.delete_workflow() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == workflows.DeleteWorkflowRequest() @@ -1294,7 +1276,7 @@ async def test_delete_workflow_async( transport: str = "grpc_asyncio", request_type=workflows.DeleteWorkflowRequest ): client = WorkflowsAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1307,13 +1289,11 @@ async def test_delete_workflow_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.delete_workflow(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == workflows.DeleteWorkflowRequest() # Establish that the response is the type that we expect. @@ -1326,17 +1306,17 @@ async def test_delete_workflow_async_from_dict(): def test_delete_workflow_field_headers(): - client = WorkflowsClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsClient(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 = workflows.DeleteWorkflowRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_workflow), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.delete_workflow(request) # Establish that the underlying gRPC stub method was called. @@ -1351,11 +1331,12 @@ def test_delete_workflow_field_headers(): @pytest.mark.asyncio async def test_delete_workflow_field_headers_async(): - client = WorkflowsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsAsyncClient(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 = workflows.DeleteWorkflowRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1363,7 +1344,6 @@ async def test_delete_workflow_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.delete_workflow(request) # Establish that the underlying gRPC stub method was called. @@ -1377,13 +1357,12 @@ async def test_delete_workflow_field_headers_async(): def test_delete_workflow_flattened(): - client = WorkflowsClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_workflow), "__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_workflow(name="name_value",) @@ -1392,12 +1371,11 @@ def test_delete_workflow_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_delete_workflow_flattened_error(): - client = WorkflowsClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1409,7 +1387,7 @@ def test_delete_workflow_flattened_error(): @pytest.mark.asyncio async def test_delete_workflow_flattened_async(): - client = WorkflowsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_workflow), "__call__") as call: @@ -1427,13 +1405,12 @@ async def test_delete_workflow_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_workflow_flattened_error_async(): - client = WorkflowsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1447,7 +1424,7 @@ def test_update_workflow( transport: str = "grpc", request_type=workflows.UpdateWorkflowRequest ): client = WorkflowsClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1458,13 +1435,11 @@ def test_update_workflow( with mock.patch.object(type(client.transport.update_workflow), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.update_workflow(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == workflows.UpdateWorkflowRequest() # Establish that the response is the type that we expect. @@ -1479,7 +1454,7 @@ def test_update_workflow_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 = WorkflowsClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1487,7 +1462,6 @@ def test_update_workflow_empty_call(): client.update_workflow() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == workflows.UpdateWorkflowRequest() @@ -1496,7 +1470,7 @@ async def test_update_workflow_async( transport: str = "grpc_asyncio", request_type=workflows.UpdateWorkflowRequest ): client = WorkflowsAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1509,13 +1483,11 @@ async def test_update_workflow_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.update_workflow(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == workflows.UpdateWorkflowRequest() # Establish that the response is the type that we expect. @@ -1528,17 +1500,17 @@ async def test_update_workflow_async_from_dict(): def test_update_workflow_field_headers(): - client = WorkflowsClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsClient(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 = workflows.UpdateWorkflowRequest() + request.workflow.name = "workflow.name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_workflow), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.update_workflow(request) # Establish that the underlying gRPC stub method was called. @@ -1555,11 +1527,12 @@ def test_update_workflow_field_headers(): @pytest.mark.asyncio async def test_update_workflow_field_headers_async(): - client = WorkflowsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsAsyncClient(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 = workflows.UpdateWorkflowRequest() + request.workflow.name = "workflow.name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1567,7 +1540,6 @@ async def test_update_workflow_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.update_workflow(request) # Establish that the underlying gRPC stub method was called. @@ -1583,32 +1555,29 @@ async def test_update_workflow_field_headers_async(): def test_update_workflow_flattened(): - client = WorkflowsClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_workflow), "__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_workflow( workflow=workflows.Workflow(name="name_value"), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].workflow == workflows.Workflow(name="name_value") - - assert args[0].update_mask == field_mask.FieldMask(paths=["paths_value"]) + assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) def test_update_workflow_flattened_error(): - client = WorkflowsClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1616,13 +1585,13 @@ def test_update_workflow_flattened_error(): client.update_workflow( workflows.UpdateWorkflowRequest(), workflow=workflows.Workflow(name="name_value"), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @pytest.mark.asyncio async def test_update_workflow_flattened_async(): - client = WorkflowsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_workflow), "__call__") as call: @@ -1636,22 +1605,20 @@ async def test_update_workflow_flattened_async(): # using the keyword arguments to the method. response = await client.update_workflow( workflow=workflows.Workflow(name="name_value"), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].workflow == workflows.Workflow(name="name_value") - - assert args[0].update_mask == field_mask.FieldMask(paths=["paths_value"]) + assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) @pytest.mark.asyncio async def test_update_workflow_flattened_error_async(): - client = WorkflowsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1659,23 +1626,23 @@ async def test_update_workflow_flattened_error_async(): await client.update_workflow( workflows.UpdateWorkflowRequest(), workflow=workflows.Workflow(name="name_value"), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.WorkflowsGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = WorkflowsClient( - 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.WorkflowsGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = WorkflowsClient( @@ -1685,7 +1652,7 @@ def test_credentials_transport_error(): # It is an error to provide scopes and a transport instance. transport = transports.WorkflowsGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = WorkflowsClient( @@ -1696,7 +1663,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.WorkflowsGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) client = WorkflowsClient(transport=transport) assert client.transport is transport @@ -1705,13 +1672,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.WorkflowsGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel transport = transports.WorkflowsGrpcAsyncIOTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel @@ -1723,23 +1690,23 @@ def test_transport_get_channel(): ) def test_transport_adc(transport_class): # Test default credentials are used if not provided. - with mock.patch.object(auth, "default") as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport_class() adc.assert_called_once() def test_transport_grpc_default(): # A client should use the gRPC transport by default. - client = WorkflowsClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsClient(credentials=ga_credentials.AnonymousCredentials(),) assert isinstance(client.transport, transports.WorkflowsGrpcTransport,) def test_workflows_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.WorkflowsTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), credentials_file="credentials.json", ) @@ -1751,7 +1718,7 @@ def test_workflows_base_transport(): ) as Transport: Transport.return_value = None transport = transports.WorkflowsTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Every method on the transport should just blindly @@ -1773,15 +1740,37 @@ def test_workflows_base_transport(): transport.operations_client +@requires_google_auth_gte_1_25_0 def test_workflows_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.workflows_v1.services.workflows.transports.WorkflowsTransport._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.WorkflowsTransport( + 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_workflows_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.workflows_v1.services.workflows.transports.WorkflowsTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.WorkflowsTransport( credentials_file="credentials.json", quota_project_id="octopus", ) @@ -1794,19 +1783,33 @@ def test_workflows_base_transport_with_credentials_file(): def test_workflows_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.workflows_v1.services.workflows.transports.WorkflowsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (credentials.AnonymousCredentials(), None) + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.WorkflowsTransport() adc.assert_called_once() +@requires_google_auth_gte_1_25_0 def test_workflows_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) + WorkflowsClient() + 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_workflows_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) WorkflowsClient() adc.assert_called_once_with( scopes=("https://www.googleapis.com/auth/cloud-platform",), @@ -1814,26 +1817,152 @@ def test_workflows_auth_adc(): ) -def test_workflows_transport_auth_adc(): +@pytest.mark.parametrize( + "transport_class", + [transports.WorkflowsGrpcTransport, transports.WorkflowsGrpcAsyncIOTransport,], +) +@requires_google_auth_gte_1_25_0 +def test_workflows_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.WorkflowsGrpcTransport( - 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.WorkflowsGrpcTransport, transports.WorkflowsGrpcAsyncIOTransport,], +) +@requires_google_auth_lt_1_25_0 +def test_workflows_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.WorkflowsGrpcTransport, grpc_helpers), + (transports.WorkflowsGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_gte_1_26_0 +def test_workflows_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( + "workflows.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="workflows.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.WorkflowsGrpcTransport, grpc_helpers), + (transports.WorkflowsGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_workflows_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( + "workflows.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.WorkflowsGrpcTransport, grpc_helpers), + (transports.WorkflowsGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_workflows_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( + "workflows.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", [transports.WorkflowsGrpcTransport, transports.WorkflowsGrpcAsyncIOTransport], ) def test_workflows_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: @@ -1872,7 +2001,7 @@ def test_workflows_grpc_transport_client_cert_source_for_mtls(transport_class): def test_workflows_host_no_port(): client = WorkflowsClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="workflows.googleapis.com" ), @@ -1882,7 +2011,7 @@ def test_workflows_host_no_port(): def test_workflows_host_with_port(): client = WorkflowsClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="workflows.googleapis.com:8000" ), @@ -1933,9 +2062,9 @@ def test_workflows_transport_channel_mtls_with_client_cert_source(transport_clas 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", @@ -2008,7 +2137,7 @@ def test_workflows_transport_channel_mtls_with_adc(transport_class): def test_workflows_grpc_lro_client(): client = WorkflowsClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) transport = client.transport @@ -2021,7 +2150,7 @@ def test_workflows_grpc_lro_client(): def test_workflows_grpc_lro_async_client(): client = WorkflowsAsyncClient( - credentials=credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", ) transport = client.transport @@ -2036,7 +2165,6 @@ def test_workflow_path(): project = "squid" location = "clam" workflow = "whelk" - expected = "projects/{project}/locations/{location}/workflows/{workflow}".format( project=project, location=location, workflow=workflow, ) @@ -2059,7 +2187,6 @@ def test_parse_workflow_path(): def test_common_billing_account_path(): billing_account = "cuttlefish" - expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -2080,7 +2207,6 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "winkle" - expected = "folders/{folder}".format(folder=folder,) actual = WorkflowsClient.common_folder_path(folder) assert expected == actual @@ -2099,7 +2225,6 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "scallop" - expected = "organizations/{organization}".format(organization=organization,) actual = WorkflowsClient.common_organization_path(organization) assert expected == actual @@ -2118,7 +2243,6 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "squid" - expected = "projects/{project}".format(project=project,) actual = WorkflowsClient.common_project_path(project) assert expected == actual @@ -2138,7 +2262,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, ) @@ -2165,7 +2288,7 @@ def test_client_withDEFAULT_CLIENT_INFO(): transports.WorkflowsTransport, "_prep_wrapped_messages" ) as prep: client = WorkflowsClient( - credentials=credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -2174,6 +2297,6 @@ def test_client_withDEFAULT_CLIENT_INFO(): ) as prep: transport_class = WorkflowsClient.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) diff --git a/tests/unit/gapic/workflows_v1beta/__init__.py b/tests/unit/gapic/workflows_v1beta/__init__.py index 42ffdf2..4de6597 100644 --- a/tests/unit/gapic/workflows_v1beta/__init__.py +++ b/tests/unit/gapic/workflows_v1beta/__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/workflows_v1beta/test_workflows.py b/tests/unit/gapic/workflows_v1beta/test_workflows.py index 773c94c..68a8871 100644 --- a/tests/unit/gapic/workflows_v1beta/test_workflows.py +++ b/tests/unit/gapic/workflows_v1beta/test_workflows.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,26 +23,56 @@ 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.workflows_v1beta.services.workflows import WorkflowsAsyncClient from google.cloud.workflows_v1beta.services.workflows import WorkflowsClient from google.cloud.workflows_v1beta.services.workflows import pagers from google.cloud.workflows_v1beta.services.workflows import transports +from google.cloud.workflows_v1beta.services.workflows.transports.base import ( + _API_CORE_VERSION, +) +from google.cloud.workflows_v1beta.services.workflows.transports.base import ( + _GOOGLE_AUTH_VERSION, +) from google.cloud.workflows_v1beta.types import workflows from google.longrunning import operations_pb2 from google.oauth2 import service_account -from google.protobuf import field_mask_pb2 as field_mask # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +import google.auth + + +# TODO(busunkim): Once google-api-core >= 1.26.0 is required: +# - Delete all the api-core and auth "less than" test cases +# - Delete these pytest markers (Make the "greater than or equal to" tests the default). +requires_google_auth_lt_1_25_0 = pytest.mark.skipif( + packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), + reason="This test requires google-auth < 1.25.0", +) +requires_google_auth_gte_1_25_0 = pytest.mark.skipif( + packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), + reason="This test requires google-auth >= 1.25.0", +) + +requires_api_core_lt_1_26_0 = pytest.mark.skipif( + packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), + reason="This test requires google-api-core < 1.26.0", +) + +requires_api_core_gte_1_26_0 = pytest.mark.skipif( + packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), + reason="This test requires google-api-core >= 1.26.0", +) def client_cert_source_callback(): @@ -87,7 +116,7 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize("client_class", [WorkflowsClient, WorkflowsAsyncClient,]) def test_workflows_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: @@ -102,7 +131,7 @@ def test_workflows_client_from_service_account_info(client_class): @pytest.mark.parametrize("client_class", [WorkflowsClient, WorkflowsAsyncClient,]) def test_workflows_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: @@ -151,7 +180,7 @@ def test_workflows_client_get_transport_class(): def test_workflows_client_client_options(client_class, transport_class, transport_name): # Check that if channel is provided we won't create a new one. with mock.patch.object(WorkflowsClient, "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() @@ -435,7 +464,7 @@ def test_list_workflows( transport: str = "grpc", request_type=workflows.ListWorkflowsRequest ): client = WorkflowsClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -448,21 +477,16 @@ def test_list_workflows( call.return_value = workflows.ListWorkflowsResponse( next_page_token="next_page_token_value", unreachable=["unreachable_value"], ) - response = client.list_workflows(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == workflows.ListWorkflowsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListWorkflowsPager) - assert response.next_page_token == "next_page_token_value" - assert response.unreachable == ["unreachable_value"] @@ -474,7 +498,7 @@ def test_list_workflows_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 = WorkflowsClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -482,7 +506,6 @@ def test_list_workflows_empty_call(): client.list_workflows() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == workflows.ListWorkflowsRequest() @@ -491,7 +514,7 @@ async def test_list_workflows_async( transport: str = "grpc_asyncio", request_type=workflows.ListWorkflowsRequest ): client = WorkflowsAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -507,20 +530,16 @@ async def test_list_workflows_async( unreachable=["unreachable_value"], ) ) - response = await client.list_workflows(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == workflows.ListWorkflowsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListWorkflowsAsyncPager) - assert response.next_page_token == "next_page_token_value" - assert response.unreachable == ["unreachable_value"] @@ -530,17 +549,17 @@ async def test_list_workflows_async_from_dict(): def test_list_workflows_field_headers(): - client = WorkflowsClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsClient(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 = workflows.ListWorkflowsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_workflows), "__call__") as call: call.return_value = workflows.ListWorkflowsResponse() - client.list_workflows(request) # Establish that the underlying gRPC stub method was called. @@ -555,11 +574,12 @@ def test_list_workflows_field_headers(): @pytest.mark.asyncio async def test_list_workflows_field_headers_async(): - client = WorkflowsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsAsyncClient(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 = workflows.ListWorkflowsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -567,7 +587,6 @@ async def test_list_workflows_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( workflows.ListWorkflowsResponse() ) - await client.list_workflows(request) # Establish that the underlying gRPC stub method was called. @@ -581,13 +600,12 @@ async def test_list_workflows_field_headers_async(): def test_list_workflows_flattened(): - client = WorkflowsClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_workflows), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = workflows.ListWorkflowsResponse() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.list_workflows(parent="parent_value",) @@ -596,12 +614,11 @@ def test_list_workflows_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" def test_list_workflows_flattened_error(): - client = WorkflowsClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -613,7 +630,7 @@ def test_list_workflows_flattened_error(): @pytest.mark.asyncio async def test_list_workflows_flattened_async(): - client = WorkflowsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_workflows), "__call__") as call: @@ -631,13 +648,12 @@ async def test_list_workflows_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" @pytest.mark.asyncio async def test_list_workflows_flattened_error_async(): - client = WorkflowsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -648,7 +664,7 @@ async def test_list_workflows_flattened_error_async(): def test_list_workflows_pager(): - client = WorkflowsClient(credentials=credentials.AnonymousCredentials,) + client = WorkflowsClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_workflows), "__call__") as call: @@ -686,7 +702,7 @@ def test_list_workflows_pager(): def test_list_workflows_pages(): - client = WorkflowsClient(credentials=credentials.AnonymousCredentials,) + client = WorkflowsClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_workflows), "__call__") as call: @@ -716,7 +732,7 @@ def test_list_workflows_pages(): @pytest.mark.asyncio async def test_list_workflows_async_pager(): - client = WorkflowsAsyncClient(credentials=credentials.AnonymousCredentials,) + client = WorkflowsAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -753,7 +769,7 @@ async def test_list_workflows_async_pager(): @pytest.mark.asyncio async def test_list_workflows_async_pages(): - client = WorkflowsAsyncClient(credentials=credentials.AnonymousCredentials,) + client = WorkflowsAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -789,7 +805,7 @@ def test_get_workflow( transport: str = "grpc", request_type=workflows.GetWorkflowRequest ): client = WorkflowsClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -807,27 +823,19 @@ def test_get_workflow( service_account="service_account_value", source_contents="source_contents_value", ) - response = client.get_workflow(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == workflows.GetWorkflowRequest() # Establish that the response is the type that we expect. - assert isinstance(response, workflows.Workflow) - assert response.name == "name_value" - assert response.description == "description_value" - assert response.state == workflows.Workflow.State.ACTIVE - assert response.revision_id == "revision_id_value" - assert response.service_account == "service_account_value" @@ -839,7 +847,7 @@ def test_get_workflow_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 = WorkflowsClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -847,7 +855,6 @@ def test_get_workflow_empty_call(): client.get_workflow() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == workflows.GetWorkflowRequest() @@ -856,7 +863,7 @@ async def test_get_workflow_async( transport: str = "grpc_asyncio", request_type=workflows.GetWorkflowRequest ): client = WorkflowsAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -875,26 +882,19 @@ async def test_get_workflow_async( service_account="service_account_value", ) ) - response = await client.get_workflow(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == workflows.GetWorkflowRequest() # Establish that the response is the type that we expect. assert isinstance(response, workflows.Workflow) - assert response.name == "name_value" - assert response.description == "description_value" - assert response.state == workflows.Workflow.State.ACTIVE - assert response.revision_id == "revision_id_value" - assert response.service_account == "service_account_value" @@ -904,17 +904,17 @@ async def test_get_workflow_async_from_dict(): def test_get_workflow_field_headers(): - client = WorkflowsClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsClient(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 = workflows.GetWorkflowRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_workflow), "__call__") as call: call.return_value = workflows.Workflow() - client.get_workflow(request) # Establish that the underlying gRPC stub method was called. @@ -929,17 +929,17 @@ def test_get_workflow_field_headers(): @pytest.mark.asyncio async def test_get_workflow_field_headers_async(): - client = WorkflowsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsAsyncClient(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 = workflows.GetWorkflowRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_workflow), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(workflows.Workflow()) - await client.get_workflow(request) # Establish that the underlying gRPC stub method was called. @@ -953,13 +953,12 @@ async def test_get_workflow_field_headers_async(): def test_get_workflow_flattened(): - client = WorkflowsClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_workflow), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = workflows.Workflow() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.get_workflow(name="name_value",) @@ -968,12 +967,11 @@ def test_get_workflow_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_get_workflow_flattened_error(): - client = WorkflowsClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -985,7 +983,7 @@ def test_get_workflow_flattened_error(): @pytest.mark.asyncio async def test_get_workflow_flattened_async(): - client = WorkflowsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_workflow), "__call__") as call: @@ -1001,13 +999,12 @@ async def test_get_workflow_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_workflow_flattened_error_async(): - client = WorkflowsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1021,7 +1018,7 @@ def test_create_workflow( transport: str = "grpc", request_type=workflows.CreateWorkflowRequest ): client = WorkflowsClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1032,13 +1029,11 @@ def test_create_workflow( with mock.patch.object(type(client.transport.create_workflow), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.create_workflow(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == workflows.CreateWorkflowRequest() # Establish that the response is the type that we expect. @@ -1053,7 +1048,7 @@ def test_create_workflow_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 = WorkflowsClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1061,7 +1056,6 @@ def test_create_workflow_empty_call(): client.create_workflow() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == workflows.CreateWorkflowRequest() @@ -1070,7 +1064,7 @@ async def test_create_workflow_async( transport: str = "grpc_asyncio", request_type=workflows.CreateWorkflowRequest ): client = WorkflowsAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1083,13 +1077,11 @@ async def test_create_workflow_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.create_workflow(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == workflows.CreateWorkflowRequest() # Establish that the response is the type that we expect. @@ -1102,17 +1094,17 @@ async def test_create_workflow_async_from_dict(): def test_create_workflow_field_headers(): - client = WorkflowsClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsClient(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 = workflows.CreateWorkflowRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_workflow), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.create_workflow(request) # Establish that the underlying gRPC stub method was called. @@ -1127,11 +1119,12 @@ def test_create_workflow_field_headers(): @pytest.mark.asyncio async def test_create_workflow_field_headers_async(): - client = WorkflowsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsAsyncClient(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 = workflows.CreateWorkflowRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1139,7 +1132,6 @@ async def test_create_workflow_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.create_workflow(request) # Establish that the underlying gRPC stub method was called. @@ -1153,13 +1145,12 @@ async def test_create_workflow_field_headers_async(): def test_create_workflow_flattened(): - client = WorkflowsClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_workflow), "__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_workflow( @@ -1172,16 +1163,13 @@ def test_create_workflow_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].workflow == workflows.Workflow(name="name_value") - assert args[0].workflow_id == "workflow_id_value" def test_create_workflow_flattened_error(): - client = WorkflowsClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1196,7 +1184,7 @@ def test_create_workflow_flattened_error(): @pytest.mark.asyncio async def test_create_workflow_flattened_async(): - client = WorkflowsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_workflow), "__call__") as call: @@ -1218,17 +1206,14 @@ async def test_create_workflow_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].workflow == workflows.Workflow(name="name_value") - assert args[0].workflow_id == "workflow_id_value" @pytest.mark.asyncio async def test_create_workflow_flattened_error_async(): - client = WorkflowsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1245,7 +1230,7 @@ def test_delete_workflow( transport: str = "grpc", request_type=workflows.DeleteWorkflowRequest ): client = WorkflowsClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1256,13 +1241,11 @@ def test_delete_workflow( with mock.patch.object(type(client.transport.delete_workflow), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.delete_workflow(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == workflows.DeleteWorkflowRequest() # Establish that the response is the type that we expect. @@ -1277,7 +1260,7 @@ def test_delete_workflow_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 = WorkflowsClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1285,7 +1268,6 @@ def test_delete_workflow_empty_call(): client.delete_workflow() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == workflows.DeleteWorkflowRequest() @@ -1294,7 +1276,7 @@ async def test_delete_workflow_async( transport: str = "grpc_asyncio", request_type=workflows.DeleteWorkflowRequest ): client = WorkflowsAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1307,13 +1289,11 @@ async def test_delete_workflow_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.delete_workflow(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == workflows.DeleteWorkflowRequest() # Establish that the response is the type that we expect. @@ -1326,17 +1306,17 @@ async def test_delete_workflow_async_from_dict(): def test_delete_workflow_field_headers(): - client = WorkflowsClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsClient(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 = workflows.DeleteWorkflowRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_workflow), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.delete_workflow(request) # Establish that the underlying gRPC stub method was called. @@ -1351,11 +1331,12 @@ def test_delete_workflow_field_headers(): @pytest.mark.asyncio async def test_delete_workflow_field_headers_async(): - client = WorkflowsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsAsyncClient(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 = workflows.DeleteWorkflowRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1363,7 +1344,6 @@ async def test_delete_workflow_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.delete_workflow(request) # Establish that the underlying gRPC stub method was called. @@ -1377,13 +1357,12 @@ async def test_delete_workflow_field_headers_async(): def test_delete_workflow_flattened(): - client = WorkflowsClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_workflow), "__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_workflow(name="name_value",) @@ -1392,12 +1371,11 @@ def test_delete_workflow_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_delete_workflow_flattened_error(): - client = WorkflowsClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1409,7 +1387,7 @@ def test_delete_workflow_flattened_error(): @pytest.mark.asyncio async def test_delete_workflow_flattened_async(): - client = WorkflowsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_workflow), "__call__") as call: @@ -1427,13 +1405,12 @@ async def test_delete_workflow_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_workflow_flattened_error_async(): - client = WorkflowsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1447,7 +1424,7 @@ def test_update_workflow( transport: str = "grpc", request_type=workflows.UpdateWorkflowRequest ): client = WorkflowsClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1458,13 +1435,11 @@ def test_update_workflow( with mock.patch.object(type(client.transport.update_workflow), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.update_workflow(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == workflows.UpdateWorkflowRequest() # Establish that the response is the type that we expect. @@ -1479,7 +1454,7 @@ def test_update_workflow_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 = WorkflowsClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1487,7 +1462,6 @@ def test_update_workflow_empty_call(): client.update_workflow() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == workflows.UpdateWorkflowRequest() @@ -1496,7 +1470,7 @@ async def test_update_workflow_async( transport: str = "grpc_asyncio", request_type=workflows.UpdateWorkflowRequest ): client = WorkflowsAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1509,13 +1483,11 @@ async def test_update_workflow_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.update_workflow(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == workflows.UpdateWorkflowRequest() # Establish that the response is the type that we expect. @@ -1528,17 +1500,17 @@ async def test_update_workflow_async_from_dict(): def test_update_workflow_field_headers(): - client = WorkflowsClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsClient(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 = workflows.UpdateWorkflowRequest() + request.workflow.name = "workflow.name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_workflow), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.update_workflow(request) # Establish that the underlying gRPC stub method was called. @@ -1555,11 +1527,12 @@ def test_update_workflow_field_headers(): @pytest.mark.asyncio async def test_update_workflow_field_headers_async(): - client = WorkflowsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsAsyncClient(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 = workflows.UpdateWorkflowRequest() + request.workflow.name = "workflow.name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1567,7 +1540,6 @@ async def test_update_workflow_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.update_workflow(request) # Establish that the underlying gRPC stub method was called. @@ -1583,32 +1555,29 @@ async def test_update_workflow_field_headers_async(): def test_update_workflow_flattened(): - client = WorkflowsClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_workflow), "__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_workflow( workflow=workflows.Workflow(name="name_value"), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].workflow == workflows.Workflow(name="name_value") - - assert args[0].update_mask == field_mask.FieldMask(paths=["paths_value"]) + assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) def test_update_workflow_flattened_error(): - client = WorkflowsClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1616,13 +1585,13 @@ def test_update_workflow_flattened_error(): client.update_workflow( workflows.UpdateWorkflowRequest(), workflow=workflows.Workflow(name="name_value"), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @pytest.mark.asyncio async def test_update_workflow_flattened_async(): - client = WorkflowsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_workflow), "__call__") as call: @@ -1636,22 +1605,20 @@ async def test_update_workflow_flattened_async(): # using the keyword arguments to the method. response = await client.update_workflow( workflow=workflows.Workflow(name="name_value"), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].workflow == workflows.Workflow(name="name_value") - - assert args[0].update_mask == field_mask.FieldMask(paths=["paths_value"]) + assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) @pytest.mark.asyncio async def test_update_workflow_flattened_error_async(): - client = WorkflowsAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1659,23 +1626,23 @@ async def test_update_workflow_flattened_error_async(): await client.update_workflow( workflows.UpdateWorkflowRequest(), workflow=workflows.Workflow(name="name_value"), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.WorkflowsGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = WorkflowsClient( - 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.WorkflowsGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = WorkflowsClient( @@ -1685,7 +1652,7 @@ def test_credentials_transport_error(): # It is an error to provide scopes and a transport instance. transport = transports.WorkflowsGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = WorkflowsClient( @@ -1696,7 +1663,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.WorkflowsGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) client = WorkflowsClient(transport=transport) assert client.transport is transport @@ -1705,13 +1672,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.WorkflowsGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel transport = transports.WorkflowsGrpcAsyncIOTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel @@ -1723,23 +1690,23 @@ def test_transport_get_channel(): ) def test_transport_adc(transport_class): # Test default credentials are used if not provided. - with mock.patch.object(auth, "default") as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport_class() adc.assert_called_once() def test_transport_grpc_default(): # A client should use the gRPC transport by default. - client = WorkflowsClient(credentials=credentials.AnonymousCredentials(),) + client = WorkflowsClient(credentials=ga_credentials.AnonymousCredentials(),) assert isinstance(client.transport, transports.WorkflowsGrpcTransport,) def test_workflows_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.WorkflowsTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), credentials_file="credentials.json", ) @@ -1751,7 +1718,7 @@ def test_workflows_base_transport(): ) as Transport: Transport.return_value = None transport = transports.WorkflowsTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Every method on the transport should just blindly @@ -1773,15 +1740,37 @@ def test_workflows_base_transport(): transport.operations_client +@requires_google_auth_gte_1_25_0 def test_workflows_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.workflows_v1beta.services.workflows.transports.WorkflowsTransport._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.WorkflowsTransport( + 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_workflows_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.workflows_v1beta.services.workflows.transports.WorkflowsTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.WorkflowsTransport( credentials_file="credentials.json", quota_project_id="octopus", ) @@ -1794,19 +1783,33 @@ def test_workflows_base_transport_with_credentials_file(): def test_workflows_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.workflows_v1beta.services.workflows.transports.WorkflowsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (credentials.AnonymousCredentials(), None) + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.WorkflowsTransport() adc.assert_called_once() +@requires_google_auth_gte_1_25_0 def test_workflows_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) + WorkflowsClient() + 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_workflows_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) WorkflowsClient() adc.assert_called_once_with( scopes=("https://www.googleapis.com/auth/cloud-platform",), @@ -1814,26 +1817,152 @@ def test_workflows_auth_adc(): ) -def test_workflows_transport_auth_adc(): +@pytest.mark.parametrize( + "transport_class", + [transports.WorkflowsGrpcTransport, transports.WorkflowsGrpcAsyncIOTransport,], +) +@requires_google_auth_gte_1_25_0 +def test_workflows_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.WorkflowsGrpcTransport( - 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.WorkflowsGrpcTransport, transports.WorkflowsGrpcAsyncIOTransport,], +) +@requires_google_auth_lt_1_25_0 +def test_workflows_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.WorkflowsGrpcTransport, grpc_helpers), + (transports.WorkflowsGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_gte_1_26_0 +def test_workflows_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( + "workflows.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="workflows.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.WorkflowsGrpcTransport, grpc_helpers), + (transports.WorkflowsGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_workflows_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( + "workflows.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.WorkflowsGrpcTransport, grpc_helpers), + (transports.WorkflowsGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_workflows_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( + "workflows.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", [transports.WorkflowsGrpcTransport, transports.WorkflowsGrpcAsyncIOTransport], ) def test_workflows_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: @@ -1872,7 +2001,7 @@ def test_workflows_grpc_transport_client_cert_source_for_mtls(transport_class): def test_workflows_host_no_port(): client = WorkflowsClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="workflows.googleapis.com" ), @@ -1882,7 +2011,7 @@ def test_workflows_host_no_port(): def test_workflows_host_with_port(): client = WorkflowsClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="workflows.googleapis.com:8000" ), @@ -1933,9 +2062,9 @@ def test_workflows_transport_channel_mtls_with_client_cert_source(transport_clas 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", @@ -2008,7 +2137,7 @@ def test_workflows_transport_channel_mtls_with_adc(transport_class): def test_workflows_grpc_lro_client(): client = WorkflowsClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) transport = client.transport @@ -2021,7 +2150,7 @@ def test_workflows_grpc_lro_client(): def test_workflows_grpc_lro_async_client(): client = WorkflowsAsyncClient( - credentials=credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", ) transport = client.transport @@ -2036,7 +2165,6 @@ def test_workflow_path(): project = "squid" location = "clam" workflow = "whelk" - expected = "projects/{project}/locations/{location}/workflows/{workflow}".format( project=project, location=location, workflow=workflow, ) @@ -2059,7 +2187,6 @@ def test_parse_workflow_path(): def test_common_billing_account_path(): billing_account = "cuttlefish" - expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -2080,7 +2207,6 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "winkle" - expected = "folders/{folder}".format(folder=folder,) actual = WorkflowsClient.common_folder_path(folder) assert expected == actual @@ -2099,7 +2225,6 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "scallop" - expected = "organizations/{organization}".format(organization=organization,) actual = WorkflowsClient.common_organization_path(organization) assert expected == actual @@ -2118,7 +2243,6 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "squid" - expected = "projects/{project}".format(project=project,) actual = WorkflowsClient.common_project_path(project) assert expected == actual @@ -2138,7 +2262,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, ) @@ -2165,7 +2288,7 @@ def test_client_withDEFAULT_CLIENT_INFO(): transports.WorkflowsTransport, "_prep_wrapped_messages" ) as prep: client = WorkflowsClient( - credentials=credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -2174,6 +2297,6 @@ def test_client_withDEFAULT_CLIENT_INFO(): ) as prep: transport_class = WorkflowsClient.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)