Skip to content
Permalink
Browse files
feat: add context manager support in client (#415)
* feat: add context manager support in client

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

* 🦉 Updates from OwlBot

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* 🦉 Updates from OwlBot

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: Anthonios Partheniou <partheniou@google.com>
  • Loading branch information
3 people committed Oct 12, 2021
1 parent 82e5dbf commit f5af16439807a0954ee78fa91cb69b9493b80176
Showing with 303 additions and 13 deletions.
  1. +6 −0 google/cloud/logging_v2/services/config_service_v2/async_client.py
  2. +14 −4 google/cloud/logging_v2/services/config_service_v2/client.py
  3. +9 −0 google/cloud/logging_v2/services/config_service_v2/transports/base.py
  4. +3 −0 google/cloud/logging_v2/services/config_service_v2/transports/grpc.py
  5. +3 −0 google/cloud/logging_v2/services/config_service_v2/transports/grpc_asyncio.py
  6. +6 −0 google/cloud/logging_v2/services/logging_service_v2/async_client.py
  7. +14 −4 google/cloud/logging_v2/services/logging_service_v2/client.py
  8. +9 −0 google/cloud/logging_v2/services/logging_service_v2/transports/base.py
  9. +3 −0 google/cloud/logging_v2/services/logging_service_v2/transports/grpc.py
  10. +3 −0 google/cloud/logging_v2/services/logging_service_v2/transports/grpc_asyncio.py
  11. +6 −0 google/cloud/logging_v2/services/metrics_service_v2/async_client.py
  12. +14 −4 google/cloud/logging_v2/services/metrics_service_v2/client.py
  13. +9 −0 google/cloud/logging_v2/services/metrics_service_v2/transports/base.py
  14. +3 −0 google/cloud/logging_v2/services/metrics_service_v2/transports/grpc.py
  15. +3 −0 google/cloud/logging_v2/services/metrics_service_v2/transports/grpc_asyncio.py
  16. +1 −0 google/cloud/logging_v2/types/log_entry.py
  17. +14 −1 google/cloud/logging_v2/types/logging.py
  18. +27 −0 google/cloud/logging_v2/types/logging_config.py
  19. +6 −0 google/cloud/logging_v2/types/logging_metrics.py
  20. +50 −0 tests/unit/gapic/logging_v2/test_config_service_v2.py
  21. +50 −0 tests/unit/gapic/logging_v2/test_logging_service_v2.py
  22. +50 −0 tests/unit/gapic/logging_v2/test_metrics_service_v2.py
@@ -1929,6 +1929,12 @@ async def update_cmek_settings(
# 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(
@@ -397,10 +397,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_buckets(
@@ -2091,6 +2088,19 @@ def update_cmek_settings(
# 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(
@@ -322,6 +322,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 list_buckets(
self,
@@ -883,5 +883,8 @@ def update_cmek_settings(
)
return self._stubs["update_cmek_settings"]

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


__all__ = ("ConfigServiceV2GrpcTransport",)
@@ -915,5 +915,8 @@ def update_cmek_settings(
)
return self._stubs["update_cmek_settings"]

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


__all__ = ("ConfigServiceV2GrpcAsyncIOTransport",)
@@ -779,6 +779,12 @@ def tail_log_entries(
# 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(
@@ -341,10 +341,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 delete_log(
@@ -886,6 +883,19 @@ def tail_log_entries(
# 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(
@@ -257,6 +257,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 delete_log(
self,
@@ -404,5 +404,8 @@ def tail_log_entries(
)
return self._stubs["tail_log_entries"]

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


__all__ = ("LoggingServiceV2GrpcTransport",)
@@ -415,5 +415,8 @@ def tail_log_entries(
)
return self._stubs["tail_log_entries"]

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


__all__ = ("LoggingServiceV2GrpcAsyncIOTransport",)
@@ -635,6 +635,12 @@ async def delete_log_metric(
request, retry=retry, timeout=timeout, metadata=metadata,
)

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(
@@ -344,10 +344,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_log_metrics(
@@ -777,6 +774,19 @@ def delete_log_metric(
request, retry=retry, timeout=timeout, metadata=metadata,
)

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(
@@ -228,6 +228,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 list_log_metrics(
self,
@@ -358,5 +358,8 @@ def delete_log_metric(
)
return self._stubs["delete_log_metric"]

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


__all__ = ("MetricsServiceV2GrpcTransport",)
@@ -368,5 +368,8 @@ def delete_log_metric(
)
return self._stubs["delete_log_metric"]

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


__all__ = ("MetricsServiceV2GrpcAsyncIOTransport",)
@@ -31,6 +31,7 @@

class LogEntry(proto.Message):
r"""An individual entry in a log.
Attributes:
log_name (str):
Required. The resource name of the log to which this log
@@ -42,6 +42,7 @@

class DeleteLogRequest(proto.Message):
r"""The parameters to DeleteLog.
Attributes:
log_name (str):
Required. The resource name of the log to delete:
@@ -65,6 +66,7 @@ class DeleteLogRequest(proto.Message):

class WriteLogEntriesRequest(proto.Message):
r"""The parameters to WriteLogEntries.
Attributes:
log_name (str):
Optional. A default log resource name that is assigned to
@@ -164,11 +166,13 @@ class WriteLogEntriesRequest(proto.Message):


class WriteLogEntriesResponse(proto.Message):
r"""Result returned from WriteLogEntries. """
r"""Result returned from WriteLogEntries.
"""


class WriteLogEntriesPartialErrors(proto.Message):
r"""Error details for WriteLogEntries with partial success.
Attributes:
log_entry_errors (Sequence[google.cloud.logging_v2.types.WriteLogEntriesPartialErrors.LogEntryErrorsEntry]):
When ``WriteLogEntriesRequest.partial_success`` is true,
@@ -187,6 +191,7 @@ class WriteLogEntriesPartialErrors(proto.Message):

class ListLogEntriesRequest(proto.Message):
r"""The parameters to ``ListLogEntries``.
Attributes:
resource_names (Sequence[str]):
Required. Names of one or more parent resources from which
@@ -249,6 +254,7 @@ class ListLogEntriesRequest(proto.Message):

class ListLogEntriesResponse(proto.Message):
r"""Result returned from ``ListLogEntries``.
Attributes:
entries (Sequence[google.cloud.logging_v2.types.LogEntry]):
A list of log entries. If ``entries`` is empty,
@@ -281,6 +287,7 @@ def raw_page(self):

class ListMonitoredResourceDescriptorsRequest(proto.Message):
r"""The parameters to ListMonitoredResourceDescriptors
Attributes:
page_size (int):
Optional. The maximum number of results to return from this
@@ -301,6 +308,7 @@ class ListMonitoredResourceDescriptorsRequest(proto.Message):

class ListMonitoredResourceDescriptorsResponse(proto.Message):
r"""Result returned from ListMonitoredResourceDescriptors.
Attributes:
resource_descriptors (Sequence[google.api.monitored_resource_pb2.MonitoredResourceDescriptor]):
A list of resource descriptors.
@@ -325,6 +333,7 @@ def raw_page(self):

class ListLogsRequest(proto.Message):
r"""The parameters to ListLogs.
Attributes:
parent (str):
Required. The resource name that owns the logs:
@@ -366,6 +375,7 @@ class ListLogsRequest(proto.Message):

class ListLogsResponse(proto.Message):
r"""Result returned from ListLogs.
Attributes:
log_names (Sequence[str]):
A list of log names. For example,
@@ -388,6 +398,7 @@ def raw_page(self):

class TailLogEntriesRequest(proto.Message):
r"""The parameters to ``TailLogEntries``.
Attributes:
resource_names (Sequence[str]):
Required. Name of a parent resource from which to retrieve
@@ -431,6 +442,7 @@ class TailLogEntriesRequest(proto.Message):

class TailLogEntriesResponse(proto.Message):
r"""Result returned from ``TailLogEntries``.
Attributes:
entries (Sequence[google.cloud.logging_v2.types.LogEntry]):
A list of log entries. Each response in the stream will
@@ -450,6 +462,7 @@ class TailLogEntriesResponse(proto.Message):

class SuppressionInfo(proto.Message):
r"""Information about entries that were omitted from the session.
Attributes:
reason (google.cloud.logging_v2.types.TailLogEntriesResponse.SuppressionInfo.Reason):
The reason that entries were omitted from the

0 comments on commit f5af164

Please sign in to comment.