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

Commit eb9fc8b

Browse files
feat: add context manager support in client (#131)
- [ ] Regenerate this pull request now. chore: fix docstring for first attribute of protos committer: @busunkim96 PiperOrigin-RevId: 401271153 Source-Link: googleapis/googleapis@787f8c9 Source-Link: https://github.com/googleapis/googleapis-gen/commit/81decffe9fc72396a8153e756d1d67a6eecfd620 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiODFkZWNmZmU5ZmM3MjM5NmE4MTUzZTc1NmQxZDY3YTZlZWNmZDYyMCJ9
1 parent 8d6fb3a commit eb9fc8b

File tree

16 files changed

+178
-8
lines changed

16 files changed

+178
-8
lines changed

google/cloud/security/privateca_v1/services/certificate_authority_service/async_client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2789,6 +2789,12 @@ async def update_certificate_template(
27892789
# Done; return the response.
27902790
return response
27912791

2792+
async def __aenter__(self):
2793+
return self
2794+
2795+
async def __aexit__(self, exc_type, exc, tb):
2796+
await self.transport.close()
2797+
27922798

27932799
try:
27942800
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

google/cloud/security/privateca_v1/services/certificate_authority_service/client.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -450,10 +450,7 @@ def __init__(
450450
client_cert_source_for_mtls=client_cert_source_func,
451451
quota_project_id=client_options.quota_project_id,
452452
client_info=client_info,
453-
always_use_jwt_access=(
454-
Transport == type(self).get_transport_class("grpc")
455-
or Transport == type(self).get_transport_class("grpc_asyncio")
456-
),
453+
always_use_jwt_access=True,
457454
)
458455

459456
def create_certificate(
@@ -3075,6 +3072,19 @@ def update_certificate_template(
30753072
# Done; return the response.
30763073
return response
30773074

3075+
def __enter__(self):
3076+
return self
3077+
3078+
def __exit__(self, type, value, traceback):
3079+
"""Releases underlying transport's resources.
3080+
3081+
.. warning::
3082+
ONLY use as a context manager if the transport is NOT shared
3083+
with other clients! Exiting the with block will CLOSE the transport
3084+
and may cause errors in other clients!
3085+
"""
3086+
self.transport.close()
3087+
30783088

30793089
try:
30803090
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

google/cloud/security/privateca_v1/services/certificate_authority_service/transports/base.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,15 @@ def _prep_wrapped_messages(self, client_info):
282282
),
283283
}
284284

285+
def close(self):
286+
"""Closes resources associated with the transport.
287+
288+
.. warning::
289+
Only call this method if the transport is NOT shared
290+
with other clients - this may cause errors in other clients!
291+
"""
292+
raise NotImplementedError()
293+
285294
@property
286295
def operations_client(self) -> operations_v1.OperationsClient:
287296
"""Return the client designed to process long-running operations."""

google/cloud/security/privateca_v1/services/certificate_authority_service/transports/grpc.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,5 +1103,8 @@ def update_certificate_template(
11031103
)
11041104
return self._stubs["update_certificate_template"]
11051105

1106+
def close(self):
1107+
self.grpc_channel.close()
1108+
11061109

11071110
__all__ = ("CertificateAuthorityServiceGrpcTransport",)

google/cloud/security/privateca_v1/services/certificate_authority_service/transports/grpc_asyncio.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,5 +1128,8 @@ def update_certificate_template(
11281128
)
11291129
return self._stubs["update_certificate_template"]
11301130

1131+
def close(self):
1132+
return self.grpc_channel.close()
1133+
11311134

11321135
__all__ = ("CertificateAuthorityServiceGrpcAsyncIOTransport",)

google/cloud/security/privateca_v1/types/resources.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,7 @@ class X509Parameters(proto.Message):
904904

905905
class CaOptions(proto.Message):
906906
r"""Describes values that are relevant in a CA certificate.
907+
907908
Attributes:
908909
is_ca (bool):
909910
Optional. Refers to the "CA" X.509 extension,
@@ -1141,6 +1142,7 @@ class KeyId(proto.Message):
11411142

11421143
class CertificateFingerprint(proto.Message):
11431144
r"""A group of fingerprints for the x509 certificate.
1145+
11441146
Attributes:
11451147
sha256_hash (str):
11461148
The SHA 256 hash, encoded in hexadecimal, of

google/cloud/security/privateca_v1/types/service.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,7 @@ class FetchCaCertsResponse(proto.Message):
872872

873873
class CertChain(proto.Message):
874874
r"""
875+
875876
Attributes:
876877
certificates (Sequence[str]):
877878
The certificates that form the CA chain, from
@@ -1290,6 +1291,7 @@ class UpdateCertificateTemplateRequest(proto.Message):
12901291

12911292
class OperationMetadata(proto.Message):
12921293
r"""Represents the metadata of the long-running operation.
1294+
12931295
Attributes:
12941296
create_time (google.protobuf.timestamp_pb2.Timestamp):
12951297
Output only. The time the operation was

google/cloud/security/privateca_v1beta1/services/certificate_authority_service/async_client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,6 +1943,12 @@ async def list_reusable_configs(
19431943
# Done; return the response.
19441944
return response
19451945

1946+
async def __aenter__(self):
1947+
return self
1948+
1949+
async def __aexit__(self, exc_type, exc, tb):
1950+
await self.transport.close()
1951+
19461952

19471953
try:
19481954
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

google/cloud/security/privateca_v1beta1/services/certificate_authority_service/client.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,10 +426,7 @@ def __init__(
426426
client_cert_source_for_mtls=client_cert_source_func,
427427
quota_project_id=client_options.quota_project_id,
428428
client_info=client_info,
429-
always_use_jwt_access=(
430-
Transport == type(self).get_transport_class("grpc")
431-
or Transport == type(self).get_transport_class("grpc_asyncio")
432-
),
429+
always_use_jwt_access=True,
433430
)
434431

435432
def create_certificate(
@@ -2202,6 +2199,19 @@ def list_reusable_configs(
22022199
# Done; return the response.
22032200
return response
22042201

2202+
def __enter__(self):
2203+
return self
2204+
2205+
def __exit__(self, type, value, traceback):
2206+
"""Releases underlying transport's resources.
2207+
2208+
.. warning::
2209+
ONLY use as a context manager if the transport is NOT shared
2210+
with other clients! Exiting the with block will CLOSE the transport
2211+
and may cause errors in other clients!
2212+
"""
2213+
self.transport.close()
2214+
22052215

22062216
try:
22072217
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

google/cloud/security/privateca_v1beta1/services/certificate_authority_service/transports/base.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,15 @@ def _prep_wrapped_messages(self, client_info):
247247
),
248248
}
249249

250+
def close(self):
251+
"""Closes resources associated with the transport.
252+
253+
.. warning::
254+
Only call this method if the transport is NOT shared
255+
with other clients - this may cause errors in other clients!
256+
"""
257+
raise NotImplementedError()
258+
250259
@property
251260
def operations_client(self) -> operations_v1.OperationsClient:
252261
"""Return the client designed to process long-running operations."""

0 commit comments

Comments
 (0)