Skip to content
This repository has been archived by the owner on Dec 31, 2023. It is now read-only.

Commit

Permalink
feat: add from_service_account_info (#52)
Browse files Browse the repository at this point in the history
This PR was generated using Autosynth. 🌈

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: googleapis/googleapis@07932bb
PiperOrigin-RevId: 355923884
Source-Link: googleapis/googleapis@5e3dace
PiperOrigin-RevId: 354996675
Source-Link: googleapis/googleapis@20712b8
PiperOrigin-RevId: 352816749
Source-Link: googleapis/googleapis@ceaaf31
PiperOrigin-RevId: 350388717
Source-Link: googleapis/googleapis@dd1d232
PiperOrigin-RevId: 350246057
Source-Link: googleapis/googleapis@5206824
  • Loading branch information
yoshi-automation committed Mar 23, 2021
1 parent 673fa1c commit 580a959
Show file tree
Hide file tree
Showing 13 changed files with 954 additions and 510 deletions.
11 changes: 11 additions & 0 deletions 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:
6 changes: 3 additions & 3 deletions 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
1 change: 1 addition & 0 deletions docs/cloudbuild_v1/types.rst
Expand Up @@ -3,4 +3,5 @@ Types for Google Devtools Cloudbuild v1 API

.. automodule:: google.cloud.devtools.cloudbuild_v1.types
:members:
:undoc-members:
:show-inheritance:
1 change: 1 addition & 0 deletions google/cloud/devtools/cloudbuild_v1/proto/cloudbuild.proto
Expand Up @@ -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";
Expand Down
330 changes: 184 additions & 146 deletions google/cloud/devtools/cloudbuild_v1/services/cloud_build/async_client.py

Large diffs are not rendered by default.

377 changes: 199 additions & 178 deletions google/cloud/devtools/cloudbuild_v1/services/cloud_build/client.py

Large diffs are not rendered by default.

43 changes: 26 additions & 17 deletions google/cloud/devtools/cloudbuild_v1/services/cloud_build/pagers.py
Expand Up @@ -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

Expand All @@ -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.
Expand All @@ -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.
"""
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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.
"""
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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.
"""
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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.
"""
Expand All @@ -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.
Expand Down
Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand All @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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=[
Expand Down
Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand All @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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=[
Expand Down

0 comments on commit 580a959

Please sign in to comment.