Skip to content
This repository was archived by the owner on Jan 17, 2024. It is now read-only.

Commit 05d1e87

Browse files
feat: add context manager support in client (#120)
- [ ] 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 b56dab6 commit 05d1e87

12 files changed

Lines changed: 100 additions & 4 deletions

File tree

google/cloud/monitoring_dashboard_v1/services/dashboards_service/async_client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,12 @@ async def update_dashboard(
444444
# Done; return the response.
445445
return response
446446

447+
async def __aenter__(self):
448+
return self
449+
450+
async def __aexit__(self, exc_type, exc, tb):
451+
await self.transport.close()
452+
447453

448454
try:
449455
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

google/cloud/monitoring_dashboard_v1/services/dashboards_service/client.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,10 +362,7 @@ def __init__(
362362
client_cert_source_for_mtls=client_cert_source_func,
363363
quota_project_id=client_options.quota_project_id,
364364
client_info=client_info,
365-
always_use_jwt_access=(
366-
Transport == type(self).get_transport_class("grpc")
367-
or Transport == type(self).get_transport_class("grpc_asyncio")
368-
),
365+
always_use_jwt_access=True,
369366
)
370367

371368
def create_dashboard(
@@ -648,6 +645,19 @@ def update_dashboard(
648645
# Done; return the response.
649646
return response
650647

648+
def __enter__(self):
649+
return self
650+
651+
def __exit__(self, type, value, traceback):
652+
"""Releases underlying transport's resources.
653+
654+
.. warning::
655+
ONLY use as a context manager if the transport is NOT shared
656+
with other clients! Exiting the with block will CLOSE the transport
657+
and may cause errors in other clients!
658+
"""
659+
self.transport.close()
660+
651661

652662
try:
653663
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/base.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,15 @@ def _prep_wrapped_messages(self, client_info):
178178
),
179179
}
180180

181+
def close(self):
182+
"""Closes resources associated with the transport.
183+
184+
.. warning::
185+
Only call this method if the transport is NOT shared
186+
with other clients - this may cause errors in other clients!
187+
"""
188+
raise NotImplementedError()
189+
181190
@property
182191
def create_dashboard(
183192
self,

google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/grpc.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,5 +387,8 @@ def update_dashboard(
387387
)
388388
return self._stubs["update_dashboard"]
389389

390+
def close(self):
391+
self.grpc_channel.close()
392+
390393

391394
__all__ = ("DashboardsServiceGrpcTransport",)

google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/grpc_asyncio.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,5 +398,8 @@ def update_dashboard(
398398
)
399399
return self._stubs["update_dashboard"]
400400

401+
def close(self):
402+
return self.grpc_channel.close()
403+
401404

402405
__all__ = ("DashboardsServiceGrpcAsyncIOTransport",)

google/cloud/monitoring_dashboard_v1/types/alertchart.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
class AlertChart(proto.Message):
2525
r"""A chart that displays alert policy data.
26+
2627
Attributes:
2728
name (str):
2829
Required. The resource name of the alert policy. The format

google/cloud/monitoring_dashboard_v1/types/dashboards_service.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
class CreateDashboardRequest(proto.Message):
3535
r"""The ``CreateDashboard`` request.
36+
3637
Attributes:
3738
parent (str):
3839
Required. The project on which to execute the request. The
@@ -59,6 +60,7 @@ class CreateDashboardRequest(proto.Message):
5960

6061
class ListDashboardsRequest(proto.Message):
6162
r"""The ``ListDashboards`` request.
63+
6264
Attributes:
6365
parent (str):
6466
Required. The scope of the dashboards to list. The format
@@ -85,6 +87,7 @@ class ListDashboardsRequest(proto.Message):
8587

8688
class ListDashboardsResponse(proto.Message):
8789
r"""The ``ListDashboards`` request.
90+
8891
Attributes:
8992
dashboards (Sequence[google.cloud.monitoring_dashboard_v1.types.Dashboard]):
9093
The list of requested dashboards.
@@ -107,6 +110,7 @@ def raw_page(self):
107110

108111
class GetDashboardRequest(proto.Message):
109112
r"""The ``GetDashboard`` request.
113+
110114
Attributes:
111115
name (str):
112116
Required. The resource name of the Dashboard. The format is
@@ -122,6 +126,7 @@ class GetDashboardRequest(proto.Message):
122126

123127
class DeleteDashboardRequest(proto.Message):
124128
r"""The ``DeleteDashboard`` request.
129+
125130
Attributes:
126131
name (str):
127132
Required. The resource name of the Dashboard. The format is:
@@ -136,6 +141,7 @@ class DeleteDashboardRequest(proto.Message):
136141

137142
class UpdateDashboardRequest(proto.Message):
138143
r"""The ``UpdateDashboard`` request.
144+
139145
Attributes:
140146
dashboard (google.cloud.monitoring_dashboard_v1.types.Dashboard):
141147
Required. The dashboard that will replace the

google/cloud/monitoring_dashboard_v1/types/layouts.py

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

105105
class Row(proto.Message):
106106
r"""Defines the layout properties and content for a row.
107+
107108
Attributes:
108109
weight (int):
109110
The relative weight of this row. The row
@@ -137,6 +138,7 @@ class ColumnLayout(proto.Message):
137138

138139
class Column(proto.Message):
139140
r"""Defines the layout properties and content for a column.
141+
140142
Attributes:
141143
weight (int):
142144
The relative weight of this column. The

google/cloud/monitoring_dashboard_v1/types/metrics.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ class RatioPart(proto.Message):
176176

177177
class Threshold(proto.Message):
178178
r"""Defines a threshold for categorizing time series values.
179+
179180
Attributes:
180181
label (str):
181182
A label for the threshold.

google/cloud/monitoring_dashboard_v1/types/text.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
class Text(proto.Message):
2525
r"""A widget that displays textual content.
26+
2627
Attributes:
2728
content (str):
2829
The text content to be displayed.

0 commit comments

Comments
 (0)