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

Commit

Permalink
feat: add context manager support in client (#35)
Browse files Browse the repository at this point in the history
- [ ] 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: googleapis/googleapis-gen@81decff
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiODFkZWNmZmU5ZmM3MjM5NmE4MTUzZTc1NmQxZDY3YTZlZWNmZDYyMCJ9
  • Loading branch information
gcf-owl-bot[bot] committed Oct 8, 2021
1 parent 7be0494 commit fa36978
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 8 deletions.
Expand Up @@ -1922,6 +1922,12 @@ async def delete_route(
# Done; return the response.
return response

async def __aenter__(self):
return self

async def __aexit__(self, exc_type, exc, tb):
await self.transport.close()


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
Expand Down
18 changes: 14 additions & 4 deletions google/cloud/datastream_v1alpha1/services/datastream/client.py
Expand Up @@ -405,10 +405,7 @@ def __init__(
client_cert_source_for_mtls=client_cert_source_func,
quota_project_id=client_options.quota_project_id,
client_info=client_info,
always_use_jwt_access=(
Transport == type(self).get_transport_class("grpc")
or Transport == type(self).get_transport_class("grpc_asyncio")
),
always_use_jwt_access=True,
)

def list_connection_profiles(
Expand Down Expand Up @@ -2176,6 +2173,19 @@ def delete_route(
# Done; return the response.
return response

def __enter__(self):
return self

def __exit__(self, type, value, traceback):
"""Releases underlying transport's resources.
.. warning::
ONLY use as a context manager if the transport is NOT shared
with other clients! Exiting the with block will CLOSE the transport
and may cause errors in other clients!
"""
self.transport.close()


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
Expand Down
Expand Up @@ -242,6 +242,15 @@ def _prep_wrapped_messages(self, client_info):
),
}

def close(self):
"""Closes resources associated with the transport.
.. warning::
Only call this method if the transport is NOT shared
with other clients - this may cause errors in other clients!
"""
raise NotImplementedError()

@property
def operations_client(self) -> operations_v1.OperationsClient:
"""Return the client designed to process long-running operations."""
Expand Down
Expand Up @@ -834,5 +834,8 @@ def delete_route(
)
return self._stubs["delete_route"]

def close(self):
self.grpc_channel.close()


__all__ = ("DatastreamGrpcTransport",)
Expand Up @@ -853,5 +853,8 @@ def delete_route(
)
return self._stubs["delete_route"]

def close(self):
return self.grpc_channel.close()


__all__ = ("DatastreamGrpcAsyncIOTransport",)
29 changes: 29 additions & 0 deletions google/cloud/datastream_v1alpha1/types/datastream.py
Expand Up @@ -58,6 +58,7 @@

class DiscoverConnectionProfileRequest(proto.Message):
r"""Request message for 'discover' ConnectionProfile request.
Attributes:
parent (str):
Required. The parent resource of the ConnectionProfile type.
Expand Down Expand Up @@ -107,6 +108,7 @@ class DiscoverConnectionProfileRequest(proto.Message):

class DiscoverConnectionProfileResponse(proto.Message):
r"""
Attributes:
oracle_rdbms (google.cloud.datastream_v1alpha1.types.OracleRdbms):
Enriched Oracle RDBMS object.
Expand All @@ -130,6 +132,7 @@ class DiscoverConnectionProfileResponse(proto.Message):

class FetchStaticIpsRequest(proto.Message):
r"""Request message for 'FetchStaticIps' request.
Attributes:
name (str):
Required. The name resource of the Response type. Must be in
Expand All @@ -149,6 +152,7 @@ class FetchStaticIpsRequest(proto.Message):

class FetchStaticIpsResponse(proto.Message):
r"""Response message for a 'FetchStaticIps' response.
Attributes:
static_ips (Sequence[str]):
list of static ips by account
Expand All @@ -168,6 +172,7 @@ def raw_page(self):

class FetchErrorsRequest(proto.Message):
r"""Request message for 'FetchErrors' request.
Attributes:
stream (str):
Name of the Stream resource for which to
Expand All @@ -179,6 +184,7 @@ class FetchErrorsRequest(proto.Message):

class FetchErrorsResponse(proto.Message):
r"""Response message for a 'FetchErrors' response.
Attributes:
errors (Sequence[google.cloud.datastream_v1alpha1.types.Error]):
The list of errors on the Stream.
Expand All @@ -191,6 +197,7 @@ class FetchErrorsResponse(proto.Message):

class ListConnectionProfilesRequest(proto.Message):
r"""
Attributes:
parent (str):
Required. The parent that owns the collection
Expand Down Expand Up @@ -223,6 +230,7 @@ class ListConnectionProfilesRequest(proto.Message):

class ListConnectionProfilesResponse(proto.Message):
r"""
Attributes:
connection_profiles (Sequence[google.cloud.datastream_v1alpha1.types.ConnectionProfile]):
List of connection profiles.
Expand All @@ -247,6 +255,7 @@ def raw_page(self):

class GetConnectionProfileRequest(proto.Message):
r"""
Attributes:
name (str):
Required. The name of the connection profile
Expand All @@ -258,6 +267,7 @@ class GetConnectionProfileRequest(proto.Message):

class CreateConnectionProfileRequest(proto.Message):
r"""
Attributes:
parent (str):
Required. The parent that owns the collection
Expand Down Expand Up @@ -297,6 +307,7 @@ class CreateConnectionProfileRequest(proto.Message):

class UpdateConnectionProfileRequest(proto.Message):
r"""
Attributes:
update_mask (google.protobuf.field_mask_pb2.FieldMask):
Optional. Field mask is used to specify the fields to be
Expand Down Expand Up @@ -338,6 +349,7 @@ class UpdateConnectionProfileRequest(proto.Message):

class DeleteConnectionProfileRequest(proto.Message):
r"""
Attributes:
name (str):
Required. The name of the connection profile
Expand Down Expand Up @@ -368,6 +380,7 @@ class DeleteConnectionProfileRequest(proto.Message):

class ListStreamsRequest(proto.Message):
r"""
Attributes:
parent (str):
Required. The parent that owns the collection
Expand Down Expand Up @@ -399,6 +412,7 @@ class ListStreamsRequest(proto.Message):

class ListStreamsResponse(proto.Message):
r"""
Attributes:
streams (Sequence[google.cloud.datastream_v1alpha1.types.Stream]):
List of streams
Expand All @@ -423,6 +437,7 @@ def raw_page(self):

class GetStreamRequest(proto.Message):
r"""
Attributes:
name (str):
Required. The name of the stream resource to
Expand All @@ -434,6 +449,7 @@ class GetStreamRequest(proto.Message):

class CreateStreamRequest(proto.Message):
r"""
Attributes:
parent (str):
Required. The parent that owns the collection
Expand Down Expand Up @@ -478,6 +494,7 @@ class CreateStreamRequest(proto.Message):

class UpdateStreamRequest(proto.Message):
r"""
Attributes:
update_mask (google.protobuf.field_mask_pb2.FieldMask):
Optional. Field mask is used to specify the fields to be
Expand Down Expand Up @@ -526,6 +543,7 @@ class UpdateStreamRequest(proto.Message):

class DeleteStreamRequest(proto.Message):
r"""
Attributes:
name (str):
Required. The name of the stream resource to
Expand Down Expand Up @@ -556,6 +574,7 @@ class DeleteStreamRequest(proto.Message):

class OperationMetadata(proto.Message):
r"""Represents the metadata of the long-running operation.
Attributes:
create_time (google.protobuf.timestamp_pb2.Timestamp):
Output only. The time the operation was
Expand Down Expand Up @@ -600,6 +619,7 @@ class OperationMetadata(proto.Message):

class CreatePrivateConnectionRequest(proto.Message):
r"""
Attributes:
parent (str):
Required. The parent that owns the collection
Expand Down Expand Up @@ -640,6 +660,7 @@ class CreatePrivateConnectionRequest(proto.Message):

class ListPrivateConnectionsRequest(proto.Message):
r"""
Attributes:
parent (str):
Required. The parent that owns the collection
Expand Down Expand Up @@ -673,6 +694,7 @@ class ListPrivateConnectionsRequest(proto.Message):

class ListPrivateConnectionsResponse(proto.Message):
r"""
Attributes:
private_connections (Sequence[google.cloud.datastream_v1alpha1.types.PrivateConnection]):
List of private connectivity configurations.
Expand All @@ -697,6 +719,7 @@ def raw_page(self):

class DeletePrivateConnectionRequest(proto.Message):
r"""
Attributes:
name (str):
Required. The name of the private
Expand Down Expand Up @@ -732,6 +755,7 @@ class DeletePrivateConnectionRequest(proto.Message):

class GetPrivateConnectionRequest(proto.Message):
r"""
Attributes:
name (str):
Required. The name of the private
Expand All @@ -743,6 +767,7 @@ class GetPrivateConnectionRequest(proto.Message):

class CreateRouteRequest(proto.Message):
r"""route creation request
Attributes:
parent (str):
Required. The parent that owns the collection
Expand Down Expand Up @@ -779,6 +804,7 @@ class CreateRouteRequest(proto.Message):

class ListRoutesRequest(proto.Message):
r"""route list request
Attributes:
parent (str):
Required. The parent that owns the collection
Expand Down Expand Up @@ -811,6 +837,7 @@ class ListRoutesRequest(proto.Message):

class ListRoutesResponse(proto.Message):
r"""route list response
Attributes:
routes (Sequence[google.cloud.datastream_v1alpha1.types.Route]):
List of Routes.
Expand All @@ -835,6 +862,7 @@ def raw_page(self):

class DeleteRouteRequest(proto.Message):
r"""route deletion request
Attributes:
name (str):
Required. The name of the Route resource to
Expand Down Expand Up @@ -865,6 +893,7 @@ class DeleteRouteRequest(proto.Message):

class GetRouteRequest(proto.Message):
r"""route get request
Attributes:
name (str):
Required. The name of the Route resource to
Expand Down

0 comments on commit fa36978

Please sign in to comment.