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

Commit

Permalink
Browse files Browse the repository at this point in the history
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: googleapis/googleapis-gen@81decff
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiODFkZWNmZmU5ZmM3MjM5NmE4MTUzZTc1NmQxZDY3YTZlZWNmZDYyMCJ9
  • Loading branch information
gcf-owl-bot[bot] committed Oct 7, 2021
1 parent 1c31449 commit 7210ecd
Show file tree
Hide file tree
Showing 27 changed files with 332 additions and 12 deletions.
Expand Up @@ -932,6 +932,12 @@ async def list_finding_type_stats(
# 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
Expand Up @@ -364,10 +364,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 create_scan_config(
Expand Down Expand Up @@ -1050,6 +1047,19 @@ def list_finding_type_stats(
# 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 @@ -307,6 +307,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 create_scan_config(
self,
Expand Down
Expand Up @@ -592,5 +592,8 @@ def list_finding_type_stats(
)
return self._stubs["list_finding_type_stats"]

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


__all__ = ("WebSecurityScannerGrpcTransport",)
Expand Up @@ -607,5 +607,8 @@ def list_finding_type_stats(
)
return self._stubs["list_finding_type_stats"]

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


__all__ = ("WebSecurityScannerGrpcAsyncIOTransport",)
6 changes: 6 additions & 0 deletions google/cloud/websecurityscanner_v1/types/finding_addon.py
Expand Up @@ -31,6 +31,7 @@

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

class OutdatedLibrary(proto.Message):
r"""Information reported for an outdated library.
Attributes:
library_name (str):
The name of the outdated library.
Expand Down Expand Up @@ -78,6 +80,7 @@ class ViolatingResource(proto.Message):

class VulnerableParameters(proto.Message):
r"""Information about vulnerable request parameters.
Attributes:
parameter_names (Sequence[str]):
The vulnerable parameter names.
Expand All @@ -88,6 +91,7 @@ class VulnerableParameters(proto.Message):

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

class Header(proto.Message):
r"""Describes a HTTP Header.
Attributes:
name (str):
Header name.
Expand All @@ -113,6 +118,7 @@ class Header(proto.Message):

class Xss(proto.Message):
r"""Information reported for an XSS.
Attributes:
stack_traces (Sequence[str]):
Stack traces leading to the point where the
Expand Down
2 changes: 2 additions & 0 deletions google/cloud/websecurityscanner_v1/types/scan_config.py
Expand Up @@ -97,6 +97,7 @@ class ExportToSecurityCommandCenter(proto.Enum):

class Authentication(proto.Message):
r"""Scan authentication configuration.
Attributes:
google_account (google.cloud.websecurityscanner_v1.types.ScanConfig.Authentication.GoogleAccount):
Authentication using a Google account.
Expand Down Expand Up @@ -199,6 +200,7 @@ class IapTestServiceAccountInfo(proto.Message):

class Schedule(proto.Message):
r"""Scan schedule configuration.
Attributes:
schedule_time (google.protobuf.timestamp_pb2.Timestamp):
A timestamp indicates when the next run will
Expand Down
18 changes: 18 additions & 0 deletions google/cloud/websecurityscanner_v1/types/web_security_scanner.py
Expand Up @@ -52,6 +52,7 @@

class CreateScanConfigRequest(proto.Message):
r"""Request for the ``CreateScanConfig`` method.
Attributes:
parent (str):
Required. The parent resource name where the
Expand All @@ -70,6 +71,7 @@ class CreateScanConfigRequest(proto.Message):

class DeleteScanConfigRequest(proto.Message):
r"""Request for the ``DeleteScanConfig`` method.
Attributes:
name (str):
Required. The resource name of the ScanConfig
Expand All @@ -82,6 +84,7 @@ class DeleteScanConfigRequest(proto.Message):

class GetScanConfigRequest(proto.Message):
r"""Request for the ``GetScanConfig`` method.
Attributes:
name (str):
Required. The resource name of the ScanConfig
Expand All @@ -94,6 +97,7 @@ class GetScanConfigRequest(proto.Message):

class ListScanConfigsRequest(proto.Message):
r"""Request for the ``ListScanConfigs`` method.
Attributes:
parent (str):
Required. The parent resource name, which
Expand All @@ -118,6 +122,7 @@ class ListScanConfigsRequest(proto.Message):

class UpdateScanConfigRequest(proto.Message):
r"""Request for the ``UpdateScanConfigRequest`` method.
Attributes:
scan_config (google.cloud.websecurityscanner_v1.types.ScanConfig):
Required. The ScanConfig to be updated. The
Expand All @@ -140,6 +145,7 @@ class UpdateScanConfigRequest(proto.Message):

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

class StartScanRunRequest(proto.Message):
r"""Request for the ``StartScanRun`` method.
Attributes:
name (str):
Required. The resource name of the ScanConfig
Expand All @@ -173,6 +180,7 @@ class StartScanRunRequest(proto.Message):

class GetScanRunRequest(proto.Message):
r"""Request for the ``GetScanRun`` method.
Attributes:
name (str):
Required. The resource name of the ScanRun to
Expand All @@ -185,6 +193,7 @@ class GetScanRunRequest(proto.Message):

class ListScanRunsRequest(proto.Message):
r"""Request for the ``ListScanRuns`` method.
Attributes:
parent (str):
Required. The parent resource name, which
Expand All @@ -209,6 +218,7 @@ class ListScanRunsRequest(proto.Message):

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

class StopScanRunRequest(proto.Message):
r"""Request for the ``StopScanRun`` method.
Attributes:
name (str):
Required. The resource name of the ScanRun to
Expand All @@ -240,6 +251,7 @@ class StopScanRunRequest(proto.Message):

class ListCrawledUrlsRequest(proto.Message):
r"""Request for the ``ListCrawledUrls`` method.
Attributes:
parent (str):
Required. The parent resource name, which
Expand All @@ -264,6 +276,7 @@ class ListCrawledUrlsRequest(proto.Message):

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

class GetFindingRequest(proto.Message):
r"""Request for the ``GetFinding`` method.
Attributes:
name (str):
Required. The resource name of the Finding to
Expand All @@ -297,6 +311,7 @@ class GetFindingRequest(proto.Message):

class ListFindingsRequest(proto.Message):
r"""Request for the ``ListFindings`` method.
Attributes:
parent (str):
Required. The parent resource name, which
Expand Down Expand Up @@ -325,6 +340,7 @@ class ListFindingsRequest(proto.Message):

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

class ListFindingTypeStatsRequest(proto.Message):
r"""Request for the ``ListFindingTypeStats`` method.
Attributes:
parent (str):
Required. The parent resource name, which
Expand All @@ -356,6 +373,7 @@ class ListFindingTypeStatsRequest(proto.Message):

class ListFindingTypeStatsResponse(proto.Message):
r"""Response for the ``ListFindingTypeStats`` method.
Attributes:
finding_type_stats (Sequence[google.cloud.websecurityscanner_v1.types.FindingTypeStats]):
The list of FindingTypeStats returned.
Expand Down
Expand Up @@ -1282,6 +1282,12 @@ async def list_finding_type_stats(
# 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
Expand Up @@ -395,10 +395,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 create_scan_config(
Expand Down Expand Up @@ -1412,6 +1409,19 @@ def list_finding_type_stats(
# 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 @@ -308,6 +308,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 create_scan_config(
self,
Expand Down
Expand Up @@ -593,5 +593,8 @@ def list_finding_type_stats(
)
return self._stubs["list_finding_type_stats"]

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


__all__ = ("WebSecurityScannerGrpcTransport",)
Expand Up @@ -608,5 +608,8 @@ def list_finding_type_stats(
)
return self._stubs["list_finding_type_stats"]

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


__all__ = ("WebSecurityScannerGrpcAsyncIOTransport",)

0 comments on commit 7210ecd

Please sign in to comment.