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

Commit f9fc0f9

Browse files
feat: add common resource helpers; expose client transport (#41)
1 parent d0bed6d commit f9fc0f9

File tree

18 files changed

+1968
-955
lines changed

18 files changed

+1968
-955
lines changed

docs/scheduler_v1/types.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ Types for Google Cloud Scheduler v1 API
33

44
.. automodule:: google.cloud.scheduler_v1.types
55
:members:
6+
:show-inheritance:

docs/scheduler_v1beta1/types.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ Types for Google Cloud Scheduler v1beta1 API
33

44
.. automodule:: google.cloud.scheduler_v1beta1.types
55
:members:
6+
:show-inheritance:

google/cloud/scheduler_v1/services/cloud_scheduler/async_client.py

Lines changed: 87 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
from google.protobuf import timestamp_pb2 as timestamp # type: ignore
3939
from google.rpc import status_pb2 as status # type: ignore
4040

41-
from .transports.base import CloudSchedulerTransport
41+
from .transports.base import CloudSchedulerTransport, DEFAULT_CLIENT_INFO
4242
from .transports.grpc_asyncio import CloudSchedulerGrpcAsyncIOTransport
4343
from .client import CloudSchedulerClient
4444

@@ -54,10 +54,51 @@ class CloudSchedulerAsyncClient:
5454
DEFAULT_MTLS_ENDPOINT = CloudSchedulerClient.DEFAULT_MTLS_ENDPOINT
5555

5656
job_path = staticmethod(CloudSchedulerClient.job_path)
57+
parse_job_path = staticmethod(CloudSchedulerClient.parse_job_path)
58+
topic_path = staticmethod(CloudSchedulerClient.topic_path)
59+
parse_topic_path = staticmethod(CloudSchedulerClient.parse_topic_path)
60+
61+
common_billing_account_path = staticmethod(
62+
CloudSchedulerClient.common_billing_account_path
63+
)
64+
parse_common_billing_account_path = staticmethod(
65+
CloudSchedulerClient.parse_common_billing_account_path
66+
)
67+
68+
common_folder_path = staticmethod(CloudSchedulerClient.common_folder_path)
69+
parse_common_folder_path = staticmethod(
70+
CloudSchedulerClient.parse_common_folder_path
71+
)
72+
73+
common_organization_path = staticmethod(
74+
CloudSchedulerClient.common_organization_path
75+
)
76+
parse_common_organization_path = staticmethod(
77+
CloudSchedulerClient.parse_common_organization_path
78+
)
79+
80+
common_project_path = staticmethod(CloudSchedulerClient.common_project_path)
81+
parse_common_project_path = staticmethod(
82+
CloudSchedulerClient.parse_common_project_path
83+
)
84+
85+
common_location_path = staticmethod(CloudSchedulerClient.common_location_path)
86+
parse_common_location_path = staticmethod(
87+
CloudSchedulerClient.parse_common_location_path
88+
)
5789

5890
from_service_account_file = CloudSchedulerClient.from_service_account_file
5991
from_service_account_json = from_service_account_file
6092

93+
@property
94+
def transport(self) -> CloudSchedulerTransport:
95+
"""Return the transport used by the client instance.
96+
97+
Returns:
98+
CloudSchedulerTransport: The transport used by the client instance.
99+
"""
100+
return self._client.transport
101+
61102
get_transport_class = functools.partial(
62103
type(CloudSchedulerClient).get_transport_class, type(CloudSchedulerClient)
63104
)
@@ -68,6 +109,7 @@ def __init__(
68109
credentials: credentials.Credentials = None,
69110
transport: Union[str, CloudSchedulerTransport] = "grpc_asyncio",
70111
client_options: ClientOptions = None,
112+
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
71113
) -> None:
72114
"""Instantiate the cloud scheduler client.
73115
@@ -83,24 +125,30 @@ def __init__(
83125
client_options (ClientOptions): Custom options for the client. It
84126
won't take effect if a ``transport`` instance is provided.
85127
(1) The ``api_endpoint`` property can be used to override the
86-
default endpoint provided by the client. GOOGLE_API_USE_MTLS
128+
default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT
87129
environment variable can also be used to override the endpoint:
88130
"always" (always use the default mTLS endpoint), "never" (always
89-
use the default regular endpoint, this is the default value for
90-
the environment variable) and "auto" (auto switch to the default
91-
mTLS endpoint if client SSL credentials is present). However,
92-
the ``api_endpoint`` property takes precedence if provided.
93-
(2) The ``client_cert_source`` property is used to provide client
94-
SSL credentials for mutual TLS transport. If not provided, the
95-
default SSL credentials will be used if present.
131+
use the default regular endpoint) and "auto" (auto switch to the
132+
default mTLS endpoint if client certificate is present, this is
133+
the default value). However, the ``api_endpoint`` property takes
134+
precedence if provided.
135+
(2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable
136+
is "true", then the ``client_cert_source`` property can be used
137+
to provide client certificate for mutual TLS transport. If
138+
not provided, the default SSL client certificate will be used if
139+
present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not
140+
set, no client certificate will be used.
96141
97142
Raises:
98143
google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
99144
creation failed for any reason.
100145
"""
101146

102147
self._client = CloudSchedulerClient(
103-
credentials=credentials, transport=transport, client_options=client_options,
148+
credentials=credentials,
149+
transport=transport,
150+
client_options=client_options,
151+
client_info=client_info,
104152
)
105153

106154
async def list_jobs(
@@ -144,7 +192,8 @@ async def list_jobs(
144192
# Create or coerce a protobuf request object.
145193
# Sanity check: If we got a request object, we should *not* have
146194
# gotten any keyword arguments that map to the request.
147-
if request is not None and any([parent]):
195+
has_flattened_params = any([parent])
196+
if request is not None and has_flattened_params:
148197
raise ValueError(
149198
"If the `request` argument is set, then none of "
150199
"the individual field arguments should be set."
@@ -167,11 +216,11 @@ async def list_jobs(
167216
maximum=60.0,
168217
multiplier=1.3,
169218
predicate=retries.if_exception_type(
170-
exceptions.ServiceUnavailable, exceptions.DeadlineExceeded,
219+
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
171220
),
172221
),
173222
default_timeout=600.0,
174-
client_info=_client_info,
223+
client_info=DEFAULT_CLIENT_INFO,
175224
)
176225

177226
# Certain fields should be provided within the metadata header;
@@ -230,7 +279,8 @@ async def get_job(
230279
# Create or coerce a protobuf request object.
231280
# Sanity check: If we got a request object, we should *not* have
232281
# gotten any keyword arguments that map to the request.
233-
if request is not None and any([name]):
282+
has_flattened_params = any([name])
283+
if request is not None and has_flattened_params:
234284
raise ValueError(
235285
"If the `request` argument is set, then none of "
236286
"the individual field arguments should be set."
@@ -253,11 +303,11 @@ async def get_job(
253303
maximum=60.0,
254304
multiplier=1.3,
255305
predicate=retries.if_exception_type(
256-
exceptions.ServiceUnavailable, exceptions.DeadlineExceeded,
306+
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
257307
),
258308
),
259309
default_timeout=600.0,
260-
client_info=_client_info,
310+
client_info=DEFAULT_CLIENT_INFO,
261311
)
262312

263313
# Certain fields should be provided within the metadata header;
@@ -323,7 +373,8 @@ async def create_job(
323373
# Create or coerce a protobuf request object.
324374
# Sanity check: If we got a request object, we should *not* have
325375
# gotten any keyword arguments that map to the request.
326-
if request is not None and any([parent, job]):
376+
has_flattened_params = any([parent, job])
377+
if request is not None and has_flattened_params:
327378
raise ValueError(
328379
"If the `request` argument is set, then none of "
329380
"the individual field arguments should be set."
@@ -344,7 +395,7 @@ async def create_job(
344395
rpc = gapic_v1.method_async.wrap_method(
345396
self._client._transport.create_job,
346397
default_timeout=600.0,
347-
client_info=_client_info,
398+
client_info=DEFAULT_CLIENT_INFO,
348399
)
349400

350401
# Certain fields should be provided within the metadata header;
@@ -420,7 +471,8 @@ async def update_job(
420471
# Create or coerce a protobuf request object.
421472
# Sanity check: If we got a request object, we should *not* have
422473
# gotten any keyword arguments that map to the request.
423-
if request is not None and any([job, update_mask]):
474+
has_flattened_params = any([job, update_mask])
475+
if request is not None and has_flattened_params:
424476
raise ValueError(
425477
"If the `request` argument is set, then none of "
426478
"the individual field arguments should be set."
@@ -441,7 +493,7 @@ async def update_job(
441493
rpc = gapic_v1.method_async.wrap_method(
442494
self._client._transport.update_job,
443495
default_timeout=600.0,
444-
client_info=_client_info,
496+
client_info=DEFAULT_CLIENT_INFO,
445497
)
446498

447499
# Certain fields should be provided within the metadata header;
@@ -488,7 +540,8 @@ async def delete_job(
488540
# Create or coerce a protobuf request object.
489541
# Sanity check: If we got a request object, we should *not* have
490542
# gotten any keyword arguments that map to the request.
491-
if request is not None and any([name]):
543+
has_flattened_params = any([name])
544+
if request is not None and has_flattened_params:
492545
raise ValueError(
493546
"If the `request` argument is set, then none of "
494547
"the individual field arguments should be set."
@@ -511,11 +564,11 @@ async def delete_job(
511564
maximum=60.0,
512565
multiplier=1.3,
513566
predicate=retries.if_exception_type(
514-
exceptions.ServiceUnavailable, exceptions.DeadlineExceeded,
567+
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
515568
),
516569
),
517570
default_timeout=600.0,
518-
client_info=_client_info,
571+
client_info=DEFAULT_CLIENT_INFO,
519572
)
520573

521574
# Certain fields should be provided within the metadata header;
@@ -578,7 +631,8 @@ async def pause_job(
578631
# Create or coerce a protobuf request object.
579632
# Sanity check: If we got a request object, we should *not* have
580633
# gotten any keyword arguments that map to the request.
581-
if request is not None and any([name]):
634+
has_flattened_params = any([name])
635+
if request is not None and has_flattened_params:
582636
raise ValueError(
583637
"If the `request` argument is set, then none of "
584638
"the individual field arguments should be set."
@@ -597,7 +651,7 @@ async def pause_job(
597651
rpc = gapic_v1.method_async.wrap_method(
598652
self._client._transport.pause_job,
599653
default_timeout=600.0,
600-
client_info=_client_info,
654+
client_info=DEFAULT_CLIENT_INFO,
601655
)
602656

603657
# Certain fields should be provided within the metadata header;
@@ -660,7 +714,8 @@ async def resume_job(
660714
# Create or coerce a protobuf request object.
661715
# Sanity check: If we got a request object, we should *not* have
662716
# gotten any keyword arguments that map to the request.
663-
if request is not None and any([name]):
717+
has_flattened_params = any([name])
718+
if request is not None and has_flattened_params:
664719
raise ValueError(
665720
"If the `request` argument is set, then none of "
666721
"the individual field arguments should be set."
@@ -679,7 +734,7 @@ async def resume_job(
679734
rpc = gapic_v1.method_async.wrap_method(
680735
self._client._transport.resume_job,
681736
default_timeout=600.0,
682-
client_info=_client_info,
737+
client_info=DEFAULT_CLIENT_INFO,
683738
)
684739

685740
# Certain fields should be provided within the metadata header;
@@ -735,7 +790,8 @@ async def run_job(
735790
# Create or coerce a protobuf request object.
736791
# Sanity check: If we got a request object, we should *not* have
737792
# gotten any keyword arguments that map to the request.
738-
if request is not None and any([name]):
793+
has_flattened_params = any([name])
794+
if request is not None and has_flattened_params:
739795
raise ValueError(
740796
"If the `request` argument is set, then none of "
741797
"the individual field arguments should be set."
@@ -754,7 +810,7 @@ async def run_job(
754810
rpc = gapic_v1.method_async.wrap_method(
755811
self._client._transport.run_job,
756812
default_timeout=600.0,
757-
client_info=_client_info,
813+
client_info=DEFAULT_CLIENT_INFO,
758814
)
759815

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

772828

773829
try:
774-
_client_info = gapic_v1.client_info.ClientInfo(
830+
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
775831
gapic_version=pkg_resources.get_distribution("google-cloud-scheduler",).version,
776832
)
777833
except pkg_resources.DistributionNotFound:
778-
_client_info = gapic_v1.client_info.ClientInfo()
834+
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo()
779835

780836

781837
__all__ = ("CloudSchedulerAsyncClient",)

0 commit comments

Comments
 (0)