32
32
from google .protobuf import duration_pb2 as duration # type: ignore
33
33
from google .protobuf import timestamp_pb2 as timestamp # type: ignore
34
34
35
- from .transports .base import IAMCredentialsTransport
35
+ from .transports .base import IAMCredentialsTransport , DEFAULT_CLIENT_INFO
36
36
from .transports .grpc_asyncio import IAMCredentialsGrpcAsyncIOTransport
37
37
from .client import IAMCredentialsClient
38
38
@@ -55,9 +55,52 @@ class IAMCredentialsAsyncClient:
55
55
DEFAULT_ENDPOINT = IAMCredentialsClient .DEFAULT_ENDPOINT
56
56
DEFAULT_MTLS_ENDPOINT = IAMCredentialsClient .DEFAULT_MTLS_ENDPOINT
57
57
58
+ service_account_path = staticmethod (IAMCredentialsClient .service_account_path )
59
+ parse_service_account_path = staticmethod (
60
+ IAMCredentialsClient .parse_service_account_path
61
+ )
62
+
63
+ common_billing_account_path = staticmethod (
64
+ IAMCredentialsClient .common_billing_account_path
65
+ )
66
+ parse_common_billing_account_path = staticmethod (
67
+ IAMCredentialsClient .parse_common_billing_account_path
68
+ )
69
+
70
+ common_folder_path = staticmethod (IAMCredentialsClient .common_folder_path )
71
+ parse_common_folder_path = staticmethod (
72
+ IAMCredentialsClient .parse_common_folder_path
73
+ )
74
+
75
+ common_organization_path = staticmethod (
76
+ IAMCredentialsClient .common_organization_path
77
+ )
78
+ parse_common_organization_path = staticmethod (
79
+ IAMCredentialsClient .parse_common_organization_path
80
+ )
81
+
82
+ common_project_path = staticmethod (IAMCredentialsClient .common_project_path )
83
+ parse_common_project_path = staticmethod (
84
+ IAMCredentialsClient .parse_common_project_path
85
+ )
86
+
87
+ common_location_path = staticmethod (IAMCredentialsClient .common_location_path )
88
+ parse_common_location_path = staticmethod (
89
+ IAMCredentialsClient .parse_common_location_path
90
+ )
91
+
58
92
from_service_account_file = IAMCredentialsClient .from_service_account_file
59
93
from_service_account_json = from_service_account_file
60
94
95
+ @property
96
+ def transport (self ) -> IAMCredentialsTransport :
97
+ """Return the transport used by the client instance.
98
+
99
+ Returns:
100
+ IAMCredentialsTransport: The transport used by the client instance.
101
+ """
102
+ return self ._client .transport
103
+
61
104
get_transport_class = functools .partial (
62
105
type (IAMCredentialsClient ).get_transport_class , type (IAMCredentialsClient )
63
106
)
@@ -68,6 +111,7 @@ def __init__(
68
111
credentials : credentials .Credentials = None ,
69
112
transport : Union [str , IAMCredentialsTransport ] = "grpc_asyncio" ,
70
113
client_options : ClientOptions = None ,
114
+ client_info : gapic_v1 .client_info .ClientInfo = DEFAULT_CLIENT_INFO ,
71
115
) -> None :
72
116
"""Instantiate the iam credentials client.
73
117
@@ -83,24 +127,30 @@ def __init__(
83
127
client_options (ClientOptions): Custom options for the client. It
84
128
won't take effect if a ``transport`` instance is provided.
85
129
(1) The ``api_endpoint`` property can be used to override the
86
- default endpoint provided by the client. GOOGLE_API_USE_MTLS
130
+ default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT
87
131
environment variable can also be used to override the endpoint:
88
132
"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.
133
+ use the default regular endpoint) and "auto" (auto switch to the
134
+ default mTLS endpoint if client certificate is present, this is
135
+ the default value). However, the ``api_endpoint`` property takes
136
+ precedence if provided.
137
+ (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable
138
+ is "true", then the ``client_cert_source`` property can be used
139
+ to provide client certificate for mutual TLS transport. If
140
+ not provided, the default SSL client certificate will be used if
141
+ present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not
142
+ set, no client certificate will be used.
96
143
97
144
Raises:
98
145
google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
99
146
creation failed for any reason.
100
147
"""
101
148
102
149
self ._client = IAMCredentialsClient (
103
- credentials = credentials , transport = transport , client_options = client_options ,
150
+ credentials = credentials ,
151
+ transport = transport ,
152
+ client_options = client_options ,
153
+ client_info = client_info ,
104
154
)
105
155
106
156
async def generate_access_token (
@@ -182,7 +232,8 @@ async def generate_access_token(
182
232
# Create or coerce a protobuf request object.
183
233
# Sanity check: If we got a request object, we should *not* have
184
234
# gotten any keyword arguments that map to the request.
185
- if request is not None and any ([name , delegates , scope , lifetime ]):
235
+ has_flattened_params = any ([name , delegates , scope , lifetime ])
236
+ if request is not None and has_flattened_params :
186
237
raise ValueError (
187
238
"If the `request` argument is set, then none of "
188
239
"the individual field arguments should be set."
@@ -195,13 +246,14 @@ async def generate_access_token(
195
246
196
247
if name is not None :
197
248
request .name = name
198
- if delegates is not None :
199
- request .delegates = delegates
200
- if scope is not None :
201
- request .scope = scope
202
249
if lifetime is not None :
203
250
request .lifetime = lifetime
204
251
252
+ if delegates :
253
+ request .delegates .extend (delegates )
254
+ if scope :
255
+ request .scope .extend (scope )
256
+
205
257
# Wrap the RPC method; this adds retry and timeout information,
206
258
# and friendly error handling.
207
259
rpc = gapic_v1 .method_async .wrap_method (
@@ -215,7 +267,7 @@ async def generate_access_token(
215
267
),
216
268
),
217
269
default_timeout = 60.0 ,
218
- client_info = _client_info ,
270
+ client_info = DEFAULT_CLIENT_INFO ,
219
271
)
220
272
221
273
# Certain fields should be provided within the metadata header;
@@ -303,7 +355,8 @@ async def generate_id_token(
303
355
# Create or coerce a protobuf request object.
304
356
# Sanity check: If we got a request object, we should *not* have
305
357
# gotten any keyword arguments that map to the request.
306
- if request is not None and any ([name , delegates , audience , include_email ]):
358
+ has_flattened_params = any ([name , delegates , audience , include_email ])
359
+ if request is not None and has_flattened_params :
307
360
raise ValueError (
308
361
"If the `request` argument is set, then none of "
309
362
"the individual field arguments should be set."
@@ -316,13 +369,14 @@ async def generate_id_token(
316
369
317
370
if name is not None :
318
371
request .name = name
319
- if delegates is not None :
320
- request .delegates = delegates
321
372
if audience is not None :
322
373
request .audience = audience
323
374
if include_email is not None :
324
375
request .include_email = include_email
325
376
377
+ if delegates :
378
+ request .delegates .extend (delegates )
379
+
326
380
# Wrap the RPC method; this adds retry and timeout information,
327
381
# and friendly error handling.
328
382
rpc = gapic_v1 .method_async .wrap_method (
@@ -336,7 +390,7 @@ async def generate_id_token(
336
390
),
337
391
),
338
392
default_timeout = 60.0 ,
339
- client_info = _client_info ,
393
+ client_info = DEFAULT_CLIENT_INFO ,
340
394
)
341
395
342
396
# Certain fields should be provided within the metadata header;
@@ -414,7 +468,8 @@ async def sign_blob(
414
468
# Create or coerce a protobuf request object.
415
469
# Sanity check: If we got a request object, we should *not* have
416
470
# gotten any keyword arguments that map to the request.
417
- if request is not None and any ([name , delegates , payload ]):
471
+ has_flattened_params = any ([name , delegates , payload ])
472
+ if request is not None and has_flattened_params :
418
473
raise ValueError (
419
474
"If the `request` argument is set, then none of "
420
475
"the individual field arguments should be set."
@@ -427,11 +482,12 @@ async def sign_blob(
427
482
428
483
if name is not None :
429
484
request .name = name
430
- if delegates is not None :
431
- request .delegates = delegates
432
485
if payload is not None :
433
486
request .payload = payload
434
487
488
+ if delegates :
489
+ request .delegates .extend (delegates )
490
+
435
491
# Wrap the RPC method; this adds retry and timeout information,
436
492
# and friendly error handling.
437
493
rpc = gapic_v1 .method_async .wrap_method (
@@ -445,7 +501,7 @@ async def sign_blob(
445
501
),
446
502
),
447
503
default_timeout = 60.0 ,
448
- client_info = _client_info ,
504
+ client_info = DEFAULT_CLIENT_INFO ,
449
505
)
450
506
451
507
# Certain fields should be provided within the metadata header;
@@ -525,7 +581,8 @@ async def sign_jwt(
525
581
# Create or coerce a protobuf request object.
526
582
# Sanity check: If we got a request object, we should *not* have
527
583
# gotten any keyword arguments that map to the request.
528
- if request is not None and any ([name , delegates , payload ]):
584
+ has_flattened_params = any ([name , delegates , payload ])
585
+ if request is not None and has_flattened_params :
529
586
raise ValueError (
530
587
"If the `request` argument is set, then none of "
531
588
"the individual field arguments should be set."
@@ -538,11 +595,12 @@ async def sign_jwt(
538
595
539
596
if name is not None :
540
597
request .name = name
541
- if delegates is not None :
542
- request .delegates = delegates
543
598
if payload is not None :
544
599
request .payload = payload
545
600
601
+ if delegates :
602
+ request .delegates .extend (delegates )
603
+
546
604
# Wrap the RPC method; this adds retry and timeout information,
547
605
# and friendly error handling.
548
606
rpc = gapic_v1 .method_async .wrap_method (
@@ -556,7 +614,7 @@ async def sign_jwt(
556
614
),
557
615
),
558
616
default_timeout = 60.0 ,
559
- client_info = _client_info ,
617
+ client_info = DEFAULT_CLIENT_INFO ,
560
618
)
561
619
562
620
# Certain fields should be provided within the metadata header;
@@ -573,11 +631,11 @@ async def sign_jwt(
573
631
574
632
575
633
try :
576
- _client_info = gapic_v1 .client_info .ClientInfo (
634
+ DEFAULT_CLIENT_INFO = gapic_v1 .client_info .ClientInfo (
577
635
gapic_version = pkg_resources .get_distribution ("google-cloud-iam" ,).version ,
578
636
)
579
637
except pkg_resources .DistributionNotFound :
580
- _client_info = gapic_v1 .client_info .ClientInfo ()
638
+ DEFAULT_CLIENT_INFO = gapic_v1 .client_info .ClientInfo ()
581
639
582
640
583
641
__all__ = ("IAMCredentialsAsyncClient" ,)
0 commit comments