From 580a95925651c8478a47fd588540088104bb9a12 Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Tue, 23 Mar 2021 13:06:07 -0700 Subject: [PATCH] feat: add `from_service_account_info` (#52) This PR was generated using Autosynth. :rainbow: Synth log will be available here: https://source.cloud.google.com/results/invocations/fb22f59c-8962-43c6-89b6-9796466cdaca/targets - [x] To automatically regenerate this PR, check this box. PiperOrigin-RevId: 359562873 Source-Link: https://github.com/googleapis/googleapis/commit/07932bb995e7dc91b43620ea8402c6668c7d102c PiperOrigin-RevId: 355923884 Source-Link: https://github.com/googleapis/googleapis/commit/5e3dacee19405529b841b53797df799c2383536c PiperOrigin-RevId: 354996675 Source-Link: https://github.com/googleapis/googleapis/commit/20712b8fe95001b312f62c6c5f33e3e3ec92cfaf PiperOrigin-RevId: 352816749 Source-Link: https://github.com/googleapis/googleapis/commit/ceaaf31b3d13badab7cf9d3b570f5639db5593d9 PiperOrigin-RevId: 350388717 Source-Link: https://github.com/googleapis/googleapis/commit/dd1d2325b189d3bb69c4a6a802185cefbd8e592e PiperOrigin-RevId: 350246057 Source-Link: https://github.com/googleapis/googleapis/commit/520682435235d9c503983a360a2090025aa47cd1 --- docs/cloudbuild_v1/cloud_build.rst | 11 + docs/cloudbuild_v1/services.rst | 6 +- docs/cloudbuild_v1/types.rst | 1 + .../cloudbuild_v1/proto/cloudbuild.proto | 1 + .../services/cloud_build/async_client.py | 330 ++++++------ .../services/cloud_build/client.py | 377 +++++++------- .../services/cloud_build/pagers.py | 43 +- .../services/cloud_build/transports/grpc.py | 23 +- .../cloud_build/transports/grpc_asyncio.py | 23 +- .../cloudbuild_v1/types/cloudbuild.py | 138 ++--- synth.metadata | 7 +- tests/unit/gapic/cloudbuild_v1/__init__.py | 15 + .../gapic/cloudbuild_v1/test_cloud_build.py | 489 +++++++++++++++--- 13 files changed, 954 insertions(+), 510 deletions(-) create mode 100644 docs/cloudbuild_v1/cloud_build.rst diff --git a/docs/cloudbuild_v1/cloud_build.rst b/docs/cloudbuild_v1/cloud_build.rst new file mode 100644 index 00000000..9fdbf01c --- /dev/null +++ b/docs/cloudbuild_v1/cloud_build.rst @@ -0,0 +1,11 @@ +CloudBuild +---------------------------- + +.. automodule:: google.cloud.devtools.cloudbuild_v1.services.cloud_build + :members: + :inherited-members: + + +.. automodule:: google.cloud.devtools.cloudbuild_v1.services.cloud_build.pagers + :members: + :inherited-members: diff --git a/docs/cloudbuild_v1/services.rst b/docs/cloudbuild_v1/services.rst index 6e93f6b3..87309bc9 100644 --- a/docs/cloudbuild_v1/services.rst +++ b/docs/cloudbuild_v1/services.rst @@ -1,6 +1,6 @@ Services for Google Devtools Cloudbuild v1 API ============================================== +.. toctree:: + :maxdepth: 2 -.. automodule:: google.cloud.devtools.cloudbuild_v1.services.cloud_build - :members: - :inherited-members: + cloud_build diff --git a/docs/cloudbuild_v1/types.rst b/docs/cloudbuild_v1/types.rst index 3fcd1832..8509d205 100644 --- a/docs/cloudbuild_v1/types.rst +++ b/docs/cloudbuild_v1/types.rst @@ -3,4 +3,5 @@ Types for Google Devtools Cloudbuild v1 API .. automodule:: google.cloud.devtools.cloudbuild_v1.types :members: + :undoc-members: :show-inheritance: diff --git a/google/cloud/devtools/cloudbuild_v1/proto/cloudbuild.proto b/google/cloud/devtools/cloudbuild_v1/proto/cloudbuild.proto index de8a1de3..689e8798 100644 --- a/google/cloud/devtools/cloudbuild_v1/proto/cloudbuild.proto +++ b/google/cloud/devtools/cloudbuild_v1/proto/cloudbuild.proto @@ -26,6 +26,7 @@ import "google/protobuf/empty.proto"; import "google/protobuf/field_mask.proto"; import "google/protobuf/timestamp.proto"; +option csharp_namespace = "Google.Cloud.CloudBuild.V1"; option go_package = "google.golang.org/genproto/googleapis/devtools/cloudbuild/v1;cloudbuild"; option java_multiple_files = true; option java_package = "com.google.cloudbuild.v1"; diff --git a/google/cloud/devtools/cloudbuild_v1/services/cloud_build/async_client.py b/google/cloud/devtools/cloudbuild_v1/services/cloud_build/async_client.py index 469f1edf..343d1e9d 100644 --- a/google/cloud/devtools/cloudbuild_v1/services/cloud_build/async_client.py +++ b/google/cloud/devtools/cloudbuild_v1/services/cloud_build/async_client.py @@ -88,7 +88,36 @@ class CloudBuildAsyncClient: CloudBuildClient.parse_common_location_path ) - from_service_account_file = CloudBuildClient.from_service_account_file + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + CloudBuildAsyncClient: The constructed client. + """ + return CloudBuildClient.from_service_account_info.__func__(CloudBuildAsyncClient, info, *args, **kwargs) # type: ignore + + @classmethod + def from_service_account_file(cls, filename: str, *args, **kwargs): + """Creates an instance of this client using the provided credentials + file. + + Args: + filename (str): The path to the service account private key json + file. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + CloudBuildAsyncClient: The constructed client. + """ + return CloudBuildClient.from_service_account_file.__func__(CloudBuildAsyncClient, filename, *args, **kwargs) # type: ignore + from_service_account_json = from_service_account_file @property @@ -169,14 +198,14 @@ async def create_build( build status (such as ``SUCCESS`` or ``FAILURE``). Args: - request (:class:`~.cloudbuild.CreateBuildRequest`): + request (:class:`google.cloud.devtools.cloudbuild_v1.types.CreateBuildRequest`): The request object. Request to create a new build. project_id (:class:`str`): Required. ID of the project. This corresponds to the ``project_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - build (:class:`~.cloudbuild.Build`): + build (:class:`google.cloud.devtools.cloudbuild_v1.types.Build`): Required. Build resource to create. This corresponds to the ``build`` field on the ``request`` instance; if ``request`` is provided, this @@ -189,33 +218,33 @@ async def create_build( sent along with the request as metadata. Returns: - ~.operation_async.AsyncOperation: + google.api_core.operation_async.AsyncOperation: An object representing a long-running operation. The result type for the operation will be - :class:``~.cloudbuild.Build``: A build resource in the - Cloud Build API. - - At a high level, a ``Build`` describes where to find - source code, how to build it (for example, the builder - image to run on the source), and where to store the - built artifacts. - - Fields can include the following variables, which will - be expanded when the build is created: - - - $PROJECT_ID: the project ID of the build. - - $BUILD_ID: the autogenerated ID of the build. - - $REPO_NAME: the source repository name specified by - RepoSource. - - $BRANCH_NAME: the branch name specified by - RepoSource. - - $TAG_NAME: the tag name specified by RepoSource. - - $REVISION_ID or $COMMIT_SHA: the commit SHA specified - by RepoSource or resolved from the specified branch - or tag. - - $SHORT_SHA: first 7 characters of $REVISION_ID or - $COMMIT_SHA. + :class:`google.cloud.devtools.cloudbuild_v1.types.Build` A + build resource in the Cloud Build API. + + At a high level, a Build describes where to find + source code, how to build it (for example, the + builder image to run on the source), and where to + store the built artifacts. + + Fields can include the following variables, which + will be expanded when the build is created: + + - $PROJECT_ID: the project ID of the build. + - $BUILD_ID: the autogenerated ID of the build. + - $REPO_NAME: the source repository name specified + by RepoSource. + - $BRANCH_NAME: the branch name specified by + RepoSource. + - $TAG_NAME: the tag name specified by RepoSource. + - $REVISION_ID or $COMMIT_SHA: the commit SHA + specified by RepoSource or resolved from the + specified branch or tag. + - $SHORT_SHA: first 7 characters of $REVISION_ID or + $COMMIT_SHA. """ # Create or coerce a protobuf request object. @@ -277,7 +306,7 @@ async def get_build( information. Args: - request (:class:`~.cloudbuild.GetBuildRequest`): + request (:class:`google.cloud.devtools.cloudbuild_v1.types.GetBuildRequest`): The request object. Request to get a build. project_id (:class:`str`): Required. ID of the project. @@ -297,29 +326,29 @@ async def get_build( sent along with the request as metadata. Returns: - ~.cloudbuild.Build: + google.cloud.devtools.cloudbuild_v1.types.Build: A build resource in the Cloud Build API. - At a high level, a ``Build`` describes where to find - source code, how to build it (for example, the builder - image to run on the source), and where to store the - built artifacts. - - Fields can include the following variables, which will - be expanded when the build is created: - - - $PROJECT_ID: the project ID of the build. - - $BUILD_ID: the autogenerated ID of the build. - - $REPO_NAME: the source repository name specified by - RepoSource. - - $BRANCH_NAME: the branch name specified by - RepoSource. - - $TAG_NAME: the tag name specified by RepoSource. - - $REVISION_ID or $COMMIT_SHA: the commit SHA specified - by RepoSource or resolved from the specified branch - or tag. - - $SHORT_SHA: first 7 characters of $REVISION_ID or - $COMMIT_SHA. + At a high level, a Build describes where to find + source code, how to build it (for example, the + builder image to run on the source), and where to + store the built artifacts. + + Fields can include the following variables, which + will be expanded when the build is created: + + - $PROJECT_ID: the project ID of the build. + - $BUILD_ID: the autogenerated ID of the build. + - $REPO_NAME: the source repository name specified + by RepoSource. + - $BRANCH_NAME: the branch name specified by + RepoSource. + - $TAG_NAME: the tag name specified by RepoSource. + - $REVISION_ID or $COMMIT_SHA: the commit SHA + specified by RepoSource or resolved from the + specified branch or tag. + - $SHORT_SHA: first 7 characters of $REVISION_ID or + $COMMIT_SHA. """ # Create or coerce a protobuf request object. @@ -379,7 +408,7 @@ async def list_builds( may have finished successfully or unsuccessfully. Args: - request (:class:`~.cloudbuild.ListBuildsRequest`): + request (:class:`google.cloud.devtools.cloudbuild_v1.types.ListBuildsRequest`): The request object. Request to list builds. project_id (:class:`str`): Required. ID of the project. @@ -389,6 +418,7 @@ async def list_builds( filter (:class:`str`): The raw filter text to constrain the results. + This corresponds to the ``filter`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -400,7 +430,7 @@ async def list_builds( sent along with the request as metadata. Returns: - ~.pagers.ListBuildsAsyncPager: + google.cloud.devtools.cloudbuild_v1.services.cloud_build.pagers.ListBuildsAsyncPager: Response including listed builds. Iterating over this object will yield results and resolve additional pages @@ -468,7 +498,7 @@ async def cancel_build( r"""Cancels a build in progress. Args: - request (:class:`~.cloudbuild.CancelBuildRequest`): + request (:class:`google.cloud.devtools.cloudbuild_v1.types.CancelBuildRequest`): The request object. Request to cancel an ongoing build. project_id (:class:`str`): Required. ID of the project. @@ -488,29 +518,29 @@ async def cancel_build( sent along with the request as metadata. Returns: - ~.cloudbuild.Build: + google.cloud.devtools.cloudbuild_v1.types.Build: A build resource in the Cloud Build API. - At a high level, a ``Build`` describes where to find - source code, how to build it (for example, the builder - image to run on the source), and where to store the - built artifacts. - - Fields can include the following variables, which will - be expanded when the build is created: - - - $PROJECT_ID: the project ID of the build. - - $BUILD_ID: the autogenerated ID of the build. - - $REPO_NAME: the source repository name specified by - RepoSource. - - $BRANCH_NAME: the branch name specified by - RepoSource. - - $TAG_NAME: the tag name specified by RepoSource. - - $REVISION_ID or $COMMIT_SHA: the commit SHA specified - by RepoSource or resolved from the specified branch - or tag. - - $SHORT_SHA: first 7 characters of $REVISION_ID or - $COMMIT_SHA. + At a high level, a Build describes where to find + source code, how to build it (for example, the + builder image to run on the source), and where to + store the built artifacts. + + Fields can include the following variables, which + will be expanded when the build is created: + + - $PROJECT_ID: the project ID of the build. + - $BUILD_ID: the autogenerated ID of the build. + - $REPO_NAME: the source repository name specified + by RepoSource. + - $BRANCH_NAME: the branch name specified by + RepoSource. + - $TAG_NAME: the tag name specified by RepoSource. + - $REVISION_ID or $COMMIT_SHA: the commit SHA + specified by RepoSource or resolved from the + specified branch or tag. + - $SHORT_SHA: first 7 characters of $REVISION_ID or + $COMMIT_SHA. """ # Create or coerce a protobuf request object. @@ -589,7 +619,7 @@ async def retry_build( settings. Args: - request (:class:`~.cloudbuild.RetryBuildRequest`): + request (:class:`google.cloud.devtools.cloudbuild_v1.types.RetryBuildRequest`): The request object. Specifies a build to retry. project_id (:class:`str`): Required. ID of the project. @@ -599,6 +629,7 @@ async def retry_build( id (:class:`str`): Required. Build ID of the original build. + This corresponds to the ``id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -610,33 +641,33 @@ async def retry_build( sent along with the request as metadata. Returns: - ~.operation_async.AsyncOperation: + google.api_core.operation_async.AsyncOperation: An object representing a long-running operation. The result type for the operation will be - :class:``~.cloudbuild.Build``: A build resource in the - Cloud Build API. - - At a high level, a ``Build`` describes where to find - source code, how to build it (for example, the builder - image to run on the source), and where to store the - built artifacts. - - Fields can include the following variables, which will - be expanded when the build is created: - - - $PROJECT_ID: the project ID of the build. - - $BUILD_ID: the autogenerated ID of the build. - - $REPO_NAME: the source repository name specified by - RepoSource. - - $BRANCH_NAME: the branch name specified by - RepoSource. - - $TAG_NAME: the tag name specified by RepoSource. - - $REVISION_ID or $COMMIT_SHA: the commit SHA specified - by RepoSource or resolved from the specified branch - or tag. - - $SHORT_SHA: first 7 characters of $REVISION_ID or - $COMMIT_SHA. + :class:`google.cloud.devtools.cloudbuild_v1.types.Build` A + build resource in the Cloud Build API. + + At a high level, a Build describes where to find + source code, how to build it (for example, the + builder image to run on the source), and where to + store the built artifacts. + + Fields can include the following variables, which + will be expanded when the build is created: + + - $PROJECT_ID: the project ID of the build. + - $BUILD_ID: the autogenerated ID of the build. + - $REPO_NAME: the source repository name specified + by RepoSource. + - $BRANCH_NAME: the branch name specified by + RepoSource. + - $TAG_NAME: the tag name specified by RepoSource. + - $REVISION_ID or $COMMIT_SHA: the commit SHA + specified by RepoSource or resolved from the + specified branch or tag. + - $SHORT_SHA: first 7 characters of $REVISION_ID or + $COMMIT_SHA. """ # Create or coerce a protobuf request object. @@ -696,16 +727,17 @@ async def create_build_trigger( This API is experimental. Args: - request (:class:`~.cloudbuild.CreateBuildTriggerRequest`): + request (:class:`google.cloud.devtools.cloudbuild_v1.types.CreateBuildTriggerRequest`): The request object. Request to create a new `BuildTrigger`. project_id (:class:`str`): Required. ID of the project for which to configure automatic builds. + This corresponds to the ``project_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - trigger (:class:`~.cloudbuild.BuildTrigger`): + trigger (:class:`google.cloud.devtools.cloudbuild_v1.types.BuildTrigger`): Required. ``BuildTrigger`` to create. This corresponds to the ``trigger`` field on the ``request`` instance; if ``request`` is provided, this @@ -718,7 +750,7 @@ async def create_build_trigger( sent along with the request as metadata. Returns: - ~.cloudbuild.BuildTrigger: + google.cloud.devtools.cloudbuild_v1.types.BuildTrigger: Configuration for an automated build in response to source repository changes. @@ -773,18 +805,20 @@ async def get_build_trigger( This API is experimental. Args: - request (:class:`~.cloudbuild.GetBuildTriggerRequest`): + request (:class:`google.cloud.devtools.cloudbuild_v1.types.GetBuildTriggerRequest`): The request object. Returns the `BuildTrigger` with the specified ID. project_id (:class:`str`): Required. ID of the project that owns the trigger. + This corresponds to the ``project_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. trigger_id (:class:`str`): Required. Identifier (``id`` or ``name``) of the ``BuildTrigger`` to get. + This corresponds to the ``trigger_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -796,7 +830,7 @@ async def get_build_trigger( sent along with the request as metadata. Returns: - ~.cloudbuild.BuildTrigger: + google.cloud.devtools.cloudbuild_v1.types.BuildTrigger: Configuration for an automated build in response to source repository changes. @@ -858,12 +892,13 @@ async def list_build_triggers( This API is experimental. Args: - request (:class:`~.cloudbuild.ListBuildTriggersRequest`): + request (:class:`google.cloud.devtools.cloudbuild_v1.types.ListBuildTriggersRequest`): The request object. Request to list existing `BuildTriggers`. project_id (:class:`str`): Required. ID of the project for which to list BuildTriggers. + This corresponds to the ``project_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -875,8 +910,8 @@ async def list_build_triggers( sent along with the request as metadata. Returns: - ~.pagers.ListBuildTriggersAsyncPager: - Response containing existing ``BuildTriggers``. + google.cloud.devtools.cloudbuild_v1.services.cloud_build.pagers.ListBuildTriggersAsyncPager: + Response containing existing BuildTriggers. Iterating over this object will yield results and resolve additional pages automatically. @@ -943,11 +978,12 @@ async def delete_build_trigger( This API is experimental. Args: - request (:class:`~.cloudbuild.DeleteBuildTriggerRequest`): + request (:class:`google.cloud.devtools.cloudbuild_v1.types.DeleteBuildTriggerRequest`): The request object. Request to delete a `BuildTrigger`. project_id (:class:`str`): Required. ID of the project that owns the trigger. + This corresponds to the ``project_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1020,12 +1056,13 @@ async def update_build_trigger( This API is experimental. Args: - request (:class:`~.cloudbuild.UpdateBuildTriggerRequest`): + request (:class:`google.cloud.devtools.cloudbuild_v1.types.UpdateBuildTriggerRequest`): The request object. Request to update an existing `BuildTrigger`. project_id (:class:`str`): Required. ID of the project that owns the trigger. + This corresponds to the ``project_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1034,7 +1071,7 @@ async def update_build_trigger( This corresponds to the ``trigger_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - trigger (:class:`~.cloudbuild.BuildTrigger`): + trigger (:class:`google.cloud.devtools.cloudbuild_v1.types.BuildTrigger`): Required. ``BuildTrigger`` to update. This corresponds to the ``trigger`` field on the ``request`` instance; if ``request`` is provided, this @@ -1047,7 +1084,7 @@ async def update_build_trigger( sent along with the request as metadata. Returns: - ~.cloudbuild.BuildTrigger: + google.cloud.devtools.cloudbuild_v1.types.BuildTrigger: Configuration for an automated build in response to source repository changes. @@ -1103,7 +1140,7 @@ async def run_build_trigger( r"""Runs a ``BuildTrigger`` at a particular source revision. Args: - request (:class:`~.cloudbuild.RunBuildTriggerRequest`): + request (:class:`google.cloud.devtools.cloudbuild_v1.types.RunBuildTriggerRequest`): The request object. Specifies a build trigger to run and the source to use. project_id (:class:`str`): @@ -1116,9 +1153,10 @@ async def run_build_trigger( This corresponds to the ``trigger_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - source (:class:`~.cloudbuild.RepoSource`): + source (:class:`google.cloud.devtools.cloudbuild_v1.types.RepoSource`): Required. Source to build against this trigger. + This corresponds to the ``source`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1130,33 +1168,33 @@ async def run_build_trigger( sent along with the request as metadata. Returns: - ~.operation_async.AsyncOperation: + google.api_core.operation_async.AsyncOperation: An object representing a long-running operation. The result type for the operation will be - :class:``~.cloudbuild.Build``: A build resource in the - Cloud Build API. - - At a high level, a ``Build`` describes where to find - source code, how to build it (for example, the builder - image to run on the source), and where to store the - built artifacts. - - Fields can include the following variables, which will - be expanded when the build is created: - - - $PROJECT_ID: the project ID of the build. - - $BUILD_ID: the autogenerated ID of the build. - - $REPO_NAME: the source repository name specified by - RepoSource. - - $BRANCH_NAME: the branch name specified by - RepoSource. - - $TAG_NAME: the tag name specified by RepoSource. - - $REVISION_ID or $COMMIT_SHA: the commit SHA specified - by RepoSource or resolved from the specified branch - or tag. - - $SHORT_SHA: first 7 characters of $REVISION_ID or - $COMMIT_SHA. + :class:`google.cloud.devtools.cloudbuild_v1.types.Build` A + build resource in the Cloud Build API. + + At a high level, a Build describes where to find + source code, how to build it (for example, the + builder image to run on the source), and where to + store the built artifacts. + + Fields can include the following variables, which + will be expanded when the build is created: + + - $PROJECT_ID: the project ID of the build. + - $BUILD_ID: the autogenerated ID of the build. + - $REPO_NAME: the source repository name specified + by RepoSource. + - $BRANCH_NAME: the branch name specified by + RepoSource. + - $TAG_NAME: the tag name specified by RepoSource. + - $REVISION_ID or $COMMIT_SHA: the commit SHA + specified by RepoSource or resolved from the + specified branch or tag. + - $SHORT_SHA: first 7 characters of $REVISION_ID or + $COMMIT_SHA. """ # Create or coerce a protobuf request object. @@ -1217,7 +1255,7 @@ async def create_worker_pool( This API is experimental. Args: - request (:class:`~.cloudbuild.CreateWorkerPoolRequest`): + request (:class:`google.cloud.devtools.cloudbuild_v1.types.CreateWorkerPoolRequest`): The request object. Request to create a new `WorkerPool`. @@ -1228,7 +1266,7 @@ async def create_worker_pool( sent along with the request as metadata. Returns: - ~.cloudbuild.WorkerPool: + google.cloud.devtools.cloudbuild_v1.types.WorkerPool: Configuration for a WorkerPool to run the builds. Workers are machines that Cloud Build @@ -1274,7 +1312,7 @@ async def get_worker_pool( This API is experimental. Args: - request (:class:`~.cloudbuild.GetWorkerPoolRequest`): + request (:class:`google.cloud.devtools.cloudbuild_v1.types.GetWorkerPoolRequest`): The request object. Request to get a `WorkerPool` with the specified name. @@ -1285,7 +1323,7 @@ async def get_worker_pool( sent along with the request as metadata. Returns: - ~.cloudbuild.WorkerPool: + google.cloud.devtools.cloudbuild_v1.types.WorkerPool: Configuration for a WorkerPool to run the builds. Workers are machines that Cloud Build @@ -1339,7 +1377,7 @@ async def delete_worker_pool( This API is experimental. Args: - request (:class:`~.cloudbuild.DeleteWorkerPoolRequest`): + request (:class:`google.cloud.devtools.cloudbuild_v1.types.DeleteWorkerPoolRequest`): The request object. Request to delete a `WorkerPool`. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -1378,7 +1416,7 @@ async def update_worker_pool( This API is experimental. Args: - request (:class:`~.cloudbuild.UpdateWorkerPoolRequest`): + request (:class:`google.cloud.devtools.cloudbuild_v1.types.UpdateWorkerPoolRequest`): The request object. Request to update a `WorkerPool`. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -1388,7 +1426,7 @@ async def update_worker_pool( sent along with the request as metadata. Returns: - ~.cloudbuild.WorkerPool: + google.cloud.devtools.cloudbuild_v1.types.WorkerPool: Configuration for a WorkerPool to run the builds. Workers are machines that Cloud Build @@ -1434,7 +1472,7 @@ async def list_worker_pools( This API is experimental. Args: - request (:class:`~.cloudbuild.ListWorkerPoolsRequest`): + request (:class:`google.cloud.devtools.cloudbuild_v1.types.ListWorkerPoolsRequest`): The request object. Request to list `WorkerPools`. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -1444,8 +1482,8 @@ async def list_worker_pools( sent along with the request as metadata. Returns: - ~.cloudbuild.ListWorkerPoolsResponse: - Response containing existing ``WorkerPools``. + google.cloud.devtools.cloudbuild_v1.types.ListWorkerPoolsResponse: + Response containing existing WorkerPools. """ # Create or coerce a protobuf request object. diff --git a/google/cloud/devtools/cloudbuild_v1/services/cloud_build/client.py b/google/cloud/devtools/cloudbuild_v1/services/cloud_build/client.py index a301a515..7f7f2490 100644 --- a/google/cloud/devtools/cloudbuild_v1/services/cloud_build/client.py +++ b/google/cloud/devtools/cloudbuild_v1/services/cloud_build/client.py @@ -120,6 +120,22 @@ def _get_default_mtls_endpoint(api_endpoint): DEFAULT_ENDPOINT ) + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + CloudBuildClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_info(info) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials @@ -132,7 +148,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): kwargs: Additional arguments to pass to the constructor. Returns: - {@api.name}: The constructed client. + CloudBuildClient: The constructed client. """ credentials = service_account.Credentials.from_service_account_file(filename) kwargs["credentials"] = credentials @@ -264,10 +280,10 @@ def __init__( credentials identify the application to the service; if none are specified, the client will attempt to ascertain the credentials from the environment. - transport (Union[str, ~.CloudBuildTransport]): The + transport (Union[str, CloudBuildTransport]): The transport to use. If set to None, a transport is chosen automatically. - client_options (client_options_lib.ClientOptions): Custom options for the + client_options (google.api_core.client_options.ClientOptions): Custom options for the client. It won't take effect if a ``transport`` instance is provided. (1) The ``api_endpoint`` property can be used to override the default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT @@ -303,21 +319,17 @@ def __init__( util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")) ) - ssl_credentials = None + client_cert_source_func = None is_mtls = False if use_client_cert: if client_options.client_cert_source: - import grpc # type: ignore - - cert, key = client_options.client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) is_mtls = True + client_cert_source_func = client_options.client_cert_source else: - creds = SslCredentials() - is_mtls = creds.is_mtls - ssl_credentials = creds.ssl_credentials if is_mtls else None + is_mtls = mtls.has_default_client_cert_source() + client_cert_source_func = ( + mtls.default_client_cert_source() if is_mtls else None + ) # Figure out which api endpoint to use. if client_options.api_endpoint is not None: @@ -360,7 +372,7 @@ def __init__( credentials_file=client_options.credentials_file, host=api_endpoint, scopes=client_options.scopes, - ssl_channel_credentials=ssl_credentials, + client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, ) @@ -382,14 +394,14 @@ def create_build( build status (such as ``SUCCESS`` or ``FAILURE``). Args: - request (:class:`~.cloudbuild.CreateBuildRequest`): + request (google.cloud.devtools.cloudbuild_v1.types.CreateBuildRequest): The request object. Request to create a new build. - project_id (:class:`str`): + project_id (str): Required. ID of the project. This corresponds to the ``project_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - build (:class:`~.cloudbuild.Build`): + build (google.cloud.devtools.cloudbuild_v1.types.Build): Required. Build resource to create. This corresponds to the ``build`` field on the ``request`` instance; if ``request`` is provided, this @@ -402,33 +414,33 @@ def create_build( sent along with the request as metadata. Returns: - ~.operation.Operation: + google.api_core.operation.Operation: An object representing a long-running operation. The result type for the operation will be - :class:``~.cloudbuild.Build``: A build resource in the - Cloud Build API. - - At a high level, a ``Build`` describes where to find - source code, how to build it (for example, the builder - image to run on the source), and where to store the - built artifacts. - - Fields can include the following variables, which will - be expanded when the build is created: - - - $PROJECT_ID: the project ID of the build. - - $BUILD_ID: the autogenerated ID of the build. - - $REPO_NAME: the source repository name specified by - RepoSource. - - $BRANCH_NAME: the branch name specified by - RepoSource. - - $TAG_NAME: the tag name specified by RepoSource. - - $REVISION_ID or $COMMIT_SHA: the commit SHA specified - by RepoSource or resolved from the specified branch - or tag. - - $SHORT_SHA: first 7 characters of $REVISION_ID or - $COMMIT_SHA. + :class:`google.cloud.devtools.cloudbuild_v1.types.Build` A + build resource in the Cloud Build API. + + At a high level, a Build describes where to find + source code, how to build it (for example, the + builder image to run on the source), and where to + store the built artifacts. + + Fields can include the following variables, which + will be expanded when the build is created: + + - $PROJECT_ID: the project ID of the build. + - $BUILD_ID: the autogenerated ID of the build. + - $REPO_NAME: the source repository name specified + by RepoSource. + - $BRANCH_NAME: the branch name specified by + RepoSource. + - $TAG_NAME: the tag name specified by RepoSource. + - $REVISION_ID or $COMMIT_SHA: the commit SHA + specified by RepoSource or resolved from the + specified branch or tag. + - $SHORT_SHA: first 7 characters of $REVISION_ID or + $COMMIT_SHA. """ # Create or coerce a protobuf request object. @@ -491,14 +503,14 @@ def get_build( information. Args: - request (:class:`~.cloudbuild.GetBuildRequest`): + request (google.cloud.devtools.cloudbuild_v1.types.GetBuildRequest): The request object. Request to get a build. - project_id (:class:`str`): + project_id (str): Required. ID of the project. This corresponds to the ``project_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - id (:class:`str`): + id (str): Required. ID of the build. This corresponds to the ``id`` field on the ``request`` instance; if ``request`` is provided, this @@ -511,29 +523,29 @@ def get_build( sent along with the request as metadata. Returns: - ~.cloudbuild.Build: + google.cloud.devtools.cloudbuild_v1.types.Build: A build resource in the Cloud Build API. - At a high level, a ``Build`` describes where to find - source code, how to build it (for example, the builder - image to run on the source), and where to store the - built artifacts. - - Fields can include the following variables, which will - be expanded when the build is created: - - - $PROJECT_ID: the project ID of the build. - - $BUILD_ID: the autogenerated ID of the build. - - $REPO_NAME: the source repository name specified by - RepoSource. - - $BRANCH_NAME: the branch name specified by - RepoSource. - - $TAG_NAME: the tag name specified by RepoSource. - - $REVISION_ID or $COMMIT_SHA: the commit SHA specified - by RepoSource or resolved from the specified branch - or tag. - - $SHORT_SHA: first 7 characters of $REVISION_ID or - $COMMIT_SHA. + At a high level, a Build describes where to find + source code, how to build it (for example, the + builder image to run on the source), and where to + store the built artifacts. + + Fields can include the following variables, which + will be expanded when the build is created: + + - $PROJECT_ID: the project ID of the build. + - $BUILD_ID: the autogenerated ID of the build. + - $REPO_NAME: the source repository name specified + by RepoSource. + - $BRANCH_NAME: the branch name specified by + RepoSource. + - $TAG_NAME: the tag name specified by RepoSource. + - $REVISION_ID or $COMMIT_SHA: the commit SHA + specified by RepoSource or resolved from the + specified branch or tag. + - $SHORT_SHA: first 7 characters of $REVISION_ID or + $COMMIT_SHA. """ # Create or coerce a protobuf request object. @@ -586,16 +598,17 @@ def list_builds( may have finished successfully or unsuccessfully. Args: - request (:class:`~.cloudbuild.ListBuildsRequest`): + request (google.cloud.devtools.cloudbuild_v1.types.ListBuildsRequest): The request object. Request to list builds. - project_id (:class:`str`): + project_id (str): Required. ID of the project. This corresponds to the ``project_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - filter (:class:`str`): + filter (str): The raw filter text to constrain the results. + This corresponds to the ``filter`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -607,7 +620,7 @@ def list_builds( sent along with the request as metadata. Returns: - ~.pagers.ListBuildsPager: + google.cloud.devtools.cloudbuild_v1.services.cloud_build.pagers.ListBuildsPager: Response including listed builds. Iterating over this object will yield results and resolve additional pages @@ -668,14 +681,14 @@ def cancel_build( r"""Cancels a build in progress. Args: - request (:class:`~.cloudbuild.CancelBuildRequest`): + request (google.cloud.devtools.cloudbuild_v1.types.CancelBuildRequest): The request object. Request to cancel an ongoing build. - project_id (:class:`str`): + project_id (str): Required. ID of the project. This corresponds to the ``project_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - id (:class:`str`): + id (str): Required. ID of the build. This corresponds to the ``id`` field on the ``request`` instance; if ``request`` is provided, this @@ -688,29 +701,29 @@ def cancel_build( sent along with the request as metadata. Returns: - ~.cloudbuild.Build: + google.cloud.devtools.cloudbuild_v1.types.Build: A build resource in the Cloud Build API. - At a high level, a ``Build`` describes where to find - source code, how to build it (for example, the builder - image to run on the source), and where to store the - built artifacts. - - Fields can include the following variables, which will - be expanded when the build is created: - - - $PROJECT_ID: the project ID of the build. - - $BUILD_ID: the autogenerated ID of the build. - - $REPO_NAME: the source repository name specified by - RepoSource. - - $BRANCH_NAME: the branch name specified by - RepoSource. - - $TAG_NAME: the tag name specified by RepoSource. - - $REVISION_ID or $COMMIT_SHA: the commit SHA specified - by RepoSource or resolved from the specified branch - or tag. - - $SHORT_SHA: first 7 characters of $REVISION_ID or - $COMMIT_SHA. + At a high level, a Build describes where to find + source code, how to build it (for example, the + builder image to run on the source), and where to + store the built artifacts. + + Fields can include the following variables, which + will be expanded when the build is created: + + - $PROJECT_ID: the project ID of the build. + - $BUILD_ID: the autogenerated ID of the build. + - $REPO_NAME: the source repository name specified + by RepoSource. + - $BRANCH_NAME: the branch name specified by + RepoSource. + - $TAG_NAME: the tag name specified by RepoSource. + - $REVISION_ID or $COMMIT_SHA: the commit SHA + specified by RepoSource or resolved from the + specified branch or tag. + - $SHORT_SHA: first 7 characters of $REVISION_ID or + $COMMIT_SHA. """ # Create or coerce a protobuf request object. @@ -790,16 +803,17 @@ def retry_build( settings. Args: - request (:class:`~.cloudbuild.RetryBuildRequest`): + request (google.cloud.devtools.cloudbuild_v1.types.RetryBuildRequest): The request object. Specifies a build to retry. - project_id (:class:`str`): + project_id (str): Required. ID of the project. This corresponds to the ``project_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - id (:class:`str`): + id (str): Required. Build ID of the original build. + This corresponds to the ``id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -811,33 +825,33 @@ def retry_build( sent along with the request as metadata. Returns: - ~.operation.Operation: + google.api_core.operation.Operation: An object representing a long-running operation. The result type for the operation will be - :class:``~.cloudbuild.Build``: A build resource in the - Cloud Build API. - - At a high level, a ``Build`` describes where to find - source code, how to build it (for example, the builder - image to run on the source), and where to store the - built artifacts. - - Fields can include the following variables, which will - be expanded when the build is created: - - - $PROJECT_ID: the project ID of the build. - - $BUILD_ID: the autogenerated ID of the build. - - $REPO_NAME: the source repository name specified by - RepoSource. - - $BRANCH_NAME: the branch name specified by - RepoSource. - - $TAG_NAME: the tag name specified by RepoSource. - - $REVISION_ID or $COMMIT_SHA: the commit SHA specified - by RepoSource or resolved from the specified branch - or tag. - - $SHORT_SHA: first 7 characters of $REVISION_ID or - $COMMIT_SHA. + :class:`google.cloud.devtools.cloudbuild_v1.types.Build` A + build resource in the Cloud Build API. + + At a high level, a Build describes where to find + source code, how to build it (for example, the + builder image to run on the source), and where to + store the built artifacts. + + Fields can include the following variables, which + will be expanded when the build is created: + + - $PROJECT_ID: the project ID of the build. + - $BUILD_ID: the autogenerated ID of the build. + - $REPO_NAME: the source repository name specified + by RepoSource. + - $BRANCH_NAME: the branch name specified by + RepoSource. + - $TAG_NAME: the tag name specified by RepoSource. + - $REVISION_ID or $COMMIT_SHA: the commit SHA + specified by RepoSource or resolved from the + specified branch or tag. + - $SHORT_SHA: first 7 characters of $REVISION_ID or + $COMMIT_SHA. """ # Create or coerce a protobuf request object. @@ -898,16 +912,17 @@ def create_build_trigger( This API is experimental. Args: - request (:class:`~.cloudbuild.CreateBuildTriggerRequest`): + request (google.cloud.devtools.cloudbuild_v1.types.CreateBuildTriggerRequest): The request object. Request to create a new `BuildTrigger`. - project_id (:class:`str`): + project_id (str): Required. ID of the project for which to configure automatic builds. + This corresponds to the ``project_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - trigger (:class:`~.cloudbuild.BuildTrigger`): + trigger (google.cloud.devtools.cloudbuild_v1.types.BuildTrigger): Required. ``BuildTrigger`` to create. This corresponds to the ``trigger`` field on the ``request`` instance; if ``request`` is provided, this @@ -920,7 +935,7 @@ def create_build_trigger( sent along with the request as metadata. Returns: - ~.cloudbuild.BuildTrigger: + google.cloud.devtools.cloudbuild_v1.types.BuildTrigger: Configuration for an automated build in response to source repository changes. @@ -976,18 +991,20 @@ def get_build_trigger( This API is experimental. Args: - request (:class:`~.cloudbuild.GetBuildTriggerRequest`): + request (google.cloud.devtools.cloudbuild_v1.types.GetBuildTriggerRequest): The request object. Returns the `BuildTrigger` with the specified ID. - project_id (:class:`str`): + project_id (str): Required. ID of the project that owns the trigger. + This corresponds to the ``project_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - trigger_id (:class:`str`): + trigger_id (str): Required. Identifier (``id`` or ``name``) of the ``BuildTrigger`` to get. + This corresponds to the ``trigger_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -999,7 +1016,7 @@ def get_build_trigger( sent along with the request as metadata. Returns: - ~.cloudbuild.BuildTrigger: + google.cloud.devtools.cloudbuild_v1.types.BuildTrigger: Configuration for an automated build in response to source repository changes. @@ -1054,12 +1071,13 @@ def list_build_triggers( This API is experimental. Args: - request (:class:`~.cloudbuild.ListBuildTriggersRequest`): + request (google.cloud.devtools.cloudbuild_v1.types.ListBuildTriggersRequest): The request object. Request to list existing `BuildTriggers`. - project_id (:class:`str`): + project_id (str): Required. ID of the project for which to list BuildTriggers. + This corresponds to the ``project_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1071,8 +1089,8 @@ def list_build_triggers( sent along with the request as metadata. Returns: - ~.pagers.ListBuildTriggersPager: - Response containing existing ``BuildTriggers``. + google.cloud.devtools.cloudbuild_v1.services.cloud_build.pagers.ListBuildTriggersPager: + Response containing existing BuildTriggers. Iterating over this object will yield results and resolve additional pages automatically. @@ -1132,15 +1150,16 @@ def delete_build_trigger( This API is experimental. Args: - request (:class:`~.cloudbuild.DeleteBuildTriggerRequest`): + request (google.cloud.devtools.cloudbuild_v1.types.DeleteBuildTriggerRequest): The request object. Request to delete a `BuildTrigger`. - project_id (:class:`str`): + project_id (str): Required. ID of the project that owns the trigger. + This corresponds to the ``project_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - trigger_id (:class:`str`): + trigger_id (str): Required. ID of the ``BuildTrigger`` to delete. This corresponds to the ``trigger_id`` field on the ``request`` instance; if ``request`` is provided, this @@ -1202,21 +1221,22 @@ def update_build_trigger( This API is experimental. Args: - request (:class:`~.cloudbuild.UpdateBuildTriggerRequest`): + request (google.cloud.devtools.cloudbuild_v1.types.UpdateBuildTriggerRequest): The request object. Request to update an existing `BuildTrigger`. - project_id (:class:`str`): + project_id (str): Required. ID of the project that owns the trigger. + This corresponds to the ``project_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - trigger_id (:class:`str`): + trigger_id (str): Required. ID of the ``BuildTrigger`` to update. This corresponds to the ``trigger_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - trigger (:class:`~.cloudbuild.BuildTrigger`): + trigger (google.cloud.devtools.cloudbuild_v1.types.BuildTrigger): Required. ``BuildTrigger`` to update. This corresponds to the ``trigger`` field on the ``request`` instance; if ``request`` is provided, this @@ -1229,7 +1249,7 @@ def update_build_trigger( sent along with the request as metadata. Returns: - ~.cloudbuild.BuildTrigger: + google.cloud.devtools.cloudbuild_v1.types.BuildTrigger: Configuration for an automated build in response to source repository changes. @@ -1286,22 +1306,23 @@ def run_build_trigger( r"""Runs a ``BuildTrigger`` at a particular source revision. Args: - request (:class:`~.cloudbuild.RunBuildTriggerRequest`): + request (google.cloud.devtools.cloudbuild_v1.types.RunBuildTriggerRequest): The request object. Specifies a build trigger to run and the source to use. - project_id (:class:`str`): + project_id (str): Required. ID of the project. This corresponds to the ``project_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - trigger_id (:class:`str`): + trigger_id (str): Required. ID of the trigger. This corresponds to the ``trigger_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - source (:class:`~.cloudbuild.RepoSource`): + source (google.cloud.devtools.cloudbuild_v1.types.RepoSource): Required. Source to build against this trigger. + This corresponds to the ``source`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1313,33 +1334,33 @@ def run_build_trigger( sent along with the request as metadata. Returns: - ~.operation.Operation: + google.api_core.operation.Operation: An object representing a long-running operation. The result type for the operation will be - :class:``~.cloudbuild.Build``: A build resource in the - Cloud Build API. - - At a high level, a ``Build`` describes where to find - source code, how to build it (for example, the builder - image to run on the source), and where to store the - built artifacts. - - Fields can include the following variables, which will - be expanded when the build is created: - - - $PROJECT_ID: the project ID of the build. - - $BUILD_ID: the autogenerated ID of the build. - - $REPO_NAME: the source repository name specified by - RepoSource. - - $BRANCH_NAME: the branch name specified by - RepoSource. - - $TAG_NAME: the tag name specified by RepoSource. - - $REVISION_ID or $COMMIT_SHA: the commit SHA specified - by RepoSource or resolved from the specified branch - or tag. - - $SHORT_SHA: first 7 characters of $REVISION_ID or - $COMMIT_SHA. + :class:`google.cloud.devtools.cloudbuild_v1.types.Build` A + build resource in the Cloud Build API. + + At a high level, a Build describes where to find + source code, how to build it (for example, the + builder image to run on the source), and where to + store the built artifacts. + + Fields can include the following variables, which + will be expanded when the build is created: + + - $PROJECT_ID: the project ID of the build. + - $BUILD_ID: the autogenerated ID of the build. + - $REPO_NAME: the source repository name specified + by RepoSource. + - $BRANCH_NAME: the branch name specified by + RepoSource. + - $TAG_NAME: the tag name specified by RepoSource. + - $REVISION_ID or $COMMIT_SHA: the commit SHA + specified by RepoSource or resolved from the + specified branch or tag. + - $SHORT_SHA: first 7 characters of $REVISION_ID or + $COMMIT_SHA. """ # Create or coerce a protobuf request object. @@ -1401,7 +1422,7 @@ def create_worker_pool( This API is experimental. Args: - request (:class:`~.cloudbuild.CreateWorkerPoolRequest`): + request (google.cloud.devtools.cloudbuild_v1.types.CreateWorkerPoolRequest): The request object. Request to create a new `WorkerPool`. @@ -1412,7 +1433,7 @@ def create_worker_pool( sent along with the request as metadata. Returns: - ~.cloudbuild.WorkerPool: + google.cloud.devtools.cloudbuild_v1.types.WorkerPool: Configuration for a WorkerPool to run the builds. Workers are machines that Cloud Build @@ -1459,7 +1480,7 @@ def get_worker_pool( This API is experimental. Args: - request (:class:`~.cloudbuild.GetWorkerPoolRequest`): + request (google.cloud.devtools.cloudbuild_v1.types.GetWorkerPoolRequest): The request object. Request to get a `WorkerPool` with the specified name. @@ -1470,7 +1491,7 @@ def get_worker_pool( sent along with the request as metadata. Returns: - ~.cloudbuild.WorkerPool: + google.cloud.devtools.cloudbuild_v1.types.WorkerPool: Configuration for a WorkerPool to run the builds. Workers are machines that Cloud Build @@ -1517,7 +1538,7 @@ def delete_worker_pool( This API is experimental. Args: - request (:class:`~.cloudbuild.DeleteWorkerPoolRequest`): + request (google.cloud.devtools.cloudbuild_v1.types.DeleteWorkerPoolRequest): The request object. Request to delete a `WorkerPool`. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -1557,7 +1578,7 @@ def update_worker_pool( This API is experimental. Args: - request (:class:`~.cloudbuild.UpdateWorkerPoolRequest`): + request (google.cloud.devtools.cloudbuild_v1.types.UpdateWorkerPoolRequest): The request object. Request to update a `WorkerPool`. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -1567,7 +1588,7 @@ def update_worker_pool( sent along with the request as metadata. Returns: - ~.cloudbuild.WorkerPool: + google.cloud.devtools.cloudbuild_v1.types.WorkerPool: Configuration for a WorkerPool to run the builds. Workers are machines that Cloud Build @@ -1614,7 +1635,7 @@ def list_worker_pools( This API is experimental. Args: - request (:class:`~.cloudbuild.ListWorkerPoolsRequest`): + request (google.cloud.devtools.cloudbuild_v1.types.ListWorkerPoolsRequest): The request object. Request to list `WorkerPools`. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -1624,8 +1645,8 @@ def list_worker_pools( sent along with the request as metadata. Returns: - ~.cloudbuild.ListWorkerPoolsResponse: - Response containing existing ``WorkerPools``. + google.cloud.devtools.cloudbuild_v1.types.ListWorkerPoolsResponse: + Response containing existing WorkerPools. """ # Create or coerce a protobuf request object. diff --git a/google/cloud/devtools/cloudbuild_v1/services/cloud_build/pagers.py b/google/cloud/devtools/cloudbuild_v1/services/cloud_build/pagers.py index 52132bd1..ea592e48 100644 --- a/google/cloud/devtools/cloudbuild_v1/services/cloud_build/pagers.py +++ b/google/cloud/devtools/cloudbuild_v1/services/cloud_build/pagers.py @@ -15,7 +15,16 @@ # limitations under the License. # -from typing import Any, AsyncIterable, Awaitable, Callable, Iterable, Sequence, Tuple +from typing import ( + Any, + AsyncIterable, + Awaitable, + Callable, + Iterable, + Sequence, + Tuple, + Optional, +) from google.cloud.devtools.cloudbuild_v1.types import cloudbuild @@ -24,7 +33,7 @@ class ListBuildsPager: """A pager for iterating through ``list_builds`` requests. This class thinly wraps an initial - :class:`~.cloudbuild.ListBuildsResponse` object, and + :class:`google.cloud.devtools.cloudbuild_v1.types.ListBuildsResponse` object, and provides an ``__iter__`` method to iterate through its ``builds`` field. @@ -33,7 +42,7 @@ class ListBuildsPager: through the ``builds`` field on the corresponding responses. - All the usual :class:`~.cloudbuild.ListBuildsResponse` + All the usual :class:`google.cloud.devtools.cloudbuild_v1.types.ListBuildsResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -51,9 +60,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.cloudbuild.ListBuildsRequest`): + request (google.cloud.devtools.cloudbuild_v1.types.ListBuildsRequest): The initial request object. - response (:class:`~.cloudbuild.ListBuildsResponse`): + response (google.cloud.devtools.cloudbuild_v1.types.ListBuildsResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -86,7 +95,7 @@ class ListBuildsAsyncPager: """A pager for iterating through ``list_builds`` requests. This class thinly wraps an initial - :class:`~.cloudbuild.ListBuildsResponse` object, and + :class:`google.cloud.devtools.cloudbuild_v1.types.ListBuildsResponse` object, and provides an ``__aiter__`` method to iterate through its ``builds`` field. @@ -95,7 +104,7 @@ class ListBuildsAsyncPager: through the ``builds`` field on the corresponding responses. - All the usual :class:`~.cloudbuild.ListBuildsResponse` + All the usual :class:`google.cloud.devtools.cloudbuild_v1.types.ListBuildsResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -113,9 +122,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.cloudbuild.ListBuildsRequest`): + request (google.cloud.devtools.cloudbuild_v1.types.ListBuildsRequest): The initial request object. - response (:class:`~.cloudbuild.ListBuildsResponse`): + response (google.cloud.devtools.cloudbuild_v1.types.ListBuildsResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -152,7 +161,7 @@ class ListBuildTriggersPager: """A pager for iterating through ``list_build_triggers`` requests. This class thinly wraps an initial - :class:`~.cloudbuild.ListBuildTriggersResponse` object, and + :class:`google.cloud.devtools.cloudbuild_v1.types.ListBuildTriggersResponse` object, and provides an ``__iter__`` method to iterate through its ``triggers`` field. @@ -161,7 +170,7 @@ class ListBuildTriggersPager: through the ``triggers`` field on the corresponding responses. - All the usual :class:`~.cloudbuild.ListBuildTriggersResponse` + All the usual :class:`google.cloud.devtools.cloudbuild_v1.types.ListBuildTriggersResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -179,9 +188,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.cloudbuild.ListBuildTriggersRequest`): + request (google.cloud.devtools.cloudbuild_v1.types.ListBuildTriggersRequest): The initial request object. - response (:class:`~.cloudbuild.ListBuildTriggersResponse`): + response (google.cloud.devtools.cloudbuild_v1.types.ListBuildTriggersResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -214,7 +223,7 @@ class ListBuildTriggersAsyncPager: """A pager for iterating through ``list_build_triggers`` requests. This class thinly wraps an initial - :class:`~.cloudbuild.ListBuildTriggersResponse` object, and + :class:`google.cloud.devtools.cloudbuild_v1.types.ListBuildTriggersResponse` object, and provides an ``__aiter__`` method to iterate through its ``triggers`` field. @@ -223,7 +232,7 @@ class ListBuildTriggersAsyncPager: through the ``triggers`` field on the corresponding responses. - All the usual :class:`~.cloudbuild.ListBuildTriggersResponse` + All the usual :class:`google.cloud.devtools.cloudbuild_v1.types.ListBuildTriggersResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -241,9 +250,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.cloudbuild.ListBuildTriggersRequest`): + request (google.cloud.devtools.cloudbuild_v1.types.ListBuildTriggersRequest): The initial request object. - response (:class:`~.cloudbuild.ListBuildTriggersResponse`): + response (google.cloud.devtools.cloudbuild_v1.types.ListBuildTriggersResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. diff --git a/google/cloud/devtools/cloudbuild_v1/services/cloud_build/transports/grpc.py b/google/cloud/devtools/cloudbuild_v1/services/cloud_build/transports/grpc.py index 08951820..82503018 100644 --- a/google/cloud/devtools/cloudbuild_v1/services/cloud_build/transports/grpc.py +++ b/google/cloud/devtools/cloudbuild_v1/services/cloud_build/transports/grpc.py @@ -67,6 +67,7 @@ def __init__( api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -97,6 +98,10 @@ def __init__( ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials for grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -113,6 +118,11 @@ def __init__( """ self._ssl_channel_credentials = ssl_channel_credentials + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -122,11 +132,6 @@ def __init__( self._grpc_channel = channel self._ssl_channel_credentials = None elif api_mtls_endpoint: - warnings.warn( - "api_mtls_endpoint and client_cert_source are deprecated", - DeprecationWarning, - ) - host = ( api_mtls_endpoint if ":" in api_mtls_endpoint @@ -170,12 +175,18 @@ def __init__( scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id ) + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + # create a new channel. The provided one is ignored. self._grpc_channel = type(self).create_channel( host, credentials=credentials, credentials_file=credentials_file, - ssl_credentials=ssl_channel_credentials, + ssl_credentials=self._ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ diff --git a/google/cloud/devtools/cloudbuild_v1/services/cloud_build/transports/grpc_asyncio.py b/google/cloud/devtools/cloudbuild_v1/services/cloud_build/transports/grpc_asyncio.py index d16e3732..3b38f75b 100644 --- a/google/cloud/devtools/cloudbuild_v1/services/cloud_build/transports/grpc_asyncio.py +++ b/google/cloud/devtools/cloudbuild_v1/services/cloud_build/transports/grpc_asyncio.py @@ -111,6 +111,7 @@ def __init__( api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -142,6 +143,10 @@ def __init__( ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials for grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -158,6 +163,11 @@ def __init__( """ self._ssl_channel_credentials = ssl_channel_credentials + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -167,11 +177,6 @@ def __init__( self._grpc_channel = channel self._ssl_channel_credentials = None elif api_mtls_endpoint: - warnings.warn( - "api_mtls_endpoint and client_cert_source are deprecated", - DeprecationWarning, - ) - host = ( api_mtls_endpoint if ":" in api_mtls_endpoint @@ -215,12 +220,18 @@ def __init__( scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id ) + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + # create a new channel. The provided one is ignored. self._grpc_channel = type(self).create_channel( host, credentials=credentials, credentials_file=credentials_file, - ssl_credentials=ssl_channel_credentials, + ssl_credentials=self._ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ diff --git a/google/cloud/devtools/cloudbuild_v1/types/cloudbuild.py b/google/cloud/devtools/cloudbuild_v1/types/cloudbuild.py index ae9dca1a..d5c158a5 100644 --- a/google/cloud/devtools/cloudbuild_v1/types/cloudbuild.py +++ b/google/cloud/devtools/cloudbuild_v1/types/cloudbuild.py @@ -100,7 +100,7 @@ class RunBuildTriggerRequest(proto.Message): Required. ID of the project. trigger_id (str): Required. ID of the trigger. - source (~.cloudbuild.RepoSource): + source (google.cloud.devtools.cloudbuild_v1.types.RepoSource): Required. Source to build against this trigger. """ @@ -172,7 +172,7 @@ class RepoSource(proto.Message): invert_regex (bool): Only trigger a build if the revision regex does NOT match the revision regex. - substitutions (Sequence[~.cloudbuild.RepoSource.SubstitutionsEntry]): + substitutions (Sequence[google.cloud.devtools.cloudbuild_v1.types.RepoSource.SubstitutionsEntry]): Substitutions to use in a triggered build. Should only be used with RunBuildTrigger """ @@ -198,10 +198,10 @@ class Source(proto.Message): r"""Location of the source in a supported storage service. Attributes: - storage_source (~.cloudbuild.StorageSource): + storage_source (google.cloud.devtools.cloudbuild_v1.types.StorageSource): If provided, get the source from this location in Google Cloud Storage. - repo_source (~.cloudbuild.RepoSource): + repo_source (google.cloud.devtools.cloudbuild_v1.types.RepoSource): If provided, get the source from this location in a Cloud Source Repository. """ @@ -224,7 +224,7 @@ class BuiltImage(proto.Message): Registry, as presented to ``docker push``. digest (str): Docker Registry 2.0 digest. - push_timing (~.cloudbuild.TimeSpan): + push_timing (google.cloud.devtools.cloudbuild_v1.types.TimeSpan): Output only. Stores timing information for pushing the specified image. """ @@ -304,7 +304,7 @@ class BuildStep(proto.Message): A list of environment variables which are encrypted using a Cloud Key Management Service crypto key. These values must be specified in the build's ``Secret``. - volumes (Sequence[~.cloudbuild.Volume]): + volumes (Sequence[google.cloud.devtools.cloudbuild_v1.types.Volume]): List of volumes to mount into the build step. Each volume is created as an empty volume prior to execution of the build step. Upon completion @@ -314,18 +314,18 @@ class BuildStep(proto.Message): Using a named volume in only one step is not valid as it is indicative of a build request with an incorrect configuration. - timing (~.cloudbuild.TimeSpan): + timing (google.cloud.devtools.cloudbuild_v1.types.TimeSpan): Output only. Stores timing information for executing this build step. - pull_timing (~.cloudbuild.TimeSpan): + pull_timing (google.cloud.devtools.cloudbuild_v1.types.TimeSpan): Output only. Stores timing information for pulling this build step's builder image only. - timeout (~.duration.Duration): + timeout (google.protobuf.duration_pb2.Duration): Time limit for executing this build step. If not defined, the step has no time limit and will be allowed to continue to run until either it completes or the build itself times out. - status (~.cloudbuild.Build.Status): + status (google.cloud.devtools.cloudbuild_v1.types.Build.Status): Output only. Status of the build step. At this time, build step status is only updated on build completion; step status is not updated in @@ -387,7 +387,7 @@ class Results(proto.Message): r"""Artifacts created by the build pipeline. Attributes: - images (Sequence[~.cloudbuild.BuiltImage]): + images (Sequence[google.cloud.devtools.cloudbuild_v1.types.BuiltImage]): Container images that were built as a part of the build. build_step_images (Sequence[str]): @@ -408,7 +408,7 @@ class Results(proto.Message): can produce this output by writing to ``$BUILDER_OUTPUT/output``. Only the first 4KB of data is stored. - artifact_timing (~.cloudbuild.TimeSpan): + artifact_timing (google.cloud.devtools.cloudbuild_v1.types.TimeSpan): Time to push all non-container artifacts. """ @@ -434,7 +434,7 @@ class ArtifactResult(proto.Message): The path of an artifact in a Google Cloud Storage bucket, with the generation number. For example, ``gs://mybucket/path/to/output.jar#generation``. - file_hash (Sequence[~.cloudbuild.FileHashes]): + file_hash (Sequence[google.cloud.devtools.cloudbuild_v1.types.FileHashes]): The file hash of the artifact. """ @@ -472,31 +472,31 @@ class Build(proto.Message): Output only. Unique identifier of the build. project_id (str): Output only. ID of the project. - status (~.cloudbuild.Build.Status): + status (google.cloud.devtools.cloudbuild_v1.types.Build.Status): Output only. Status of the build. status_detail (str): Output only. Customer-readable message about the current status. - source (~.cloudbuild.Source): + source (google.cloud.devtools.cloudbuild_v1.types.Source): The location of the source files to build. - steps (Sequence[~.cloudbuild.BuildStep]): + steps (Sequence[google.cloud.devtools.cloudbuild_v1.types.BuildStep]): Required. The operations to be performed on the workspace. - results (~.cloudbuild.Results): + results (google.cloud.devtools.cloudbuild_v1.types.Results): Output only. Results of the build. - create_time (~.timestamp.Timestamp): + create_time (google.protobuf.timestamp_pb2.Timestamp): Output only. Time at which the request to create the build was received. - start_time (~.timestamp.Timestamp): + start_time (google.protobuf.timestamp_pb2.Timestamp): Output only. Time at which execution of the build was started. - finish_time (~.timestamp.Timestamp): + finish_time (google.protobuf.timestamp_pb2.Timestamp): Output only. Time at which execution of the build was finished. The difference between finish_time and start_time is the duration of the build's execution. - timeout (~.duration.Duration): + timeout (google.protobuf.duration_pb2.Duration): Amount of time that this build should be allowed to run, to second granularity. If this amount of time elapses, work on the build will cease and the build status will be @@ -517,13 +517,13 @@ class Build(proto.Message): If any of the images fail to be pushed, the build status is marked ``FAILURE``. - queue_ttl (~.duration.Duration): + queue_ttl (google.protobuf.duration_pb2.Duration): TTL in queue for this build. If provided and the build is enqueued longer than this value, the build will expire and the build status will be ``EXPIRED``. The TTL starts ticking from create_time. - artifacts (~.cloudbuild.Artifacts): + artifacts (google.cloud.devtools.cloudbuild_v1.types.Artifacts): Artifacts produced by the build that should be uploaded upon successful completion of all build steps. @@ -533,26 +533,26 @@ class Build(proto.Message): Requirements `__). Logs file names will be of the format ``${logs_bucket}/log-${build_id}.txt``. - source_provenance (~.cloudbuild.SourceProvenance): + source_provenance (google.cloud.devtools.cloudbuild_v1.types.SourceProvenance): Output only. A permanent fixed identifier for source. build_trigger_id (str): Output only. The ID of the ``BuildTrigger`` that triggered this build, if it was triggered automatically. - options (~.cloudbuild.BuildOptions): + options (google.cloud.devtools.cloudbuild_v1.types.BuildOptions): Special options for this build. log_url (str): Output only. URL to logs for this build in Google Cloud Console. - substitutions (Sequence[~.cloudbuild.Build.SubstitutionsEntry]): + substitutions (Sequence[google.cloud.devtools.cloudbuild_v1.types.Build.SubstitutionsEntry]): Substitutions data for ``Build`` resource. tags (Sequence[str]): Tags for annotation of a ``Build``. These are not docker tags. - secrets (Sequence[~.cloudbuild.Secret]): + secrets (Sequence[google.cloud.devtools.cloudbuild_v1.types.Secret]): Secrets to decrypt using Cloud Key Management Service. - timing (Sequence[~.cloudbuild.Build.TimingEntry]): + timing (Sequence[google.cloud.devtools.cloudbuild_v1.types.Build.TimingEntry]): Output only. Stores timing information for phases of the build. Valid keys are: @@ -652,7 +652,7 @@ class Artifacts(proto.Message): If any of the images fail to be pushed, the build is marked FAILURE. - objects (~.cloudbuild.Artifacts.ArtifactObjects): + objects (google.cloud.devtools.cloudbuild_v1.types.Artifacts.ArtifactObjects): A list of objects to be uploaded to Cloud Storage upon successful completion of all build steps. @@ -684,7 +684,7 @@ class ArtifactObjects(proto.Message): paths (Sequence[str]): Path globs used to match files in the build's workspace. - timing (~.cloudbuild.TimeSpan): + timing (google.cloud.devtools.cloudbuild_v1.types.TimeSpan): Output only. Stores timing information for pushing all artifact objects. """ @@ -704,9 +704,9 @@ class TimeSpan(proto.Message): r"""Start and end times for a build execution phase. Attributes: - start_time (~.timestamp.Timestamp): + start_time (google.protobuf.timestamp_pb2.Timestamp): Start of time span. - end_time (~.timestamp.Timestamp): + end_time (google.protobuf.timestamp_pb2.Timestamp): End of time span. """ @@ -719,7 +719,7 @@ class BuildOperationMetadata(proto.Message): r"""Metadata for build operations. Attributes: - build (~.cloudbuild.Build): + build (google.cloud.devtools.cloudbuild_v1.types.Build): The build that the operation is tracking. """ @@ -731,13 +731,13 @@ class SourceProvenance(proto.Message): or verify that some source was used for this build. Attributes: - resolved_storage_source (~.cloudbuild.StorageSource): + resolved_storage_source (google.cloud.devtools.cloudbuild_v1.types.StorageSource): A copy of the build's ``source.storage_source``, if exists, with any generations resolved. - resolved_repo_source (~.cloudbuild.RepoSource): + resolved_repo_source (google.cloud.devtools.cloudbuild_v1.types.RepoSource): A copy of the build's ``source.repo_source``, if exists, with any revisions resolved. - file_hashes (Sequence[~.cloudbuild.SourceProvenance.FileHashesEntry]): + file_hashes (Sequence[google.cloud.devtools.cloudbuild_v1.types.SourceProvenance.FileHashesEntry]): Output only. Hash(es) of the build source, which can be used to verify that the original source integrity was maintained in the build. Note that ``FileHashes`` will only be @@ -769,7 +769,7 @@ class FileHashes(proto.Message): to the build. Attributes: - file_hash (Sequence[~.cloudbuild.Hash]): + file_hash (Sequence[google.cloud.devtools.cloudbuild_v1.types.Hash]): Collection of file hashes. """ @@ -780,7 +780,7 @@ class Hash(proto.Message): r"""Container message for hash values. Attributes: - type_ (~.cloudbuild.Hash.HashType): + type_ (google.cloud.devtools.cloudbuild_v1.types.Hash.HashType): The type of hash that was performed. value (bytes): The hash value. @@ -806,7 +806,7 @@ class Secret(proto.Message): kms_key_name (str): Cloud KMS key name to use to decrypt these envs. - secret_env (Sequence[~.cloudbuild.Secret.SecretEnvEntry]): + secret_env (Sequence[google.cloud.devtools.cloudbuild_v1.types.Secret.SecretEnvEntry]): Map of environment variable name to its encrypted value. Secret environment variables must be unique @@ -830,7 +830,7 @@ class CreateBuildRequest(proto.Message): Format: ``projects/{project}/locations/{location}`` project_id (str): Required. ID of the project. - build (~.cloudbuild.Build): + build (google.cloud.devtools.cloudbuild_v1.types.Build): Required. Build resource to create. """ @@ -894,7 +894,7 @@ class ListBuildsResponse(proto.Message): r"""Response including listed builds. Attributes: - builds (Sequence[~.cloudbuild.Build]): + builds (Sequence[google.cloud.devtools.cloudbuild_v1.types.Build]): Builds will be sorted by ``create_time``, descending. next_page_token (str): Token to receive the next page of results. @@ -949,7 +949,7 @@ class BuildTrigger(proto.Message): character. tags (Sequence[str]): Tags for annotation of a ``BuildTrigger`` - trigger_template (~.cloudbuild.RepoSource): + trigger_template (google.cloud.devtools.cloudbuild_v1.types.RepoSource): Template describing the types of source changes to trigger a build. @@ -958,23 +958,23 @@ class BuildTrigger(proto.Message): that regular expression will trigger a build. Mutually exclusive with ``github``. - github (~.cloudbuild.GitHubEventsConfig): + github (google.cloud.devtools.cloudbuild_v1.types.GitHubEventsConfig): GitHubEventsConfig describes the configuration of a trigger that creates a build whenever a GitHub event is received. Mutually exclusive with ``trigger_template``. - build (~.cloudbuild.Build): + build (google.cloud.devtools.cloudbuild_v1.types.Build): Contents of the build template. filename (str): Path, from the source root, to a file whose contents is used for the template. - create_time (~.timestamp.Timestamp): + create_time (google.protobuf.timestamp_pb2.Timestamp): Output only. Time when the trigger was created. disabled (bool): If true, the trigger will never automatically execute a build. - substitutions (Sequence[~.cloudbuild.BuildTrigger.SubstitutionsEntry]): + substitutions (Sequence[google.cloud.devtools.cloudbuild_v1.types.BuildTrigger.SubstitutionsEntry]): Substitutions for Build resource. The keys must match the following regular expression: ``^_[A-Z0-9_]+$``. ignored_files (Sequence[str]): @@ -1049,9 +1049,9 @@ class GitHubEventsConfig(proto.Message): for https://github.com/googlecloudplatform/cloud- builders is "cloud-builders". - pull_request (~.cloudbuild.PullRequestFilter): + pull_request (google.cloud.devtools.cloudbuild_v1.types.PullRequestFilter): filter to match changes in pull requests. - push (~.cloudbuild.PushFilter): + push (google.cloud.devtools.cloudbuild_v1.types.PushFilter): filter to match changes in refs like branches, tags. """ @@ -1079,7 +1079,7 @@ class PullRequestFilter(proto.Message): The syntax of the regular expressions accepted is the syntax accepted by RE2 and described at https://github.com/google/re2/wiki/Syntax - comment_control (~.cloudbuild.PullRequestFilter.CommentControl): + comment_control (google.cloud.devtools.cloudbuild_v1.types.PullRequestFilter.CommentControl): Configure builds to run whether a repository owner or collaborator need to comment ``/gcbrun``. invert_regex (bool): @@ -1133,7 +1133,7 @@ class CreateBuildTriggerRequest(proto.Message): project_id (str): Required. ID of the project for which to configure automatic builds. - trigger (~.cloudbuild.BuildTrigger): + trigger (google.cloud.devtools.cloudbuild_v1.types.BuildTrigger): Required. ``BuildTrigger`` to create. """ @@ -1184,7 +1184,7 @@ class ListBuildTriggersResponse(proto.Message): r"""Response containing existing ``BuildTriggers``. Attributes: - triggers (Sequence[~.cloudbuild.BuildTrigger]): + triggers (Sequence[google.cloud.devtools.cloudbuild_v1.types.BuildTrigger]): ``BuildTriggers`` for the project, sorted by ``create_time`` descending. next_page_token (str): @@ -1225,7 +1225,7 @@ class UpdateBuildTriggerRequest(proto.Message): trigger. trigger_id (str): Required. ID of the ``BuildTrigger`` to update. - trigger (~.cloudbuild.BuildTrigger): + trigger (google.cloud.devtools.cloudbuild_v1.types.BuildTrigger): Required. ``BuildTrigger`` to update. """ @@ -1240,11 +1240,11 @@ class BuildOptions(proto.Message): r"""Optional arguments to enable specific features of builds. Attributes: - source_provenance_hash (Sequence[~.cloudbuild.Hash.HashType]): + source_provenance_hash (Sequence[google.cloud.devtools.cloudbuild_v1.types.Hash.HashType]): Requested hash for SourceProvenance. - requested_verify_option (~.cloudbuild.BuildOptions.VerifyOption): + requested_verify_option (google.cloud.devtools.cloudbuild_v1.types.BuildOptions.VerifyOption): Requested verifiability options. - machine_type (~.cloudbuild.BuildOptions.MachineType): + machine_type (google.cloud.devtools.cloudbuild_v1.types.BuildOptions.MachineType): Compute Engine machine type on which to run the build. disk_size_gb (int): @@ -1256,7 +1256,7 @@ class BuildOptions(proto.Message): requested. At present, the maximum disk size is 1000GB; builds that request more than the maximum are rejected with an error. - substitution_option (~.cloudbuild.BuildOptions.SubstitutionOption): + substitution_option (google.cloud.devtools.cloudbuild_v1.types.BuildOptions.SubstitutionOption): Option to specify behavior when there is an error in the substitution checks. @@ -1269,7 +1269,7 @@ class BuildOptions(proto.Message): NOTE: this is always enabled for triggered builds and cannot be overridden in the build configuration file. - log_streaming_option (~.cloudbuild.BuildOptions.LogStreamingOption): + log_streaming_option (google.cloud.devtools.cloudbuild_v1.types.BuildOptions.LogStreamingOption): Option to define build log streaming behavior to Google Cloud Storage. worker_pool (str): @@ -1277,7 +1277,7 @@ class BuildOptions(proto.Message): projects/{project}/locations/{location}/workerPools/{workerPool} This field is experimental. - logging (~.cloudbuild.BuildOptions.LoggingMode): + logging (google.cloud.devtools.cloudbuild_v1.types.BuildOptions.LoggingMode): Option to specify the logging mode, which determines if and where build logs are stored. env (Sequence[str]): @@ -1295,7 +1295,7 @@ class BuildOptions(proto.Message): values must be specified in the build's ``Secret``. These variables will be available to all build steps in this build. - volumes (Sequence[~.cloudbuild.Volume]): + volumes (Sequence[google.cloud.devtools.cloudbuild_v1.types.Volume]): Global list of volumes to mount for ALL build steps Each volume is created as an empty volume prior @@ -1398,26 +1398,26 @@ class WorkerPool(proto.Message): worker_count (int): Total number of workers to be created across all requested regions. - worker_config (~.cloudbuild.WorkerConfig): + worker_config (google.cloud.devtools.cloudbuild_v1.types.WorkerConfig): Configuration to be used for a creating workers in the ``WorkerPool``. - regions (Sequence[~.cloudbuild.WorkerPool.Region]): + regions (Sequence[google.cloud.devtools.cloudbuild_v1.types.WorkerPool.Region]): List of regions to create the ``WorkerPool``. Regions can't be empty. If Cloud Build adds a new GCP region in the future, the existing ``WorkerPool`` will not be enabled in the new region automatically; you must add the new region to the ``regions`` field to enable the ``WorkerPool`` in that region. - create_time (~.timestamp.Timestamp): + create_time (google.protobuf.timestamp_pb2.Timestamp): Output only. Time at which the request to create the ``WorkerPool`` was received. - update_time (~.timestamp.Timestamp): + update_time (google.protobuf.timestamp_pb2.Timestamp): Output only. Time at which the request to update the ``WorkerPool`` was received. - delete_time (~.timestamp.Timestamp): + delete_time (google.protobuf.timestamp_pb2.Timestamp): Output only. Time at which the request to delete the ``WorkerPool`` was received. - status (~.cloudbuild.WorkerPool.Status): + status (google.cloud.devtools.cloudbuild_v1.types.WorkerPool.Status): Output only. WorkerPool Status. """ @@ -1481,7 +1481,7 @@ class WorkerConfig(proto.Message): size specified in the ``build_options`` will be created on demand at build time. For more information see https://cloud.google.com/cloud-build/docs/api/reference/rest/v1/projects.builds#buildoptions - network (~.cloudbuild.Network): + network (google.cloud.devtools.cloudbuild_v1.types.Network): The network definition used to create the worker. If this section is left empty, the workers will be created in WorkerPool.project_id on the default network. @@ -1533,7 +1533,7 @@ class CreateWorkerPoolRequest(proto.Message): Attributes: parent (str): ID of the parent project. - worker_pool (~.cloudbuild.WorkerPool): + worker_pool (google.cloud.devtools.cloudbuild_v1.types.WorkerPool): ``WorkerPool`` resource to create. """ @@ -1576,7 +1576,7 @@ class UpdateWorkerPoolRequest(proto.Message): The field will contain name of the resource requested, for example: "projects/project-1/workerPools/workerpool-name". - worker_pool (~.cloudbuild.WorkerPool): + worker_pool (google.cloud.devtools.cloudbuild_v1.types.WorkerPool): ``WorkerPool`` resource to update. """ @@ -1600,7 +1600,7 @@ class ListWorkerPoolsResponse(proto.Message): r"""Response containing existing ``WorkerPools``. Attributes: - worker_pools (Sequence[~.cloudbuild.WorkerPool]): + worker_pools (Sequence[google.cloud.devtools.cloudbuild_v1.types.WorkerPool]): ``WorkerPools`` for the project. """ diff --git a/synth.metadata b/synth.metadata index 3f1b5306..44004b36 100644 --- a/synth.metadata +++ b/synth.metadata @@ -4,15 +4,15 @@ "git": { "name": ".", "remote": "https://github.com/googleapis/python-cloudbuild.git", - "sha": "f6727f06010876d8d6d6cd36bb2645c9bab1eca4" + "sha": "8be798a90b63d1f5abe730831e1d8c79b7993125" } }, { "git": { "name": "googleapis", "remote": "https://github.com/googleapis/googleapis.git", - "sha": "dd372aa22ded7a8ba6f0e03a80e06358a3fa0907", - "internalRef": "347055288" + "sha": "07932bb995e7dc91b43620ea8402c6668c7d102c", + "internalRef": "359562873" } }, { @@ -92,6 +92,7 @@ "MANIFEST.in", "docs/_static/custom.css", "docs/_templates/layout.html", + "docs/cloudbuild_v1/cloud_build.rst", "docs/cloudbuild_v1/services.rst", "docs/cloudbuild_v1/types.rst", "docs/conf.py", diff --git a/tests/unit/gapic/cloudbuild_v1/__init__.py b/tests/unit/gapic/cloudbuild_v1/__init__.py index 8b137891..42ffdf2b 100644 --- a/tests/unit/gapic/cloudbuild_v1/__init__.py +++ b/tests/unit/gapic/cloudbuild_v1/__init__.py @@ -1 +1,16 @@ +# -*- 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/cloudbuild_v1/test_cloud_build.py b/tests/unit/gapic/cloudbuild_v1/test_cloud_build.py index f2e43205..4aec130c 100644 --- a/tests/unit/gapic/cloudbuild_v1/test_cloud_build.py +++ b/tests/unit/gapic/cloudbuild_v1/test_cloud_build.py @@ -89,7 +89,22 @@ def test__get_default_mtls_endpoint(): assert CloudBuildClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi -@pytest.mark.parametrize("client_class", [CloudBuildClient, CloudBuildAsyncClient]) +@pytest.mark.parametrize("client_class", [CloudBuildClient, CloudBuildAsyncClient,]) +def test_cloud_build_client_from_service_account_info(client_class): + creds = credentials.AnonymousCredentials() + with mock.patch.object( + service_account.Credentials, "from_service_account_info" + ) as factory: + factory.return_value = creds + info = {"valid": True} + client = client_class.from_service_account_info(info) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + assert client.transport._host == "cloudbuild.googleapis.com:443" + + +@pytest.mark.parametrize("client_class", [CloudBuildClient, CloudBuildAsyncClient,]) def test_cloud_build_client_from_service_account_file(client_class): creds = credentials.AnonymousCredentials() with mock.patch.object( @@ -98,16 +113,21 @@ def test_cloud_build_client_from_service_account_file(client_class): factory.return_value = creds client = client_class.from_service_account_file("dummy/file/path.json") assert client.transport._credentials == creds + assert isinstance(client, client_class) client = client_class.from_service_account_json("dummy/file/path.json") assert client.transport._credentials == creds + assert isinstance(client, client_class) assert client.transport._host == "cloudbuild.googleapis.com:443" def test_cloud_build_client_get_transport_class(): transport = CloudBuildClient.get_transport_class() - assert transport == transports.CloudBuildGrpcTransport + available_transports = [ + transports.CloudBuildGrpcTransport, + ] + assert transport in available_transports transport = CloudBuildClient.get_transport_class("grpc") assert transport == transports.CloudBuildGrpcTransport @@ -156,7 +176,7 @@ def test_cloud_build_client_client_options( credentials_file=None, host="squid.clam.whelk", scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -172,7 +192,7 @@ def test_cloud_build_client_client_options( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -188,7 +208,7 @@ def test_cloud_build_client_client_options( credentials_file=None, host=client.DEFAULT_MTLS_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -216,7 +236,7 @@ def test_cloud_build_client_client_options( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -265,29 +285,25 @@ def test_cloud_build_client_mtls_env_auto( client_cert_source=client_cert_source_callback ) with mock.patch.object(transport_class, "__init__") as patched: - ssl_channel_creds = mock.Mock() - with mock.patch( - "grpc.ssl_channel_credentials", return_value=ssl_channel_creds - ): - patched.return_value = None - client = client_class(client_options=options) + patched.return_value = None + client = client_class(client_options=options) - if use_client_cert_env == "false": - expected_ssl_channel_creds = None - expected_host = client.DEFAULT_ENDPOINT - else: - expected_ssl_channel_creds = ssl_channel_creds - expected_host = client.DEFAULT_MTLS_ENDPOINT + if use_client_cert_env == "false": + expected_client_cert_source = None + expected_host = client.DEFAULT_ENDPOINT + else: + expected_client_cert_source = client_cert_source_callback + expected_host = client.DEFAULT_MTLS_ENDPOINT - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - ssl_channel_credentials=expected_ssl_channel_creds, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) # Check the case ADC client cert is provided. Whether client cert is used depends on # GOOGLE_API_USE_CLIENT_CERTIFICATE value. @@ -296,66 +312,53 @@ def test_cloud_build_client_mtls_env_auto( ): with mock.patch.object(transport_class, "__init__") as patched: with mock.patch( - "google.auth.transport.grpc.SslCredentials.__init__", return_value=None + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, ): with mock.patch( - "google.auth.transport.grpc.SslCredentials.is_mtls", - new_callable=mock.PropertyMock, - ) as is_mtls_mock: - with mock.patch( - "google.auth.transport.grpc.SslCredentials.ssl_credentials", - new_callable=mock.PropertyMock, - ) as ssl_credentials_mock: - if use_client_cert_env == "false": - is_mtls_mock.return_value = False - ssl_credentials_mock.return_value = None - expected_host = client.DEFAULT_ENDPOINT - expected_ssl_channel_creds = None - else: - is_mtls_mock.return_value = True - ssl_credentials_mock.return_value = mock.Mock() - expected_host = client.DEFAULT_MTLS_ENDPOINT - expected_ssl_channel_creds = ( - ssl_credentials_mock.return_value - ) - - patched.return_value = None - client = client_class() - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - ssl_channel_credentials=expected_ssl_channel_creds, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) + "google.auth.transport.mtls.default_client_cert_source", + return_value=client_cert_source_callback, + ): + if use_client_cert_env == "false": + expected_host = client.DEFAULT_ENDPOINT + expected_client_cert_source = None + else: + expected_host = client.DEFAULT_MTLS_ENDPOINT + expected_client_cert_source = client_cert_source_callback - # Check the case client_cert_source and ADC client cert are not provided. - with mock.patch.dict( - os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} - ): - with mock.patch.object(transport_class, "__init__") as patched: - with mock.patch( - "google.auth.transport.grpc.SslCredentials.__init__", return_value=None - ): - with mock.patch( - "google.auth.transport.grpc.SslCredentials.is_mtls", - new_callable=mock.PropertyMock, - ) as is_mtls_mock: - is_mtls_mock.return_value = False patched.return_value = None client = client_class() patched.assert_called_once_with( credentials=None, credentials_file=None, - host=client.DEFAULT_ENDPOINT, + host=expected_host, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) + # Check the case client_cert_source and ADC client cert are not provided. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + with mock.patch.object(transport_class, "__init__") as patched: + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + patched.return_value = None + client = client_class() + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -381,7 +384,7 @@ def test_cloud_build_client_client_options_scopes( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=["1", "2"], - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -411,7 +414,7 @@ def test_cloud_build_client_client_options_credentials_file( credentials_file="credentials.json", host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -428,7 +431,7 @@ def test_cloud_build_client_client_options_from_dict(): credentials_file=None, host="squid.clam.whelk", scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -466,6 +469,22 @@ def test_create_build_from_dict(): test_create_build(request_type=dict) +def test_create_build_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 = CloudBuildClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_build), "__call__") as call: + client.create_build() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudbuild.CreateBuildRequest() + + @pytest.mark.asyncio async def test_create_build_async( transport: str = "grpc_asyncio", request_type=cloudbuild.CreateBuildRequest @@ -646,6 +665,22 @@ def test_get_build_from_dict(): test_get_build(request_type=dict) +def test_get_build_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 = CloudBuildClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_build), "__call__") as call: + client.get_build() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudbuild.GetBuildRequest() + + @pytest.mark.asyncio async def test_get_build_async( transport: str = "grpc_asyncio", request_type=cloudbuild.GetBuildRequest @@ -824,6 +859,22 @@ def test_list_builds_from_dict(): test_list_builds(request_type=dict) +def test_list_builds_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 = CloudBuildClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_builds), "__call__") as call: + client.list_builds() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudbuild.ListBuildsRequest() + + @pytest.mark.asyncio async def test_list_builds_async( transport: str = "grpc_asyncio", request_type=cloudbuild.ListBuildsRequest @@ -1127,6 +1178,22 @@ def test_cancel_build_from_dict(): test_cancel_build(request_type=dict) +def test_cancel_build_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 = CloudBuildClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_build), "__call__") as call: + client.cancel_build() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudbuild.CancelBuildRequest() + + @pytest.mark.asyncio async def test_cancel_build_async( transport: str = "grpc_asyncio", request_type=cloudbuild.CancelBuildRequest @@ -1306,6 +1373,22 @@ def test_retry_build_from_dict(): test_retry_build(request_type=dict) +def test_retry_build_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 = CloudBuildClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.retry_build), "__call__") as call: + client.retry_build() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudbuild.RetryBuildRequest() + + @pytest.mark.asyncio async def test_retry_build_async( transport: str = "grpc_asyncio", request_type=cloudbuild.RetryBuildRequest @@ -1479,6 +1562,24 @@ def test_create_build_trigger_from_dict(): test_create_build_trigger(request_type=dict) +def test_create_build_trigger_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 = CloudBuildClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_build_trigger), "__call__" + ) as call: + client.create_build_trigger() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudbuild.CreateBuildTriggerRequest() + + @pytest.mark.asyncio async def test_create_build_trigger_async( transport: str = "grpc_asyncio", request_type=cloudbuild.CreateBuildTriggerRequest @@ -1682,6 +1783,24 @@ def test_get_build_trigger_from_dict(): test_get_build_trigger(request_type=dict) +def test_get_build_trigger_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 = CloudBuildClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_build_trigger), "__call__" + ) as call: + client.get_build_trigger() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudbuild.GetBuildTriggerRequest() + + @pytest.mark.asyncio async def test_get_build_trigger_async( transport: str = "grpc_asyncio", request_type=cloudbuild.GetBuildTriggerRequest @@ -1864,6 +1983,24 @@ def test_list_build_triggers_from_dict(): test_list_build_triggers(request_type=dict) +def test_list_build_triggers_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 = CloudBuildClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_build_triggers), "__call__" + ) as call: + client.list_build_triggers() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudbuild.ListBuildTriggersRequest() + + @pytest.mark.asyncio async def test_list_build_triggers_async( transport: str = "grpc_asyncio", request_type=cloudbuild.ListBuildTriggersRequest @@ -2154,6 +2291,24 @@ def test_delete_build_trigger_from_dict(): test_delete_build_trigger(request_type=dict) +def test_delete_build_trigger_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 = CloudBuildClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_build_trigger), "__call__" + ) as call: + client.delete_build_trigger() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudbuild.DeleteBuildTriggerRequest() + + @pytest.mark.asyncio async def test_delete_build_trigger_async( transport: str = "grpc_asyncio", request_type=cloudbuild.DeleteBuildTriggerRequest @@ -2329,6 +2484,24 @@ def test_update_build_trigger_from_dict(): test_update_build_trigger(request_type=dict) +def test_update_build_trigger_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 = CloudBuildClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_build_trigger), "__call__" + ) as call: + client.update_build_trigger() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudbuild.UpdateBuildTriggerRequest() + + @pytest.mark.asyncio async def test_update_build_trigger_async( transport: str = "grpc_asyncio", request_type=cloudbuild.UpdateBuildTriggerRequest @@ -2516,6 +2689,24 @@ def test_run_build_trigger_from_dict(): test_run_build_trigger(request_type=dict) +def test_run_build_trigger_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 = CloudBuildClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.run_build_trigger), "__call__" + ) as call: + client.run_build_trigger() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudbuild.RunBuildTriggerRequest() + + @pytest.mark.asyncio async def test_run_build_trigger_async( transport: str = "grpc_asyncio", request_type=cloudbuild.RunBuildTriggerRequest @@ -2701,6 +2892,24 @@ def test_create_worker_pool_from_dict(): test_create_worker_pool(request_type=dict) +def test_create_worker_pool_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 = CloudBuildClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_worker_pool), "__call__" + ) as call: + client.create_worker_pool() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudbuild.CreateWorkerPoolRequest() + + @pytest.mark.asyncio async def test_create_worker_pool_async( transport: str = "grpc_asyncio", request_type=cloudbuild.CreateWorkerPoolRequest @@ -2810,6 +3019,22 @@ def test_get_worker_pool_from_dict(): test_get_worker_pool(request_type=dict) +def test_get_worker_pool_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 = CloudBuildClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_worker_pool), "__call__") as call: + client.get_worker_pool() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudbuild.GetWorkerPoolRequest() + + @pytest.mark.asyncio async def test_get_worker_pool_async( transport: str = "grpc_asyncio", request_type=cloudbuild.GetWorkerPoolRequest @@ -2899,6 +3124,24 @@ def test_delete_worker_pool_from_dict(): test_delete_worker_pool(request_type=dict) +def test_delete_worker_pool_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 = CloudBuildClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_worker_pool), "__call__" + ) as call: + client.delete_worker_pool() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudbuild.DeleteWorkerPoolRequest() + + @pytest.mark.asyncio async def test_delete_worker_pool_async( transport: str = "grpc_asyncio", request_type=cloudbuild.DeleteWorkerPoolRequest @@ -2989,6 +3232,24 @@ def test_update_worker_pool_from_dict(): test_update_worker_pool(request_type=dict) +def test_update_worker_pool_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 = CloudBuildClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_worker_pool), "__call__" + ) as call: + client.update_worker_pool() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudbuild.UpdateWorkerPoolRequest() + + @pytest.mark.asyncio async def test_update_worker_pool_async( transport: str = "grpc_asyncio", request_type=cloudbuild.UpdateWorkerPoolRequest @@ -3081,6 +3342,24 @@ def test_list_worker_pools_from_dict(): test_list_worker_pools(request_type=dict) +def test_list_worker_pools_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 = CloudBuildClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_worker_pools), "__call__" + ) as call: + client.list_worker_pools() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudbuild.ListWorkerPoolsRequest() + + @pytest.mark.asyncio async def test_list_worker_pools_async( transport: str = "grpc_asyncio", request_type=cloudbuild.ListWorkerPoolsRequest @@ -3175,7 +3454,7 @@ def test_transport_get_channel(): @pytest.mark.parametrize( "transport_class", - [transports.CloudBuildGrpcTransport, transports.CloudBuildGrpcAsyncIOTransport], + [transports.CloudBuildGrpcTransport, transports.CloudBuildGrpcAsyncIOTransport,], ) def test_transport_adc(transport_class): # Test default credentials are used if not provided. @@ -3295,6 +3574,48 @@ def test_cloud_build_transport_auth_adc(): ) +@pytest.mark.parametrize( + "transport_class", + [transports.CloudBuildGrpcTransport, transports.CloudBuildGrpcAsyncIOTransport], +) +def test_cloud_build_grpc_transport_client_cert_source_for_mtls(transport_class): + cred = credentials.AnonymousCredentials() + + # Check ssl_channel_credentials is used if provided. + with mock.patch.object(transport_class, "create_channel") as mock_create_channel: + mock_ssl_channel_creds = mock.Mock() + transport_class( + host="squid.clam.whelk", + credentials=cred, + ssl_channel_credentials=mock_ssl_channel_creds, + ) + mock_create_channel.assert_called_once_with( + "squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=("https://www.googleapis.com/auth/cloud-platform",), + ssl_credentials=mock_ssl_channel_creds, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls + # is used. + with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): + with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: + transport_class( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback, + ) + expected_cert, expected_key = client_cert_source_callback() + mock_ssl_cred.assert_called_once_with( + certificate_chain=expected_cert, private_key=expected_key + ) + + def test_cloud_build_host_no_port(): client = CloudBuildClient( credentials=credentials.AnonymousCredentials(), @@ -3316,7 +3637,7 @@ def test_cloud_build_host_with_port(): def test_cloud_build_grpc_transport_channel(): - channel = grpc.insecure_channel("http://localhost/") + channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.CloudBuildGrpcTransport( @@ -3328,7 +3649,7 @@ def test_cloud_build_grpc_transport_channel(): def test_cloud_build_grpc_asyncio_transport_channel(): - channel = aio.insecure_channel("http://localhost/") + channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.CloudBuildGrpcAsyncIOTransport( @@ -3339,6 +3660,8 @@ def test_cloud_build_grpc_asyncio_transport_channel(): assert transport._ssl_channel_credentials == None +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. @pytest.mark.parametrize( "transport_class", [transports.CloudBuildGrpcTransport, transports.CloudBuildGrpcAsyncIOTransport], @@ -3348,7 +3671,7 @@ def test_cloud_build_transport_channel_mtls_with_client_cert_source(transport_cl "grpc.ssl_channel_credentials", autospec=True ) as grpc_ssl_channel_cred: with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_ssl_cred = mock.Mock() grpc_ssl_channel_cred.return_value = mock_ssl_cred @@ -3386,6 +3709,8 @@ def test_cloud_build_transport_channel_mtls_with_client_cert_source(transport_cl assert transport._ssl_channel_credentials == mock_ssl_cred +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. @pytest.mark.parametrize( "transport_class", [transports.CloudBuildGrpcTransport, transports.CloudBuildGrpcAsyncIOTransport], @@ -3398,7 +3723,7 @@ def test_cloud_build_transport_channel_mtls_with_adc(transport_class): ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), ): with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel