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

Commit 7210ecd

Browse files
feat: add context manager support in client (#114)
- [ ] 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 1c31449 commit 7210ecd

File tree

27 files changed

+332
-12
lines changed

27 files changed

+332
-12
lines changed

‎google/cloud/websecurityscanner_v1/services/web_security_scanner/async_client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,12 @@ async def list_finding_type_stats(
932932
# Done; return the response.
933933
return response
934934

935+
async def __aenter__(self):
936+
return self
937+
938+
async def __aexit__(self, exc_type, exc, tb):
939+
await self.transport.close()
940+
935941

936942
try:
937943
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

‎google/cloud/websecurityscanner_v1/services/web_security_scanner/client.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,7 @@ def __init__(
364364
client_cert_source_for_mtls=client_cert_source_func,
365365
quota_project_id=client_options.quota_project_id,
366366
client_info=client_info,
367-
always_use_jwt_access=(
368-
Transport == type(self).get_transport_class("grpc")
369-
or Transport == type(self).get_transport_class("grpc_asyncio")
370-
),
367+
always_use_jwt_access=True,
371368
)
372369

373370
def create_scan_config(
@@ -1050,6 +1047,19 @@ def list_finding_type_stats(
10501047
# Done; return the response.
10511048
return response
10521049

1050+
def __enter__(self):
1051+
return self
1052+
1053+
def __exit__(self, type, value, traceback):
1054+
"""Releases underlying transport's resources.
1055+
1056+
.. warning::
1057+
ONLY use as a context manager if the transport is NOT shared
1058+
with other clients! Exiting the with block will CLOSE the transport
1059+
and may cause errors in other clients!
1060+
"""
1061+
self.transport.close()
1062+
10531063

10541064
try:
10551065
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

‎google/cloud/websecurityscanner_v1/services/web_security_scanner/transports/base.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,15 @@ def _prep_wrapped_messages(self, client_info):
307307
),
308308
}
309309

310+
def close(self):
311+
"""Closes resources associated with the transport.
312+
313+
.. warning::
314+
Only call this method if the transport is NOT shared
315+
with other clients - this may cause errors in other clients!
316+
"""
317+
raise NotImplementedError()
318+
310319
@property
311320
def create_scan_config(
312321
self,

‎google/cloud/websecurityscanner_v1/services/web_security_scanner/transports/grpc.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,5 +592,8 @@ def list_finding_type_stats(
592592
)
593593
return self._stubs["list_finding_type_stats"]
594594

595+
def close(self):
596+
self.grpc_channel.close()
597+
595598

596599
__all__ = ("WebSecurityScannerGrpcTransport",)

‎google/cloud/websecurityscanner_v1/services/web_security_scanner/transports/grpc_asyncio.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,5 +607,8 @@ def list_finding_type_stats(
607607
)
608608
return self._stubs["list_finding_type_stats"]
609609

610+
def close(self):
611+
return self.grpc_channel.close()
612+
610613

611614
__all__ = ("WebSecurityScannerGrpcAsyncIOTransport",)

‎google/cloud/websecurityscanner_v1/types/finding_addon.py

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

3232
class Form(proto.Message):
3333
r"""! Information about a vulnerability with an HTML.
34+
3435
Attributes:
3536
action_uri (str):
3637
! The URI where to send the form when it's
@@ -46,6 +47,7 @@ class Form(proto.Message):
4647

4748
class OutdatedLibrary(proto.Message):
4849
r"""Information reported for an outdated library.
50+
4951
Attributes:
5052
library_name (str):
5153
The name of the outdated library.
@@ -78,6 +80,7 @@ class ViolatingResource(proto.Message):
7880

7981
class VulnerableParameters(proto.Message):
8082
r"""Information about vulnerable request parameters.
83+
8184
Attributes:
8285
parameter_names (Sequence[str]):
8386
The vulnerable parameter names.
@@ -88,6 +91,7 @@ class VulnerableParameters(proto.Message):
8891

8992
class VulnerableHeaders(proto.Message):
9093
r"""Information about vulnerable or missing HTTP Headers.
94+
9195
Attributes:
9296
headers (Sequence[google.cloud.websecurityscanner_v1.types.VulnerableHeaders.Header]):
9397
List of vulnerable headers.
@@ -97,6 +101,7 @@ class VulnerableHeaders(proto.Message):
97101

98102
class Header(proto.Message):
99103
r"""Describes a HTTP Header.
104+
100105
Attributes:
101106
name (str):
102107
Header name.
@@ -113,6 +118,7 @@ class Header(proto.Message):
113118

114119
class Xss(proto.Message):
115120
r"""Information reported for an XSS.
121+
116122
Attributes:
117123
stack_traces (Sequence[str]):
118124
Stack traces leading to the point where the

‎google/cloud/websecurityscanner_v1/types/scan_config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ class ExportToSecurityCommandCenter(proto.Enum):
9797

9898
class Authentication(proto.Message):
9999
r"""Scan authentication configuration.
100+
100101
Attributes:
101102
google_account (google.cloud.websecurityscanner_v1.types.ScanConfig.Authentication.GoogleAccount):
102103
Authentication using a Google account.
@@ -199,6 +200,7 @@ class IapTestServiceAccountInfo(proto.Message):
199200

200201
class Schedule(proto.Message):
201202
r"""Scan schedule configuration.
203+
202204
Attributes:
203205
schedule_time (google.protobuf.timestamp_pb2.Timestamp):
204206
A timestamp indicates when the next run will

‎google/cloud/websecurityscanner_v1/types/web_security_scanner.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252

5353
class CreateScanConfigRequest(proto.Message):
5454
r"""Request for the ``CreateScanConfig`` method.
55+
5556
Attributes:
5657
parent (str):
5758
Required. The parent resource name where the
@@ -70,6 +71,7 @@ class CreateScanConfigRequest(proto.Message):
7071

7172
class DeleteScanConfigRequest(proto.Message):
7273
r"""Request for the ``DeleteScanConfig`` method.
74+
7375
Attributes:
7476
name (str):
7577
Required. The resource name of the ScanConfig
@@ -82,6 +84,7 @@ class DeleteScanConfigRequest(proto.Message):
8284

8385
class GetScanConfigRequest(proto.Message):
8486
r"""Request for the ``GetScanConfig`` method.
87+
8588
Attributes:
8689
name (str):
8790
Required. The resource name of the ScanConfig
@@ -94,6 +97,7 @@ class GetScanConfigRequest(proto.Message):
9497

9598
class ListScanConfigsRequest(proto.Message):
9699
r"""Request for the ``ListScanConfigs`` method.
100+
97101
Attributes:
98102
parent (str):
99103
Required. The parent resource name, which
@@ -118,6 +122,7 @@ class ListScanConfigsRequest(proto.Message):
118122

119123
class UpdateScanConfigRequest(proto.Message):
120124
r"""Request for the ``UpdateScanConfigRequest`` method.
125+
121126
Attributes:
122127
scan_config (google.cloud.websecurityscanner_v1.types.ScanConfig):
123128
Required. The ScanConfig to be updated. The
@@ -140,6 +145,7 @@ class UpdateScanConfigRequest(proto.Message):
140145

141146
class ListScanConfigsResponse(proto.Message):
142147
r"""Response for the ``ListScanConfigs`` method.
148+
143149
Attributes:
144150
scan_configs (Sequence[google.cloud.websecurityscanner_v1.types.ScanConfig]):
145151
The list of ScanConfigs returned.
@@ -161,6 +167,7 @@ def raw_page(self):
161167

162168
class StartScanRunRequest(proto.Message):
163169
r"""Request for the ``StartScanRun`` method.
170+
164171
Attributes:
165172
name (str):
166173
Required. The resource name of the ScanConfig
@@ -173,6 +180,7 @@ class StartScanRunRequest(proto.Message):
173180

174181
class GetScanRunRequest(proto.Message):
175182
r"""Request for the ``GetScanRun`` method.
183+
176184
Attributes:
177185
name (str):
178186
Required. The resource name of the ScanRun to
@@ -185,6 +193,7 @@ class GetScanRunRequest(proto.Message):
185193

186194
class ListScanRunsRequest(proto.Message):
187195
r"""Request for the ``ListScanRuns`` method.
196+
188197
Attributes:
189198
parent (str):
190199
Required. The parent resource name, which
@@ -209,6 +218,7 @@ class ListScanRunsRequest(proto.Message):
209218

210219
class ListScanRunsResponse(proto.Message):
211220
r"""Response for the ``ListScanRuns`` method.
221+
212222
Attributes:
213223
scan_runs (Sequence[google.cloud.websecurityscanner_v1.types.ScanRun]):
214224
The list of ScanRuns returned.
@@ -228,6 +238,7 @@ def raw_page(self):
228238

229239
class StopScanRunRequest(proto.Message):
230240
r"""Request for the ``StopScanRun`` method.
241+
231242
Attributes:
232243
name (str):
233244
Required. The resource name of the ScanRun to
@@ -240,6 +251,7 @@ class StopScanRunRequest(proto.Message):
240251

241252
class ListCrawledUrlsRequest(proto.Message):
242253
r"""Request for the ``ListCrawledUrls`` method.
254+
243255
Attributes:
244256
parent (str):
245257
Required. The parent resource name, which
@@ -264,6 +276,7 @@ class ListCrawledUrlsRequest(proto.Message):
264276

265277
class ListCrawledUrlsResponse(proto.Message):
266278
r"""Response for the ``ListCrawledUrls`` method.
279+
267280
Attributes:
268281
crawled_urls (Sequence[google.cloud.websecurityscanner_v1.types.CrawledUrl]):
269282
The list of CrawledUrls returned.
@@ -285,6 +298,7 @@ def raw_page(self):
285298

286299
class GetFindingRequest(proto.Message):
287300
r"""Request for the ``GetFinding`` method.
301+
288302
Attributes:
289303
name (str):
290304
Required. The resource name of the Finding to
@@ -297,6 +311,7 @@ class GetFindingRequest(proto.Message):
297311

298312
class ListFindingsRequest(proto.Message):
299313
r"""Request for the ``ListFindings`` method.
314+
300315
Attributes:
301316
parent (str):
302317
Required. The parent resource name, which
@@ -325,6 +340,7 @@ class ListFindingsRequest(proto.Message):
325340

326341
class ListFindingsResponse(proto.Message):
327342
r"""Response for the ``ListFindings`` method.
343+
328344
Attributes:
329345
findings (Sequence[google.cloud.websecurityscanner_v1.types.Finding]):
330346
The list of Findings returned.
@@ -344,6 +360,7 @@ def raw_page(self):
344360

345361
class ListFindingTypeStatsRequest(proto.Message):
346362
r"""Request for the ``ListFindingTypeStats`` method.
363+
347364
Attributes:
348365
parent (str):
349366
Required. The parent resource name, which
@@ -356,6 +373,7 @@ class ListFindingTypeStatsRequest(proto.Message):
356373

357374
class ListFindingTypeStatsResponse(proto.Message):
358375
r"""Response for the ``ListFindingTypeStats`` method.
376+
359377
Attributes:
360378
finding_type_stats (Sequence[google.cloud.websecurityscanner_v1.types.FindingTypeStats]):
361379
The list of FindingTypeStats returned.

‎google/cloud/websecurityscanner_v1alpha/services/web_security_scanner/async_client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,12 @@ async def list_finding_type_stats(
12821282
# Done; return the response.
12831283
return response
12841284

1285+
async def __aenter__(self):
1286+
return self
1287+
1288+
async def __aexit__(self, exc_type, exc, tb):
1289+
await self.transport.close()
1290+
12851291

12861292
try:
12871293
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

‎google/cloud/websecurityscanner_v1alpha/services/web_security_scanner/client.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -395,10 +395,7 @@ def __init__(
395395
client_cert_source_for_mtls=client_cert_source_func,
396396
quota_project_id=client_options.quota_project_id,
397397
client_info=client_info,
398-
always_use_jwt_access=(
399-
Transport == type(self).get_transport_class("grpc")
400-
or Transport == type(self).get_transport_class("grpc_asyncio")
401-
),
398+
always_use_jwt_access=True,
402399
)
403400

404401
def create_scan_config(
@@ -1412,6 +1409,19 @@ def list_finding_type_stats(
14121409
# Done; return the response.
14131410
return response
14141411

1412+
def __enter__(self):
1413+
return self
1414+
1415+
def __exit__(self, type, value, traceback):
1416+
"""Releases underlying transport's resources.
1417+
1418+
.. warning::
1419+
ONLY use as a context manager if the transport is NOT shared
1420+
with other clients! Exiting the with block will CLOSE the transport
1421+
and may cause errors in other clients!
1422+
"""
1423+
self.transport.close()
1424+
14151425

14161426
try:
14171427
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

0 commit comments

Comments
 (0)