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

Commit

Permalink
feat: add common resource helpers; expose client transport (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshi-automation committed Dec 8, 2020
1 parent d0bed6d commit f9fc0f9
Show file tree
Hide file tree
Showing 18 changed files with 1,968 additions and 955 deletions.
1 change: 1 addition & 0 deletions docs/scheduler_v1/types.rst
Expand Up @@ -3,3 +3,4 @@ Types for Google Cloud Scheduler v1 API

.. automodule:: google.cloud.scheduler_v1.types
:members:
:show-inheritance:
1 change: 1 addition & 0 deletions docs/scheduler_v1beta1/types.rst
Expand Up @@ -3,3 +3,4 @@ Types for Google Cloud Scheduler v1beta1 API

.. automodule:: google.cloud.scheduler_v1beta1.types
:members:
:show-inheritance:
118 changes: 87 additions & 31 deletions google/cloud/scheduler_v1/services/cloud_scheduler/async_client.py
Expand Up @@ -38,7 +38,7 @@
from google.protobuf import timestamp_pb2 as timestamp # type: ignore
from google.rpc import status_pb2 as status # type: ignore

from .transports.base import CloudSchedulerTransport
from .transports.base import CloudSchedulerTransport, DEFAULT_CLIENT_INFO
from .transports.grpc_asyncio import CloudSchedulerGrpcAsyncIOTransport
from .client import CloudSchedulerClient

Expand All @@ -54,10 +54,51 @@ class CloudSchedulerAsyncClient:
DEFAULT_MTLS_ENDPOINT = CloudSchedulerClient.DEFAULT_MTLS_ENDPOINT

job_path = staticmethod(CloudSchedulerClient.job_path)
parse_job_path = staticmethod(CloudSchedulerClient.parse_job_path)
topic_path = staticmethod(CloudSchedulerClient.topic_path)
parse_topic_path = staticmethod(CloudSchedulerClient.parse_topic_path)

common_billing_account_path = staticmethod(
CloudSchedulerClient.common_billing_account_path
)
parse_common_billing_account_path = staticmethod(
CloudSchedulerClient.parse_common_billing_account_path
)

common_folder_path = staticmethod(CloudSchedulerClient.common_folder_path)
parse_common_folder_path = staticmethod(
CloudSchedulerClient.parse_common_folder_path
)

common_organization_path = staticmethod(
CloudSchedulerClient.common_organization_path
)
parse_common_organization_path = staticmethod(
CloudSchedulerClient.parse_common_organization_path
)

common_project_path = staticmethod(CloudSchedulerClient.common_project_path)
parse_common_project_path = staticmethod(
CloudSchedulerClient.parse_common_project_path
)

common_location_path = staticmethod(CloudSchedulerClient.common_location_path)
parse_common_location_path = staticmethod(
CloudSchedulerClient.parse_common_location_path
)

from_service_account_file = CloudSchedulerClient.from_service_account_file
from_service_account_json = from_service_account_file

@property
def transport(self) -> CloudSchedulerTransport:
"""Return the transport used by the client instance.
Returns:
CloudSchedulerTransport: The transport used by the client instance.
"""
return self._client.transport

get_transport_class = functools.partial(
type(CloudSchedulerClient).get_transport_class, type(CloudSchedulerClient)
)
Expand All @@ -68,6 +109,7 @@ def __init__(
credentials: credentials.Credentials = None,
transport: Union[str, CloudSchedulerTransport] = "grpc_asyncio",
client_options: ClientOptions = None,
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
) -> None:
"""Instantiate the cloud scheduler client.
Expand All @@ -83,24 +125,30 @@ def __init__(
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
default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT
environment variable can also be used to override the endpoint:
"always" (always use the default mTLS endpoint), "never" (always
use the default regular endpoint, this is the default value for
the environment variable) and "auto" (auto switch to the default
mTLS endpoint if client SSL credentials is present). However,
the ``api_endpoint`` property takes precedence if provided.
(2) The ``client_cert_source`` property is used to provide client
SSL credentials for mutual TLS transport. If not provided, the
default SSL credentials will be used if present.
use the default regular endpoint) and "auto" (auto switch to the
default mTLS endpoint if client certificate is present, this is
the default value). However, the ``api_endpoint`` property takes
precedence if provided.
(2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable
is "true", then the ``client_cert_source`` property can be used
to provide client certificate for mutual TLS transport. If
not provided, the default SSL client certificate will be used if
present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not
set, no client certificate will be used.
Raises:
google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
creation failed for any reason.
"""

self._client = CloudSchedulerClient(
credentials=credentials, transport=transport, client_options=client_options,
credentials=credentials,
transport=transport,
client_options=client_options,
client_info=client_info,
)

async def list_jobs(
Expand Down Expand Up @@ -144,7 +192,8 @@ async def list_jobs(
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
if request is not None and any([parent]):
has_flattened_params = any([parent])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
"the individual field arguments should be set."
Expand All @@ -167,11 +216,11 @@ async def list_jobs(
maximum=60.0,
multiplier=1.3,
predicate=retries.if_exception_type(
exceptions.ServiceUnavailable, exceptions.DeadlineExceeded,
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
),
),
default_timeout=600.0,
client_info=_client_info,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
Expand Down Expand Up @@ -230,7 +279,8 @@ async def get_job(
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
if request is not None and any([name]):
has_flattened_params = any([name])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
"the individual field arguments should be set."
Expand All @@ -253,11 +303,11 @@ async def get_job(
maximum=60.0,
multiplier=1.3,
predicate=retries.if_exception_type(
exceptions.ServiceUnavailable, exceptions.DeadlineExceeded,
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
),
),
default_timeout=600.0,
client_info=_client_info,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
Expand Down Expand Up @@ -323,7 +373,8 @@ async def create_job(
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
if request is not None and any([parent, job]):
has_flattened_params = any([parent, job])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
"the individual field arguments should be set."
Expand All @@ -344,7 +395,7 @@ async def create_job(
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.create_job,
default_timeout=600.0,
client_info=_client_info,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
Expand Down Expand Up @@ -420,7 +471,8 @@ async def update_job(
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
if request is not None and any([job, update_mask]):
has_flattened_params = any([job, update_mask])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
"the individual field arguments should be set."
Expand All @@ -441,7 +493,7 @@ async def update_job(
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.update_job,
default_timeout=600.0,
client_info=_client_info,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
Expand Down Expand Up @@ -488,7 +540,8 @@ async def delete_job(
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
if request is not None and any([name]):
has_flattened_params = any([name])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
"the individual field arguments should be set."
Expand All @@ -511,11 +564,11 @@ async def delete_job(
maximum=60.0,
multiplier=1.3,
predicate=retries.if_exception_type(
exceptions.ServiceUnavailable, exceptions.DeadlineExceeded,
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
),
),
default_timeout=600.0,
client_info=_client_info,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
Expand Down Expand Up @@ -578,7 +631,8 @@ async def pause_job(
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
if request is not None and any([name]):
has_flattened_params = any([name])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
"the individual field arguments should be set."
Expand All @@ -597,7 +651,7 @@ async def pause_job(
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.pause_job,
default_timeout=600.0,
client_info=_client_info,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
Expand Down Expand Up @@ -660,7 +714,8 @@ async def resume_job(
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
if request is not None and any([name]):
has_flattened_params = any([name])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
"the individual field arguments should be set."
Expand All @@ -679,7 +734,7 @@ async def resume_job(
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.resume_job,
default_timeout=600.0,
client_info=_client_info,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
Expand Down Expand Up @@ -735,7 +790,8 @@ async def run_job(
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
if request is not None and any([name]):
has_flattened_params = any([name])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
"the individual field arguments should be set."
Expand All @@ -754,7 +810,7 @@ async def run_job(
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.run_job,
default_timeout=600.0,
client_info=_client_info,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
Expand All @@ -771,11 +827,11 @@ async def run_job(


try:
_client_info = gapic_v1.client_info.ClientInfo(
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
gapic_version=pkg_resources.get_distribution("google-cloud-scheduler",).version,
)
except pkg_resources.DistributionNotFound:
_client_info = gapic_v1.client_info.ClientInfo()
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo()


__all__ = ("CloudSchedulerAsyncClient",)

0 comments on commit f9fc0f9

Please sign in to comment.