From 309174923e00e7463ea98d3f5c2805afafddf7fe Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Sat, 15 May 2021 08:52:48 -0400 Subject: [PATCH] chore: upgrade gapic-generator-python to 0.46.3 (#57) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: upgrade gapic-generator-python to 0.46.3 PiperOrigin-RevId: 373649163 Source-Link: https://github.com/googleapis/googleapis/commit/7e1b14e6c7a9ab96d2db7e4a131981f162446d34 Source-Link: https://github.com/googleapis/googleapis-gen/commit/0a3c7d272d697796db75857bac73905c68e498c3 * 🦉 Updates from OwlBot Co-authored-by: Owl Bot fix: add async client to %name_%version/init.py chore: add autogenerated snippets chore: remove auth, policy, and options from the reserved names list feat: support self-signed JWT flow for service accounts chore: enable GAPIC metadata generation chore: sort subpackages in %namespace/%name/init.py --- .../web_security_scanner.rst | 1 - .../web_security_scanner.rst | 1 - .../web_security_scanner.rst | 1 - .../cloud/websecurityscanner_v1/__init__.py | 11 +- .../websecurityscanner_v1/gapic_metadata.json | 153 +++ .../services/__init__.py | 1 - .../services/web_security_scanner/__init__.py | 2 - .../web_security_scanner/async_client.py | 79 +- .../services/web_security_scanner/client.py | 89 +- .../services/web_security_scanner/pagers.py | 10 +- .../transports/__init__.py | 2 - .../web_security_scanner/transports/base.py | 189 ++-- .../web_security_scanner/transports/grpc.py | 28 +- .../transports/grpc_asyncio.py | 29 +- .../websecurityscanner_v1/types/__init__.py | 2 - .../types/crawled_url.py | 10 +- .../websecurityscanner_v1/types/finding.py | 39 +- .../types/finding_addon.py | 43 +- .../types/finding_type_stats.py | 7 +- .../types/scan_config.py | 54 +- .../types/scan_config_error.py | 5 +- .../websecurityscanner_v1/types/scan_run.py | 29 +- .../types/scan_run_error_trace.py | 7 +- .../types/scan_run_warning_trace.py | 2 - .../types/web_security_scanner.py | 92 +- .../websecurityscanner_v1alpha/__init__.py | 11 +- .../gapic_metadata.json | 153 +++ .../services/__init__.py | 1 - .../services/web_security_scanner/__init__.py | 2 - .../web_security_scanner/async_client.py | 83 +- .../services/web_security_scanner/client.py | 114 +-- .../services/web_security_scanner/pagers.py | 10 +- .../transports/__init__.py | 2 - .../web_security_scanner/transports/base.py | 193 ++-- .../web_security_scanner/transports/grpc.py | 28 +- .../transports/grpc_asyncio.py | 29 +- .../types/__init__.py | 2 - .../types/crawled_url.py | 10 +- .../types/finding.py | 35 +- .../types/finding_addon.py | 33 +- .../types/finding_type_stats.py | 6 +- .../types/scan_config.py | 45 +- .../types/scan_run.py | 27 +- .../types/web_security_scanner.py | 92 +- .../websecurityscanner_v1beta/__init__.py | 11 +- .../gapic_metadata.json | 153 +++ .../services/__init__.py | 1 - .../services/web_security_scanner/__init__.py | 2 - .../web_security_scanner/async_client.py | 83 +- .../services/web_security_scanner/client.py | 114 +-- .../services/web_security_scanner/pagers.py | 10 +- .../transports/__init__.py | 2 - .../web_security_scanner/transports/base.py | 193 ++-- .../web_security_scanner/transports/grpc.py | 28 +- .../transports/grpc_asyncio.py | 29 +- .../types/__init__.py | 2 - .../types/crawled_url.py | 10 +- .../types/finding.py | 38 +- .../types/finding_addon.py | 39 +- .../types/finding_type_stats.py | 7 +- .../types/scan_config.py | 47 +- .../types/scan_config_error.py | 5 +- .../types/scan_run.py | 29 +- .../types/scan_run_error_trace.py | 7 +- .../types/scan_run_warning_trace.py | 2 - .../types/web_security_scanner.py | 92 +- .../fixup_websecurityscanner_v1_keywords.py | 31 +- ...xup_websecurityscanner_v1alpha_keywords.py | 31 +- ...ixup_websecurityscanner_v1beta_keywords.py | 31 +- tests/__init__.py | 15 + tests/unit/__init__.py | 15 + tests/unit/gapic/__init__.py | 15 + .../gapic/websecurityscanner_v1/__init__.py | 1 - .../test_web_security_scanner.py | 740 +++++++------- .../websecurityscanner_v1alpha/__init__.py | 1 - .../test_web_security_scanner.py | 935 ++++++++--------- .../websecurityscanner_v1beta/__init__.py | 1 - .../test_web_security_scanner.py | 947 +++++++++--------- 78 files changed, 2829 insertions(+), 2600 deletions(-) create mode 100644 google/cloud/websecurityscanner_v1/gapic_metadata.json create mode 100644 google/cloud/websecurityscanner_v1alpha/gapic_metadata.json create mode 100644 google/cloud/websecurityscanner_v1beta/gapic_metadata.json create mode 100644 tests/__init__.py create mode 100644 tests/unit/__init__.py create mode 100644 tests/unit/gapic/__init__.py diff --git a/docs/websecurityscanner_v1/web_security_scanner.rst b/docs/websecurityscanner_v1/web_security_scanner.rst index 659c139..4925421 100644 --- a/docs/websecurityscanner_v1/web_security_scanner.rst +++ b/docs/websecurityscanner_v1/web_security_scanner.rst @@ -5,7 +5,6 @@ WebSecurityScanner :members: :inherited-members: - .. automodule:: google.cloud.websecurityscanner_v1.services.web_security_scanner.pagers :members: :inherited-members: diff --git a/docs/websecurityscanner_v1alpha/web_security_scanner.rst b/docs/websecurityscanner_v1alpha/web_security_scanner.rst index f4ac232..1bb5688 100644 --- a/docs/websecurityscanner_v1alpha/web_security_scanner.rst +++ b/docs/websecurityscanner_v1alpha/web_security_scanner.rst @@ -5,7 +5,6 @@ WebSecurityScanner :members: :inherited-members: - .. automodule:: google.cloud.websecurityscanner_v1alpha.services.web_security_scanner.pagers :members: :inherited-members: diff --git a/docs/websecurityscanner_v1beta/web_security_scanner.rst b/docs/websecurityscanner_v1beta/web_security_scanner.rst index ed00e33..8918ace 100644 --- a/docs/websecurityscanner_v1beta/web_security_scanner.rst +++ b/docs/websecurityscanner_v1beta/web_security_scanner.rst @@ -5,7 +5,6 @@ WebSecurityScanner :members: :inherited-members: - .. automodule:: google.cloud.websecurityscanner_v1beta.services.web_security_scanner.pagers :members: :inherited-members: diff --git a/google/cloud/websecurityscanner_v1/__init__.py b/google/cloud/websecurityscanner_v1/__init__.py index c5228bc..a3713bb 100644 --- a/google/cloud/websecurityscanner_v1/__init__.py +++ b/google/cloud/websecurityscanner_v1/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,6 +15,8 @@ # from .services.web_security_scanner import WebSecurityScannerClient +from .services.web_security_scanner import WebSecurityScannerAsyncClient + from .types.crawled_url import CrawledUrl from .types.finding import Finding from .types.finding_addon import Form @@ -37,10 +38,10 @@ from .types.web_security_scanner import GetScanRunRequest from .types.web_security_scanner import ListCrawledUrlsRequest from .types.web_security_scanner import ListCrawledUrlsResponse -from .types.web_security_scanner import ListFindingTypeStatsRequest -from .types.web_security_scanner import ListFindingTypeStatsResponse from .types.web_security_scanner import ListFindingsRequest from .types.web_security_scanner import ListFindingsResponse +from .types.web_security_scanner import ListFindingTypeStatsRequest +from .types.web_security_scanner import ListFindingTypeStatsResponse from .types.web_security_scanner import ListScanConfigsRequest from .types.web_security_scanner import ListScanConfigsResponse from .types.web_security_scanner import ListScanRunsRequest @@ -49,8 +50,8 @@ from .types.web_security_scanner import StopScanRunRequest from .types.web_security_scanner import UpdateScanConfigRequest - __all__ = ( + "WebSecurityScannerAsyncClient", "CrawledUrl", "CreateScanConfigRequest", "DeleteScanConfigRequest", @@ -82,6 +83,6 @@ "ViolatingResource", "VulnerableHeaders", "VulnerableParameters", - "Xss", "WebSecurityScannerClient", + "Xss", ) diff --git a/google/cloud/websecurityscanner_v1/gapic_metadata.json b/google/cloud/websecurityscanner_v1/gapic_metadata.json new file mode 100644 index 0000000..2b6f23a --- /dev/null +++ b/google/cloud/websecurityscanner_v1/gapic_metadata.json @@ -0,0 +1,153 @@ + { + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", + "language": "python", + "libraryPackage": "google.cloud.websecurityscanner_v1", + "protoPackage": "google.cloud.websecurityscanner.v1", + "schema": "1.0", + "services": { + "WebSecurityScanner": { + "clients": { + "grpc": { + "libraryClient": "WebSecurityScannerClient", + "rpcs": { + "CreateScanConfig": { + "methods": [ + "create_scan_config" + ] + }, + "DeleteScanConfig": { + "methods": [ + "delete_scan_config" + ] + }, + "GetFinding": { + "methods": [ + "get_finding" + ] + }, + "GetScanConfig": { + "methods": [ + "get_scan_config" + ] + }, + "GetScanRun": { + "methods": [ + "get_scan_run" + ] + }, + "ListCrawledUrls": { + "methods": [ + "list_crawled_urls" + ] + }, + "ListFindingTypeStats": { + "methods": [ + "list_finding_type_stats" + ] + }, + "ListFindings": { + "methods": [ + "list_findings" + ] + }, + "ListScanConfigs": { + "methods": [ + "list_scan_configs" + ] + }, + "ListScanRuns": { + "methods": [ + "list_scan_runs" + ] + }, + "StartScanRun": { + "methods": [ + "start_scan_run" + ] + }, + "StopScanRun": { + "methods": [ + "stop_scan_run" + ] + }, + "UpdateScanConfig": { + "methods": [ + "update_scan_config" + ] + } + } + }, + "grpc-async": { + "libraryClient": "WebSecurityScannerAsyncClient", + "rpcs": { + "CreateScanConfig": { + "methods": [ + "create_scan_config" + ] + }, + "DeleteScanConfig": { + "methods": [ + "delete_scan_config" + ] + }, + "GetFinding": { + "methods": [ + "get_finding" + ] + }, + "GetScanConfig": { + "methods": [ + "get_scan_config" + ] + }, + "GetScanRun": { + "methods": [ + "get_scan_run" + ] + }, + "ListCrawledUrls": { + "methods": [ + "list_crawled_urls" + ] + }, + "ListFindingTypeStats": { + "methods": [ + "list_finding_type_stats" + ] + }, + "ListFindings": { + "methods": [ + "list_findings" + ] + }, + "ListScanConfigs": { + "methods": [ + "list_scan_configs" + ] + }, + "ListScanRuns": { + "methods": [ + "list_scan_runs" + ] + }, + "StartScanRun": { + "methods": [ + "start_scan_run" + ] + }, + "StopScanRun": { + "methods": [ + "stop_scan_run" + ] + }, + "UpdateScanConfig": { + "methods": [ + "update_scan_config" + ] + } + } + } + } + } + } +} diff --git a/google/cloud/websecurityscanner_v1/services/__init__.py b/google/cloud/websecurityscanner_v1/services/__init__.py index 42ffdf2..4de6597 100644 --- a/google/cloud/websecurityscanner_v1/services/__init__.py +++ b/google/cloud/websecurityscanner_v1/services/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/google/cloud/websecurityscanner_v1/services/web_security_scanner/__init__.py b/google/cloud/websecurityscanner_v1/services/web_security_scanner/__init__.py index d841cb5..4aae8e1 100644 --- a/google/cloud/websecurityscanner_v1/services/web_security_scanner/__init__.py +++ b/google/cloud/websecurityscanner_v1/services/web_security_scanner/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from .client import WebSecurityScannerClient from .async_client import WebSecurityScannerAsyncClient diff --git a/google/cloud/websecurityscanner_v1/services/web_security_scanner/async_client.py b/google/cloud/websecurityscanner_v1/services/web_security_scanner/async_client.py index 125c55f..a877e7f 100644 --- a/google/cloud/websecurityscanner_v1/services/web_security_scanner/async_client.py +++ b/google/cloud/websecurityscanner_v1/services/web_security_scanner/async_client.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict import functools import re @@ -22,10 +20,10 @@ import pkg_resources import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore from google.cloud.websecurityscanner_v1.services.web_security_scanner import pagers @@ -38,8 +36,7 @@ from google.cloud.websecurityscanner_v1.types import scan_run_error_trace from google.cloud.websecurityscanner_v1.types import scan_run_warning_trace from google.cloud.websecurityscanner_v1.types import web_security_scanner -from google.protobuf import timestamp_pb2 as timestamp # type: ignore - +from google.protobuf import timestamp_pb2 # type: ignore from .transports.base import WebSecurityScannerTransport, DEFAULT_CLIENT_INFO from .transports.grpc_asyncio import WebSecurityScannerGrpcAsyncIOTransport from .client import WebSecurityScannerClient @@ -59,31 +56,26 @@ class WebSecurityScannerAsyncClient: finding_path = staticmethod(WebSecurityScannerClient.finding_path) parse_finding_path = staticmethod(WebSecurityScannerClient.parse_finding_path) - common_billing_account_path = staticmethod( WebSecurityScannerClient.common_billing_account_path ) parse_common_billing_account_path = staticmethod( WebSecurityScannerClient.parse_common_billing_account_path ) - common_folder_path = staticmethod(WebSecurityScannerClient.common_folder_path) parse_common_folder_path = staticmethod( WebSecurityScannerClient.parse_common_folder_path ) - common_organization_path = staticmethod( WebSecurityScannerClient.common_organization_path ) parse_common_organization_path = staticmethod( WebSecurityScannerClient.parse_common_organization_path ) - common_project_path = staticmethod(WebSecurityScannerClient.common_project_path) parse_common_project_path = staticmethod( WebSecurityScannerClient.parse_common_project_path ) - common_location_path = staticmethod(WebSecurityScannerClient.common_location_path) parse_common_location_path = staticmethod( WebSecurityScannerClient.parse_common_location_path @@ -91,7 +83,8 @@ class WebSecurityScannerAsyncClient: @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -106,7 +99,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -123,7 +116,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> WebSecurityScannerTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: WebSecurityScannerTransport: The transport used by the client instance. @@ -138,12 +131,12 @@ def transport(self) -> WebSecurityScannerTransport: def __init__( self, *, - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, transport: Union[str, WebSecurityScannerTransport] = "grpc_asyncio", client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the web security scanner client. + """Instantiates the web security scanner client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -175,7 +168,6 @@ def __init__( google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport creation failed for any reason. """ - self._client = WebSecurityScannerClient( credentials=credentials, transport=transport, @@ -197,7 +189,6 @@ async def create_scan_config( request (:class:`google.cloud.websecurityscanner_v1.types.CreateScanConfigRequest`): The request object. Request for the `CreateScanConfig` method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -211,7 +202,6 @@ async def create_scan_config( """ # Create or coerce a protobuf request object. - request = web_security_scanner.CreateScanConfigRequest(request) # Wrap the RPC method; this adds retry and timeout information, @@ -249,7 +239,6 @@ async def delete_scan_config( request (:class:`google.cloud.websecurityscanner_v1.types.DeleteScanConfigRequest`): The request object. Request for the `DeleteScanConfig` method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -257,7 +246,6 @@ async def delete_scan_config( sent along with the request as metadata. """ # Create or coerce a protobuf request object. - request = web_security_scanner.DeleteScanConfigRequest(request) # Wrap the RPC method; this adds retry and timeout information, @@ -269,7 +257,8 @@ async def delete_scan_config( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -302,7 +291,6 @@ async def get_scan_config( request (:class:`google.cloud.websecurityscanner_v1.types.GetScanConfigRequest`): The request object. Request for the `GetScanConfig` method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -316,7 +304,6 @@ async def get_scan_config( """ # Create or coerce a protobuf request object. - request = web_security_scanner.GetScanConfigRequest(request) # Wrap the RPC method; this adds retry and timeout information, @@ -328,7 +315,8 @@ async def get_scan_config( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -362,7 +350,6 @@ async def list_scan_configs( request (:class:`google.cloud.websecurityscanner_v1.types.ListScanConfigsRequest`): The request object. Request for the `ListScanConfigs` method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -378,7 +365,6 @@ async def list_scan_configs( """ # Create or coerce a protobuf request object. - request = web_security_scanner.ListScanConfigsRequest(request) # Wrap the RPC method; this adds retry and timeout information, @@ -390,7 +376,8 @@ async def list_scan_configs( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -431,7 +418,6 @@ async def update_scan_config( request (:class:`google.cloud.websecurityscanner_v1.types.UpdateScanConfigRequest`): The request object. Request for the `UpdateScanConfigRequest` method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -445,7 +431,6 @@ async def update_scan_config( """ # Create or coerce a protobuf request object. - request = web_security_scanner.UpdateScanConfigRequest(request) # Wrap the RPC method; this adds retry and timeout information, @@ -484,7 +469,6 @@ async def start_scan_run( request (:class:`google.cloud.websecurityscanner_v1.types.StartScanRunRequest`): The request object. Request for the `StartScanRun` method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -499,7 +483,6 @@ async def start_scan_run( """ # Create or coerce a protobuf request object. - request = web_security_scanner.StartScanRunRequest(request) # Wrap the RPC method; this adds retry and timeout information, @@ -535,7 +518,6 @@ async def get_scan_run( Args: request (:class:`google.cloud.websecurityscanner_v1.types.GetScanRunRequest`): The request object. Request for the `GetScanRun` method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -550,7 +532,6 @@ async def get_scan_run( """ # Create or coerce a protobuf request object. - request = web_security_scanner.GetScanRunRequest(request) # Wrap the RPC method; this adds retry and timeout information, @@ -562,7 +543,8 @@ async def get_scan_run( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -597,7 +579,6 @@ async def list_scan_runs( request (:class:`google.cloud.websecurityscanner_v1.types.ListScanRunsRequest`): The request object. Request for the `ListScanRuns` method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -613,7 +594,6 @@ async def list_scan_runs( """ # Create or coerce a protobuf request object. - request = web_security_scanner.ListScanRunsRequest(request) # Wrap the RPC method; this adds retry and timeout information, @@ -625,7 +605,8 @@ async def list_scan_runs( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -665,7 +646,6 @@ async def stop_scan_run( request (:class:`google.cloud.websecurityscanner_v1.types.StopScanRunRequest`): The request object. Request for the `StopScanRun` method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -680,7 +660,6 @@ async def stop_scan_run( """ # Create or coerce a protobuf request object. - request = web_security_scanner.StopScanRunRequest(request) # Wrap the RPC method; this adds retry and timeout information, @@ -717,7 +696,6 @@ async def list_crawled_urls( request (:class:`google.cloud.websecurityscanner_v1.types.ListCrawledUrlsRequest`): The request object. Request for the `ListCrawledUrls` method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -733,7 +711,6 @@ async def list_crawled_urls( """ # Create or coerce a protobuf request object. - request = web_security_scanner.ListCrawledUrlsRequest(request) # Wrap the RPC method; this adds retry and timeout information, @@ -745,7 +722,8 @@ async def list_crawled_urls( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -784,7 +762,6 @@ async def get_finding( Args: request (:class:`google.cloud.websecurityscanner_v1.types.GetFindingRequest`): The request object. Request for the `GetFinding` method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -799,7 +776,6 @@ async def get_finding( """ # Create or coerce a protobuf request object. - request = web_security_scanner.GetFindingRequest(request) # Wrap the RPC method; this adds retry and timeout information, @@ -811,7 +787,8 @@ async def get_finding( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -845,7 +822,6 @@ async def list_findings( request (:class:`google.cloud.websecurityscanner_v1.types.ListFindingsRequest`): The request object. Request for the `ListFindings` method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -861,7 +837,6 @@ async def list_findings( """ # Create or coerce a protobuf request object. - request = web_security_scanner.ListFindingsRequest(request) # Wrap the RPC method; this adds retry and timeout information, @@ -873,7 +848,8 @@ async def list_findings( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -913,7 +889,6 @@ async def list_finding_type_stats( request (:class:`google.cloud.websecurityscanner_v1.types.ListFindingTypeStatsRequest`): The request object. Request for the `ListFindingTypeStats` method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -925,7 +900,6 @@ async def list_finding_type_stats( Response for the ListFindingTypeStats method. """ # Create or coerce a protobuf request object. - request = web_security_scanner.ListFindingTypeStatsRequest(request) # Wrap the RPC method; this adds retry and timeout information, @@ -937,7 +911,8 @@ async def list_finding_type_stats( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), diff --git a/google/cloud/websecurityscanner_v1/services/web_security_scanner/client.py b/google/cloud/websecurityscanner_v1/services/web_security_scanner/client.py index 4b2ebd6..975c24c 100644 --- a/google/cloud/websecurityscanner_v1/services/web_security_scanner/client.py +++ b/google/cloud/websecurityscanner_v1/services/web_security_scanner/client.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict from distutils import util import os @@ -23,10 +21,10 @@ import pkg_resources from google.api_core import client_options as client_options_lib # type: ignore -from google.api_core import exceptions # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport import mtls # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.auth.exceptions import MutualTLSChannelError # type: ignore @@ -42,8 +40,7 @@ from google.cloud.websecurityscanner_v1.types import scan_run_error_trace from google.cloud.websecurityscanner_v1.types import scan_run_warning_trace from google.cloud.websecurityscanner_v1.types import web_security_scanner -from google.protobuf import timestamp_pb2 as timestamp # type: ignore - +from google.protobuf import timestamp_pb2 # type: ignore from .transports.base import WebSecurityScannerTransport, DEFAULT_CLIENT_INFO from .transports.grpc import WebSecurityScannerGrpcTransport from .transports.grpc_asyncio import WebSecurityScannerGrpcAsyncIOTransport @@ -66,7 +63,7 @@ class WebSecurityScannerClientMeta(type): def get_transport_class( cls, label: str = None, ) -> Type[WebSecurityScannerTransport]: - """Return an appropriate transport class. + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -93,7 +90,8 @@ class WebSecurityScannerClient(metaclass=WebSecurityScannerClientMeta): @staticmethod def _get_default_mtls_endpoint(api_endpoint): - """Convert api endpoint to mTLS endpoint. + """Converts api endpoint to mTLS endpoint. + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. Args: @@ -127,7 +125,8 @@ def _get_default_mtls_endpoint(api_endpoint): @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -144,7 +143,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -163,10 +162,11 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> WebSecurityScannerTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - WebSecurityScannerTransport: The transport used by the client instance. + WebSecurityScannerTransport: The transport used by the client + instance. """ return self._transport @@ -174,7 +174,7 @@ def transport(self) -> WebSecurityScannerTransport: def finding_path( project: str, scan_config: str, scan_run: str, finding: str, ) -> str: - """Return a fully-qualified finding string.""" + """Returns a fully-qualified finding string.""" return "projects/{project}/scanConfigs/{scan_config}/scanRuns/{scan_run}/findings/{finding}".format( project=project, scan_config=scan_config, @@ -184,7 +184,7 @@ def finding_path( @staticmethod def parse_finding_path(path: str) -> Dict[str, str]: - """Parse a finding path into its component segments.""" + """Parses a finding path into its component segments.""" m = re.match( r"^projects/(?P.+?)/scanConfigs/(?P.+?)/scanRuns/(?P.+?)/findings/(?P.+?)$", path, @@ -193,7 +193,7 @@ def parse_finding_path(path: str) -> Dict[str, str]: @staticmethod def common_billing_account_path(billing_account: str,) -> str: - """Return a fully-qualified billing_account string.""" + """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -206,7 +206,7 @@ def parse_common_billing_account_path(path: str) -> Dict[str, str]: @staticmethod def common_folder_path(folder: str,) -> str: - """Return a fully-qualified folder string.""" + """Returns a fully-qualified folder string.""" return "folders/{folder}".format(folder=folder,) @staticmethod @@ -217,7 +217,7 @@ def parse_common_folder_path(path: str) -> Dict[str, str]: @staticmethod def common_organization_path(organization: str,) -> str: - """Return a fully-qualified organization string.""" + """Returns a fully-qualified organization string.""" return "organizations/{organization}".format(organization=organization,) @staticmethod @@ -228,7 +228,7 @@ def parse_common_organization_path(path: str) -> Dict[str, str]: @staticmethod def common_project_path(project: str,) -> str: - """Return a fully-qualified project string.""" + """Returns a fully-qualified project string.""" return "projects/{project}".format(project=project,) @staticmethod @@ -239,7 +239,7 @@ def parse_common_project_path(path: str) -> Dict[str, str]: @staticmethod def common_location_path(project: str, location: str,) -> str: - """Return a fully-qualified location string.""" + """Returns a fully-qualified location string.""" return "projects/{project}/locations/{location}".format( project=project, location=location, ) @@ -253,12 +253,12 @@ def parse_common_location_path(path: str) -> Dict[str, str]: def __init__( self, *, - credentials: Optional[credentials.Credentials] = None, + credentials: Optional[ga_credentials.Credentials] = None, transport: Union[str, WebSecurityScannerTransport, None] = None, client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the web security scanner client. + """Instantiates the web security scanner client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -313,9 +313,10 @@ def __init__( client_cert_source_func = client_options.client_cert_source else: is_mtls = mtls.has_default_client_cert_source() - client_cert_source_func = ( - mtls.default_client_cert_source() if is_mtls else None - ) + if is_mtls: + client_cert_source_func = mtls.default_client_cert_source() + else: + client_cert_source_func = None # Figure out which api endpoint to use. if client_options.api_endpoint is not None: @@ -327,12 +328,14 @@ def __init__( elif use_mtls_env == "always": api_endpoint = self.DEFAULT_MTLS_ENDPOINT elif use_mtls_env == "auto": - api_endpoint = ( - self.DEFAULT_MTLS_ENDPOINT if is_mtls else self.DEFAULT_ENDPOINT - ) + if is_mtls: + api_endpoint = self.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = self.DEFAULT_ENDPOINT else: raise MutualTLSChannelError( - "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted values: never, auto, always" + "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted " + "values: never, auto, always" ) # Save or instantiate the transport. @@ -347,8 +350,8 @@ def __init__( ) if client_options.scopes: raise ValueError( - "When providing a transport instance, " - "provide its scopes directly." + "When providing a transport instance, provide its scopes " + "directly." ) self._transport = transport else: @@ -377,7 +380,6 @@ def create_scan_config( request (google.cloud.websecurityscanner_v1.types.CreateScanConfigRequest): The request object. Request for the `CreateScanConfig` method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -391,7 +393,6 @@ def create_scan_config( """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes # in a web_security_scanner.CreateScanConfigRequest. # There's no risk of modifying the input as we've already verified @@ -430,7 +431,6 @@ def delete_scan_config( request (google.cloud.websecurityscanner_v1.types.DeleteScanConfigRequest): The request object. Request for the `DeleteScanConfig` method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -438,7 +438,6 @@ def delete_scan_config( sent along with the request as metadata. """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes # in a web_security_scanner.DeleteScanConfigRequest. # There's no risk of modifying the input as we've already verified @@ -475,7 +474,6 @@ def get_scan_config( request (google.cloud.websecurityscanner_v1.types.GetScanConfigRequest): The request object. Request for the `GetScanConfig` method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -489,7 +487,6 @@ def get_scan_config( """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes # in a web_security_scanner.GetScanConfigRequest. # There's no risk of modifying the input as we've already verified @@ -527,7 +524,6 @@ def list_scan_configs( request (google.cloud.websecurityscanner_v1.types.ListScanConfigsRequest): The request object. Request for the `ListScanConfigs` method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -543,7 +539,6 @@ def list_scan_configs( """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes # in a web_security_scanner.ListScanConfigsRequest. # There's no risk of modifying the input as we've already verified @@ -588,7 +583,6 @@ def update_scan_config( request (google.cloud.websecurityscanner_v1.types.UpdateScanConfigRequest): The request object. Request for the `UpdateScanConfigRequest` method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -602,7 +596,6 @@ def update_scan_config( """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes # in a web_security_scanner.UpdateScanConfigRequest. # There's no risk of modifying the input as we've already verified @@ -642,7 +635,6 @@ def start_scan_run( request (google.cloud.websecurityscanner_v1.types.StartScanRunRequest): The request object. Request for the `StartScanRun` method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -657,7 +649,6 @@ def start_scan_run( """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes # in a web_security_scanner.StartScanRunRequest. # There's no risk of modifying the input as we've already verified @@ -694,7 +685,6 @@ def get_scan_run( Args: request (google.cloud.websecurityscanner_v1.types.GetScanRunRequest): The request object. Request for the `GetScanRun` method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -709,7 +699,6 @@ def get_scan_run( """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes # in a web_security_scanner.GetScanRunRequest. # There's no risk of modifying the input as we've already verified @@ -748,7 +737,6 @@ def list_scan_runs( request (google.cloud.websecurityscanner_v1.types.ListScanRunsRequest): The request object. Request for the `ListScanRuns` method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -764,7 +752,6 @@ def list_scan_runs( """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes # in a web_security_scanner.ListScanRunsRequest. # There's no risk of modifying the input as we've already verified @@ -808,7 +795,6 @@ def stop_scan_run( request (google.cloud.websecurityscanner_v1.types.StopScanRunRequest): The request object. Request for the `StopScanRun` method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -823,7 +809,6 @@ def stop_scan_run( """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes # in a web_security_scanner.StopScanRunRequest. # There's no risk of modifying the input as we've already verified @@ -861,7 +846,6 @@ def list_crawled_urls( request (google.cloud.websecurityscanner_v1.types.ListCrawledUrlsRequest): The request object. Request for the `ListCrawledUrls` method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -877,7 +861,6 @@ def list_crawled_urls( """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes # in a web_security_scanner.ListCrawledUrlsRequest. # There's no risk of modifying the input as we've already verified @@ -920,7 +903,6 @@ def get_finding( Args: request (google.cloud.websecurityscanner_v1.types.GetFindingRequest): The request object. Request for the `GetFinding` method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -935,7 +917,6 @@ def get_finding( """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes # in a web_security_scanner.GetFindingRequest. # There's no risk of modifying the input as we've already verified @@ -973,7 +954,6 @@ def list_findings( request (google.cloud.websecurityscanner_v1.types.ListFindingsRequest): The request object. Request for the `ListFindings` method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -989,7 +969,6 @@ def list_findings( """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes # in a web_security_scanner.ListFindingsRequest. # There's no risk of modifying the input as we've already verified @@ -1033,7 +1012,6 @@ def list_finding_type_stats( request (google.cloud.websecurityscanner_v1.types.ListFindingTypeStatsRequest): The request object. Request for the `ListFindingTypeStats` method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1045,7 +1023,6 @@ def list_finding_type_stats( Response for the ListFindingTypeStats method. """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes # in a web_security_scanner.ListFindingTypeStatsRequest. # There's no risk of modifying the input as we've already verified diff --git a/google/cloud/websecurityscanner_v1/services/web_security_scanner/pagers.py b/google/cloud/websecurityscanner_v1/services/web_security_scanner/pagers.py index 7b59634..38adf57 100644 --- a/google/cloud/websecurityscanner_v1/services/web_security_scanner/pagers.py +++ b/google/cloud/websecurityscanner_v1/services/web_security_scanner/pagers.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from typing import ( Any, AsyncIterable, @@ -121,7 +119,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -251,7 +249,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -379,7 +377,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -509,7 +507,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and diff --git a/google/cloud/websecurityscanner_v1/services/web_security_scanner/transports/__init__.py b/google/cloud/websecurityscanner_v1/services/web_security_scanner/transports/__init__.py index caf0502..fce7d6c 100644 --- a/google/cloud/websecurityscanner_v1/services/web_security_scanner/transports/__init__.py +++ b/google/cloud/websecurityscanner_v1/services/web_security_scanner/transports/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict from typing import Dict, Type diff --git a/google/cloud/websecurityscanner_v1/services/web_security_scanner/transports/base.py b/google/cloud/websecurityscanner_v1/services/web_security_scanner/transports/base.py index 801b65b..4fc57e8 100644 --- a/google/cloud/websecurityscanner_v1/services/web_security_scanner/transports/base.py +++ b/google/cloud/websecurityscanner_v1/services/web_security_scanner/transports/base.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,23 +13,23 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import abc -import typing +from typing import Awaitable, Callable, Dict, Optional, Sequence, Union +import packaging.version import pkg_resources -from google import auth # type: ignore -from google.api_core import exceptions # type: ignore +import google.auth # type: ignore +import google.api_core # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.cloud.websecurityscanner_v1.types import finding from google.cloud.websecurityscanner_v1.types import scan_config from google.cloud.websecurityscanner_v1.types import scan_run from google.cloud.websecurityscanner_v1.types import web_security_scanner -from google.protobuf import empty_pb2 as empty # type: ignore - +from google.protobuf import empty_pb2 # type: ignore try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( @@ -41,27 +40,41 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() +try: + # google.auth.__version__ was added in 1.26.0 + _GOOGLE_AUTH_VERSION = google.auth.__version__ +except AttributeError: + try: # try pkg_resources if it is available + _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version + except pkg_resources.DistributionNotFound: # pragma: NO COVER + _GOOGLE_AUTH_VERSION = None + +_API_CORE_VERSION = google.api_core.__version__ + class WebSecurityScannerTransport(abc.ABC): """Abstract transport class for WebSecurityScanner.""" AUTH_SCOPES = ("https://www.googleapis.com/auth/cloud-platform",) + DEFAULT_HOST: str = "websecurityscanner.googleapis.com" + def __init__( self, *, - host: str = "websecurityscanner.googleapis.com", - credentials: credentials.Credentials = None, - credentials_file: typing.Optional[str] = None, - scopes: typing.Optional[typing.Sequence[str]] = AUTH_SCOPES, - quota_project_id: typing.Optional[str] = None, + host: str = DEFAULT_HOST, + credentials: ga_credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, **kwargs, ) -> None: """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -70,7 +83,7 @@ def __init__( credentials_file (Optional[str]): A file with credentials that can be loaded with :func:`google.auth.load_credentials_from_file`. This argument is mutually exclusive with credentials. - scope (Optional[Sequence[str]]): A list of scopes. + scopes (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -84,29 +97,76 @@ def __init__( host += ":443" self._host = host + scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + # Save the scopes. self._scopes = scopes or self.AUTH_SCOPES # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: - raise exceptions.DuplicateCredentialArgs( + raise core_exceptions.DuplicateCredentialArgs( "'credentials_file' and 'credentials' are mutually exclusive" ) if credentials_file is not None: - credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=self._scopes, quota_project_id=quota_project_id + credentials, _ = google.auth.load_credentials_from_file( + credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) elif credentials is None: - credentials, _ = auth.default( - scopes=self._scopes, quota_project_id=quota_project_id + credentials, _ = google.auth.default( + **scopes_kwargs, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials + # TODO(busunkim): These two class methods are in the base transport + # to avoid duplicating code across the transport classes. These functions + # should be deleted once the minimum required versions of google-api-core + # and google-auth are increased. + + # TODO: Remove this function once google-auth >= 1.25.0 is required + @classmethod + def _get_scopes_kwargs( + cls, host: str, scopes: Optional[Sequence[str]] + ) -> Dict[str, Optional[Sequence[str]]]: + """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" + + scopes_kwargs = {} + + if _GOOGLE_AUTH_VERSION and ( + packaging.version.parse(_GOOGLE_AUTH_VERSION) + >= packaging.version.parse("1.25.0") + ): + scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} + else: + scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} + + return scopes_kwargs + + # TODO: Remove this function once google-api-core >= 1.26.0 is required + @classmethod + def _get_self_signed_jwt_kwargs( + cls, host: str, scopes: Optional[Sequence[str]] + ) -> Dict[str, Union[Optional[Sequence[str]], str]]: + """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" + + self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} + + if _API_CORE_VERSION and ( + packaging.version.parse(_API_CORE_VERSION) + >= packaging.version.parse("1.26.0") + ): + self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES + self_signed_jwt_kwargs["scopes"] = scopes + self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST + else: + self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES + + return self_signed_jwt_kwargs + def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { @@ -120,7 +180,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -134,7 +195,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -148,7 +210,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -168,7 +231,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -182,7 +246,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -199,7 +264,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -213,7 +279,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -227,7 +294,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -241,7 +309,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -253,38 +322,38 @@ def _prep_wrapped_messages(self, client_info): @property def create_scan_config( self, - ) -> typing.Callable[ + ) -> Callable[ [web_security_scanner.CreateScanConfigRequest], - typing.Union[scan_config.ScanConfig, typing.Awaitable[scan_config.ScanConfig]], + Union[scan_config.ScanConfig, Awaitable[scan_config.ScanConfig]], ]: raise NotImplementedError() @property def delete_scan_config( self, - ) -> typing.Callable[ + ) -> Callable[ [web_security_scanner.DeleteScanConfigRequest], - typing.Union[empty.Empty, typing.Awaitable[empty.Empty]], + Union[empty_pb2.Empty, Awaitable[empty_pb2.Empty]], ]: raise NotImplementedError() @property def get_scan_config( self, - ) -> typing.Callable[ + ) -> Callable[ [web_security_scanner.GetScanConfigRequest], - typing.Union[scan_config.ScanConfig, typing.Awaitable[scan_config.ScanConfig]], + Union[scan_config.ScanConfig, Awaitable[scan_config.ScanConfig]], ]: raise NotImplementedError() @property def list_scan_configs( self, - ) -> typing.Callable[ + ) -> Callable[ [web_security_scanner.ListScanConfigsRequest], - typing.Union[ + Union[ web_security_scanner.ListScanConfigsResponse, - typing.Awaitable[web_security_scanner.ListScanConfigsResponse], + Awaitable[web_security_scanner.ListScanConfigsResponse], ], ]: raise NotImplementedError() @@ -292,38 +361,38 @@ def list_scan_configs( @property def update_scan_config( self, - ) -> typing.Callable[ + ) -> Callable[ [web_security_scanner.UpdateScanConfigRequest], - typing.Union[scan_config.ScanConfig, typing.Awaitable[scan_config.ScanConfig]], + Union[scan_config.ScanConfig, Awaitable[scan_config.ScanConfig]], ]: raise NotImplementedError() @property def start_scan_run( self, - ) -> typing.Callable[ + ) -> Callable[ [web_security_scanner.StartScanRunRequest], - typing.Union[scan_run.ScanRun, typing.Awaitable[scan_run.ScanRun]], + Union[scan_run.ScanRun, Awaitable[scan_run.ScanRun]], ]: raise NotImplementedError() @property def get_scan_run( self, - ) -> typing.Callable[ + ) -> Callable[ [web_security_scanner.GetScanRunRequest], - typing.Union[scan_run.ScanRun, typing.Awaitable[scan_run.ScanRun]], + Union[scan_run.ScanRun, Awaitable[scan_run.ScanRun]], ]: raise NotImplementedError() @property def list_scan_runs( self, - ) -> typing.Callable[ + ) -> Callable[ [web_security_scanner.ListScanRunsRequest], - typing.Union[ + Union[ web_security_scanner.ListScanRunsResponse, - typing.Awaitable[web_security_scanner.ListScanRunsResponse], + Awaitable[web_security_scanner.ListScanRunsResponse], ], ]: raise NotImplementedError() @@ -331,20 +400,20 @@ def list_scan_runs( @property def stop_scan_run( self, - ) -> typing.Callable[ + ) -> Callable[ [web_security_scanner.StopScanRunRequest], - typing.Union[scan_run.ScanRun, typing.Awaitable[scan_run.ScanRun]], + Union[scan_run.ScanRun, Awaitable[scan_run.ScanRun]], ]: raise NotImplementedError() @property def list_crawled_urls( self, - ) -> typing.Callable[ + ) -> Callable[ [web_security_scanner.ListCrawledUrlsRequest], - typing.Union[ + Union[ web_security_scanner.ListCrawledUrlsResponse, - typing.Awaitable[web_security_scanner.ListCrawledUrlsResponse], + Awaitable[web_security_scanner.ListCrawledUrlsResponse], ], ]: raise NotImplementedError() @@ -352,20 +421,20 @@ def list_crawled_urls( @property def get_finding( self, - ) -> typing.Callable[ + ) -> Callable[ [web_security_scanner.GetFindingRequest], - typing.Union[finding.Finding, typing.Awaitable[finding.Finding]], + Union[finding.Finding, Awaitable[finding.Finding]], ]: raise NotImplementedError() @property def list_findings( self, - ) -> typing.Callable[ + ) -> Callable[ [web_security_scanner.ListFindingsRequest], - typing.Union[ + Union[ web_security_scanner.ListFindingsResponse, - typing.Awaitable[web_security_scanner.ListFindingsResponse], + Awaitable[web_security_scanner.ListFindingsResponse], ], ]: raise NotImplementedError() @@ -373,11 +442,11 @@ def list_findings( @property def list_finding_type_stats( self, - ) -> typing.Callable[ + ) -> Callable[ [web_security_scanner.ListFindingTypeStatsRequest], - typing.Union[ + Union[ web_security_scanner.ListFindingTypeStatsResponse, - typing.Awaitable[web_security_scanner.ListFindingTypeStatsResponse], + Awaitable[web_security_scanner.ListFindingTypeStatsResponse], ], ]: raise NotImplementedError() diff --git a/google/cloud/websecurityscanner_v1/services/web_security_scanner/transports/grpc.py b/google/cloud/websecurityscanner_v1/services/web_security_scanner/transports/grpc.py index 05d0e96..0ed405e 100644 --- a/google/cloud/websecurityscanner_v1/services/web_security_scanner/transports/grpc.py +++ b/google/cloud/websecurityscanner_v1/services/web_security_scanner/transports/grpc.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,14 +13,13 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import warnings -from typing import Callable, Dict, Optional, Sequence, Tuple +from typing import Callable, Dict, Optional, Sequence, Tuple, Union from google.api_core import grpc_helpers # type: ignore from google.api_core import gapic_v1 # type: ignore -from google import auth # type: ignore -from google.auth import credentials # type: ignore +import google.auth # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore import grpc # type: ignore @@ -30,8 +28,7 @@ from google.cloud.websecurityscanner_v1.types import scan_config from google.cloud.websecurityscanner_v1.types import scan_run from google.cloud.websecurityscanner_v1.types import web_security_scanner -from google.protobuf import empty_pb2 as empty # type: ignore - +from google.protobuf import empty_pb2 # type: ignore from .base import WebSecurityScannerTransport, DEFAULT_CLIENT_INFO @@ -57,7 +54,7 @@ def __init__( self, *, host: str = "websecurityscanner.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: str = None, scopes: Sequence[str] = None, channel: grpc.Channel = None, @@ -71,7 +68,8 @@ def __init__( """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -181,7 +179,7 @@ def __init__( def create_channel( cls, host: str = "websecurityscanner.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: str = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, @@ -212,13 +210,15 @@ def create_channel( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ - scopes = scopes or cls.AUTH_SCOPES + + self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) + return grpc_helpers.create_channel( host, credentials=credentials, credentials_file=credentials_file, - scopes=scopes, quota_project_id=quota_project_id, + **self_signed_jwt_kwargs, **kwargs, ) @@ -259,7 +259,7 @@ def create_scan_config( @property def delete_scan_config( self, - ) -> Callable[[web_security_scanner.DeleteScanConfigRequest], empty.Empty]: + ) -> Callable[[web_security_scanner.DeleteScanConfigRequest], empty_pb2.Empty]: r"""Return a callable for the delete scan config method over gRPC. Deletes an existing ScanConfig and its child @@ -279,7 +279,7 @@ def delete_scan_config( self._stubs["delete_scan_config"] = self.grpc_channel.unary_unary( "/google.cloud.websecurityscanner.v1.WebSecurityScanner/DeleteScanConfig", request_serializer=web_security_scanner.DeleteScanConfigRequest.serialize, - response_deserializer=empty.Empty.FromString, + response_deserializer=empty_pb2.Empty.FromString, ) return self._stubs["delete_scan_config"] diff --git a/google/cloud/websecurityscanner_v1/services/web_security_scanner/transports/grpc_asyncio.py b/google/cloud/websecurityscanner_v1/services/web_security_scanner/transports/grpc_asyncio.py index 22da14d..a055772 100644 --- a/google/cloud/websecurityscanner_v1/services/web_security_scanner/transports/grpc_asyncio.py +++ b/google/cloud/websecurityscanner_v1/services/web_security_scanner/transports/grpc_asyncio.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,15 +13,14 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import warnings -from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple +from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union from google.api_core import gapic_v1 # type: ignore from google.api_core import grpc_helpers_async # type: ignore -from google import auth # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore @@ -31,8 +29,7 @@ from google.cloud.websecurityscanner_v1.types import scan_config from google.cloud.websecurityscanner_v1.types import scan_run from google.cloud.websecurityscanner_v1.types import web_security_scanner -from google.protobuf import empty_pb2 as empty # type: ignore - +from google.protobuf import empty_pb2 # type: ignore from .base import WebSecurityScannerTransport, DEFAULT_CLIENT_INFO from .grpc import WebSecurityScannerGrpcTransport @@ -60,7 +57,7 @@ class WebSecurityScannerGrpcAsyncIOTransport(WebSecurityScannerTransport): def create_channel( cls, host: str = "websecurityscanner.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, @@ -87,13 +84,15 @@ def create_channel( Returns: aio.Channel: A gRPC AsyncIO channel object. """ - scopes = scopes or cls.AUTH_SCOPES + + self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) + return grpc_helpers_async.create_channel( host, credentials=credentials, credentials_file=credentials_file, - scopes=scopes, quota_project_id=quota_project_id, + **self_signed_jwt_kwargs, **kwargs, ) @@ -101,7 +100,7 @@ def __init__( self, *, host: str = "websecurityscanner.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, channel: aio.Channel = None, @@ -115,7 +114,8 @@ def __init__( """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -173,7 +173,6 @@ def __init__( # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - else: if api_mtls_endpoint: host = api_mtls_endpoint @@ -265,7 +264,7 @@ def create_scan_config( def delete_scan_config( self, ) -> Callable[ - [web_security_scanner.DeleteScanConfigRequest], Awaitable[empty.Empty] + [web_security_scanner.DeleteScanConfigRequest], Awaitable[empty_pb2.Empty] ]: r"""Return a callable for the delete scan config method over gRPC. @@ -286,7 +285,7 @@ def delete_scan_config( self._stubs["delete_scan_config"] = self.grpc_channel.unary_unary( "/google.cloud.websecurityscanner.v1.WebSecurityScanner/DeleteScanConfig", request_serializer=web_security_scanner.DeleteScanConfigRequest.serialize, - response_deserializer=empty.Empty.FromString, + response_deserializer=empty_pb2.Empty.FromString, ) return self._stubs["delete_scan_config"] diff --git a/google/cloud/websecurityscanner_v1/types/__init__.py b/google/cloud/websecurityscanner_v1/types/__init__.py index d1f7fe5..33fc9ea 100644 --- a/google/cloud/websecurityscanner_v1/types/__init__.py +++ b/google/cloud/websecurityscanner_v1/types/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from .crawled_url import CrawledUrl from .finding import Finding from .finding_addon import ( diff --git a/google/cloud/websecurityscanner_v1/types/crawled_url.py b/google/cloud/websecurityscanner_v1/types/crawled_url.py index d66c7e8..bb383e1 100644 --- a/google/cloud/websecurityscanner_v1/types/crawled_url.py +++ b/google/cloud/websecurityscanner_v1/types/crawled_url.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore @@ -40,11 +38,9 @@ class CrawledUrl(proto.Message): used to visit the URL. """ - http_method = proto.Field(proto.STRING, number=1) - - url = proto.Field(proto.STRING, number=2) - - body = proto.Field(proto.STRING, number=3) + http_method = proto.Field(proto.STRING, number=1,) + url = proto.Field(proto.STRING, number=2,) + body = proto.Field(proto.STRING, number=3,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/websecurityscanner_v1/types/finding.py b/google/cloud/websecurityscanner_v1/types/finding.py index e11e57d..d229356 100644 --- a/google/cloud/websecurityscanner_v1/types/finding.py +++ b/google/cloud/websecurityscanner_v1/types/finding.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,10 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.websecurityscanner_v1.types import finding_addon @@ -106,46 +103,30 @@ class Severity(proto.Enum): MEDIUM = 3 LOW = 4 - name = proto.Field(proto.STRING, number=1) - - finding_type = proto.Field(proto.STRING, number=2) - + name = proto.Field(proto.STRING, number=1,) + finding_type = proto.Field(proto.STRING, number=2,) severity = proto.Field(proto.ENUM, number=17, enum=Severity,) - - http_method = proto.Field(proto.STRING, number=3) - - fuzzed_url = proto.Field(proto.STRING, number=4) - - body = proto.Field(proto.STRING, number=5) - - description = proto.Field(proto.STRING, number=6) - - reproduction_url = proto.Field(proto.STRING, number=7) - - frame_url = proto.Field(proto.STRING, number=8) - - final_url = proto.Field(proto.STRING, number=9) - - tracking_id = proto.Field(proto.STRING, number=10) - + http_method = proto.Field(proto.STRING, number=3,) + fuzzed_url = proto.Field(proto.STRING, number=4,) + body = proto.Field(proto.STRING, number=5,) + description = proto.Field(proto.STRING, number=6,) + reproduction_url = proto.Field(proto.STRING, number=7,) + frame_url = proto.Field(proto.STRING, number=8,) + final_url = proto.Field(proto.STRING, number=9,) + tracking_id = proto.Field(proto.STRING, number=10,) form = proto.Field(proto.MESSAGE, number=16, message=finding_addon.Form,) - outdated_library = proto.Field( proto.MESSAGE, number=11, message=finding_addon.OutdatedLibrary, ) - violating_resource = proto.Field( proto.MESSAGE, number=12, message=finding_addon.ViolatingResource, ) - vulnerable_headers = proto.Field( proto.MESSAGE, number=15, message=finding_addon.VulnerableHeaders, ) - vulnerable_parameters = proto.Field( proto.MESSAGE, number=13, message=finding_addon.VulnerableParameters, ) - xss = proto.Field(proto.MESSAGE, number=14, message=finding_addon.Xss,) diff --git a/google/cloud/websecurityscanner_v1/types/finding_addon.py b/google/cloud/websecurityscanner_v1/types/finding_addon.py index a743d39..9fddb89 100644 --- a/google/cloud/websecurityscanner_v1/types/finding_addon.py +++ b/google/cloud/websecurityscanner_v1/types/finding_addon.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore @@ -33,7 +31,6 @@ 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 @@ -43,14 +40,12 @@ class Form(proto.Message): vulnerability. """ - action_uri = proto.Field(proto.STRING, number=1) - - fields = proto.RepeatedField(proto.STRING, number=2) + action_uri = proto.Field(proto.STRING, number=1,) + fields = proto.RepeatedField(proto.STRING, number=2,) class OutdatedLibrary(proto.Message): r"""Information reported for an outdated library. - Attributes: library_name (str): The name of the outdated library. @@ -61,11 +56,9 @@ class OutdatedLibrary(proto.Message): vulnerabilities in the library. """ - library_name = proto.Field(proto.STRING, number=1) - - version = proto.Field(proto.STRING, number=2) - - learn_more_urls = proto.RepeatedField(proto.STRING, number=3) + library_name = proto.Field(proto.STRING, number=1,) + version = proto.Field(proto.STRING, number=2,) + learn_more_urls = proto.RepeatedField(proto.STRING, number=3,) class ViolatingResource(proto.Message): @@ -79,25 +72,22 @@ class ViolatingResource(proto.Message): URL of this violating resource. """ - content_type = proto.Field(proto.STRING, number=1) - - resource_url = proto.Field(proto.STRING, number=2) + content_type = proto.Field(proto.STRING, number=1,) + resource_url = proto.Field(proto.STRING, number=2,) class VulnerableParameters(proto.Message): r"""Information about vulnerable request parameters. - Attributes: parameter_names (Sequence[str]): The vulnerable parameter names. """ - parameter_names = proto.RepeatedField(proto.STRING, number=1) + parameter_names = proto.RepeatedField(proto.STRING, number=1,) 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. @@ -107,7 +97,6 @@ class VulnerableHeaders(proto.Message): class Header(proto.Message): r"""Describes a HTTP Header. - Attributes: name (str): Header name. @@ -115,18 +104,15 @@ class Header(proto.Message): Header value. """ - name = proto.Field(proto.STRING, number=1) - - value = proto.Field(proto.STRING, number=2) + name = proto.Field(proto.STRING, number=1,) + value = proto.Field(proto.STRING, number=2,) headers = proto.RepeatedField(proto.MESSAGE, number=1, message=Header,) - missing_headers = proto.RepeatedField(proto.MESSAGE, number=2, message=Header,) class Xss(proto.Message): r"""Information reported for an XSS. - Attributes: stack_traces (Sequence[str]): Stack traces leading to the point where the @@ -161,13 +147,10 @@ class AttackVector(proto.Enum): SAME_ORIGIN = 14 USER_CONTROLLABLE_URL = 15 - stack_traces = proto.RepeatedField(proto.STRING, number=1) - - error_message = proto.Field(proto.STRING, number=2) - + stack_traces = proto.RepeatedField(proto.STRING, number=1,) + error_message = proto.Field(proto.STRING, number=2,) attack_vector = proto.Field(proto.ENUM, number=3, enum=AttackVector,) - - stored_xss_seeding_url = proto.Field(proto.STRING, number=4) + stored_xss_seeding_url = proto.Field(proto.STRING, number=4,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/websecurityscanner_v1/types/finding_type_stats.py b/google/cloud/websecurityscanner_v1/types/finding_type_stats.py index 5f69387..a9c0543 100644 --- a/google/cloud/websecurityscanner_v1/types/finding_type_stats.py +++ b/google/cloud/websecurityscanner_v1/types/finding_type_stats.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore @@ -36,9 +34,8 @@ class FindingTypeStats(proto.Message): to this finding type. """ - finding_type = proto.Field(proto.STRING, number=1) - - finding_count = proto.Field(proto.INT32, number=2) + finding_type = proto.Field(proto.STRING, number=1,) + finding_count = proto.Field(proto.INT32, number=2,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/websecurityscanner_v1/types/scan_config.py b/google/cloud/websecurityscanner_v1/types/scan_config.py index 05286f0..b8b5154 100644 --- a/google/cloud/websecurityscanner_v1/types/scan_config.py +++ b/google/cloud/websecurityscanner_v1/types/scan_config.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,11 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - -from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore __protobuf__ = proto.module( @@ -100,7 +97,6 @@ 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. @@ -126,9 +122,8 @@ class GoogleAccount(proto.Message): included in audit logs. """ - username = proto.Field(proto.STRING, number=1) - - password = proto.Field(proto.STRING, number=2) + username = proto.Field(proto.STRING, number=1,) + password = proto.Field(proto.STRING, number=2,) class CustomAccount(proto.Message): r"""Describes authentication configuration that uses a custom @@ -147,11 +142,9 @@ class CustomAccount(proto.Message): Required. The login form URL of the website. """ - username = proto.Field(proto.STRING, number=1) - - password = proto.Field(proto.STRING, number=2) - - login_url = proto.Field(proto.STRING, number=3) + username = proto.Field(proto.STRING, number=1,) + password = proto.Field(proto.STRING, number=2,) + login_url = proto.Field(proto.STRING, number=3,) class IapCredential(proto.Message): r"""Describes authentication configuration for Identity-Aware- @@ -176,7 +169,7 @@ class IapTestServiceAccountInfo(proto.Message): (IAP). """ - target_audience_client_id = proto.Field(proto.STRING, number=1) + target_audience_client_id = proto.Field(proto.STRING, number=1,) iap_test_service_account_info = proto.Field( proto.MESSAGE, @@ -191,14 +184,12 @@ class IapTestServiceAccountInfo(proto.Message): oneof="authentication", message="ScanConfig.Authentication.GoogleAccount", ) - custom_account = proto.Field( proto.MESSAGE, number=2, oneof="authentication", message="ScanConfig.Authentication.CustomAccount", ) - iap_credential = proto.Field( proto.MESSAGE, number=4, @@ -208,7 +199,6 @@ 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 @@ -222,36 +212,24 @@ class Schedule(proto.Message): """ schedule_time = proto.Field( - proto.MESSAGE, number=1, message=timestamp.Timestamp, + proto.MESSAGE, number=1, message=timestamp_pb2.Timestamp, ) + interval_duration_days = proto.Field(proto.INT32, number=2,) - interval_duration_days = proto.Field(proto.INT32, number=2) - - name = proto.Field(proto.STRING, number=1) - - display_name = proto.Field(proto.STRING, number=2) - - max_qps = proto.Field(proto.INT32, number=3) - - starting_urls = proto.RepeatedField(proto.STRING, number=4) - + name = proto.Field(proto.STRING, number=1,) + display_name = proto.Field(proto.STRING, number=2,) + max_qps = proto.Field(proto.INT32, number=3,) + starting_urls = proto.RepeatedField(proto.STRING, number=4,) authentication = proto.Field(proto.MESSAGE, number=5, message=Authentication,) - user_agent = proto.Field(proto.ENUM, number=6, enum=UserAgent,) - - blacklist_patterns = proto.RepeatedField(proto.STRING, number=7) - + blacklist_patterns = proto.RepeatedField(proto.STRING, number=7,) schedule = proto.Field(proto.MESSAGE, number=8, message=Schedule,) - export_to_security_command_center = proto.Field( proto.ENUM, number=10, enum=ExportToSecurityCommandCenter, ) - risk_level = proto.Field(proto.ENUM, number=12, enum=RiskLevel,) - - managed_scan = proto.Field(proto.BOOL, number=13) - - static_ip_scan = proto.Field(proto.BOOL, number=14) + managed_scan = proto.Field(proto.BOOL, number=13,) + static_ip_scan = proto.Field(proto.BOOL, number=14,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/websecurityscanner_v1/types/scan_config_error.py b/google/cloud/websecurityscanner_v1/types/scan_config_error.py index 10237a0..c66fcbc 100644 --- a/google/cloud/websecurityscanner_v1/types/scan_config_error.py +++ b/google/cloud/websecurityscanner_v1/types/scan_config_error.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore @@ -90,8 +88,7 @@ class Code(proto.Enum): UNSUPPORTED_URL_SCHEME = 42 code = proto.Field(proto.ENUM, number=1, enum=Code,) - - field_name = proto.Field(proto.STRING, number=2) + field_name = proto.Field(proto.STRING, number=2,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/websecurityscanner_v1/types/scan_run.py b/google/cloud/websecurityscanner_v1/types/scan_run.py index 0328dc6..896b0a8 100644 --- a/google/cloud/websecurityscanner_v1/types/scan_run.py +++ b/google/cloud/websecurityscanner_v1/types/scan_run.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,13 +13,11 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.websecurityscanner_v1.types import scan_run_error_trace from google.cloud.websecurityscanner_v1.types import scan_run_warning_trace -from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore __protobuf__ = proto.module( @@ -97,28 +94,18 @@ class ResultState(proto.Enum): ERROR = 2 KILLED = 3 - name = proto.Field(proto.STRING, number=1) - + name = proto.Field(proto.STRING, number=1,) execution_state = proto.Field(proto.ENUM, number=2, enum=ExecutionState,) - result_state = proto.Field(proto.ENUM, number=3, enum=ResultState,) - - start_time = proto.Field(proto.MESSAGE, number=4, message=timestamp.Timestamp,) - - end_time = proto.Field(proto.MESSAGE, number=5, message=timestamp.Timestamp,) - - urls_crawled_count = proto.Field(proto.INT64, number=6) - - urls_tested_count = proto.Field(proto.INT64, number=7) - - has_vulnerabilities = proto.Field(proto.BOOL, number=8) - - progress_percent = proto.Field(proto.INT32, number=9) - + start_time = proto.Field(proto.MESSAGE, number=4, message=timestamp_pb2.Timestamp,) + end_time = proto.Field(proto.MESSAGE, number=5, message=timestamp_pb2.Timestamp,) + urls_crawled_count = proto.Field(proto.INT64, number=6,) + urls_tested_count = proto.Field(proto.INT64, number=7,) + has_vulnerabilities = proto.Field(proto.BOOL, number=8,) + progress_percent = proto.Field(proto.INT32, number=9,) error_trace = proto.Field( proto.MESSAGE, number=10, message=scan_run_error_trace.ScanRunErrorTrace, ) - warning_traces = proto.RepeatedField( proto.MESSAGE, number=11, message=scan_run_warning_trace.ScanRunWarningTrace, ) diff --git a/google/cloud/websecurityscanner_v1/types/scan_run_error_trace.py b/google/cloud/websecurityscanner_v1/types/scan_run_error_trace.py index 3f22a86..dd6c153 100644 --- a/google/cloud/websecurityscanner_v1/types/scan_run_error_trace.py +++ b/google/cloud/websecurityscanner_v1/types/scan_run_error_trace.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,10 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.websecurityscanner_v1.types import ( scan_config_error as gcw_scan_config_error, ) @@ -61,12 +58,10 @@ class Code(proto.Enum): TOO_MANY_HTTP_ERRORS = 6 code = proto.Field(proto.ENUM, number=1, enum=Code,) - scan_config_error = proto.Field( proto.MESSAGE, number=2, message=gcw_scan_config_error.ScanConfigError, ) - - most_common_http_error_code = proto.Field(proto.INT32, number=3) + most_common_http_error_code = proto.Field(proto.INT32, number=3,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/websecurityscanner_v1/types/scan_run_warning_trace.py b/google/cloud/websecurityscanner_v1/types/scan_run_warning_trace.py index 0c95acf..d514bcd 100644 --- a/google/cloud/websecurityscanner_v1/types/scan_run_warning_trace.py +++ b/google/cloud/websecurityscanner_v1/types/scan_run_warning_trace.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore diff --git a/google/cloud/websecurityscanner_v1/types/web_security_scanner.py b/google/cloud/websecurityscanner_v1/types/web_security_scanner.py index c783f42..be87be7 100644 --- a/google/cloud/websecurityscanner_v1/types/web_security_scanner.py +++ b/google/cloud/websecurityscanner_v1/types/web_security_scanner.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,10 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.websecurityscanner_v1.types import crawled_url from google.cloud.websecurityscanner_v1.types import finding from google.cloud.websecurityscanner_v1.types import ( @@ -25,7 +22,7 @@ ) from google.cloud.websecurityscanner_v1.types import scan_config as gcw_scan_config from google.cloud.websecurityscanner_v1.types import scan_run -from google.protobuf import field_mask_pb2 as field_mask # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore __protobuf__ = proto.module( @@ -55,7 +52,6 @@ class CreateScanConfigRequest(proto.Message): r"""Request for the ``CreateScanConfig`` method. - Attributes: parent (str): Required. The parent resource name where the @@ -66,8 +62,7 @@ class CreateScanConfigRequest(proto.Message): Required. The ScanConfig to be created. """ - parent = proto.Field(proto.STRING, number=1) - + parent = proto.Field(proto.STRING, number=1,) scan_config = proto.Field( proto.MESSAGE, number=2, message=gcw_scan_config.ScanConfig, ) @@ -75,7 +70,6 @@ class CreateScanConfigRequest(proto.Message): class DeleteScanConfigRequest(proto.Message): r"""Request for the ``DeleteScanConfig`` method. - Attributes: name (str): Required. The resource name of the ScanConfig @@ -83,12 +77,11 @@ class DeleteScanConfigRequest(proto.Message): 'projects/{projectId}/scanConfigs/{scanConfigId}'. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class GetScanConfigRequest(proto.Message): r"""Request for the ``GetScanConfig`` method. - Attributes: name (str): Required. The resource name of the ScanConfig @@ -96,12 +89,11 @@ class GetScanConfigRequest(proto.Message): 'projects/{projectId}/scanConfigs/{scanConfigId}'. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class ListScanConfigsRequest(proto.Message): r"""Request for the ``ListScanConfigs`` method. - Attributes: parent (str): Required. The parent resource name, which @@ -119,16 +111,13 @@ class ListScanConfigsRequest(proto.Message): reasonable value. """ - parent = proto.Field(proto.STRING, number=1) - - page_token = proto.Field(proto.STRING, number=2) - - page_size = proto.Field(proto.INT32, number=3) + parent = proto.Field(proto.STRING, number=1,) + page_token = proto.Field(proto.STRING, number=2,) + page_size = proto.Field(proto.INT32, number=3,) 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 @@ -144,13 +133,13 @@ class UpdateScanConfigRequest(proto.Message): scan_config = proto.Field( proto.MESSAGE, number=2, message=gcw_scan_config.ScanConfig, ) - - update_mask = proto.Field(proto.MESSAGE, number=3, message=field_mask.FieldMask,) + update_mask = proto.Field( + proto.MESSAGE, number=3, message=field_mask_pb2.FieldMask, + ) 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. @@ -167,13 +156,11 @@ def raw_page(self): scan_configs = proto.RepeatedField( proto.MESSAGE, number=1, message=gcw_scan_config.ScanConfig, ) - - next_page_token = proto.Field(proto.STRING, number=2) + next_page_token = proto.Field(proto.STRING, number=2,) class StartScanRunRequest(proto.Message): r"""Request for the ``StartScanRun`` method. - Attributes: name (str): Required. The resource name of the ScanConfig @@ -181,12 +168,11 @@ class StartScanRunRequest(proto.Message): 'projects/{projectId}/scanConfigs/{scanConfigId}'. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class GetScanRunRequest(proto.Message): r"""Request for the ``GetScanRun`` method. - Attributes: name (str): Required. The resource name of the ScanRun to @@ -194,12 +180,11 @@ class GetScanRunRequest(proto.Message): 'projects/{projectId}/scanConfigs/{scanConfigId}/scanRuns/{scanRunId}'. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class ListScanRunsRequest(proto.Message): r"""Request for the ``ListScanRuns`` method. - Attributes: parent (str): Required. The parent resource name, which @@ -217,16 +202,13 @@ class ListScanRunsRequest(proto.Message): reasonable value. """ - parent = proto.Field(proto.STRING, number=1) - - page_token = proto.Field(proto.STRING, number=2) - - page_size = proto.Field(proto.INT32, number=3) + parent = proto.Field(proto.STRING, number=1,) + page_token = proto.Field(proto.STRING, number=2,) + page_size = proto.Field(proto.INT32, number=3,) 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. @@ -241,13 +223,11 @@ def raw_page(self): return self scan_runs = proto.RepeatedField(proto.MESSAGE, number=1, message=scan_run.ScanRun,) - - next_page_token = proto.Field(proto.STRING, number=2) + next_page_token = proto.Field(proto.STRING, number=2,) class StopScanRunRequest(proto.Message): r"""Request for the ``StopScanRun`` method. - Attributes: name (str): Required. The resource name of the ScanRun to @@ -255,12 +235,11 @@ class StopScanRunRequest(proto.Message): 'projects/{projectId}/scanConfigs/{scanConfigId}/scanRuns/{scanRunId}'. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class ListCrawledUrlsRequest(proto.Message): r"""Request for the ``ListCrawledUrls`` method. - Attributes: parent (str): Required. The parent resource name, which @@ -278,16 +257,13 @@ class ListCrawledUrlsRequest(proto.Message): reasonable value. """ - parent = proto.Field(proto.STRING, number=1) - - page_token = proto.Field(proto.STRING, number=2) - - page_size = proto.Field(proto.INT32, number=3) + parent = proto.Field(proto.STRING, number=1,) + page_token = proto.Field(proto.STRING, number=2,) + page_size = proto.Field(proto.INT32, number=3,) 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. @@ -304,13 +280,11 @@ def raw_page(self): crawled_urls = proto.RepeatedField( proto.MESSAGE, number=1, message=crawled_url.CrawledUrl, ) - - next_page_token = proto.Field(proto.STRING, number=2) + next_page_token = proto.Field(proto.STRING, number=2,) class GetFindingRequest(proto.Message): r"""Request for the ``GetFinding`` method. - Attributes: name (str): Required. The resource name of the Finding to @@ -318,12 +292,11 @@ class GetFindingRequest(proto.Message): 'projects/{projectId}/scanConfigs/{scanConfigId}/scanRuns/{scanRunId}/findings/{findingId}'. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class ListFindingsRequest(proto.Message): r"""Request for the ``ListFindings`` method. - Attributes: parent (str): Required. The parent resource name, which @@ -344,18 +317,14 @@ class ListFindingsRequest(proto.Message): reasonable value. """ - parent = proto.Field(proto.STRING, number=1) - - filter = proto.Field(proto.STRING, number=2) - - page_token = proto.Field(proto.STRING, number=3) - - page_size = proto.Field(proto.INT32, number=4) + parent = proto.Field(proto.STRING, number=1,) + filter = proto.Field(proto.STRING, number=2,) + page_token = proto.Field(proto.STRING, number=3,) + page_size = proto.Field(proto.INT32, number=4,) class ListFindingsResponse(proto.Message): r"""Response for the ``ListFindings`` method. - Attributes: findings (Sequence[google.cloud.websecurityscanner_v1.types.Finding]): The list of Findings returned. @@ -370,13 +339,11 @@ def raw_page(self): return self findings = proto.RepeatedField(proto.MESSAGE, number=1, message=finding.Finding,) - - next_page_token = proto.Field(proto.STRING, number=2) + next_page_token = proto.Field(proto.STRING, number=2,) class ListFindingTypeStatsRequest(proto.Message): r"""Request for the ``ListFindingTypeStats`` method. - Attributes: parent (str): Required. The parent resource name, which @@ -384,12 +351,11 @@ class ListFindingTypeStatsRequest(proto.Message): 'projects/{projectId}/scanConfigs/{scanConfigId}/scanRuns/{scanRunId}'. """ - parent = proto.Field(proto.STRING, number=1) + parent = proto.Field(proto.STRING, number=1,) 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. diff --git a/google/cloud/websecurityscanner_v1alpha/__init__.py b/google/cloud/websecurityscanner_v1alpha/__init__.py index c38963d..ee2817a 100644 --- a/google/cloud/websecurityscanner_v1alpha/__init__.py +++ b/google/cloud/websecurityscanner_v1alpha/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,6 +15,8 @@ # from .services.web_security_scanner import WebSecurityScannerClient +from .services.web_security_scanner import WebSecurityScannerAsyncClient + from .types.crawled_url import CrawledUrl from .types.finding import Finding from .types.finding_addon import OutdatedLibrary @@ -33,10 +34,10 @@ from .types.web_security_scanner import GetScanRunRequest from .types.web_security_scanner import ListCrawledUrlsRequest from .types.web_security_scanner import ListCrawledUrlsResponse -from .types.web_security_scanner import ListFindingTypeStatsRequest -from .types.web_security_scanner import ListFindingTypeStatsResponse from .types.web_security_scanner import ListFindingsRequest from .types.web_security_scanner import ListFindingsResponse +from .types.web_security_scanner import ListFindingTypeStatsRequest +from .types.web_security_scanner import ListFindingTypeStatsResponse from .types.web_security_scanner import ListScanConfigsRequest from .types.web_security_scanner import ListScanConfigsResponse from .types.web_security_scanner import ListScanRunsRequest @@ -45,8 +46,8 @@ from .types.web_security_scanner import StopScanRunRequest from .types.web_security_scanner import UpdateScanConfigRequest - __all__ = ( + "WebSecurityScannerAsyncClient", "CrawledUrl", "CreateScanConfigRequest", "DeleteScanConfigRequest", @@ -74,6 +75,6 @@ "ViolatingResource", "VulnerableHeaders", "VulnerableParameters", - "Xss", "WebSecurityScannerClient", + "Xss", ) diff --git a/google/cloud/websecurityscanner_v1alpha/gapic_metadata.json b/google/cloud/websecurityscanner_v1alpha/gapic_metadata.json new file mode 100644 index 0000000..f43f913 --- /dev/null +++ b/google/cloud/websecurityscanner_v1alpha/gapic_metadata.json @@ -0,0 +1,153 @@ + { + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", + "language": "python", + "libraryPackage": "google.cloud.websecurityscanner_v1alpha", + "protoPackage": "google.cloud.websecurityscanner.v1alpha", + "schema": "1.0", + "services": { + "WebSecurityScanner": { + "clients": { + "grpc": { + "libraryClient": "WebSecurityScannerClient", + "rpcs": { + "CreateScanConfig": { + "methods": [ + "create_scan_config" + ] + }, + "DeleteScanConfig": { + "methods": [ + "delete_scan_config" + ] + }, + "GetFinding": { + "methods": [ + "get_finding" + ] + }, + "GetScanConfig": { + "methods": [ + "get_scan_config" + ] + }, + "GetScanRun": { + "methods": [ + "get_scan_run" + ] + }, + "ListCrawledUrls": { + "methods": [ + "list_crawled_urls" + ] + }, + "ListFindingTypeStats": { + "methods": [ + "list_finding_type_stats" + ] + }, + "ListFindings": { + "methods": [ + "list_findings" + ] + }, + "ListScanConfigs": { + "methods": [ + "list_scan_configs" + ] + }, + "ListScanRuns": { + "methods": [ + "list_scan_runs" + ] + }, + "StartScanRun": { + "methods": [ + "start_scan_run" + ] + }, + "StopScanRun": { + "methods": [ + "stop_scan_run" + ] + }, + "UpdateScanConfig": { + "methods": [ + "update_scan_config" + ] + } + } + }, + "grpc-async": { + "libraryClient": "WebSecurityScannerAsyncClient", + "rpcs": { + "CreateScanConfig": { + "methods": [ + "create_scan_config" + ] + }, + "DeleteScanConfig": { + "methods": [ + "delete_scan_config" + ] + }, + "GetFinding": { + "methods": [ + "get_finding" + ] + }, + "GetScanConfig": { + "methods": [ + "get_scan_config" + ] + }, + "GetScanRun": { + "methods": [ + "get_scan_run" + ] + }, + "ListCrawledUrls": { + "methods": [ + "list_crawled_urls" + ] + }, + "ListFindingTypeStats": { + "methods": [ + "list_finding_type_stats" + ] + }, + "ListFindings": { + "methods": [ + "list_findings" + ] + }, + "ListScanConfigs": { + "methods": [ + "list_scan_configs" + ] + }, + "ListScanRuns": { + "methods": [ + "list_scan_runs" + ] + }, + "StartScanRun": { + "methods": [ + "start_scan_run" + ] + }, + "StopScanRun": { + "methods": [ + "stop_scan_run" + ] + }, + "UpdateScanConfig": { + "methods": [ + "update_scan_config" + ] + } + } + } + } + } + } +} diff --git a/google/cloud/websecurityscanner_v1alpha/services/__init__.py b/google/cloud/websecurityscanner_v1alpha/services/__init__.py index 42ffdf2..4de6597 100644 --- a/google/cloud/websecurityscanner_v1alpha/services/__init__.py +++ b/google/cloud/websecurityscanner_v1alpha/services/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/google/cloud/websecurityscanner_v1alpha/services/web_security_scanner/__init__.py b/google/cloud/websecurityscanner_v1alpha/services/web_security_scanner/__init__.py index d841cb5..4aae8e1 100644 --- a/google/cloud/websecurityscanner_v1alpha/services/web_security_scanner/__init__.py +++ b/google/cloud/websecurityscanner_v1alpha/services/web_security_scanner/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from .client import WebSecurityScannerClient from .async_client import WebSecurityScannerAsyncClient diff --git a/google/cloud/websecurityscanner_v1alpha/services/web_security_scanner/async_client.py b/google/cloud/websecurityscanner_v1alpha/services/web_security_scanner/async_client.py index ae8c9d8..f333926 100644 --- a/google/cloud/websecurityscanner_v1alpha/services/web_security_scanner/async_client.py +++ b/google/cloud/websecurityscanner_v1alpha/services/web_security_scanner/async_client.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict import functools import re @@ -22,10 +20,10 @@ import pkg_resources import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore from google.cloud.websecurityscanner_v1alpha.services.web_security_scanner import pagers @@ -37,9 +35,8 @@ from google.cloud.websecurityscanner_v1alpha.types import scan_config as gcw_scan_config from google.cloud.websecurityscanner_v1alpha.types import scan_run from google.cloud.websecurityscanner_v1alpha.types import web_security_scanner -from google.protobuf import field_mask_pb2 as field_mask # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore - +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore from .transports.base import WebSecurityScannerTransport, DEFAULT_CLIENT_INFO from .transports.grpc_asyncio import WebSecurityScannerGrpcAsyncIOTransport from .client import WebSecurityScannerClient @@ -65,31 +62,26 @@ class WebSecurityScannerAsyncClient: ) scan_run_path = staticmethod(WebSecurityScannerClient.scan_run_path) parse_scan_run_path = staticmethod(WebSecurityScannerClient.parse_scan_run_path) - common_billing_account_path = staticmethod( WebSecurityScannerClient.common_billing_account_path ) parse_common_billing_account_path = staticmethod( WebSecurityScannerClient.parse_common_billing_account_path ) - common_folder_path = staticmethod(WebSecurityScannerClient.common_folder_path) parse_common_folder_path = staticmethod( WebSecurityScannerClient.parse_common_folder_path ) - common_organization_path = staticmethod( WebSecurityScannerClient.common_organization_path ) parse_common_organization_path = staticmethod( WebSecurityScannerClient.parse_common_organization_path ) - common_project_path = staticmethod(WebSecurityScannerClient.common_project_path) parse_common_project_path = staticmethod( WebSecurityScannerClient.parse_common_project_path ) - common_location_path = staticmethod(WebSecurityScannerClient.common_location_path) parse_common_location_path = staticmethod( WebSecurityScannerClient.parse_common_location_path @@ -97,7 +89,8 @@ class WebSecurityScannerAsyncClient: @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -112,7 +105,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -129,7 +122,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> WebSecurityScannerTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: WebSecurityScannerTransport: The transport used by the client instance. @@ -144,12 +137,12 @@ def transport(self) -> WebSecurityScannerTransport: def __init__( self, *, - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, transport: Union[str, WebSecurityScannerTransport] = "grpc_asyncio", client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the web security scanner client. + """Instantiates the web security scanner client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -181,7 +174,6 @@ def __init__( google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport creation failed for any reason. """ - self._client = WebSecurityScannerClient( credentials=credentials, transport=transport, @@ -221,7 +213,6 @@ async def create_scan_config( This corresponds to the ``scan_config`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -249,7 +240,6 @@ async def create_scan_config( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if scan_config is not None: @@ -300,7 +290,6 @@ async def delete_scan_config( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -321,7 +310,6 @@ async def delete_scan_config( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -334,7 +322,8 @@ async def delete_scan_config( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -377,7 +366,6 @@ async def get_scan_config( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -405,7 +393,6 @@ async def get_scan_config( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -418,7 +405,8 @@ async def get_scan_config( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -461,7 +449,6 @@ async def list_scan_configs( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -490,7 +477,6 @@ async def list_scan_configs( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -503,7 +489,8 @@ async def list_scan_configs( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -534,7 +521,7 @@ async def update_scan_config( request: web_security_scanner.UpdateScanConfigRequest = None, *, scan_config: gcw_scan_config.ScanConfig = None, - update_mask: field_mask.FieldMask = None, + update_mask: field_mask_pb2.FieldMask = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), @@ -564,7 +551,6 @@ async def update_scan_config( This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -592,7 +578,6 @@ async def update_scan_config( # If we have keyword arguments corresponding to fields on the # request, apply these. - if scan_config is not None: request.scan_config = scan_config if update_mask is not None: @@ -644,7 +629,6 @@ async def start_scan_run( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -671,7 +655,6 @@ async def start_scan_run( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -718,7 +701,6 @@ async def get_scan_run( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -745,7 +727,6 @@ async def get_scan_run( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -758,7 +739,8 @@ async def get_scan_run( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -803,7 +785,6 @@ async def list_scan_runs( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -832,7 +813,6 @@ async def list_scan_runs( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -845,7 +825,8 @@ async def list_scan_runs( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -895,7 +876,6 @@ async def stop_scan_run( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -922,7 +902,6 @@ async def stop_scan_run( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -970,7 +949,6 @@ async def list_crawled_urls( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -999,7 +977,6 @@ async def list_crawled_urls( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -1012,7 +989,8 @@ async def list_crawled_urls( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -1061,7 +1039,6 @@ async def get_finding( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1089,7 +1066,6 @@ async def get_finding( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -1102,7 +1078,8 @@ async def get_finding( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -1155,7 +1132,6 @@ async def list_findings( This corresponds to the ``filter`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1184,7 +1160,6 @@ async def list_findings( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if filter is not None: @@ -1199,7 +1174,8 @@ async def list_findings( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -1249,7 +1225,6 @@ async def list_finding_type_stats( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1274,7 +1249,6 @@ async def list_finding_type_stats( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -1287,7 +1261,8 @@ async def list_finding_type_stats( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), diff --git a/google/cloud/websecurityscanner_v1alpha/services/web_security_scanner/client.py b/google/cloud/websecurityscanner_v1alpha/services/web_security_scanner/client.py index 23c8def..70be14d 100644 --- a/google/cloud/websecurityscanner_v1alpha/services/web_security_scanner/client.py +++ b/google/cloud/websecurityscanner_v1alpha/services/web_security_scanner/client.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict from distutils import util import os @@ -23,10 +21,10 @@ import pkg_resources from google.api_core import client_options as client_options_lib # type: ignore -from google.api_core import exceptions # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport import mtls # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.auth.exceptions import MutualTLSChannelError # type: ignore @@ -41,9 +39,8 @@ from google.cloud.websecurityscanner_v1alpha.types import scan_config as gcw_scan_config from google.cloud.websecurityscanner_v1alpha.types import scan_run from google.cloud.websecurityscanner_v1alpha.types import web_security_scanner -from google.protobuf import field_mask_pb2 as field_mask # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore - +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore from .transports.base import WebSecurityScannerTransport, DEFAULT_CLIENT_INFO from .transports.grpc import WebSecurityScannerGrpcTransport from .transports.grpc_asyncio import WebSecurityScannerGrpcAsyncIOTransport @@ -66,7 +63,7 @@ class WebSecurityScannerClientMeta(type): def get_transport_class( cls, label: str = None, ) -> Type[WebSecurityScannerTransport]: - """Return an appropriate transport class. + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -93,7 +90,8 @@ class WebSecurityScannerClient(metaclass=WebSecurityScannerClientMeta): @staticmethod def _get_default_mtls_endpoint(api_endpoint): - """Convert api endpoint to mTLS endpoint. + """Converts api endpoint to mTLS endpoint. + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. Args: @@ -127,7 +125,8 @@ def _get_default_mtls_endpoint(api_endpoint): @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -144,7 +143,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -163,10 +162,11 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> WebSecurityScannerTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - WebSecurityScannerTransport: The transport used by the client instance. + WebSecurityScannerTransport: The transport used by the client + instance. """ return self._transport @@ -174,7 +174,7 @@ def transport(self) -> WebSecurityScannerTransport: def finding_path( project: str, scan_config: str, scan_run: str, finding: str, ) -> str: - """Return a fully-qualified finding string.""" + """Returns a fully-qualified finding string.""" return "projects/{project}/scanConfigs/{scan_config}/scanRuns/{scan_run}/findings/{finding}".format( project=project, scan_config=scan_config, @@ -184,7 +184,7 @@ def finding_path( @staticmethod def parse_finding_path(path: str) -> Dict[str, str]: - """Parse a finding path into its component segments.""" + """Parses a finding path into its component segments.""" m = re.match( r"^projects/(?P.+?)/scanConfigs/(?P.+?)/scanRuns/(?P.+?)/findings/(?P.+?)$", path, @@ -193,14 +193,14 @@ def parse_finding_path(path: str) -> Dict[str, str]: @staticmethod def scan_config_path(project: str, scan_config: str,) -> str: - """Return a fully-qualified scan_config string.""" + """Returns a fully-qualified scan_config string.""" return "projects/{project}/scanConfigs/{scan_config}".format( project=project, scan_config=scan_config, ) @staticmethod def parse_scan_config_path(path: str) -> Dict[str, str]: - """Parse a scan_config path into its component segments.""" + """Parses a scan_config path into its component segments.""" m = re.match( r"^projects/(?P.+?)/scanConfigs/(?P.+?)$", path ) @@ -208,14 +208,14 @@ def parse_scan_config_path(path: str) -> Dict[str, str]: @staticmethod def scan_run_path(project: str, scan_config: str, scan_run: str,) -> str: - """Return a fully-qualified scan_run string.""" + """Returns a fully-qualified scan_run string.""" return "projects/{project}/scanConfigs/{scan_config}/scanRuns/{scan_run}".format( project=project, scan_config=scan_config, scan_run=scan_run, ) @staticmethod def parse_scan_run_path(path: str) -> Dict[str, str]: - """Parse a scan_run path into its component segments.""" + """Parses a scan_run path into its component segments.""" m = re.match( r"^projects/(?P.+?)/scanConfigs/(?P.+?)/scanRuns/(?P.+?)$", path, @@ -224,7 +224,7 @@ def parse_scan_run_path(path: str) -> Dict[str, str]: @staticmethod def common_billing_account_path(billing_account: str,) -> str: - """Return a fully-qualified billing_account string.""" + """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -237,7 +237,7 @@ def parse_common_billing_account_path(path: str) -> Dict[str, str]: @staticmethod def common_folder_path(folder: str,) -> str: - """Return a fully-qualified folder string.""" + """Returns a fully-qualified folder string.""" return "folders/{folder}".format(folder=folder,) @staticmethod @@ -248,7 +248,7 @@ def parse_common_folder_path(path: str) -> Dict[str, str]: @staticmethod def common_organization_path(organization: str,) -> str: - """Return a fully-qualified organization string.""" + """Returns a fully-qualified organization string.""" return "organizations/{organization}".format(organization=organization,) @staticmethod @@ -259,7 +259,7 @@ def parse_common_organization_path(path: str) -> Dict[str, str]: @staticmethod def common_project_path(project: str,) -> str: - """Return a fully-qualified project string.""" + """Returns a fully-qualified project string.""" return "projects/{project}".format(project=project,) @staticmethod @@ -270,7 +270,7 @@ def parse_common_project_path(path: str) -> Dict[str, str]: @staticmethod def common_location_path(project: str, location: str,) -> str: - """Return a fully-qualified location string.""" + """Returns a fully-qualified location string.""" return "projects/{project}/locations/{location}".format( project=project, location=location, ) @@ -284,12 +284,12 @@ def parse_common_location_path(path: str) -> Dict[str, str]: def __init__( self, *, - credentials: Optional[credentials.Credentials] = None, + credentials: Optional[ga_credentials.Credentials] = None, transport: Union[str, WebSecurityScannerTransport, None] = None, client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the web security scanner client. + """Instantiates the web security scanner client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -344,9 +344,10 @@ def __init__( client_cert_source_func = client_options.client_cert_source else: is_mtls = mtls.has_default_client_cert_source() - client_cert_source_func = ( - mtls.default_client_cert_source() if is_mtls else None - ) + if is_mtls: + client_cert_source_func = mtls.default_client_cert_source() + else: + client_cert_source_func = None # Figure out which api endpoint to use. if client_options.api_endpoint is not None: @@ -358,12 +359,14 @@ def __init__( elif use_mtls_env == "always": api_endpoint = self.DEFAULT_MTLS_ENDPOINT elif use_mtls_env == "auto": - api_endpoint = ( - self.DEFAULT_MTLS_ENDPOINT if is_mtls else self.DEFAULT_ENDPOINT - ) + if is_mtls: + api_endpoint = self.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = self.DEFAULT_ENDPOINT else: raise MutualTLSChannelError( - "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted values: never, auto, always" + "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted " + "values: never, auto, always" ) # Save or instantiate the transport. @@ -378,8 +381,8 @@ def __init__( ) if client_options.scopes: raise ValueError( - "When providing a transport instance, " - "provide its scopes directly." + "When providing a transport instance, provide its scopes " + "directly." ) self._transport = transport else: @@ -426,7 +429,6 @@ def create_scan_config( This corresponds to the ``scan_config`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -456,10 +458,8 @@ def create_scan_config( # there are no flattened fields. if not isinstance(request, web_security_scanner.CreateScanConfigRequest): request = web_security_scanner.CreateScanConfigRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if scan_config is not None: @@ -506,7 +506,6 @@ def delete_scan_config( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -529,10 +528,8 @@ def delete_scan_config( # there are no flattened fields. if not isinstance(request, web_security_scanner.DeleteScanConfigRequest): request = web_security_scanner.DeleteScanConfigRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -575,7 +572,6 @@ def get_scan_config( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -605,10 +601,8 @@ def get_scan_config( # there are no flattened fields. if not isinstance(request, web_security_scanner.GetScanConfigRequest): request = web_security_scanner.GetScanConfigRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -651,7 +645,6 @@ def list_scan_configs( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -682,10 +675,8 @@ def list_scan_configs( # there are no flattened fields. if not isinstance(request, web_security_scanner.ListScanConfigsRequest): request = web_security_scanner.ListScanConfigsRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -716,7 +707,7 @@ def update_scan_config( request: web_security_scanner.UpdateScanConfigRequest = None, *, scan_config: gcw_scan_config.ScanConfig = None, - update_mask: field_mask.FieldMask = None, + update_mask: field_mask_pb2.FieldMask = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), @@ -746,7 +737,6 @@ def update_scan_config( This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -776,10 +766,8 @@ def update_scan_config( # there are no flattened fields. if not isinstance(request, web_security_scanner.UpdateScanConfigRequest): request = web_security_scanner.UpdateScanConfigRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if scan_config is not None: request.scan_config = scan_config if update_mask is not None: @@ -827,7 +815,6 @@ def start_scan_run( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -856,10 +843,8 @@ def start_scan_run( # there are no flattened fields. if not isinstance(request, web_security_scanner.StartScanRunRequest): request = web_security_scanner.StartScanRunRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -902,7 +887,6 @@ def get_scan_run( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -931,10 +915,8 @@ def get_scan_run( # there are no flattened fields. if not isinstance(request, web_security_scanner.GetScanRunRequest): request = web_security_scanner.GetScanRunRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -979,7 +961,6 @@ def list_scan_runs( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1010,10 +991,8 @@ def list_scan_runs( # there are no flattened fields. if not isinstance(request, web_security_scanner.ListScanRunsRequest): request = web_security_scanner.ListScanRunsRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -1063,7 +1042,6 @@ def stop_scan_run( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1092,10 +1070,8 @@ def stop_scan_run( # there are no flattened fields. if not isinstance(request, web_security_scanner.StopScanRunRequest): request = web_security_scanner.StopScanRunRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -1139,7 +1115,6 @@ def list_crawled_urls( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1170,10 +1145,8 @@ def list_crawled_urls( # there are no flattened fields. if not isinstance(request, web_security_scanner.ListCrawledUrlsRequest): request = web_security_scanner.ListCrawledUrlsRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -1222,7 +1195,6 @@ def get_finding( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1252,10 +1224,8 @@ def get_finding( # there are no flattened fields. if not isinstance(request, web_security_scanner.GetFindingRequest): request = web_security_scanner.GetFindingRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -1308,7 +1278,6 @@ def list_findings( This corresponds to the ``filter`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1339,10 +1308,8 @@ def list_findings( # there are no flattened fields. if not isinstance(request, web_security_scanner.ListFindingsRequest): request = web_security_scanner.ListFindingsRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if filter is not None: @@ -1394,7 +1361,6 @@ def list_finding_type_stats( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1421,10 +1387,8 @@ def list_finding_type_stats( # there are no flattened fields. if not isinstance(request, web_security_scanner.ListFindingTypeStatsRequest): request = web_security_scanner.ListFindingTypeStatsRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent diff --git a/google/cloud/websecurityscanner_v1alpha/services/web_security_scanner/pagers.py b/google/cloud/websecurityscanner_v1alpha/services/web_security_scanner/pagers.py index 4b1fa68..fa8e3e9 100644 --- a/google/cloud/websecurityscanner_v1alpha/services/web_security_scanner/pagers.py +++ b/google/cloud/websecurityscanner_v1alpha/services/web_security_scanner/pagers.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from typing import ( Any, AsyncIterable, @@ -121,7 +119,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -251,7 +249,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -379,7 +377,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -509,7 +507,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and diff --git a/google/cloud/websecurityscanner_v1alpha/services/web_security_scanner/transports/__init__.py b/google/cloud/websecurityscanner_v1alpha/services/web_security_scanner/transports/__init__.py index caf0502..fce7d6c 100644 --- a/google/cloud/websecurityscanner_v1alpha/services/web_security_scanner/transports/__init__.py +++ b/google/cloud/websecurityscanner_v1alpha/services/web_security_scanner/transports/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict from typing import Dict, Type diff --git a/google/cloud/websecurityscanner_v1alpha/services/web_security_scanner/transports/base.py b/google/cloud/websecurityscanner_v1alpha/services/web_security_scanner/transports/base.py index 888581d..ee46300 100644 --- a/google/cloud/websecurityscanner_v1alpha/services/web_security_scanner/transports/base.py +++ b/google/cloud/websecurityscanner_v1alpha/services/web_security_scanner/transports/base.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,24 +13,24 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import abc -import typing +from typing import Awaitable, Callable, Dict, Optional, Sequence, Union +import packaging.version import pkg_resources -from google import auth # type: ignore -from google.api_core import exceptions # type: ignore +import google.auth # type: ignore +import google.api_core # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.cloud.websecurityscanner_v1alpha.types import finding from google.cloud.websecurityscanner_v1alpha.types import scan_config from google.cloud.websecurityscanner_v1alpha.types import scan_config as gcw_scan_config from google.cloud.websecurityscanner_v1alpha.types import scan_run from google.cloud.websecurityscanner_v1alpha.types import web_security_scanner -from google.protobuf import empty_pb2 as empty # type: ignore - +from google.protobuf import empty_pb2 # type: ignore try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( @@ -42,27 +41,41 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() +try: + # google.auth.__version__ was added in 1.26.0 + _GOOGLE_AUTH_VERSION = google.auth.__version__ +except AttributeError: + try: # try pkg_resources if it is available + _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version + except pkg_resources.DistributionNotFound: # pragma: NO COVER + _GOOGLE_AUTH_VERSION = None + +_API_CORE_VERSION = google.api_core.__version__ + class WebSecurityScannerTransport(abc.ABC): """Abstract transport class for WebSecurityScanner.""" AUTH_SCOPES = ("https://www.googleapis.com/auth/cloud-platform",) + DEFAULT_HOST: str = "websecurityscanner.googleapis.com" + def __init__( self, *, - host: str = "websecurityscanner.googleapis.com", - credentials: credentials.Credentials = None, - credentials_file: typing.Optional[str] = None, - scopes: typing.Optional[typing.Sequence[str]] = AUTH_SCOPES, - quota_project_id: typing.Optional[str] = None, + host: str = DEFAULT_HOST, + credentials: ga_credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, **kwargs, ) -> None: """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -71,7 +84,7 @@ def __init__( credentials_file (Optional[str]): A file with credentials that can be loaded with :func:`google.auth.load_credentials_from_file`. This argument is mutually exclusive with credentials. - scope (Optional[Sequence[str]]): A list of scopes. + scopes (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -85,29 +98,76 @@ def __init__( host += ":443" self._host = host + scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + # Save the scopes. self._scopes = scopes or self.AUTH_SCOPES # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: - raise exceptions.DuplicateCredentialArgs( + raise core_exceptions.DuplicateCredentialArgs( "'credentials_file' and 'credentials' are mutually exclusive" ) if credentials_file is not None: - credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=self._scopes, quota_project_id=quota_project_id + credentials, _ = google.auth.load_credentials_from_file( + credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) elif credentials is None: - credentials, _ = auth.default( - scopes=self._scopes, quota_project_id=quota_project_id + credentials, _ = google.auth.default( + **scopes_kwargs, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials + # TODO(busunkim): These two class methods are in the base transport + # to avoid duplicating code across the transport classes. These functions + # should be deleted once the minimum required versions of google-api-core + # and google-auth are increased. + + # TODO: Remove this function once google-auth >= 1.25.0 is required + @classmethod + def _get_scopes_kwargs( + cls, host: str, scopes: Optional[Sequence[str]] + ) -> Dict[str, Optional[Sequence[str]]]: + """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" + + scopes_kwargs = {} + + if _GOOGLE_AUTH_VERSION and ( + packaging.version.parse(_GOOGLE_AUTH_VERSION) + >= packaging.version.parse("1.25.0") + ): + scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} + else: + scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} + + return scopes_kwargs + + # TODO: Remove this function once google-api-core >= 1.26.0 is required + @classmethod + def _get_self_signed_jwt_kwargs( + cls, host: str, scopes: Optional[Sequence[str]] + ) -> Dict[str, Union[Optional[Sequence[str]], str]]: + """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" + + self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} + + if _API_CORE_VERSION and ( + packaging.version.parse(_API_CORE_VERSION) + >= packaging.version.parse("1.26.0") + ): + self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES + self_signed_jwt_kwargs["scopes"] = scopes + self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST + else: + self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES + + return self_signed_jwt_kwargs + def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { @@ -121,7 +181,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -135,7 +196,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -149,7 +211,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -169,7 +232,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -183,7 +247,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -200,7 +265,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -214,7 +280,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -228,7 +295,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -242,7 +310,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -254,40 +323,38 @@ def _prep_wrapped_messages(self, client_info): @property def create_scan_config( self, - ) -> typing.Callable[ + ) -> Callable[ [web_security_scanner.CreateScanConfigRequest], - typing.Union[ - gcw_scan_config.ScanConfig, typing.Awaitable[gcw_scan_config.ScanConfig] - ], + Union[gcw_scan_config.ScanConfig, Awaitable[gcw_scan_config.ScanConfig]], ]: raise NotImplementedError() @property def delete_scan_config( self, - ) -> typing.Callable[ + ) -> Callable[ [web_security_scanner.DeleteScanConfigRequest], - typing.Union[empty.Empty, typing.Awaitable[empty.Empty]], + Union[empty_pb2.Empty, Awaitable[empty_pb2.Empty]], ]: raise NotImplementedError() @property def get_scan_config( self, - ) -> typing.Callable[ + ) -> Callable[ [web_security_scanner.GetScanConfigRequest], - typing.Union[scan_config.ScanConfig, typing.Awaitable[scan_config.ScanConfig]], + Union[scan_config.ScanConfig, Awaitable[scan_config.ScanConfig]], ]: raise NotImplementedError() @property def list_scan_configs( self, - ) -> typing.Callable[ + ) -> Callable[ [web_security_scanner.ListScanConfigsRequest], - typing.Union[ + Union[ web_security_scanner.ListScanConfigsResponse, - typing.Awaitable[web_security_scanner.ListScanConfigsResponse], + Awaitable[web_security_scanner.ListScanConfigsResponse], ], ]: raise NotImplementedError() @@ -295,40 +362,38 @@ def list_scan_configs( @property def update_scan_config( self, - ) -> typing.Callable[ + ) -> Callable[ [web_security_scanner.UpdateScanConfigRequest], - typing.Union[ - gcw_scan_config.ScanConfig, typing.Awaitable[gcw_scan_config.ScanConfig] - ], + Union[gcw_scan_config.ScanConfig, Awaitable[gcw_scan_config.ScanConfig]], ]: raise NotImplementedError() @property def start_scan_run( self, - ) -> typing.Callable[ + ) -> Callable[ [web_security_scanner.StartScanRunRequest], - typing.Union[scan_run.ScanRun, typing.Awaitable[scan_run.ScanRun]], + Union[scan_run.ScanRun, Awaitable[scan_run.ScanRun]], ]: raise NotImplementedError() @property def get_scan_run( self, - ) -> typing.Callable[ + ) -> Callable[ [web_security_scanner.GetScanRunRequest], - typing.Union[scan_run.ScanRun, typing.Awaitable[scan_run.ScanRun]], + Union[scan_run.ScanRun, Awaitable[scan_run.ScanRun]], ]: raise NotImplementedError() @property def list_scan_runs( self, - ) -> typing.Callable[ + ) -> Callable[ [web_security_scanner.ListScanRunsRequest], - typing.Union[ + Union[ web_security_scanner.ListScanRunsResponse, - typing.Awaitable[web_security_scanner.ListScanRunsResponse], + Awaitable[web_security_scanner.ListScanRunsResponse], ], ]: raise NotImplementedError() @@ -336,20 +401,20 @@ def list_scan_runs( @property def stop_scan_run( self, - ) -> typing.Callable[ + ) -> Callable[ [web_security_scanner.StopScanRunRequest], - typing.Union[scan_run.ScanRun, typing.Awaitable[scan_run.ScanRun]], + Union[scan_run.ScanRun, Awaitable[scan_run.ScanRun]], ]: raise NotImplementedError() @property def list_crawled_urls( self, - ) -> typing.Callable[ + ) -> Callable[ [web_security_scanner.ListCrawledUrlsRequest], - typing.Union[ + Union[ web_security_scanner.ListCrawledUrlsResponse, - typing.Awaitable[web_security_scanner.ListCrawledUrlsResponse], + Awaitable[web_security_scanner.ListCrawledUrlsResponse], ], ]: raise NotImplementedError() @@ -357,20 +422,20 @@ def list_crawled_urls( @property def get_finding( self, - ) -> typing.Callable[ + ) -> Callable[ [web_security_scanner.GetFindingRequest], - typing.Union[finding.Finding, typing.Awaitable[finding.Finding]], + Union[finding.Finding, Awaitable[finding.Finding]], ]: raise NotImplementedError() @property def list_findings( self, - ) -> typing.Callable[ + ) -> Callable[ [web_security_scanner.ListFindingsRequest], - typing.Union[ + Union[ web_security_scanner.ListFindingsResponse, - typing.Awaitable[web_security_scanner.ListFindingsResponse], + Awaitable[web_security_scanner.ListFindingsResponse], ], ]: raise NotImplementedError() @@ -378,11 +443,11 @@ def list_findings( @property def list_finding_type_stats( self, - ) -> typing.Callable[ + ) -> Callable[ [web_security_scanner.ListFindingTypeStatsRequest], - typing.Union[ + Union[ web_security_scanner.ListFindingTypeStatsResponse, - typing.Awaitable[web_security_scanner.ListFindingTypeStatsResponse], + Awaitable[web_security_scanner.ListFindingTypeStatsResponse], ], ]: raise NotImplementedError() diff --git a/google/cloud/websecurityscanner_v1alpha/services/web_security_scanner/transports/grpc.py b/google/cloud/websecurityscanner_v1alpha/services/web_security_scanner/transports/grpc.py index 590745c..e12fc52 100644 --- a/google/cloud/websecurityscanner_v1alpha/services/web_security_scanner/transports/grpc.py +++ b/google/cloud/websecurityscanner_v1alpha/services/web_security_scanner/transports/grpc.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,14 +13,13 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import warnings -from typing import Callable, Dict, Optional, Sequence, Tuple +from typing import Callable, Dict, Optional, Sequence, Tuple, Union from google.api_core import grpc_helpers # type: ignore from google.api_core import gapic_v1 # type: ignore -from google import auth # type: ignore -from google.auth import credentials # type: ignore +import google.auth # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore import grpc # type: ignore @@ -31,8 +29,7 @@ from google.cloud.websecurityscanner_v1alpha.types import scan_config as gcw_scan_config from google.cloud.websecurityscanner_v1alpha.types import scan_run from google.cloud.websecurityscanner_v1alpha.types import web_security_scanner -from google.protobuf import empty_pb2 as empty # type: ignore - +from google.protobuf import empty_pb2 # type: ignore from .base import WebSecurityScannerTransport, DEFAULT_CLIENT_INFO @@ -58,7 +55,7 @@ def __init__( self, *, host: str = "websecurityscanner.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: str = None, scopes: Sequence[str] = None, channel: grpc.Channel = None, @@ -72,7 +69,8 @@ def __init__( """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -182,7 +180,7 @@ def __init__( def create_channel( cls, host: str = "websecurityscanner.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: str = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, @@ -213,13 +211,15 @@ def create_channel( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ - scopes = scopes or cls.AUTH_SCOPES + + self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) + return grpc_helpers.create_channel( host, credentials=credentials, credentials_file=credentials_file, - scopes=scopes, quota_project_id=quota_project_id, + **self_signed_jwt_kwargs, **kwargs, ) @@ -260,7 +260,7 @@ def create_scan_config( @property def delete_scan_config( self, - ) -> Callable[[web_security_scanner.DeleteScanConfigRequest], empty.Empty]: + ) -> Callable[[web_security_scanner.DeleteScanConfigRequest], empty_pb2.Empty]: r"""Return a callable for the delete scan config method over gRPC. Deletes an existing ScanConfig and its child @@ -280,7 +280,7 @@ def delete_scan_config( self._stubs["delete_scan_config"] = self.grpc_channel.unary_unary( "/google.cloud.websecurityscanner.v1alpha.WebSecurityScanner/DeleteScanConfig", request_serializer=web_security_scanner.DeleteScanConfigRequest.serialize, - response_deserializer=empty.Empty.FromString, + response_deserializer=empty_pb2.Empty.FromString, ) return self._stubs["delete_scan_config"] diff --git a/google/cloud/websecurityscanner_v1alpha/services/web_security_scanner/transports/grpc_asyncio.py b/google/cloud/websecurityscanner_v1alpha/services/web_security_scanner/transports/grpc_asyncio.py index 790f807..824d9b1 100644 --- a/google/cloud/websecurityscanner_v1alpha/services/web_security_scanner/transports/grpc_asyncio.py +++ b/google/cloud/websecurityscanner_v1alpha/services/web_security_scanner/transports/grpc_asyncio.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,15 +13,14 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import warnings -from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple +from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union from google.api_core import gapic_v1 # type: ignore from google.api_core import grpc_helpers_async # type: ignore -from google import auth # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore @@ -32,8 +30,7 @@ from google.cloud.websecurityscanner_v1alpha.types import scan_config as gcw_scan_config from google.cloud.websecurityscanner_v1alpha.types import scan_run from google.cloud.websecurityscanner_v1alpha.types import web_security_scanner -from google.protobuf import empty_pb2 as empty # type: ignore - +from google.protobuf import empty_pb2 # type: ignore from .base import WebSecurityScannerTransport, DEFAULT_CLIENT_INFO from .grpc import WebSecurityScannerGrpcTransport @@ -61,7 +58,7 @@ class WebSecurityScannerGrpcAsyncIOTransport(WebSecurityScannerTransport): def create_channel( cls, host: str = "websecurityscanner.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, @@ -88,13 +85,15 @@ def create_channel( Returns: aio.Channel: A gRPC AsyncIO channel object. """ - scopes = scopes or cls.AUTH_SCOPES + + self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) + return grpc_helpers_async.create_channel( host, credentials=credentials, credentials_file=credentials_file, - scopes=scopes, quota_project_id=quota_project_id, + **self_signed_jwt_kwargs, **kwargs, ) @@ -102,7 +101,7 @@ def __init__( self, *, host: str = "websecurityscanner.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, channel: aio.Channel = None, @@ -116,7 +115,8 @@ def __init__( """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -174,7 +174,6 @@ def __init__( # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - else: if api_mtls_endpoint: host = api_mtls_endpoint @@ -266,7 +265,7 @@ def create_scan_config( def delete_scan_config( self, ) -> Callable[ - [web_security_scanner.DeleteScanConfigRequest], Awaitable[empty.Empty] + [web_security_scanner.DeleteScanConfigRequest], Awaitable[empty_pb2.Empty] ]: r"""Return a callable for the delete scan config method over gRPC. @@ -287,7 +286,7 @@ def delete_scan_config( self._stubs["delete_scan_config"] = self.grpc_channel.unary_unary( "/google.cloud.websecurityscanner.v1alpha.WebSecurityScanner/DeleteScanConfig", request_serializer=web_security_scanner.DeleteScanConfigRequest.serialize, - response_deserializer=empty.Empty.FromString, + response_deserializer=empty_pb2.Empty.FromString, ) return self._stubs["delete_scan_config"] diff --git a/google/cloud/websecurityscanner_v1alpha/types/__init__.py b/google/cloud/websecurityscanner_v1alpha/types/__init__.py index 987723d..23f827c 100644 --- a/google/cloud/websecurityscanner_v1alpha/types/__init__.py +++ b/google/cloud/websecurityscanner_v1alpha/types/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from .crawled_url import CrawledUrl from .finding import Finding from .finding_addon import ( diff --git a/google/cloud/websecurityscanner_v1alpha/types/crawled_url.py b/google/cloud/websecurityscanner_v1alpha/types/crawled_url.py index 92b27b0..7b07f1e 100644 --- a/google/cloud/websecurityscanner_v1alpha/types/crawled_url.py +++ b/google/cloud/websecurityscanner_v1alpha/types/crawled_url.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore @@ -40,11 +38,9 @@ class CrawledUrl(proto.Message): used to visit the URL. """ - http_method = proto.Field(proto.STRING, number=1) - - url = proto.Field(proto.STRING, number=2) - - body = proto.Field(proto.STRING, number=3) + http_method = proto.Field(proto.STRING, number=1,) + url = proto.Field(proto.STRING, number=2,) + body = proto.Field(proto.STRING, number=3,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/websecurityscanner_v1alpha/types/finding.py b/google/cloud/websecurityscanner_v1alpha/types/finding.py index 1f3c597..f2c33b2 100644 --- a/google/cloud/websecurityscanner_v1alpha/types/finding.py +++ b/google/cloud/websecurityscanner_v1alpha/types/finding.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,10 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.websecurityscanner_v1alpha.types import finding_addon @@ -98,42 +95,28 @@ class FindingType(proto.Enum): MISSPELLED_SECURITY_HEADER_NAME = 10 MISMATCHING_SECURITY_HEADER_VALUES = 11 - name = proto.Field(proto.STRING, number=1) - + name = proto.Field(proto.STRING, number=1,) finding_type = proto.Field(proto.ENUM, number=2, enum=FindingType,) - - http_method = proto.Field(proto.STRING, number=3) - - fuzzed_url = proto.Field(proto.STRING, number=4) - - body = proto.Field(proto.STRING, number=5) - - description = proto.Field(proto.STRING, number=6) - - reproduction_url = proto.Field(proto.STRING, number=7) - - frame_url = proto.Field(proto.STRING, number=8) - - final_url = proto.Field(proto.STRING, number=9) - - tracking_id = proto.Field(proto.STRING, number=10) - + http_method = proto.Field(proto.STRING, number=3,) + fuzzed_url = proto.Field(proto.STRING, number=4,) + body = proto.Field(proto.STRING, number=5,) + description = proto.Field(proto.STRING, number=6,) + reproduction_url = proto.Field(proto.STRING, number=7,) + frame_url = proto.Field(proto.STRING, number=8,) + final_url = proto.Field(proto.STRING, number=9,) + tracking_id = proto.Field(proto.STRING, number=10,) outdated_library = proto.Field( proto.MESSAGE, number=11, message=finding_addon.OutdatedLibrary, ) - violating_resource = proto.Field( proto.MESSAGE, number=12, message=finding_addon.ViolatingResource, ) - vulnerable_headers = proto.Field( proto.MESSAGE, number=15, message=finding_addon.VulnerableHeaders, ) - vulnerable_parameters = proto.Field( proto.MESSAGE, number=13, message=finding_addon.VulnerableParameters, ) - xss = proto.Field(proto.MESSAGE, number=14, message=finding_addon.Xss,) diff --git a/google/cloud/websecurityscanner_v1alpha/types/finding_addon.py b/google/cloud/websecurityscanner_v1alpha/types/finding_addon.py index 254e73e..a1ce6ff 100644 --- a/google/cloud/websecurityscanner_v1alpha/types/finding_addon.py +++ b/google/cloud/websecurityscanner_v1alpha/types/finding_addon.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore @@ -32,7 +30,6 @@ class OutdatedLibrary(proto.Message): r"""Information reported for an outdated library. - Attributes: library_name (str): The name of the outdated library. @@ -43,11 +40,9 @@ class OutdatedLibrary(proto.Message): vulnerabilities in the library. """ - library_name = proto.Field(proto.STRING, number=1) - - version = proto.Field(proto.STRING, number=2) - - learn_more_urls = proto.RepeatedField(proto.STRING, number=3) + library_name = proto.Field(proto.STRING, number=1,) + version = proto.Field(proto.STRING, number=2,) + learn_more_urls = proto.RepeatedField(proto.STRING, number=3,) class ViolatingResource(proto.Message): @@ -61,25 +56,22 @@ class ViolatingResource(proto.Message): URL of this violating resource. """ - content_type = proto.Field(proto.STRING, number=1) - - resource_url = proto.Field(proto.STRING, number=2) + content_type = proto.Field(proto.STRING, number=1,) + resource_url = proto.Field(proto.STRING, number=2,) class VulnerableParameters(proto.Message): r"""Information about vulnerable request parameters. - Attributes: parameter_names (Sequence[str]): The vulnerable parameter names. """ - parameter_names = proto.RepeatedField(proto.STRING, number=1) + parameter_names = proto.RepeatedField(proto.STRING, number=1,) class VulnerableHeaders(proto.Message): r"""Information about vulnerable or missing HTTP Headers. - Attributes: headers (Sequence[google.cloud.websecurityscanner_v1alpha.types.VulnerableHeaders.Header]): List of vulnerable headers. @@ -89,7 +81,6 @@ class VulnerableHeaders(proto.Message): class Header(proto.Message): r"""Describes a HTTP Header. - Attributes: name (str): Header name. @@ -97,18 +88,15 @@ class Header(proto.Message): Header value. """ - name = proto.Field(proto.STRING, number=1) - - value = proto.Field(proto.STRING, number=2) + name = proto.Field(proto.STRING, number=1,) + value = proto.Field(proto.STRING, number=2,) headers = proto.RepeatedField(proto.MESSAGE, number=1, message=Header,) - missing_headers = proto.RepeatedField(proto.MESSAGE, number=2, message=Header,) class Xss(proto.Message): r"""Information reported for an XSS. - Attributes: stack_traces (Sequence[str]): Stack traces leading to the point where the @@ -118,9 +106,8 @@ class Xss(proto.Message): breakage. """ - stack_traces = proto.RepeatedField(proto.STRING, number=1) - - error_message = proto.Field(proto.STRING, number=2) + stack_traces = proto.RepeatedField(proto.STRING, number=1,) + error_message = proto.Field(proto.STRING, number=2,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/websecurityscanner_v1alpha/types/finding_type_stats.py b/google/cloud/websecurityscanner_v1alpha/types/finding_type_stats.py index 6b4c336..74e1c9a 100644 --- a/google/cloud/websecurityscanner_v1alpha/types/finding_type_stats.py +++ b/google/cloud/websecurityscanner_v1alpha/types/finding_type_stats.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,10 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.websecurityscanner_v1alpha.types import finding @@ -39,8 +36,7 @@ class FindingTypeStats(proto.Message): """ finding_type = proto.Field(proto.ENUM, number=1, enum=finding.Finding.FindingType,) - - finding_count = proto.Field(proto.INT32, number=2) + finding_count = proto.Field(proto.INT32, number=2,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/websecurityscanner_v1alpha/types/scan_config.py b/google/cloud/websecurityscanner_v1alpha/types/scan_config.py index 64315a5..966d62a 100644 --- a/google/cloud/websecurityscanner_v1alpha/types/scan_config.py +++ b/google/cloud/websecurityscanner_v1alpha/types/scan_config.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,12 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.websecurityscanner_v1alpha.types import scan_run -from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore __protobuf__ = proto.module( @@ -82,7 +79,6 @@ class TargetPlatform(proto.Enum): class Authentication(proto.Message): r"""Scan authentication configuration. - Attributes: google_account (google.cloud.websecurityscanner_v1alpha.types.ScanConfig.Authentication.GoogleAccount): Authentication using a Google account. @@ -105,9 +101,8 @@ class GoogleAccount(proto.Message): included in audit logs. """ - username = proto.Field(proto.STRING, number=1) - - password = proto.Field(proto.STRING, number=2) + username = proto.Field(proto.STRING, number=1,) + password = proto.Field(proto.STRING, number=2,) class CustomAccount(proto.Message): r"""Describes authentication configuration that uses a custom @@ -126,11 +121,9 @@ class CustomAccount(proto.Message): Required. The login form URL of the website. """ - username = proto.Field(proto.STRING, number=1) - - password = proto.Field(proto.STRING, number=2) - - login_url = proto.Field(proto.STRING, number=3) + username = proto.Field(proto.STRING, number=1,) + password = proto.Field(proto.STRING, number=2,) + login_url = proto.Field(proto.STRING, number=3,) google_account = proto.Field( proto.MESSAGE, @@ -138,7 +131,6 @@ class CustomAccount(proto.Message): oneof="authentication", message="ScanConfig.Authentication.GoogleAccount", ) - custom_account = proto.Field( proto.MESSAGE, number=2, @@ -148,7 +140,6 @@ class CustomAccount(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 @@ -162,29 +153,19 @@ class Schedule(proto.Message): """ schedule_time = proto.Field( - proto.MESSAGE, number=1, message=timestamp.Timestamp, + proto.MESSAGE, number=1, message=timestamp_pb2.Timestamp, ) + interval_duration_days = proto.Field(proto.INT32, number=2,) - interval_duration_days = proto.Field(proto.INT32, number=2) - - name = proto.Field(proto.STRING, number=1) - - display_name = proto.Field(proto.STRING, number=2) - - max_qps = proto.Field(proto.INT32, number=3) - - starting_urls = proto.RepeatedField(proto.STRING, number=4) - + name = proto.Field(proto.STRING, number=1,) + display_name = proto.Field(proto.STRING, number=2,) + max_qps = proto.Field(proto.INT32, number=3,) + starting_urls = proto.RepeatedField(proto.STRING, number=4,) authentication = proto.Field(proto.MESSAGE, number=5, message=Authentication,) - user_agent = proto.Field(proto.ENUM, number=6, enum=UserAgent,) - - blacklist_patterns = proto.RepeatedField(proto.STRING, number=7) - + blacklist_patterns = proto.RepeatedField(proto.STRING, number=7,) schedule = proto.Field(proto.MESSAGE, number=8, message=Schedule,) - target_platforms = proto.RepeatedField(proto.ENUM, number=9, enum=TargetPlatform,) - latest_run = proto.Field(proto.MESSAGE, number=11, message=scan_run.ScanRun,) diff --git a/google/cloud/websecurityscanner_v1alpha/types/scan_run.py b/google/cloud/websecurityscanner_v1alpha/types/scan_run.py index fac0c85..bcc7404 100644 --- a/google/cloud/websecurityscanner_v1alpha/types/scan_run.py +++ b/google/cloud/websecurityscanner_v1alpha/types/scan_run.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,11 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - -from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore __protobuf__ = proto.module( @@ -85,23 +82,15 @@ class ResultState(proto.Enum): ERROR = 2 KILLED = 3 - name = proto.Field(proto.STRING, number=1) - + name = proto.Field(proto.STRING, number=1,) execution_state = proto.Field(proto.ENUM, number=2, enum=ExecutionState,) - result_state = proto.Field(proto.ENUM, number=3, enum=ResultState,) - - start_time = proto.Field(proto.MESSAGE, number=4, message=timestamp.Timestamp,) - - end_time = proto.Field(proto.MESSAGE, number=5, message=timestamp.Timestamp,) - - urls_crawled_count = proto.Field(proto.INT64, number=6) - - urls_tested_count = proto.Field(proto.INT64, number=7) - - has_vulnerabilities = proto.Field(proto.BOOL, number=8) - - progress_percent = proto.Field(proto.INT32, number=9) + start_time = proto.Field(proto.MESSAGE, number=4, message=timestamp_pb2.Timestamp,) + end_time = proto.Field(proto.MESSAGE, number=5, message=timestamp_pb2.Timestamp,) + urls_crawled_count = proto.Field(proto.INT64, number=6,) + urls_tested_count = proto.Field(proto.INT64, number=7,) + has_vulnerabilities = proto.Field(proto.BOOL, number=8,) + progress_percent = proto.Field(proto.INT32, number=9,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/websecurityscanner_v1alpha/types/web_security_scanner.py b/google/cloud/websecurityscanner_v1alpha/types/web_security_scanner.py index f898e05..d134a3c 100644 --- a/google/cloud/websecurityscanner_v1alpha/types/web_security_scanner.py +++ b/google/cloud/websecurityscanner_v1alpha/types/web_security_scanner.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,10 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.websecurityscanner_v1alpha.types import crawled_url from google.cloud.websecurityscanner_v1alpha.types import finding from google.cloud.websecurityscanner_v1alpha.types import ( @@ -25,7 +22,7 @@ ) from google.cloud.websecurityscanner_v1alpha.types import scan_config as gcw_scan_config from google.cloud.websecurityscanner_v1alpha.types import scan_run -from google.protobuf import field_mask_pb2 as field_mask # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore __protobuf__ = proto.module( @@ -55,7 +52,6 @@ class CreateScanConfigRequest(proto.Message): r"""Request for the ``CreateScanConfig`` method. - Attributes: parent (str): Required. The parent resource name where the @@ -66,8 +62,7 @@ class CreateScanConfigRequest(proto.Message): Required. The ScanConfig to be created. """ - parent = proto.Field(proto.STRING, number=1) - + parent = proto.Field(proto.STRING, number=1,) scan_config = proto.Field( proto.MESSAGE, number=2, message=gcw_scan_config.ScanConfig, ) @@ -75,7 +70,6 @@ class CreateScanConfigRequest(proto.Message): class DeleteScanConfigRequest(proto.Message): r"""Request for the ``DeleteScanConfig`` method. - Attributes: name (str): Required. The resource name of the ScanConfig @@ -83,12 +77,11 @@ class DeleteScanConfigRequest(proto.Message): 'projects/{projectId}/scanConfigs/{scanConfigId}'. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class GetScanConfigRequest(proto.Message): r"""Request for the ``GetScanConfig`` method. - Attributes: name (str): Required. The resource name of the ScanConfig @@ -96,12 +89,11 @@ class GetScanConfigRequest(proto.Message): 'projects/{projectId}/scanConfigs/{scanConfigId}'. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class ListScanConfigsRequest(proto.Message): r"""Request for the ``ListScanConfigs`` method. - Attributes: parent (str): Required. The parent resource name, which @@ -119,16 +111,13 @@ class ListScanConfigsRequest(proto.Message): reasonable value. """ - parent = proto.Field(proto.STRING, number=1) - - page_token = proto.Field(proto.STRING, number=2) - - page_size = proto.Field(proto.INT32, number=3) + parent = proto.Field(proto.STRING, number=1,) + page_token = proto.Field(proto.STRING, number=2,) + page_size = proto.Field(proto.INT32, number=3,) class UpdateScanConfigRequest(proto.Message): r"""Request for the ``UpdateScanConfigRequest`` method. - Attributes: scan_config (google.cloud.websecurityscanner_v1alpha.types.ScanConfig): Required. The ScanConfig to be updated. The @@ -144,13 +133,13 @@ class UpdateScanConfigRequest(proto.Message): scan_config = proto.Field( proto.MESSAGE, number=2, message=gcw_scan_config.ScanConfig, ) - - update_mask = proto.Field(proto.MESSAGE, number=3, message=field_mask.FieldMask,) + update_mask = proto.Field( + proto.MESSAGE, number=3, message=field_mask_pb2.FieldMask, + ) class ListScanConfigsResponse(proto.Message): r"""Response for the ``ListScanConfigs`` method. - Attributes: scan_configs (Sequence[google.cloud.websecurityscanner_v1alpha.types.ScanConfig]): The list of ScanConfigs returned. @@ -167,13 +156,11 @@ def raw_page(self): scan_configs = proto.RepeatedField( proto.MESSAGE, number=1, message=gcw_scan_config.ScanConfig, ) - - next_page_token = proto.Field(proto.STRING, number=2) + next_page_token = proto.Field(proto.STRING, number=2,) class StartScanRunRequest(proto.Message): r"""Request for the ``StartScanRun`` method. - Attributes: name (str): Required. The resource name of the ScanConfig @@ -181,12 +168,11 @@ class StartScanRunRequest(proto.Message): 'projects/{projectId}/scanConfigs/{scanConfigId}'. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class GetScanRunRequest(proto.Message): r"""Request for the ``GetScanRun`` method. - Attributes: name (str): Required. The resource name of the ScanRun to @@ -194,12 +180,11 @@ class GetScanRunRequest(proto.Message): 'projects/{projectId}/scanConfigs/{scanConfigId}/scanRuns/{scanRunId}'. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class ListScanRunsRequest(proto.Message): r"""Request for the ``ListScanRuns`` method. - Attributes: parent (str): Required. The parent resource name, which @@ -217,16 +202,13 @@ class ListScanRunsRequest(proto.Message): reasonable value. """ - parent = proto.Field(proto.STRING, number=1) - - page_token = proto.Field(proto.STRING, number=2) - - page_size = proto.Field(proto.INT32, number=3) + parent = proto.Field(proto.STRING, number=1,) + page_token = proto.Field(proto.STRING, number=2,) + page_size = proto.Field(proto.INT32, number=3,) class ListScanRunsResponse(proto.Message): r"""Response for the ``ListScanRuns`` method. - Attributes: scan_runs (Sequence[google.cloud.websecurityscanner_v1alpha.types.ScanRun]): The list of ScanRuns returned. @@ -241,13 +223,11 @@ def raw_page(self): return self scan_runs = proto.RepeatedField(proto.MESSAGE, number=1, message=scan_run.ScanRun,) - - next_page_token = proto.Field(proto.STRING, number=2) + next_page_token = proto.Field(proto.STRING, number=2,) class StopScanRunRequest(proto.Message): r"""Request for the ``StopScanRun`` method. - Attributes: name (str): Required. The resource name of the ScanRun to @@ -255,12 +235,11 @@ class StopScanRunRequest(proto.Message): 'projects/{projectId}/scanConfigs/{scanConfigId}/scanRuns/{scanRunId}'. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class ListCrawledUrlsRequest(proto.Message): r"""Request for the ``ListCrawledUrls`` method. - Attributes: parent (str): Required. The parent resource name, which @@ -278,16 +257,13 @@ class ListCrawledUrlsRequest(proto.Message): reasonable value. """ - parent = proto.Field(proto.STRING, number=1) - - page_token = proto.Field(proto.STRING, number=2) - - page_size = proto.Field(proto.INT32, number=3) + parent = proto.Field(proto.STRING, number=1,) + page_token = proto.Field(proto.STRING, number=2,) + page_size = proto.Field(proto.INT32, number=3,) class ListCrawledUrlsResponse(proto.Message): r"""Response for the ``ListCrawledUrls`` method. - Attributes: crawled_urls (Sequence[google.cloud.websecurityscanner_v1alpha.types.CrawledUrl]): The list of CrawledUrls returned. @@ -304,13 +280,11 @@ def raw_page(self): crawled_urls = proto.RepeatedField( proto.MESSAGE, number=1, message=crawled_url.CrawledUrl, ) - - next_page_token = proto.Field(proto.STRING, number=2) + next_page_token = proto.Field(proto.STRING, number=2,) class GetFindingRequest(proto.Message): r"""Request for the ``GetFinding`` method. - Attributes: name (str): Required. The resource name of the Finding to @@ -318,12 +292,11 @@ class GetFindingRequest(proto.Message): 'projects/{projectId}/scanConfigs/{scanConfigId}/scanRuns/{scanRunId}/findings/{findingId}'. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class ListFindingsRequest(proto.Message): r"""Request for the ``ListFindings`` method. - Attributes: parent (str): Required. The parent resource name, which @@ -345,18 +318,14 @@ class ListFindingsRequest(proto.Message): reasonable value. """ - parent = proto.Field(proto.STRING, number=1) - - filter = proto.Field(proto.STRING, number=2) - - page_token = proto.Field(proto.STRING, number=3) - - page_size = proto.Field(proto.INT32, number=4) + parent = proto.Field(proto.STRING, number=1,) + filter = proto.Field(proto.STRING, number=2,) + page_token = proto.Field(proto.STRING, number=3,) + page_size = proto.Field(proto.INT32, number=4,) class ListFindingsResponse(proto.Message): r"""Response for the ``ListFindings`` method. - Attributes: findings (Sequence[google.cloud.websecurityscanner_v1alpha.types.Finding]): The list of Findings returned. @@ -371,13 +340,11 @@ def raw_page(self): return self findings = proto.RepeatedField(proto.MESSAGE, number=1, message=finding.Finding,) - - next_page_token = proto.Field(proto.STRING, number=2) + next_page_token = proto.Field(proto.STRING, number=2,) class ListFindingTypeStatsRequest(proto.Message): r"""Request for the ``ListFindingTypeStats`` method. - Attributes: parent (str): Required. The parent resource name, which @@ -385,12 +352,11 @@ class ListFindingTypeStatsRequest(proto.Message): 'projects/{projectId}/scanConfigs/{scanConfigId}/scanRuns/{scanRunId}'. """ - parent = proto.Field(proto.STRING, number=1) + parent = proto.Field(proto.STRING, number=1,) class ListFindingTypeStatsResponse(proto.Message): r"""Response for the ``ListFindingTypeStats`` method. - Attributes: finding_type_stats (Sequence[google.cloud.websecurityscanner_v1alpha.types.FindingTypeStats]): The list of FindingTypeStats returned. diff --git a/google/cloud/websecurityscanner_v1beta/__init__.py b/google/cloud/websecurityscanner_v1beta/__init__.py index c5228bc..a3713bb 100644 --- a/google/cloud/websecurityscanner_v1beta/__init__.py +++ b/google/cloud/websecurityscanner_v1beta/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,6 +15,8 @@ # from .services.web_security_scanner import WebSecurityScannerClient +from .services.web_security_scanner import WebSecurityScannerAsyncClient + from .types.crawled_url import CrawledUrl from .types.finding import Finding from .types.finding_addon import Form @@ -37,10 +38,10 @@ from .types.web_security_scanner import GetScanRunRequest from .types.web_security_scanner import ListCrawledUrlsRequest from .types.web_security_scanner import ListCrawledUrlsResponse -from .types.web_security_scanner import ListFindingTypeStatsRequest -from .types.web_security_scanner import ListFindingTypeStatsResponse from .types.web_security_scanner import ListFindingsRequest from .types.web_security_scanner import ListFindingsResponse +from .types.web_security_scanner import ListFindingTypeStatsRequest +from .types.web_security_scanner import ListFindingTypeStatsResponse from .types.web_security_scanner import ListScanConfigsRequest from .types.web_security_scanner import ListScanConfigsResponse from .types.web_security_scanner import ListScanRunsRequest @@ -49,8 +50,8 @@ from .types.web_security_scanner import StopScanRunRequest from .types.web_security_scanner import UpdateScanConfigRequest - __all__ = ( + "WebSecurityScannerAsyncClient", "CrawledUrl", "CreateScanConfigRequest", "DeleteScanConfigRequest", @@ -82,6 +83,6 @@ "ViolatingResource", "VulnerableHeaders", "VulnerableParameters", - "Xss", "WebSecurityScannerClient", + "Xss", ) diff --git a/google/cloud/websecurityscanner_v1beta/gapic_metadata.json b/google/cloud/websecurityscanner_v1beta/gapic_metadata.json new file mode 100644 index 0000000..114e6f0 --- /dev/null +++ b/google/cloud/websecurityscanner_v1beta/gapic_metadata.json @@ -0,0 +1,153 @@ + { + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", + "language": "python", + "libraryPackage": "google.cloud.websecurityscanner_v1beta", + "protoPackage": "google.cloud.websecurityscanner.v1beta", + "schema": "1.0", + "services": { + "WebSecurityScanner": { + "clients": { + "grpc": { + "libraryClient": "WebSecurityScannerClient", + "rpcs": { + "CreateScanConfig": { + "methods": [ + "create_scan_config" + ] + }, + "DeleteScanConfig": { + "methods": [ + "delete_scan_config" + ] + }, + "GetFinding": { + "methods": [ + "get_finding" + ] + }, + "GetScanConfig": { + "methods": [ + "get_scan_config" + ] + }, + "GetScanRun": { + "methods": [ + "get_scan_run" + ] + }, + "ListCrawledUrls": { + "methods": [ + "list_crawled_urls" + ] + }, + "ListFindingTypeStats": { + "methods": [ + "list_finding_type_stats" + ] + }, + "ListFindings": { + "methods": [ + "list_findings" + ] + }, + "ListScanConfigs": { + "methods": [ + "list_scan_configs" + ] + }, + "ListScanRuns": { + "methods": [ + "list_scan_runs" + ] + }, + "StartScanRun": { + "methods": [ + "start_scan_run" + ] + }, + "StopScanRun": { + "methods": [ + "stop_scan_run" + ] + }, + "UpdateScanConfig": { + "methods": [ + "update_scan_config" + ] + } + } + }, + "grpc-async": { + "libraryClient": "WebSecurityScannerAsyncClient", + "rpcs": { + "CreateScanConfig": { + "methods": [ + "create_scan_config" + ] + }, + "DeleteScanConfig": { + "methods": [ + "delete_scan_config" + ] + }, + "GetFinding": { + "methods": [ + "get_finding" + ] + }, + "GetScanConfig": { + "methods": [ + "get_scan_config" + ] + }, + "GetScanRun": { + "methods": [ + "get_scan_run" + ] + }, + "ListCrawledUrls": { + "methods": [ + "list_crawled_urls" + ] + }, + "ListFindingTypeStats": { + "methods": [ + "list_finding_type_stats" + ] + }, + "ListFindings": { + "methods": [ + "list_findings" + ] + }, + "ListScanConfigs": { + "methods": [ + "list_scan_configs" + ] + }, + "ListScanRuns": { + "methods": [ + "list_scan_runs" + ] + }, + "StartScanRun": { + "methods": [ + "start_scan_run" + ] + }, + "StopScanRun": { + "methods": [ + "stop_scan_run" + ] + }, + "UpdateScanConfig": { + "methods": [ + "update_scan_config" + ] + } + } + } + } + } + } +} diff --git a/google/cloud/websecurityscanner_v1beta/services/__init__.py b/google/cloud/websecurityscanner_v1beta/services/__init__.py index 42ffdf2..4de6597 100644 --- a/google/cloud/websecurityscanner_v1beta/services/__init__.py +++ b/google/cloud/websecurityscanner_v1beta/services/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/google/cloud/websecurityscanner_v1beta/services/web_security_scanner/__init__.py b/google/cloud/websecurityscanner_v1beta/services/web_security_scanner/__init__.py index d841cb5..4aae8e1 100644 --- a/google/cloud/websecurityscanner_v1beta/services/web_security_scanner/__init__.py +++ b/google/cloud/websecurityscanner_v1beta/services/web_security_scanner/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from .client import WebSecurityScannerClient from .async_client import WebSecurityScannerAsyncClient diff --git a/google/cloud/websecurityscanner_v1beta/services/web_security_scanner/async_client.py b/google/cloud/websecurityscanner_v1beta/services/web_security_scanner/async_client.py index fe720d7..99824a4 100644 --- a/google/cloud/websecurityscanner_v1beta/services/web_security_scanner/async_client.py +++ b/google/cloud/websecurityscanner_v1beta/services/web_security_scanner/async_client.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict import functools import re @@ -22,10 +20,10 @@ import pkg_resources import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore from google.cloud.websecurityscanner_v1beta.services.web_security_scanner import pagers @@ -39,9 +37,8 @@ from google.cloud.websecurityscanner_v1beta.types import scan_run_error_trace from google.cloud.websecurityscanner_v1beta.types import scan_run_warning_trace from google.cloud.websecurityscanner_v1beta.types import web_security_scanner -from google.protobuf import field_mask_pb2 as field_mask # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore - +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore from .transports.base import WebSecurityScannerTransport, DEFAULT_CLIENT_INFO from .transports.grpc_asyncio import WebSecurityScannerGrpcAsyncIOTransport from .client import WebSecurityScannerClient @@ -67,31 +64,26 @@ class WebSecurityScannerAsyncClient: ) scan_run_path = staticmethod(WebSecurityScannerClient.scan_run_path) parse_scan_run_path = staticmethod(WebSecurityScannerClient.parse_scan_run_path) - common_billing_account_path = staticmethod( WebSecurityScannerClient.common_billing_account_path ) parse_common_billing_account_path = staticmethod( WebSecurityScannerClient.parse_common_billing_account_path ) - common_folder_path = staticmethod(WebSecurityScannerClient.common_folder_path) parse_common_folder_path = staticmethod( WebSecurityScannerClient.parse_common_folder_path ) - common_organization_path = staticmethod( WebSecurityScannerClient.common_organization_path ) parse_common_organization_path = staticmethod( WebSecurityScannerClient.parse_common_organization_path ) - common_project_path = staticmethod(WebSecurityScannerClient.common_project_path) parse_common_project_path = staticmethod( WebSecurityScannerClient.parse_common_project_path ) - common_location_path = staticmethod(WebSecurityScannerClient.common_location_path) parse_common_location_path = staticmethod( WebSecurityScannerClient.parse_common_location_path @@ -99,7 +91,8 @@ class WebSecurityScannerAsyncClient: @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -114,7 +107,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -131,7 +124,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> WebSecurityScannerTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: WebSecurityScannerTransport: The transport used by the client instance. @@ -146,12 +139,12 @@ def transport(self) -> WebSecurityScannerTransport: def __init__( self, *, - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, transport: Union[str, WebSecurityScannerTransport] = "grpc_asyncio", client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the web security scanner client. + """Instantiates the web security scanner client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -183,7 +176,6 @@ def __init__( google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport creation failed for any reason. """ - self._client = WebSecurityScannerClient( credentials=credentials, transport=transport, @@ -223,7 +215,6 @@ async def create_scan_config( This corresponds to the ``scan_config`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -250,7 +241,6 @@ async def create_scan_config( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if scan_config is not None: @@ -301,7 +291,6 @@ async def delete_scan_config( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -322,7 +311,6 @@ async def delete_scan_config( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -335,7 +323,8 @@ async def delete_scan_config( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -378,7 +367,6 @@ async def get_scan_config( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -405,7 +393,6 @@ async def get_scan_config( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -418,7 +405,8 @@ async def get_scan_config( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -461,7 +449,6 @@ async def list_scan_configs( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -490,7 +477,6 @@ async def list_scan_configs( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -503,7 +489,8 @@ async def list_scan_configs( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -534,7 +521,7 @@ async def update_scan_config( request: web_security_scanner.UpdateScanConfigRequest = None, *, scan_config: gcw_scan_config.ScanConfig = None, - update_mask: field_mask.FieldMask = None, + update_mask: field_mask_pb2.FieldMask = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), @@ -564,7 +551,6 @@ async def update_scan_config( This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -591,7 +577,6 @@ async def update_scan_config( # If we have keyword arguments corresponding to fields on the # request, apply these. - if scan_config is not None: request.scan_config = scan_config if update_mask is not None: @@ -643,7 +628,6 @@ async def start_scan_run( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -671,7 +655,6 @@ async def start_scan_run( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -718,7 +701,6 @@ async def get_scan_run( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -746,7 +728,6 @@ async def get_scan_run( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -759,7 +740,8 @@ async def get_scan_run( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -804,7 +786,6 @@ async def list_scan_runs( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -833,7 +814,6 @@ async def list_scan_runs( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -846,7 +826,8 @@ async def list_scan_runs( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -896,7 +877,6 @@ async def stop_scan_run( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -924,7 +904,6 @@ async def stop_scan_run( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -972,7 +951,6 @@ async def list_crawled_urls( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1001,7 +979,6 @@ async def list_crawled_urls( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -1014,7 +991,8 @@ async def list_crawled_urls( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -1063,7 +1041,6 @@ async def get_finding( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1091,7 +1068,6 @@ async def get_finding( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -1104,7 +1080,8 @@ async def get_finding( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -1157,7 +1134,6 @@ async def list_findings( This corresponds to the ``filter`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1186,7 +1162,6 @@ async def list_findings( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if filter is not None: @@ -1201,7 +1176,8 @@ async def list_findings( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -1251,7 +1227,6 @@ async def list_finding_type_stats( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1276,7 +1251,6 @@ async def list_finding_type_stats( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -1289,7 +1263,8 @@ async def list_finding_type_stats( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), diff --git a/google/cloud/websecurityscanner_v1beta/services/web_security_scanner/client.py b/google/cloud/websecurityscanner_v1beta/services/web_security_scanner/client.py index fcf40a2..134fce8 100644 --- a/google/cloud/websecurityscanner_v1beta/services/web_security_scanner/client.py +++ b/google/cloud/websecurityscanner_v1beta/services/web_security_scanner/client.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict from distutils import util import os @@ -23,10 +21,10 @@ import pkg_resources from google.api_core import client_options as client_options_lib # type: ignore -from google.api_core import exceptions # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport import mtls # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.auth.exceptions import MutualTLSChannelError # type: ignore @@ -43,9 +41,8 @@ from google.cloud.websecurityscanner_v1beta.types import scan_run_error_trace from google.cloud.websecurityscanner_v1beta.types import scan_run_warning_trace from google.cloud.websecurityscanner_v1beta.types import web_security_scanner -from google.protobuf import field_mask_pb2 as field_mask # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore - +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore from .transports.base import WebSecurityScannerTransport, DEFAULT_CLIENT_INFO from .transports.grpc import WebSecurityScannerGrpcTransport from .transports.grpc_asyncio import WebSecurityScannerGrpcAsyncIOTransport @@ -68,7 +65,7 @@ class WebSecurityScannerClientMeta(type): def get_transport_class( cls, label: str = None, ) -> Type[WebSecurityScannerTransport]: - """Return an appropriate transport class. + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -95,7 +92,8 @@ class WebSecurityScannerClient(metaclass=WebSecurityScannerClientMeta): @staticmethod def _get_default_mtls_endpoint(api_endpoint): - """Convert api endpoint to mTLS endpoint. + """Converts api endpoint to mTLS endpoint. + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. Args: @@ -129,7 +127,8 @@ def _get_default_mtls_endpoint(api_endpoint): @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -146,7 +145,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -165,10 +164,11 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> WebSecurityScannerTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - WebSecurityScannerTransport: The transport used by the client instance. + WebSecurityScannerTransport: The transport used by the client + instance. """ return self._transport @@ -176,7 +176,7 @@ def transport(self) -> WebSecurityScannerTransport: def finding_path( project: str, scan_config: str, scan_run: str, finding: str, ) -> str: - """Return a fully-qualified finding string.""" + """Returns a fully-qualified finding string.""" return "projects/{project}/scanConfigs/{scan_config}/scanRuns/{scan_run}/findings/{finding}".format( project=project, scan_config=scan_config, @@ -186,7 +186,7 @@ def finding_path( @staticmethod def parse_finding_path(path: str) -> Dict[str, str]: - """Parse a finding path into its component segments.""" + """Parses a finding path into its component segments.""" m = re.match( r"^projects/(?P.+?)/scanConfigs/(?P.+?)/scanRuns/(?P.+?)/findings/(?P.+?)$", path, @@ -195,14 +195,14 @@ def parse_finding_path(path: str) -> Dict[str, str]: @staticmethod def scan_config_path(project: str, scan_config: str,) -> str: - """Return a fully-qualified scan_config string.""" + """Returns a fully-qualified scan_config string.""" return "projects/{project}/scanConfigs/{scan_config}".format( project=project, scan_config=scan_config, ) @staticmethod def parse_scan_config_path(path: str) -> Dict[str, str]: - """Parse a scan_config path into its component segments.""" + """Parses a scan_config path into its component segments.""" m = re.match( r"^projects/(?P.+?)/scanConfigs/(?P.+?)$", path ) @@ -210,14 +210,14 @@ def parse_scan_config_path(path: str) -> Dict[str, str]: @staticmethod def scan_run_path(project: str, scan_config: str, scan_run: str,) -> str: - """Return a fully-qualified scan_run string.""" + """Returns a fully-qualified scan_run string.""" return "projects/{project}/scanConfigs/{scan_config}/scanRuns/{scan_run}".format( project=project, scan_config=scan_config, scan_run=scan_run, ) @staticmethod def parse_scan_run_path(path: str) -> Dict[str, str]: - """Parse a scan_run path into its component segments.""" + """Parses a scan_run path into its component segments.""" m = re.match( r"^projects/(?P.+?)/scanConfigs/(?P.+?)/scanRuns/(?P.+?)$", path, @@ -226,7 +226,7 @@ def parse_scan_run_path(path: str) -> Dict[str, str]: @staticmethod def common_billing_account_path(billing_account: str,) -> str: - """Return a fully-qualified billing_account string.""" + """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -239,7 +239,7 @@ def parse_common_billing_account_path(path: str) -> Dict[str, str]: @staticmethod def common_folder_path(folder: str,) -> str: - """Return a fully-qualified folder string.""" + """Returns a fully-qualified folder string.""" return "folders/{folder}".format(folder=folder,) @staticmethod @@ -250,7 +250,7 @@ def parse_common_folder_path(path: str) -> Dict[str, str]: @staticmethod def common_organization_path(organization: str,) -> str: - """Return a fully-qualified organization string.""" + """Returns a fully-qualified organization string.""" return "organizations/{organization}".format(organization=organization,) @staticmethod @@ -261,7 +261,7 @@ def parse_common_organization_path(path: str) -> Dict[str, str]: @staticmethod def common_project_path(project: str,) -> str: - """Return a fully-qualified project string.""" + """Returns a fully-qualified project string.""" return "projects/{project}".format(project=project,) @staticmethod @@ -272,7 +272,7 @@ def parse_common_project_path(path: str) -> Dict[str, str]: @staticmethod def common_location_path(project: str, location: str,) -> str: - """Return a fully-qualified location string.""" + """Returns a fully-qualified location string.""" return "projects/{project}/locations/{location}".format( project=project, location=location, ) @@ -286,12 +286,12 @@ def parse_common_location_path(path: str) -> Dict[str, str]: def __init__( self, *, - credentials: Optional[credentials.Credentials] = None, + credentials: Optional[ga_credentials.Credentials] = None, transport: Union[str, WebSecurityScannerTransport, None] = None, client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the web security scanner client. + """Instantiates the web security scanner client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -346,9 +346,10 @@ def __init__( client_cert_source_func = client_options.client_cert_source else: is_mtls = mtls.has_default_client_cert_source() - client_cert_source_func = ( - mtls.default_client_cert_source() if is_mtls else None - ) + if is_mtls: + client_cert_source_func = mtls.default_client_cert_source() + else: + client_cert_source_func = None # Figure out which api endpoint to use. if client_options.api_endpoint is not None: @@ -360,12 +361,14 @@ def __init__( elif use_mtls_env == "always": api_endpoint = self.DEFAULT_MTLS_ENDPOINT elif use_mtls_env == "auto": - api_endpoint = ( - self.DEFAULT_MTLS_ENDPOINT if is_mtls else self.DEFAULT_ENDPOINT - ) + if is_mtls: + api_endpoint = self.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = self.DEFAULT_ENDPOINT else: raise MutualTLSChannelError( - "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted values: never, auto, always" + "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted " + "values: never, auto, always" ) # Save or instantiate the transport. @@ -380,8 +383,8 @@ def __init__( ) if client_options.scopes: raise ValueError( - "When providing a transport instance, " - "provide its scopes directly." + "When providing a transport instance, provide its scopes " + "directly." ) self._transport = transport else: @@ -428,7 +431,6 @@ def create_scan_config( This corresponds to the ``scan_config`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -457,10 +459,8 @@ def create_scan_config( # there are no flattened fields. if not isinstance(request, web_security_scanner.CreateScanConfigRequest): request = web_security_scanner.CreateScanConfigRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if scan_config is not None: @@ -507,7 +507,6 @@ def delete_scan_config( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -530,10 +529,8 @@ def delete_scan_config( # there are no flattened fields. if not isinstance(request, web_security_scanner.DeleteScanConfigRequest): request = web_security_scanner.DeleteScanConfigRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -576,7 +573,6 @@ def get_scan_config( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -605,10 +601,8 @@ def get_scan_config( # there are no flattened fields. if not isinstance(request, web_security_scanner.GetScanConfigRequest): request = web_security_scanner.GetScanConfigRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -651,7 +645,6 @@ def list_scan_configs( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -682,10 +675,8 @@ def list_scan_configs( # there are no flattened fields. if not isinstance(request, web_security_scanner.ListScanConfigsRequest): request = web_security_scanner.ListScanConfigsRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -716,7 +707,7 @@ def update_scan_config( request: web_security_scanner.UpdateScanConfigRequest = None, *, scan_config: gcw_scan_config.ScanConfig = None, - update_mask: field_mask.FieldMask = None, + update_mask: field_mask_pb2.FieldMask = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), @@ -746,7 +737,6 @@ def update_scan_config( This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -775,10 +765,8 @@ def update_scan_config( # there are no flattened fields. if not isinstance(request, web_security_scanner.UpdateScanConfigRequest): request = web_security_scanner.UpdateScanConfigRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if scan_config is not None: request.scan_config = scan_config if update_mask is not None: @@ -826,7 +814,6 @@ def start_scan_run( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -856,10 +843,8 @@ def start_scan_run( # there are no flattened fields. if not isinstance(request, web_security_scanner.StartScanRunRequest): request = web_security_scanner.StartScanRunRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -902,7 +887,6 @@ def get_scan_run( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -932,10 +916,8 @@ def get_scan_run( # there are no flattened fields. if not isinstance(request, web_security_scanner.GetScanRunRequest): request = web_security_scanner.GetScanRunRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -980,7 +962,6 @@ def list_scan_runs( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1011,10 +992,8 @@ def list_scan_runs( # there are no flattened fields. if not isinstance(request, web_security_scanner.ListScanRunsRequest): request = web_security_scanner.ListScanRunsRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -1064,7 +1043,6 @@ def stop_scan_run( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1094,10 +1072,8 @@ def stop_scan_run( # there are no flattened fields. if not isinstance(request, web_security_scanner.StopScanRunRequest): request = web_security_scanner.StopScanRunRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -1141,7 +1117,6 @@ def list_crawled_urls( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1172,10 +1147,8 @@ def list_crawled_urls( # there are no flattened fields. if not isinstance(request, web_security_scanner.ListCrawledUrlsRequest): request = web_security_scanner.ListCrawledUrlsRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -1224,7 +1197,6 @@ def get_finding( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1254,10 +1226,8 @@ def get_finding( # there are no flattened fields. if not isinstance(request, web_security_scanner.GetFindingRequest): request = web_security_scanner.GetFindingRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -1310,7 +1280,6 @@ def list_findings( This corresponds to the ``filter`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1341,10 +1310,8 @@ def list_findings( # there are no flattened fields. if not isinstance(request, web_security_scanner.ListFindingsRequest): request = web_security_scanner.ListFindingsRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if filter is not None: @@ -1396,7 +1363,6 @@ def list_finding_type_stats( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1423,10 +1389,8 @@ def list_finding_type_stats( # there are no flattened fields. if not isinstance(request, web_security_scanner.ListFindingTypeStatsRequest): request = web_security_scanner.ListFindingTypeStatsRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent diff --git a/google/cloud/websecurityscanner_v1beta/services/web_security_scanner/pagers.py b/google/cloud/websecurityscanner_v1beta/services/web_security_scanner/pagers.py index 0c39cda..b5520f9 100644 --- a/google/cloud/websecurityscanner_v1beta/services/web_security_scanner/pagers.py +++ b/google/cloud/websecurityscanner_v1beta/services/web_security_scanner/pagers.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from typing import ( Any, AsyncIterable, @@ -121,7 +119,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -251,7 +249,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -379,7 +377,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -509,7 +507,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and diff --git a/google/cloud/websecurityscanner_v1beta/services/web_security_scanner/transports/__init__.py b/google/cloud/websecurityscanner_v1beta/services/web_security_scanner/transports/__init__.py index caf0502..fce7d6c 100644 --- a/google/cloud/websecurityscanner_v1beta/services/web_security_scanner/transports/__init__.py +++ b/google/cloud/websecurityscanner_v1beta/services/web_security_scanner/transports/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict from typing import Dict, Type diff --git a/google/cloud/websecurityscanner_v1beta/services/web_security_scanner/transports/base.py b/google/cloud/websecurityscanner_v1beta/services/web_security_scanner/transports/base.py index f1de54a..acca6a3 100644 --- a/google/cloud/websecurityscanner_v1beta/services/web_security_scanner/transports/base.py +++ b/google/cloud/websecurityscanner_v1beta/services/web_security_scanner/transports/base.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,24 +13,24 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import abc -import typing +from typing import Awaitable, Callable, Dict, Optional, Sequence, Union +import packaging.version import pkg_resources -from google import auth # type: ignore -from google.api_core import exceptions # type: ignore +import google.auth # type: ignore +import google.api_core # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.cloud.websecurityscanner_v1beta.types import finding from google.cloud.websecurityscanner_v1beta.types import scan_config from google.cloud.websecurityscanner_v1beta.types import scan_config as gcw_scan_config from google.cloud.websecurityscanner_v1beta.types import scan_run from google.cloud.websecurityscanner_v1beta.types import web_security_scanner -from google.protobuf import empty_pb2 as empty # type: ignore - +from google.protobuf import empty_pb2 # type: ignore try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( @@ -42,27 +41,41 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() +try: + # google.auth.__version__ was added in 1.26.0 + _GOOGLE_AUTH_VERSION = google.auth.__version__ +except AttributeError: + try: # try pkg_resources if it is available + _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version + except pkg_resources.DistributionNotFound: # pragma: NO COVER + _GOOGLE_AUTH_VERSION = None + +_API_CORE_VERSION = google.api_core.__version__ + class WebSecurityScannerTransport(abc.ABC): """Abstract transport class for WebSecurityScanner.""" AUTH_SCOPES = ("https://www.googleapis.com/auth/cloud-platform",) + DEFAULT_HOST: str = "websecurityscanner.googleapis.com" + def __init__( self, *, - host: str = "websecurityscanner.googleapis.com", - credentials: credentials.Credentials = None, - credentials_file: typing.Optional[str] = None, - scopes: typing.Optional[typing.Sequence[str]] = AUTH_SCOPES, - quota_project_id: typing.Optional[str] = None, + host: str = DEFAULT_HOST, + credentials: ga_credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, **kwargs, ) -> None: """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -71,7 +84,7 @@ def __init__( credentials_file (Optional[str]): A file with credentials that can be loaded with :func:`google.auth.load_credentials_from_file`. This argument is mutually exclusive with credentials. - scope (Optional[Sequence[str]]): A list of scopes. + scopes (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -85,29 +98,76 @@ def __init__( host += ":443" self._host = host + scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + # Save the scopes. self._scopes = scopes or self.AUTH_SCOPES # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: - raise exceptions.DuplicateCredentialArgs( + raise core_exceptions.DuplicateCredentialArgs( "'credentials_file' and 'credentials' are mutually exclusive" ) if credentials_file is not None: - credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=self._scopes, quota_project_id=quota_project_id + credentials, _ = google.auth.load_credentials_from_file( + credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) elif credentials is None: - credentials, _ = auth.default( - scopes=self._scopes, quota_project_id=quota_project_id + credentials, _ = google.auth.default( + **scopes_kwargs, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials + # TODO(busunkim): These two class methods are in the base transport + # to avoid duplicating code across the transport classes. These functions + # should be deleted once the minimum required versions of google-api-core + # and google-auth are increased. + + # TODO: Remove this function once google-auth >= 1.25.0 is required + @classmethod + def _get_scopes_kwargs( + cls, host: str, scopes: Optional[Sequence[str]] + ) -> Dict[str, Optional[Sequence[str]]]: + """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" + + scopes_kwargs = {} + + if _GOOGLE_AUTH_VERSION and ( + packaging.version.parse(_GOOGLE_AUTH_VERSION) + >= packaging.version.parse("1.25.0") + ): + scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} + else: + scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} + + return scopes_kwargs + + # TODO: Remove this function once google-api-core >= 1.26.0 is required + @classmethod + def _get_self_signed_jwt_kwargs( + cls, host: str, scopes: Optional[Sequence[str]] + ) -> Dict[str, Union[Optional[Sequence[str]], str]]: + """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" + + self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} + + if _API_CORE_VERSION and ( + packaging.version.parse(_API_CORE_VERSION) + >= packaging.version.parse("1.26.0") + ): + self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES + self_signed_jwt_kwargs["scopes"] = scopes + self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST + else: + self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES + + return self_signed_jwt_kwargs + def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { @@ -121,7 +181,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -135,7 +196,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -149,7 +211,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -169,7 +232,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -183,7 +247,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -200,7 +265,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -214,7 +280,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -228,7 +295,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -242,7 +310,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -254,40 +323,38 @@ def _prep_wrapped_messages(self, client_info): @property def create_scan_config( self, - ) -> typing.Callable[ + ) -> Callable[ [web_security_scanner.CreateScanConfigRequest], - typing.Union[ - gcw_scan_config.ScanConfig, typing.Awaitable[gcw_scan_config.ScanConfig] - ], + Union[gcw_scan_config.ScanConfig, Awaitable[gcw_scan_config.ScanConfig]], ]: raise NotImplementedError() @property def delete_scan_config( self, - ) -> typing.Callable[ + ) -> Callable[ [web_security_scanner.DeleteScanConfigRequest], - typing.Union[empty.Empty, typing.Awaitable[empty.Empty]], + Union[empty_pb2.Empty, Awaitable[empty_pb2.Empty]], ]: raise NotImplementedError() @property def get_scan_config( self, - ) -> typing.Callable[ + ) -> Callable[ [web_security_scanner.GetScanConfigRequest], - typing.Union[scan_config.ScanConfig, typing.Awaitable[scan_config.ScanConfig]], + Union[scan_config.ScanConfig, Awaitable[scan_config.ScanConfig]], ]: raise NotImplementedError() @property def list_scan_configs( self, - ) -> typing.Callable[ + ) -> Callable[ [web_security_scanner.ListScanConfigsRequest], - typing.Union[ + Union[ web_security_scanner.ListScanConfigsResponse, - typing.Awaitable[web_security_scanner.ListScanConfigsResponse], + Awaitable[web_security_scanner.ListScanConfigsResponse], ], ]: raise NotImplementedError() @@ -295,40 +362,38 @@ def list_scan_configs( @property def update_scan_config( self, - ) -> typing.Callable[ + ) -> Callable[ [web_security_scanner.UpdateScanConfigRequest], - typing.Union[ - gcw_scan_config.ScanConfig, typing.Awaitable[gcw_scan_config.ScanConfig] - ], + Union[gcw_scan_config.ScanConfig, Awaitable[gcw_scan_config.ScanConfig]], ]: raise NotImplementedError() @property def start_scan_run( self, - ) -> typing.Callable[ + ) -> Callable[ [web_security_scanner.StartScanRunRequest], - typing.Union[scan_run.ScanRun, typing.Awaitable[scan_run.ScanRun]], + Union[scan_run.ScanRun, Awaitable[scan_run.ScanRun]], ]: raise NotImplementedError() @property def get_scan_run( self, - ) -> typing.Callable[ + ) -> Callable[ [web_security_scanner.GetScanRunRequest], - typing.Union[scan_run.ScanRun, typing.Awaitable[scan_run.ScanRun]], + Union[scan_run.ScanRun, Awaitable[scan_run.ScanRun]], ]: raise NotImplementedError() @property def list_scan_runs( self, - ) -> typing.Callable[ + ) -> Callable[ [web_security_scanner.ListScanRunsRequest], - typing.Union[ + Union[ web_security_scanner.ListScanRunsResponse, - typing.Awaitable[web_security_scanner.ListScanRunsResponse], + Awaitable[web_security_scanner.ListScanRunsResponse], ], ]: raise NotImplementedError() @@ -336,20 +401,20 @@ def list_scan_runs( @property def stop_scan_run( self, - ) -> typing.Callable[ + ) -> Callable[ [web_security_scanner.StopScanRunRequest], - typing.Union[scan_run.ScanRun, typing.Awaitable[scan_run.ScanRun]], + Union[scan_run.ScanRun, Awaitable[scan_run.ScanRun]], ]: raise NotImplementedError() @property def list_crawled_urls( self, - ) -> typing.Callable[ + ) -> Callable[ [web_security_scanner.ListCrawledUrlsRequest], - typing.Union[ + Union[ web_security_scanner.ListCrawledUrlsResponse, - typing.Awaitable[web_security_scanner.ListCrawledUrlsResponse], + Awaitable[web_security_scanner.ListCrawledUrlsResponse], ], ]: raise NotImplementedError() @@ -357,20 +422,20 @@ def list_crawled_urls( @property def get_finding( self, - ) -> typing.Callable[ + ) -> Callable[ [web_security_scanner.GetFindingRequest], - typing.Union[finding.Finding, typing.Awaitable[finding.Finding]], + Union[finding.Finding, Awaitable[finding.Finding]], ]: raise NotImplementedError() @property def list_findings( self, - ) -> typing.Callable[ + ) -> Callable[ [web_security_scanner.ListFindingsRequest], - typing.Union[ + Union[ web_security_scanner.ListFindingsResponse, - typing.Awaitable[web_security_scanner.ListFindingsResponse], + Awaitable[web_security_scanner.ListFindingsResponse], ], ]: raise NotImplementedError() @@ -378,11 +443,11 @@ def list_findings( @property def list_finding_type_stats( self, - ) -> typing.Callable[ + ) -> Callable[ [web_security_scanner.ListFindingTypeStatsRequest], - typing.Union[ + Union[ web_security_scanner.ListFindingTypeStatsResponse, - typing.Awaitable[web_security_scanner.ListFindingTypeStatsResponse], + Awaitable[web_security_scanner.ListFindingTypeStatsResponse], ], ]: raise NotImplementedError() diff --git a/google/cloud/websecurityscanner_v1beta/services/web_security_scanner/transports/grpc.py b/google/cloud/websecurityscanner_v1beta/services/web_security_scanner/transports/grpc.py index f6977ea..2614f79 100644 --- a/google/cloud/websecurityscanner_v1beta/services/web_security_scanner/transports/grpc.py +++ b/google/cloud/websecurityscanner_v1beta/services/web_security_scanner/transports/grpc.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,14 +13,13 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import warnings -from typing import Callable, Dict, Optional, Sequence, Tuple +from typing import Callable, Dict, Optional, Sequence, Tuple, Union from google.api_core import grpc_helpers # type: ignore from google.api_core import gapic_v1 # type: ignore -from google import auth # type: ignore -from google.auth import credentials # type: ignore +import google.auth # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore import grpc # type: ignore @@ -31,8 +29,7 @@ from google.cloud.websecurityscanner_v1beta.types import scan_config as gcw_scan_config from google.cloud.websecurityscanner_v1beta.types import scan_run from google.cloud.websecurityscanner_v1beta.types import web_security_scanner -from google.protobuf import empty_pb2 as empty # type: ignore - +from google.protobuf import empty_pb2 # type: ignore from .base import WebSecurityScannerTransport, DEFAULT_CLIENT_INFO @@ -58,7 +55,7 @@ def __init__( self, *, host: str = "websecurityscanner.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: str = None, scopes: Sequence[str] = None, channel: grpc.Channel = None, @@ -72,7 +69,8 @@ def __init__( """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -182,7 +180,7 @@ def __init__( def create_channel( cls, host: str = "websecurityscanner.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: str = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, @@ -213,13 +211,15 @@ def create_channel( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ - scopes = scopes or cls.AUTH_SCOPES + + self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) + return grpc_helpers.create_channel( host, credentials=credentials, credentials_file=credentials_file, - scopes=scopes, quota_project_id=quota_project_id, + **self_signed_jwt_kwargs, **kwargs, ) @@ -260,7 +260,7 @@ def create_scan_config( @property def delete_scan_config( self, - ) -> Callable[[web_security_scanner.DeleteScanConfigRequest], empty.Empty]: + ) -> Callable[[web_security_scanner.DeleteScanConfigRequest], empty_pb2.Empty]: r"""Return a callable for the delete scan config method over gRPC. Deletes an existing ScanConfig and its child @@ -280,7 +280,7 @@ def delete_scan_config( self._stubs["delete_scan_config"] = self.grpc_channel.unary_unary( "/google.cloud.websecurityscanner.v1beta.WebSecurityScanner/DeleteScanConfig", request_serializer=web_security_scanner.DeleteScanConfigRequest.serialize, - response_deserializer=empty.Empty.FromString, + response_deserializer=empty_pb2.Empty.FromString, ) return self._stubs["delete_scan_config"] diff --git a/google/cloud/websecurityscanner_v1beta/services/web_security_scanner/transports/grpc_asyncio.py b/google/cloud/websecurityscanner_v1beta/services/web_security_scanner/transports/grpc_asyncio.py index f6055d5..4b976bb 100644 --- a/google/cloud/websecurityscanner_v1beta/services/web_security_scanner/transports/grpc_asyncio.py +++ b/google/cloud/websecurityscanner_v1beta/services/web_security_scanner/transports/grpc_asyncio.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,15 +13,14 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import warnings -from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple +from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union from google.api_core import gapic_v1 # type: ignore from google.api_core import grpc_helpers_async # type: ignore -from google import auth # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore @@ -32,8 +30,7 @@ from google.cloud.websecurityscanner_v1beta.types import scan_config as gcw_scan_config from google.cloud.websecurityscanner_v1beta.types import scan_run from google.cloud.websecurityscanner_v1beta.types import web_security_scanner -from google.protobuf import empty_pb2 as empty # type: ignore - +from google.protobuf import empty_pb2 # type: ignore from .base import WebSecurityScannerTransport, DEFAULT_CLIENT_INFO from .grpc import WebSecurityScannerGrpcTransport @@ -61,7 +58,7 @@ class WebSecurityScannerGrpcAsyncIOTransport(WebSecurityScannerTransport): def create_channel( cls, host: str = "websecurityscanner.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, @@ -88,13 +85,15 @@ def create_channel( Returns: aio.Channel: A gRPC AsyncIO channel object. """ - scopes = scopes or cls.AUTH_SCOPES + + self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) + return grpc_helpers_async.create_channel( host, credentials=credentials, credentials_file=credentials_file, - scopes=scopes, quota_project_id=quota_project_id, + **self_signed_jwt_kwargs, **kwargs, ) @@ -102,7 +101,7 @@ def __init__( self, *, host: str = "websecurityscanner.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, channel: aio.Channel = None, @@ -116,7 +115,8 @@ def __init__( """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -174,7 +174,6 @@ def __init__( # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - else: if api_mtls_endpoint: host = api_mtls_endpoint @@ -266,7 +265,7 @@ def create_scan_config( def delete_scan_config( self, ) -> Callable[ - [web_security_scanner.DeleteScanConfigRequest], Awaitable[empty.Empty] + [web_security_scanner.DeleteScanConfigRequest], Awaitable[empty_pb2.Empty] ]: r"""Return a callable for the delete scan config method over gRPC. @@ -287,7 +286,7 @@ def delete_scan_config( self._stubs["delete_scan_config"] = self.grpc_channel.unary_unary( "/google.cloud.websecurityscanner.v1beta.WebSecurityScanner/DeleteScanConfig", request_serializer=web_security_scanner.DeleteScanConfigRequest.serialize, - response_deserializer=empty.Empty.FromString, + response_deserializer=empty_pb2.Empty.FromString, ) return self._stubs["delete_scan_config"] diff --git a/google/cloud/websecurityscanner_v1beta/types/__init__.py b/google/cloud/websecurityscanner_v1beta/types/__init__.py index d1f7fe5..33fc9ea 100644 --- a/google/cloud/websecurityscanner_v1beta/types/__init__.py +++ b/google/cloud/websecurityscanner_v1beta/types/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from .crawled_url import CrawledUrl from .finding import Finding from .finding_addon import ( diff --git a/google/cloud/websecurityscanner_v1beta/types/crawled_url.py b/google/cloud/websecurityscanner_v1beta/types/crawled_url.py index 0218c40..fd828c0 100644 --- a/google/cloud/websecurityscanner_v1beta/types/crawled_url.py +++ b/google/cloud/websecurityscanner_v1beta/types/crawled_url.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore @@ -40,11 +38,9 @@ class CrawledUrl(proto.Message): visit the URL. """ - http_method = proto.Field(proto.STRING, number=1) - - url = proto.Field(proto.STRING, number=2) - - body = proto.Field(proto.STRING, number=3) + http_method = proto.Field(proto.STRING, number=1,) + url = proto.Field(proto.STRING, number=2,) + body = proto.Field(proto.STRING, number=3,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/websecurityscanner_v1beta/types/finding.py b/google/cloud/websecurityscanner_v1beta/types/finding.py index cc21be8..a5b5455 100644 --- a/google/cloud/websecurityscanner_v1beta/types/finding.py +++ b/google/cloud/websecurityscanner_v1beta/types/finding.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,10 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.websecurityscanner_v1beta.types import finding_addon @@ -90,44 +87,29 @@ class Finding(proto.Message): an XSS, if any. """ - name = proto.Field(proto.STRING, number=1) - - finding_type = proto.Field(proto.STRING, number=2) - - http_method = proto.Field(proto.STRING, number=3) - - fuzzed_url = proto.Field(proto.STRING, number=4) - - body = proto.Field(proto.STRING, number=5) - - description = proto.Field(proto.STRING, number=6) - - reproduction_url = proto.Field(proto.STRING, number=7) - - frame_url = proto.Field(proto.STRING, number=8) - - final_url = proto.Field(proto.STRING, number=9) - - tracking_id = proto.Field(proto.STRING, number=10) - + name = proto.Field(proto.STRING, number=1,) + finding_type = proto.Field(proto.STRING, number=2,) + http_method = proto.Field(proto.STRING, number=3,) + fuzzed_url = proto.Field(proto.STRING, number=4,) + body = proto.Field(proto.STRING, number=5,) + description = proto.Field(proto.STRING, number=6,) + reproduction_url = proto.Field(proto.STRING, number=7,) + frame_url = proto.Field(proto.STRING, number=8,) + final_url = proto.Field(proto.STRING, number=9,) + tracking_id = proto.Field(proto.STRING, number=10,) form = proto.Field(proto.MESSAGE, number=16, message=finding_addon.Form,) - outdated_library = proto.Field( proto.MESSAGE, number=11, message=finding_addon.OutdatedLibrary, ) - violating_resource = proto.Field( proto.MESSAGE, number=12, message=finding_addon.ViolatingResource, ) - vulnerable_headers = proto.Field( proto.MESSAGE, number=15, message=finding_addon.VulnerableHeaders, ) - vulnerable_parameters = proto.Field( proto.MESSAGE, number=13, message=finding_addon.VulnerableParameters, ) - xss = proto.Field(proto.MESSAGE, number=14, message=finding_addon.Xss,) diff --git a/google/cloud/websecurityscanner_v1beta/types/finding_addon.py b/google/cloud/websecurityscanner_v1beta/types/finding_addon.py index 71c6929..cd44522 100644 --- a/google/cloud/websecurityscanner_v1beta/types/finding_addon.py +++ b/google/cloud/websecurityscanner_v1beta/types/finding_addon.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore @@ -33,7 +31,6 @@ 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 @@ -43,14 +40,12 @@ class Form(proto.Message): vulnerability. """ - action_uri = proto.Field(proto.STRING, number=1) - - fields = proto.RepeatedField(proto.STRING, number=2) + action_uri = proto.Field(proto.STRING, number=1,) + fields = proto.RepeatedField(proto.STRING, number=2,) class OutdatedLibrary(proto.Message): r"""Information reported for an outdated library. - Attributes: library_name (str): The name of the outdated library. @@ -61,11 +56,9 @@ class OutdatedLibrary(proto.Message): vulnerabilities in the library. """ - library_name = proto.Field(proto.STRING, number=1) - - version = proto.Field(proto.STRING, number=2) - - learn_more_urls = proto.RepeatedField(proto.STRING, number=3) + library_name = proto.Field(proto.STRING, number=1,) + version = proto.Field(proto.STRING, number=2,) + learn_more_urls = proto.RepeatedField(proto.STRING, number=3,) class ViolatingResource(proto.Message): @@ -79,25 +72,22 @@ class ViolatingResource(proto.Message): URL of this violating resource. """ - content_type = proto.Field(proto.STRING, number=1) - - resource_url = proto.Field(proto.STRING, number=2) + content_type = proto.Field(proto.STRING, number=1,) + resource_url = proto.Field(proto.STRING, number=2,) class VulnerableParameters(proto.Message): r"""Information about vulnerable request parameters. - Attributes: parameter_names (Sequence[str]): The vulnerable parameter names. """ - parameter_names = proto.RepeatedField(proto.STRING, number=1) + parameter_names = proto.RepeatedField(proto.STRING, number=1,) class VulnerableHeaders(proto.Message): r"""Information about vulnerable or missing HTTP Headers. - Attributes: headers (Sequence[google.cloud.websecurityscanner_v1beta.types.VulnerableHeaders.Header]): List of vulnerable headers. @@ -107,7 +97,6 @@ class VulnerableHeaders(proto.Message): class Header(proto.Message): r"""Describes a HTTP Header. - Attributes: name (str): Header name. @@ -115,18 +104,15 @@ class Header(proto.Message): Header value. """ - name = proto.Field(proto.STRING, number=1) - - value = proto.Field(proto.STRING, number=2) + name = proto.Field(proto.STRING, number=1,) + value = proto.Field(proto.STRING, number=2,) headers = proto.RepeatedField(proto.MESSAGE, number=1, message=Header,) - missing_headers = proto.RepeatedField(proto.MESSAGE, number=2, message=Header,) class Xss(proto.Message): r"""Information reported for an XSS. - Attributes: stack_traces (Sequence[str]): Stack traces leading to the point where the @@ -136,9 +122,8 @@ class Xss(proto.Message): breakage. """ - stack_traces = proto.RepeatedField(proto.STRING, number=1) - - error_message = proto.Field(proto.STRING, number=2) + stack_traces = proto.RepeatedField(proto.STRING, number=1,) + error_message = proto.Field(proto.STRING, number=2,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/websecurityscanner_v1beta/types/finding_type_stats.py b/google/cloud/websecurityscanner_v1beta/types/finding_type_stats.py index 13ba498..dc4782e 100644 --- a/google/cloud/websecurityscanner_v1beta/types/finding_type_stats.py +++ b/google/cloud/websecurityscanner_v1beta/types/finding_type_stats.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore @@ -35,9 +33,8 @@ class FindingTypeStats(proto.Message): finding type. """ - finding_type = proto.Field(proto.STRING, number=1) - - finding_count = proto.Field(proto.INT32, number=2) + finding_type = proto.Field(proto.STRING, number=1,) + finding_count = proto.Field(proto.INT32, number=2,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/websecurityscanner_v1beta/types/scan_config.py b/google/cloud/websecurityscanner_v1beta/types/scan_config.py index 99b1512..3b553c7 100644 --- a/google/cloud/websecurityscanner_v1beta/types/scan_config.py +++ b/google/cloud/websecurityscanner_v1beta/types/scan_config.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,12 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.websecurityscanner_v1beta.types import scan_run -from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore __protobuf__ = proto.module( @@ -105,7 +102,6 @@ class ExportToSecurityCommandCenter(proto.Enum): class Authentication(proto.Message): r"""Scan authentication configuration. - Attributes: google_account (google.cloud.websecurityscanner_v1beta.types.ScanConfig.Authentication.GoogleAccount): Authentication using a Google account. @@ -128,9 +124,8 @@ class GoogleAccount(proto.Message): included in audit logs. """ - username = proto.Field(proto.STRING, number=1) - - password = proto.Field(proto.STRING, number=2) + username = proto.Field(proto.STRING, number=1,) + password = proto.Field(proto.STRING, number=2,) class CustomAccount(proto.Message): r"""Describes authentication configuration that uses a custom @@ -149,11 +144,9 @@ class CustomAccount(proto.Message): Required. The login form URL of the website. """ - username = proto.Field(proto.STRING, number=1) - - password = proto.Field(proto.STRING, number=2) - - login_url = proto.Field(proto.STRING, number=3) + username = proto.Field(proto.STRING, number=1,) + password = proto.Field(proto.STRING, number=2,) + login_url = proto.Field(proto.STRING, number=3,) google_account = proto.Field( proto.MESSAGE, @@ -161,7 +154,6 @@ class CustomAccount(proto.Message): oneof="authentication", message="ScanConfig.Authentication.GoogleAccount", ) - custom_account = proto.Field( proto.MESSAGE, number=2, @@ -171,7 +163,6 @@ class CustomAccount(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 @@ -185,35 +176,23 @@ class Schedule(proto.Message): """ schedule_time = proto.Field( - proto.MESSAGE, number=1, message=timestamp.Timestamp, + proto.MESSAGE, number=1, message=timestamp_pb2.Timestamp, ) + interval_duration_days = proto.Field(proto.INT32, number=2,) - interval_duration_days = proto.Field(proto.INT32, number=2) - - name = proto.Field(proto.STRING, number=1) - - display_name = proto.Field(proto.STRING, number=2) - - max_qps = proto.Field(proto.INT32, number=3) - - starting_urls = proto.RepeatedField(proto.STRING, number=4) - + name = proto.Field(proto.STRING, number=1,) + display_name = proto.Field(proto.STRING, number=2,) + max_qps = proto.Field(proto.INT32, number=3,) + starting_urls = proto.RepeatedField(proto.STRING, number=4,) authentication = proto.Field(proto.MESSAGE, number=5, message=Authentication,) - user_agent = proto.Field(proto.ENUM, number=6, enum=UserAgent,) - - blacklist_patterns = proto.RepeatedField(proto.STRING, number=7) - + blacklist_patterns = proto.RepeatedField(proto.STRING, number=7,) schedule = proto.Field(proto.MESSAGE, number=8, message=Schedule,) - target_platforms = proto.RepeatedField(proto.ENUM, number=9, enum=TargetPlatform,) - export_to_security_command_center = proto.Field( proto.ENUM, number=10, enum=ExportToSecurityCommandCenter, ) - latest_run = proto.Field(proto.MESSAGE, number=11, message=scan_run.ScanRun,) - risk_level = proto.Field(proto.ENUM, number=12, enum=RiskLevel,) diff --git a/google/cloud/websecurityscanner_v1beta/types/scan_config_error.py b/google/cloud/websecurityscanner_v1beta/types/scan_config_error.py index c977169..ac92d67 100644 --- a/google/cloud/websecurityscanner_v1beta/types/scan_config_error.py +++ b/google/cloud/websecurityscanner_v1beta/types/scan_config_error.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore @@ -90,8 +88,7 @@ class Code(proto.Enum): UNSUPPORTED_URL_SCHEME = 42 code = proto.Field(proto.ENUM, number=1, enum=Code,) - - field_name = proto.Field(proto.STRING, number=2) + field_name = proto.Field(proto.STRING, number=2,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/websecurityscanner_v1beta/types/scan_run.py b/google/cloud/websecurityscanner_v1beta/types/scan_run.py index 99f5faa..1de3440 100644 --- a/google/cloud/websecurityscanner_v1beta/types/scan_run.py +++ b/google/cloud/websecurityscanner_v1beta/types/scan_run.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,13 +13,11 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.websecurityscanner_v1beta.types import scan_run_error_trace from google.cloud.websecurityscanner_v1beta.types import scan_run_warning_trace -from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore __protobuf__ = proto.module( @@ -94,28 +91,18 @@ class ResultState(proto.Enum): ERROR = 2 KILLED = 3 - name = proto.Field(proto.STRING, number=1) - + name = proto.Field(proto.STRING, number=1,) execution_state = proto.Field(proto.ENUM, number=2, enum=ExecutionState,) - result_state = proto.Field(proto.ENUM, number=3, enum=ResultState,) - - start_time = proto.Field(proto.MESSAGE, number=4, message=timestamp.Timestamp,) - - end_time = proto.Field(proto.MESSAGE, number=5, message=timestamp.Timestamp,) - - urls_crawled_count = proto.Field(proto.INT64, number=6) - - urls_tested_count = proto.Field(proto.INT64, number=7) - - has_vulnerabilities = proto.Field(proto.BOOL, number=8) - - progress_percent = proto.Field(proto.INT32, number=9) - + start_time = proto.Field(proto.MESSAGE, number=4, message=timestamp_pb2.Timestamp,) + end_time = proto.Field(proto.MESSAGE, number=5, message=timestamp_pb2.Timestamp,) + urls_crawled_count = proto.Field(proto.INT64, number=6,) + urls_tested_count = proto.Field(proto.INT64, number=7,) + has_vulnerabilities = proto.Field(proto.BOOL, number=8,) + progress_percent = proto.Field(proto.INT32, number=9,) error_trace = proto.Field( proto.MESSAGE, number=10, message=scan_run_error_trace.ScanRunErrorTrace, ) - warning_traces = proto.RepeatedField( proto.MESSAGE, number=11, message=scan_run_warning_trace.ScanRunWarningTrace, ) diff --git a/google/cloud/websecurityscanner_v1beta/types/scan_run_error_trace.py b/google/cloud/websecurityscanner_v1beta/types/scan_run_error_trace.py index 326f3e3..946172e 100644 --- a/google/cloud/websecurityscanner_v1beta/types/scan_run_error_trace.py +++ b/google/cloud/websecurityscanner_v1beta/types/scan_run_error_trace.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,10 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.websecurityscanner_v1beta.types import ( scan_config_error as gcw_scan_config_error, ) @@ -60,12 +57,10 @@ class Code(proto.Enum): TOO_MANY_HTTP_ERRORS = 6 code = proto.Field(proto.ENUM, number=1, enum=Code,) - scan_config_error = proto.Field( proto.MESSAGE, number=2, message=gcw_scan_config_error.ScanConfigError, ) - - most_common_http_error_code = proto.Field(proto.INT32, number=3) + most_common_http_error_code = proto.Field(proto.INT32, number=3,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/websecurityscanner_v1beta/types/scan_run_warning_trace.py b/google/cloud/websecurityscanner_v1beta/types/scan_run_warning_trace.py index 418bbb3..f5477f7 100644 --- a/google/cloud/websecurityscanner_v1beta/types/scan_run_warning_trace.py +++ b/google/cloud/websecurityscanner_v1beta/types/scan_run_warning_trace.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore diff --git a/google/cloud/websecurityscanner_v1beta/types/web_security_scanner.py b/google/cloud/websecurityscanner_v1beta/types/web_security_scanner.py index f2aa99e..5b50ec3 100644 --- a/google/cloud/websecurityscanner_v1beta/types/web_security_scanner.py +++ b/google/cloud/websecurityscanner_v1beta/types/web_security_scanner.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,10 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.websecurityscanner_v1beta.types import crawled_url from google.cloud.websecurityscanner_v1beta.types import finding from google.cloud.websecurityscanner_v1beta.types import ( @@ -25,7 +22,7 @@ ) from google.cloud.websecurityscanner_v1beta.types import scan_config as gcw_scan_config from google.cloud.websecurityscanner_v1beta.types import scan_run -from google.protobuf import field_mask_pb2 as field_mask # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore __protobuf__ = proto.module( @@ -55,7 +52,6 @@ class CreateScanConfigRequest(proto.Message): r"""Request for the ``CreateScanConfig`` method. - Attributes: parent (str): Required. The parent resource name where the @@ -66,8 +62,7 @@ class CreateScanConfigRequest(proto.Message): Required. The ScanConfig to be created. """ - parent = proto.Field(proto.STRING, number=1) - + parent = proto.Field(proto.STRING, number=1,) scan_config = proto.Field( proto.MESSAGE, number=2, message=gcw_scan_config.ScanConfig, ) @@ -75,7 +70,6 @@ class CreateScanConfigRequest(proto.Message): class DeleteScanConfigRequest(proto.Message): r"""Request for the ``DeleteScanConfig`` method. - Attributes: name (str): Required. The resource name of the ScanConfig @@ -83,12 +77,11 @@ class DeleteScanConfigRequest(proto.Message): 'projects/{projectId}/scanConfigs/{scanConfigId}'. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class GetScanConfigRequest(proto.Message): r"""Request for the ``GetScanConfig`` method. - Attributes: name (str): Required. The resource name of the ScanConfig @@ -96,12 +89,11 @@ class GetScanConfigRequest(proto.Message): 'projects/{projectId}/scanConfigs/{scanConfigId}'. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class ListScanConfigsRequest(proto.Message): r"""Request for the ``ListScanConfigs`` method. - Attributes: parent (str): Required. The parent resource name, which @@ -119,16 +111,13 @@ class ListScanConfigsRequest(proto.Message): reasonable value. """ - parent = proto.Field(proto.STRING, number=1) - - page_token = proto.Field(proto.STRING, number=2) - - page_size = proto.Field(proto.INT32, number=3) + parent = proto.Field(proto.STRING, number=1,) + page_token = proto.Field(proto.STRING, number=2,) + page_size = proto.Field(proto.INT32, number=3,) class UpdateScanConfigRequest(proto.Message): r"""Request for the ``UpdateScanConfigRequest`` method. - Attributes: scan_config (google.cloud.websecurityscanner_v1beta.types.ScanConfig): Required. The ScanConfig to be updated. The @@ -144,13 +133,13 @@ class UpdateScanConfigRequest(proto.Message): scan_config = proto.Field( proto.MESSAGE, number=2, message=gcw_scan_config.ScanConfig, ) - - update_mask = proto.Field(proto.MESSAGE, number=3, message=field_mask.FieldMask,) + update_mask = proto.Field( + proto.MESSAGE, number=3, message=field_mask_pb2.FieldMask, + ) class ListScanConfigsResponse(proto.Message): r"""Response for the ``ListScanConfigs`` method. - Attributes: scan_configs (Sequence[google.cloud.websecurityscanner_v1beta.types.ScanConfig]): The list of ScanConfigs returned. @@ -167,13 +156,11 @@ def raw_page(self): scan_configs = proto.RepeatedField( proto.MESSAGE, number=1, message=gcw_scan_config.ScanConfig, ) - - next_page_token = proto.Field(proto.STRING, number=2) + next_page_token = proto.Field(proto.STRING, number=2,) class StartScanRunRequest(proto.Message): r"""Request for the ``StartScanRun`` method. - Attributes: name (str): Required. The resource name of the ScanConfig @@ -181,12 +168,11 @@ class StartScanRunRequest(proto.Message): 'projects/{projectId}/scanConfigs/{scanConfigId}'. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class GetScanRunRequest(proto.Message): r"""Request for the ``GetScanRun`` method. - Attributes: name (str): Required. The resource name of the ScanRun to @@ -194,12 +180,11 @@ class GetScanRunRequest(proto.Message): 'projects/{projectId}/scanConfigs/{scanConfigId}/scanRuns/{scanRunId}'. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class ListScanRunsRequest(proto.Message): r"""Request for the ``ListScanRuns`` method. - Attributes: parent (str): Required. The parent resource name, which @@ -217,16 +202,13 @@ class ListScanRunsRequest(proto.Message): reasonable value. """ - parent = proto.Field(proto.STRING, number=1) - - page_token = proto.Field(proto.STRING, number=2) - - page_size = proto.Field(proto.INT32, number=3) + parent = proto.Field(proto.STRING, number=1,) + page_token = proto.Field(proto.STRING, number=2,) + page_size = proto.Field(proto.INT32, number=3,) class ListScanRunsResponse(proto.Message): r"""Response for the ``ListScanRuns`` method. - Attributes: scan_runs (Sequence[google.cloud.websecurityscanner_v1beta.types.ScanRun]): The list of ScanRuns returned. @@ -241,13 +223,11 @@ def raw_page(self): return self scan_runs = proto.RepeatedField(proto.MESSAGE, number=1, message=scan_run.ScanRun,) - - next_page_token = proto.Field(proto.STRING, number=2) + next_page_token = proto.Field(proto.STRING, number=2,) class StopScanRunRequest(proto.Message): r"""Request for the ``StopScanRun`` method. - Attributes: name (str): Required. The resource name of the ScanRun to @@ -255,12 +235,11 @@ class StopScanRunRequest(proto.Message): 'projects/{projectId}/scanConfigs/{scanConfigId}/scanRuns/{scanRunId}'. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class ListCrawledUrlsRequest(proto.Message): r"""Request for the ``ListCrawledUrls`` method. - Attributes: parent (str): Required. The parent resource name, which @@ -278,16 +257,13 @@ class ListCrawledUrlsRequest(proto.Message): reasonable value. """ - parent = proto.Field(proto.STRING, number=1) - - page_token = proto.Field(proto.STRING, number=2) - - page_size = proto.Field(proto.INT32, number=3) + parent = proto.Field(proto.STRING, number=1,) + page_token = proto.Field(proto.STRING, number=2,) + page_size = proto.Field(proto.INT32, number=3,) class ListCrawledUrlsResponse(proto.Message): r"""Response for the ``ListCrawledUrls`` method. - Attributes: crawled_urls (Sequence[google.cloud.websecurityscanner_v1beta.types.CrawledUrl]): The list of CrawledUrls returned. @@ -304,13 +280,11 @@ def raw_page(self): crawled_urls = proto.RepeatedField( proto.MESSAGE, number=1, message=crawled_url.CrawledUrl, ) - - next_page_token = proto.Field(proto.STRING, number=2) + next_page_token = proto.Field(proto.STRING, number=2,) class GetFindingRequest(proto.Message): r"""Request for the ``GetFinding`` method. - Attributes: name (str): Required. The resource name of the Finding to @@ -318,12 +292,11 @@ class GetFindingRequest(proto.Message): 'projects/{projectId}/scanConfigs/{scanConfigId}/scanRuns/{scanRunId}/findings/{findingId}'. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class ListFindingsRequest(proto.Message): r"""Request for the ``ListFindings`` method. - Attributes: parent (str): Required. The parent resource name, which @@ -345,18 +318,14 @@ class ListFindingsRequest(proto.Message): reasonable value. """ - parent = proto.Field(proto.STRING, number=1) - - filter = proto.Field(proto.STRING, number=2) - - page_token = proto.Field(proto.STRING, number=3) - - page_size = proto.Field(proto.INT32, number=4) + parent = proto.Field(proto.STRING, number=1,) + filter = proto.Field(proto.STRING, number=2,) + page_token = proto.Field(proto.STRING, number=3,) + page_size = proto.Field(proto.INT32, number=4,) class ListFindingsResponse(proto.Message): r"""Response for the ``ListFindings`` method. - Attributes: findings (Sequence[google.cloud.websecurityscanner_v1beta.types.Finding]): The list of Findings returned. @@ -371,13 +340,11 @@ def raw_page(self): return self findings = proto.RepeatedField(proto.MESSAGE, number=1, message=finding.Finding,) - - next_page_token = proto.Field(proto.STRING, number=2) + next_page_token = proto.Field(proto.STRING, number=2,) class ListFindingTypeStatsRequest(proto.Message): r"""Request for the ``ListFindingTypeStats`` method. - Attributes: parent (str): Required. The parent resource name, which @@ -385,12 +352,11 @@ class ListFindingTypeStatsRequest(proto.Message): 'projects/{projectId}/scanConfigs/{scanConfigId}/scanRuns/{scanRunId}'. """ - parent = proto.Field(proto.STRING, number=1) + parent = proto.Field(proto.STRING, number=1,) class ListFindingTypeStatsResponse(proto.Message): r"""Response for the ``ListFindingTypeStats`` method. - Attributes: finding_type_stats (Sequence[google.cloud.websecurityscanner_v1beta.types.FindingTypeStats]): The list of FindingTypeStats returned. diff --git a/scripts/fixup_websecurityscanner_v1_keywords.py b/scripts/fixup_websecurityscanner_v1_keywords.py index 26129c3..cdd5da0 100644 --- a/scripts/fixup_websecurityscanner_v1_keywords.py +++ b/scripts/fixup_websecurityscanner_v1_keywords.py @@ -1,6 +1,5 @@ #! /usr/bin/env python3 # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,7 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import argparse import os import libcst as cst @@ -41,20 +39,19 @@ def partition( class websecurityscannerCallTransformer(cst.CSTTransformer): CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { - 'create_scan_config': ('parent', 'scan_config', ), - 'delete_scan_config': ('name', ), - 'get_finding': ('name', ), - 'get_scan_config': ('name', ), - 'get_scan_run': ('name', ), - 'list_crawled_urls': ('parent', 'page_token', 'page_size', ), - 'list_findings': ('parent', 'filter', 'page_token', 'page_size', ), - 'list_finding_type_stats': ('parent', ), - 'list_scan_configs': ('parent', 'page_token', 'page_size', ), - 'list_scan_runs': ('parent', 'page_token', 'page_size', ), - 'start_scan_run': ('name', ), - 'stop_scan_run': ('name', ), - 'update_scan_config': ('scan_config', 'update_mask', ), - + 'create_scan_config': ('parent', 'scan_config', ), + 'delete_scan_config': ('name', ), + 'get_finding': ('name', ), + 'get_scan_config': ('name', ), + 'get_scan_run': ('name', ), + 'list_crawled_urls': ('parent', 'page_token', 'page_size', ), + 'list_findings': ('parent', 'filter', 'page_token', 'page_size', ), + 'list_finding_type_stats': ('parent', ), + 'list_scan_configs': ('parent', 'page_token', 'page_size', ), + 'list_scan_runs': ('parent', 'page_token', 'page_size', ), + 'start_scan_run': ('name', ), + 'stop_scan_run': ('name', ), + 'update_scan_config': ('scan_config', 'update_mask', ), } def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: @@ -85,7 +82,7 @@ def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: value=cst.Dict([ cst.DictElement( cst.SimpleString("'{}'".format(name)), - cst.Element(value=arg.value) +cst.Element(value=arg.value) ) # Note: the args + kwargs looks silly, but keep in mind that # the control parameters had to be stripped out, and that diff --git a/scripts/fixup_websecurityscanner_v1alpha_keywords.py b/scripts/fixup_websecurityscanner_v1alpha_keywords.py index 26129c3..cdd5da0 100644 --- a/scripts/fixup_websecurityscanner_v1alpha_keywords.py +++ b/scripts/fixup_websecurityscanner_v1alpha_keywords.py @@ -1,6 +1,5 @@ #! /usr/bin/env python3 # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,7 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import argparse import os import libcst as cst @@ -41,20 +39,19 @@ def partition( class websecurityscannerCallTransformer(cst.CSTTransformer): CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { - 'create_scan_config': ('parent', 'scan_config', ), - 'delete_scan_config': ('name', ), - 'get_finding': ('name', ), - 'get_scan_config': ('name', ), - 'get_scan_run': ('name', ), - 'list_crawled_urls': ('parent', 'page_token', 'page_size', ), - 'list_findings': ('parent', 'filter', 'page_token', 'page_size', ), - 'list_finding_type_stats': ('parent', ), - 'list_scan_configs': ('parent', 'page_token', 'page_size', ), - 'list_scan_runs': ('parent', 'page_token', 'page_size', ), - 'start_scan_run': ('name', ), - 'stop_scan_run': ('name', ), - 'update_scan_config': ('scan_config', 'update_mask', ), - + 'create_scan_config': ('parent', 'scan_config', ), + 'delete_scan_config': ('name', ), + 'get_finding': ('name', ), + 'get_scan_config': ('name', ), + 'get_scan_run': ('name', ), + 'list_crawled_urls': ('parent', 'page_token', 'page_size', ), + 'list_findings': ('parent', 'filter', 'page_token', 'page_size', ), + 'list_finding_type_stats': ('parent', ), + 'list_scan_configs': ('parent', 'page_token', 'page_size', ), + 'list_scan_runs': ('parent', 'page_token', 'page_size', ), + 'start_scan_run': ('name', ), + 'stop_scan_run': ('name', ), + 'update_scan_config': ('scan_config', 'update_mask', ), } def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: @@ -85,7 +82,7 @@ def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: value=cst.Dict([ cst.DictElement( cst.SimpleString("'{}'".format(name)), - cst.Element(value=arg.value) +cst.Element(value=arg.value) ) # Note: the args + kwargs looks silly, but keep in mind that # the control parameters had to be stripped out, and that diff --git a/scripts/fixup_websecurityscanner_v1beta_keywords.py b/scripts/fixup_websecurityscanner_v1beta_keywords.py index 26129c3..cdd5da0 100644 --- a/scripts/fixup_websecurityscanner_v1beta_keywords.py +++ b/scripts/fixup_websecurityscanner_v1beta_keywords.py @@ -1,6 +1,5 @@ #! /usr/bin/env python3 # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,7 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import argparse import os import libcst as cst @@ -41,20 +39,19 @@ def partition( class websecurityscannerCallTransformer(cst.CSTTransformer): CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { - 'create_scan_config': ('parent', 'scan_config', ), - 'delete_scan_config': ('name', ), - 'get_finding': ('name', ), - 'get_scan_config': ('name', ), - 'get_scan_run': ('name', ), - 'list_crawled_urls': ('parent', 'page_token', 'page_size', ), - 'list_findings': ('parent', 'filter', 'page_token', 'page_size', ), - 'list_finding_type_stats': ('parent', ), - 'list_scan_configs': ('parent', 'page_token', 'page_size', ), - 'list_scan_runs': ('parent', 'page_token', 'page_size', ), - 'start_scan_run': ('name', ), - 'stop_scan_run': ('name', ), - 'update_scan_config': ('scan_config', 'update_mask', ), - + 'create_scan_config': ('parent', 'scan_config', ), + 'delete_scan_config': ('name', ), + 'get_finding': ('name', ), + 'get_scan_config': ('name', ), + 'get_scan_run': ('name', ), + 'list_crawled_urls': ('parent', 'page_token', 'page_size', ), + 'list_findings': ('parent', 'filter', 'page_token', 'page_size', ), + 'list_finding_type_stats': ('parent', ), + 'list_scan_configs': ('parent', 'page_token', 'page_size', ), + 'list_scan_runs': ('parent', 'page_token', 'page_size', ), + 'start_scan_run': ('name', ), + 'stop_scan_run': ('name', ), + 'update_scan_config': ('scan_config', 'update_mask', ), } def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: @@ -85,7 +82,7 @@ def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: value=cst.Dict([ cst.DictElement( cst.SimpleString("'{}'".format(name)), - cst.Element(value=arg.value) +cst.Element(value=arg.value) ) # Note: the args + kwargs looks silly, but keep in mind that # the control parameters had to be stripped out, and that diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..4de6597 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py new file mode 100644 index 0000000..4de6597 --- /dev/null +++ b/tests/unit/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/tests/unit/gapic/__init__.py b/tests/unit/gapic/__init__.py new file mode 100644 index 0000000..4de6597 --- /dev/null +++ b/tests/unit/gapic/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/tests/unit/gapic/websecurityscanner_v1/__init__.py b/tests/unit/gapic/websecurityscanner_v1/__init__.py index 42ffdf2..4de6597 100644 --- a/tests/unit/gapic/websecurityscanner_v1/__init__.py +++ b/tests/unit/gapic/websecurityscanner_v1/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/unit/gapic/websecurityscanner_v1/test_web_security_scanner.py b/tests/unit/gapic/websecurityscanner_v1/test_web_security_scanner.py index 7d5d1a7..c0912c5 100644 --- a/tests/unit/gapic/websecurityscanner_v1/test_web_security_scanner.py +++ b/tests/unit/gapic/websecurityscanner_v1/test_web_security_scanner.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import os import mock +import packaging.version import grpc from grpc.experimental import aio @@ -24,13 +23,13 @@ import pytest from proto.marshal.rules.dates import DurationRule, TimestampRule -from google import auth + from google.api_core import client_options -from google.api_core import exceptions +from google.api_core import exceptions as core_exceptions from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async -from google.auth import credentials +from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.websecurityscanner_v1.services.web_security_scanner import ( WebSecurityScannerAsyncClient, @@ -40,6 +39,12 @@ ) from google.cloud.websecurityscanner_v1.services.web_security_scanner import pagers from google.cloud.websecurityscanner_v1.services.web_security_scanner import transports +from google.cloud.websecurityscanner_v1.services.web_security_scanner.transports.base import ( + _API_CORE_VERSION, +) +from google.cloud.websecurityscanner_v1.services.web_security_scanner.transports.base import ( + _GOOGLE_AUTH_VERSION, +) from google.cloud.websecurityscanner_v1.types import crawled_url from google.cloud.websecurityscanner_v1.types import finding from google.cloud.websecurityscanner_v1.types import finding_addon @@ -50,8 +55,32 @@ from google.cloud.websecurityscanner_v1.types import scan_run_warning_trace from google.cloud.websecurityscanner_v1.types import web_security_scanner from google.oauth2 import service_account -from google.protobuf import field_mask_pb2 as field_mask # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +import google.auth + + +# TODO(busunkim): Once google-api-core >= 1.26.0 is required: +# - Delete all the api-core and auth "less than" test cases +# - Delete these pytest markers (Make the "greater than or equal to" tests the default). +requires_google_auth_lt_1_25_0 = pytest.mark.skipif( + packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), + reason="This test requires google-auth < 1.25.0", +) +requires_google_auth_gte_1_25_0 = pytest.mark.skipif( + packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), + reason="This test requires google-auth >= 1.25.0", +) + +requires_api_core_lt_1_26_0 = pytest.mark.skipif( + packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), + reason="This test requires google-api-core < 1.26.0", +) + +requires_api_core_gte_1_26_0 = pytest.mark.skipif( + packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), + reason="This test requires google-api-core >= 1.26.0", +) def client_cert_source_callback(): @@ -103,7 +132,7 @@ def test__get_default_mtls_endpoint(): "client_class", [WebSecurityScannerClient, WebSecurityScannerAsyncClient,] ) def test_web_security_scanner_client_from_service_account_info(client_class): - creds = credentials.AnonymousCredentials() + creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -120,7 +149,7 @@ def test_web_security_scanner_client_from_service_account_info(client_class): "client_class", [WebSecurityScannerClient, WebSecurityScannerAsyncClient,] ) def test_web_security_scanner_client_from_service_account_file(client_class): - creds = credentials.AnonymousCredentials() + creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -173,7 +202,7 @@ def test_web_security_scanner_client_client_options( ): # Check that if channel is provided we won't create a new one. with mock.patch.object(WebSecurityScannerClient, "get_transport_class") as gtc: - transport = transport_class(credentials=credentials.AnonymousCredentials()) + transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) client = client_class(transport=transport) gtc.assert_not_called() @@ -471,7 +500,7 @@ def test_create_scan_config( transport: str = "grpc", request_type=web_security_scanner.CreateScanConfigRequest ): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -495,40 +524,27 @@ def test_create_scan_config( managed_scan=True, static_ip_scan=True, ) - response = client.create_scan_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.CreateScanConfigRequest() # Establish that the response is the type that we expect. - assert isinstance(response, scan_config.ScanConfig) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.max_qps == 761 - assert response.starting_urls == ["starting_urls_value"] - assert response.user_agent == scan_config.ScanConfig.UserAgent.CHROME_LINUX - assert response.blacklist_patterns == ["blacklist_patterns_value"] - assert ( response.export_to_security_command_center == scan_config.ScanConfig.ExportToSecurityCommandCenter.ENABLED ) - assert response.risk_level == scan_config.ScanConfig.RiskLevel.NORMAL - assert response.managed_scan is True - assert response.static_ip_scan is True @@ -540,7 +556,7 @@ def test_create_scan_config_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -550,7 +566,6 @@ def test_create_scan_config_empty_call(): client.create_scan_config() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.CreateScanConfigRequest() @@ -560,7 +575,7 @@ async def test_create_scan_config_async( request_type=web_security_scanner.CreateScanConfigRequest, ): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -586,39 +601,27 @@ async def test_create_scan_config_async( static_ip_scan=True, ) ) - response = await client.create_scan_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.CreateScanConfigRequest() # Establish that the response is the type that we expect. assert isinstance(response, scan_config.ScanConfig) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.max_qps == 761 - assert response.starting_urls == ["starting_urls_value"] - assert response.user_agent == scan_config.ScanConfig.UserAgent.CHROME_LINUX - assert response.blacklist_patterns == ["blacklist_patterns_value"] - assert ( response.export_to_security_command_center == scan_config.ScanConfig.ExportToSecurityCommandCenter.ENABLED ) - assert response.risk_level == scan_config.ScanConfig.RiskLevel.NORMAL - assert response.managed_scan is True - assert response.static_ip_scan is True @@ -628,11 +631,14 @@ async def test_create_scan_config_async_from_dict(): def test_create_scan_config_field_headers(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.CreateScanConfigRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -640,7 +646,6 @@ def test_create_scan_config_field_headers(): type(client.transport.create_scan_config), "__call__" ) as call: call.return_value = scan_config.ScanConfig() - client.create_scan_config(request) # Establish that the underlying gRPC stub method was called. @@ -656,12 +661,13 @@ def test_create_scan_config_field_headers(): @pytest.mark.asyncio async def test_create_scan_config_field_headers_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.CreateScanConfigRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -671,7 +677,6 @@ async def test_create_scan_config_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( scan_config.ScanConfig() ) - await client.create_scan_config(request) # Establish that the underlying gRPC stub method was called. @@ -688,7 +693,7 @@ def test_delete_scan_config( transport: str = "grpc", request_type=web_security_scanner.DeleteScanConfigRequest ): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -701,13 +706,11 @@ def test_delete_scan_config( ) as call: # Designate an appropriate return value for the call. call.return_value = None - response = client.delete_scan_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.DeleteScanConfigRequest() # Establish that the response is the type that we expect. @@ -722,7 +725,7 @@ def test_delete_scan_config_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -732,7 +735,6 @@ def test_delete_scan_config_empty_call(): client.delete_scan_config() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.DeleteScanConfigRequest() @@ -742,7 +744,7 @@ async def test_delete_scan_config_async( request_type=web_security_scanner.DeleteScanConfigRequest, ): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -755,13 +757,11 @@ async def test_delete_scan_config_async( ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - response = await client.delete_scan_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.DeleteScanConfigRequest() # Establish that the response is the type that we expect. @@ -774,11 +774,14 @@ async def test_delete_scan_config_async_from_dict(): def test_delete_scan_config_field_headers(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.DeleteScanConfigRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -786,7 +789,6 @@ def test_delete_scan_config_field_headers(): type(client.transport.delete_scan_config), "__call__" ) as call: call.return_value = None - client.delete_scan_config(request) # Establish that the underlying gRPC stub method was called. @@ -802,12 +804,13 @@ def test_delete_scan_config_field_headers(): @pytest.mark.asyncio async def test_delete_scan_config_field_headers_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.DeleteScanConfigRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -815,7 +818,6 @@ async def test_delete_scan_config_field_headers_async(): type(client.transport.delete_scan_config), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - await client.delete_scan_config(request) # Establish that the underlying gRPC stub method was called. @@ -832,7 +834,7 @@ def test_get_scan_config( transport: str = "grpc", request_type=web_security_scanner.GetScanConfigRequest ): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -854,40 +856,27 @@ def test_get_scan_config( managed_scan=True, static_ip_scan=True, ) - response = client.get_scan_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.GetScanConfigRequest() # Establish that the response is the type that we expect. - assert isinstance(response, scan_config.ScanConfig) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.max_qps == 761 - assert response.starting_urls == ["starting_urls_value"] - assert response.user_agent == scan_config.ScanConfig.UserAgent.CHROME_LINUX - assert response.blacklist_patterns == ["blacklist_patterns_value"] - assert ( response.export_to_security_command_center == scan_config.ScanConfig.ExportToSecurityCommandCenter.ENABLED ) - assert response.risk_level == scan_config.ScanConfig.RiskLevel.NORMAL - assert response.managed_scan is True - assert response.static_ip_scan is True @@ -899,7 +888,7 @@ def test_get_scan_config_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -907,7 +896,6 @@ def test_get_scan_config_empty_call(): client.get_scan_config() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.GetScanConfigRequest() @@ -917,7 +905,7 @@ async def test_get_scan_config_async( request_type=web_security_scanner.GetScanConfigRequest, ): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -941,39 +929,27 @@ async def test_get_scan_config_async( static_ip_scan=True, ) ) - response = await client.get_scan_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.GetScanConfigRequest() # Establish that the response is the type that we expect. assert isinstance(response, scan_config.ScanConfig) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.max_qps == 761 - assert response.starting_urls == ["starting_urls_value"] - assert response.user_agent == scan_config.ScanConfig.UserAgent.CHROME_LINUX - assert response.blacklist_patterns == ["blacklist_patterns_value"] - assert ( response.export_to_security_command_center == scan_config.ScanConfig.ExportToSecurityCommandCenter.ENABLED ) - assert response.risk_level == scan_config.ScanConfig.RiskLevel.NORMAL - assert response.managed_scan is True - assert response.static_ip_scan is True @@ -983,17 +959,19 @@ async def test_get_scan_config_async_from_dict(): def test_get_scan_config_field_headers(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.GetScanConfigRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_scan_config), "__call__") as call: call.return_value = scan_config.ScanConfig() - client.get_scan_config(request) # Establish that the underlying gRPC stub method was called. @@ -1009,12 +987,13 @@ def test_get_scan_config_field_headers(): @pytest.mark.asyncio async def test_get_scan_config_field_headers_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.GetScanConfigRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1022,7 +1001,6 @@ async def test_get_scan_config_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( scan_config.ScanConfig() ) - await client.get_scan_config(request) # Establish that the underlying gRPC stub method was called. @@ -1039,7 +1017,7 @@ def test_list_scan_configs( transport: str = "grpc", request_type=web_security_scanner.ListScanConfigsRequest ): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1054,19 +1032,15 @@ def test_list_scan_configs( call.return_value = web_security_scanner.ListScanConfigsResponse( next_page_token="next_page_token_value", ) - response = client.list_scan_configs(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.ListScanConfigsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListScanConfigsPager) - assert response.next_page_token == "next_page_token_value" @@ -1078,7 +1052,7 @@ def test_list_scan_configs_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1088,7 +1062,6 @@ def test_list_scan_configs_empty_call(): client.list_scan_configs() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.ListScanConfigsRequest() @@ -1098,7 +1071,7 @@ async def test_list_scan_configs_async( request_type=web_security_scanner.ListScanConfigsRequest, ): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1115,18 +1088,15 @@ async def test_list_scan_configs_async( next_page_token="next_page_token_value", ) ) - response = await client.list_scan_configs(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.ListScanConfigsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListScanConfigsAsyncPager) - assert response.next_page_token == "next_page_token_value" @@ -1136,11 +1106,14 @@ async def test_list_scan_configs_async_from_dict(): def test_list_scan_configs_field_headers(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.ListScanConfigsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1148,7 +1121,6 @@ def test_list_scan_configs_field_headers(): type(client.transport.list_scan_configs), "__call__" ) as call: call.return_value = web_security_scanner.ListScanConfigsResponse() - client.list_scan_configs(request) # Establish that the underlying gRPC stub method was called. @@ -1164,12 +1136,13 @@ def test_list_scan_configs_field_headers(): @pytest.mark.asyncio async def test_list_scan_configs_field_headers_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.ListScanConfigsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1179,7 +1152,6 @@ async def test_list_scan_configs_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( web_security_scanner.ListScanConfigsResponse() ) - await client.list_scan_configs(request) # Establish that the underlying gRPC stub method was called. @@ -1193,7 +1165,7 @@ async def test_list_scan_configs_field_headers_async(): def test_list_scan_configs_pager(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials,) + client = WebSecurityScannerClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1235,7 +1207,7 @@ def test_list_scan_configs_pager(): def test_list_scan_configs_pages(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials,) + client = WebSecurityScannerClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1270,7 +1242,7 @@ def test_list_scan_configs_pages(): @pytest.mark.asyncio async def test_list_scan_configs_async_pager(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1313,7 +1285,7 @@ async def test_list_scan_configs_async_pager(): @pytest.mark.asyncio async def test_list_scan_configs_async_pages(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1354,7 +1326,7 @@ def test_update_scan_config( transport: str = "grpc", request_type=web_security_scanner.UpdateScanConfigRequest ): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1378,40 +1350,27 @@ def test_update_scan_config( managed_scan=True, static_ip_scan=True, ) - response = client.update_scan_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.UpdateScanConfigRequest() # Establish that the response is the type that we expect. - assert isinstance(response, scan_config.ScanConfig) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.max_qps == 761 - assert response.starting_urls == ["starting_urls_value"] - assert response.user_agent == scan_config.ScanConfig.UserAgent.CHROME_LINUX - assert response.blacklist_patterns == ["blacklist_patterns_value"] - assert ( response.export_to_security_command_center == scan_config.ScanConfig.ExportToSecurityCommandCenter.ENABLED ) - assert response.risk_level == scan_config.ScanConfig.RiskLevel.NORMAL - assert response.managed_scan is True - assert response.static_ip_scan is True @@ -1423,7 +1382,7 @@ def test_update_scan_config_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1433,7 +1392,6 @@ def test_update_scan_config_empty_call(): client.update_scan_config() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.UpdateScanConfigRequest() @@ -1443,7 +1401,7 @@ async def test_update_scan_config_async( request_type=web_security_scanner.UpdateScanConfigRequest, ): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1469,39 +1427,27 @@ async def test_update_scan_config_async( static_ip_scan=True, ) ) - response = await client.update_scan_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.UpdateScanConfigRequest() # Establish that the response is the type that we expect. assert isinstance(response, scan_config.ScanConfig) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.max_qps == 761 - assert response.starting_urls == ["starting_urls_value"] - assert response.user_agent == scan_config.ScanConfig.UserAgent.CHROME_LINUX - assert response.blacklist_patterns == ["blacklist_patterns_value"] - assert ( response.export_to_security_command_center == scan_config.ScanConfig.ExportToSecurityCommandCenter.ENABLED ) - assert response.risk_level == scan_config.ScanConfig.RiskLevel.NORMAL - assert response.managed_scan is True - assert response.static_ip_scan is True @@ -1511,11 +1457,14 @@ async def test_update_scan_config_async_from_dict(): def test_update_scan_config_field_headers(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.UpdateScanConfigRequest() + request.scan_config.name = "scan_config.name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1523,7 +1472,6 @@ def test_update_scan_config_field_headers(): type(client.transport.update_scan_config), "__call__" ) as call: call.return_value = scan_config.ScanConfig() - client.update_scan_config(request) # Establish that the underlying gRPC stub method was called. @@ -1541,12 +1489,13 @@ def test_update_scan_config_field_headers(): @pytest.mark.asyncio async def test_update_scan_config_field_headers_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.UpdateScanConfigRequest() + request.scan_config.name = "scan_config.name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1556,7 +1505,6 @@ async def test_update_scan_config_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( scan_config.ScanConfig() ) - await client.update_scan_config(request) # Establish that the underlying gRPC stub method was called. @@ -1575,7 +1523,7 @@ def test_start_scan_run( transport: str = "grpc", request_type=web_security_scanner.StartScanRunRequest ): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1594,31 +1542,21 @@ def test_start_scan_run( has_vulnerabilities=True, progress_percent=1733, ) - response = client.start_scan_run(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.StartScanRunRequest() # Establish that the response is the type that we expect. - assert isinstance(response, scan_run.ScanRun) - assert response.name == "name_value" - assert response.execution_state == scan_run.ScanRun.ExecutionState.QUEUED - assert response.result_state == scan_run.ScanRun.ResultState.SUCCESS - assert response.urls_crawled_count == 1935 - assert response.urls_tested_count == 1846 - assert response.has_vulnerabilities is True - assert response.progress_percent == 1733 @@ -1630,7 +1568,7 @@ def test_start_scan_run_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1638,7 +1576,6 @@ def test_start_scan_run_empty_call(): client.start_scan_run() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.StartScanRunRequest() @@ -1648,7 +1585,7 @@ async def test_start_scan_run_async( request_type=web_security_scanner.StartScanRunRequest, ): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1669,30 +1606,21 @@ async def test_start_scan_run_async( progress_percent=1733, ) ) - response = await client.start_scan_run(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.StartScanRunRequest() # Establish that the response is the type that we expect. assert isinstance(response, scan_run.ScanRun) - assert response.name == "name_value" - assert response.execution_state == scan_run.ScanRun.ExecutionState.QUEUED - assert response.result_state == scan_run.ScanRun.ResultState.SUCCESS - assert response.urls_crawled_count == 1935 - assert response.urls_tested_count == 1846 - assert response.has_vulnerabilities is True - assert response.progress_percent == 1733 @@ -1702,17 +1630,19 @@ async def test_start_scan_run_async_from_dict(): def test_start_scan_run_field_headers(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.StartScanRunRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.start_scan_run), "__call__") as call: call.return_value = scan_run.ScanRun() - client.start_scan_run(request) # Establish that the underlying gRPC stub method was called. @@ -1728,18 +1658,18 @@ def test_start_scan_run_field_headers(): @pytest.mark.asyncio async def test_start_scan_run_field_headers_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.StartScanRunRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.start_scan_run), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(scan_run.ScanRun()) - await client.start_scan_run(request) # Establish that the underlying gRPC stub method was called. @@ -1756,7 +1686,7 @@ def test_get_scan_run( transport: str = "grpc", request_type=web_security_scanner.GetScanRunRequest ): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1775,31 +1705,21 @@ def test_get_scan_run( has_vulnerabilities=True, progress_percent=1733, ) - response = client.get_scan_run(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.GetScanRunRequest() # Establish that the response is the type that we expect. - assert isinstance(response, scan_run.ScanRun) - assert response.name == "name_value" - assert response.execution_state == scan_run.ScanRun.ExecutionState.QUEUED - assert response.result_state == scan_run.ScanRun.ResultState.SUCCESS - assert response.urls_crawled_count == 1935 - assert response.urls_tested_count == 1846 - assert response.has_vulnerabilities is True - assert response.progress_percent == 1733 @@ -1811,7 +1731,7 @@ def test_get_scan_run_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1819,7 +1739,6 @@ def test_get_scan_run_empty_call(): client.get_scan_run() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.GetScanRunRequest() @@ -1828,7 +1747,7 @@ async def test_get_scan_run_async( transport: str = "grpc_asyncio", request_type=web_security_scanner.GetScanRunRequest ): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1849,30 +1768,21 @@ async def test_get_scan_run_async( progress_percent=1733, ) ) - response = await client.get_scan_run(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.GetScanRunRequest() # Establish that the response is the type that we expect. assert isinstance(response, scan_run.ScanRun) - assert response.name == "name_value" - assert response.execution_state == scan_run.ScanRun.ExecutionState.QUEUED - assert response.result_state == scan_run.ScanRun.ResultState.SUCCESS - assert response.urls_crawled_count == 1935 - assert response.urls_tested_count == 1846 - assert response.has_vulnerabilities is True - assert response.progress_percent == 1733 @@ -1882,17 +1792,19 @@ async def test_get_scan_run_async_from_dict(): def test_get_scan_run_field_headers(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.GetScanRunRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_scan_run), "__call__") as call: call.return_value = scan_run.ScanRun() - client.get_scan_run(request) # Establish that the underlying gRPC stub method was called. @@ -1908,18 +1820,18 @@ def test_get_scan_run_field_headers(): @pytest.mark.asyncio async def test_get_scan_run_field_headers_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.GetScanRunRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_scan_run), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(scan_run.ScanRun()) - await client.get_scan_run(request) # Establish that the underlying gRPC stub method was called. @@ -1936,7 +1848,7 @@ def test_list_scan_runs( transport: str = "grpc", request_type=web_security_scanner.ListScanRunsRequest ): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1949,19 +1861,15 @@ def test_list_scan_runs( call.return_value = web_security_scanner.ListScanRunsResponse( next_page_token="next_page_token_value", ) - response = client.list_scan_runs(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.ListScanRunsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListScanRunsPager) - assert response.next_page_token == "next_page_token_value" @@ -1973,7 +1881,7 @@ def test_list_scan_runs_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1981,7 +1889,6 @@ def test_list_scan_runs_empty_call(): client.list_scan_runs() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.ListScanRunsRequest() @@ -1991,7 +1898,7 @@ async def test_list_scan_runs_async( request_type=web_security_scanner.ListScanRunsRequest, ): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2006,18 +1913,15 @@ async def test_list_scan_runs_async( next_page_token="next_page_token_value", ) ) - response = await client.list_scan_runs(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.ListScanRunsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListScanRunsAsyncPager) - assert response.next_page_token == "next_page_token_value" @@ -2027,17 +1931,19 @@ async def test_list_scan_runs_async_from_dict(): def test_list_scan_runs_field_headers(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.ListScanRunsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_scan_runs), "__call__") as call: call.return_value = web_security_scanner.ListScanRunsResponse() - client.list_scan_runs(request) # Establish that the underlying gRPC stub method was called. @@ -2053,12 +1959,13 @@ def test_list_scan_runs_field_headers(): @pytest.mark.asyncio async def test_list_scan_runs_field_headers_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.ListScanRunsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2066,7 +1973,6 @@ async def test_list_scan_runs_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( web_security_scanner.ListScanRunsResponse() ) - await client.list_scan_runs(request) # Establish that the underlying gRPC stub method was called. @@ -2080,7 +1986,7 @@ async def test_list_scan_runs_field_headers_async(): def test_list_scan_runs_pager(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials,) + client = WebSecurityScannerClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_scan_runs), "__call__") as call: @@ -2116,7 +2022,7 @@ def test_list_scan_runs_pager(): def test_list_scan_runs_pages(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials,) + client = WebSecurityScannerClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_scan_runs), "__call__") as call: @@ -2145,7 +2051,7 @@ def test_list_scan_runs_pages(): @pytest.mark.asyncio async def test_list_scan_runs_async_pager(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2182,7 +2088,7 @@ async def test_list_scan_runs_async_pager(): @pytest.mark.asyncio async def test_list_scan_runs_async_pages(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2217,7 +2123,7 @@ def test_stop_scan_run( transport: str = "grpc", request_type=web_security_scanner.StopScanRunRequest ): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2236,31 +2142,21 @@ def test_stop_scan_run( has_vulnerabilities=True, progress_percent=1733, ) - response = client.stop_scan_run(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.StopScanRunRequest() # Establish that the response is the type that we expect. - assert isinstance(response, scan_run.ScanRun) - assert response.name == "name_value" - assert response.execution_state == scan_run.ScanRun.ExecutionState.QUEUED - assert response.result_state == scan_run.ScanRun.ResultState.SUCCESS - assert response.urls_crawled_count == 1935 - assert response.urls_tested_count == 1846 - assert response.has_vulnerabilities is True - assert response.progress_percent == 1733 @@ -2272,7 +2168,7 @@ def test_stop_scan_run_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2280,7 +2176,6 @@ def test_stop_scan_run_empty_call(): client.stop_scan_run() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.StopScanRunRequest() @@ -2290,7 +2185,7 @@ async def test_stop_scan_run_async( request_type=web_security_scanner.StopScanRunRequest, ): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2311,30 +2206,21 @@ async def test_stop_scan_run_async( progress_percent=1733, ) ) - response = await client.stop_scan_run(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.StopScanRunRequest() # Establish that the response is the type that we expect. assert isinstance(response, scan_run.ScanRun) - assert response.name == "name_value" - assert response.execution_state == scan_run.ScanRun.ExecutionState.QUEUED - assert response.result_state == scan_run.ScanRun.ResultState.SUCCESS - assert response.urls_crawled_count == 1935 - assert response.urls_tested_count == 1846 - assert response.has_vulnerabilities is True - assert response.progress_percent == 1733 @@ -2344,17 +2230,19 @@ async def test_stop_scan_run_async_from_dict(): def test_stop_scan_run_field_headers(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.StopScanRunRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.stop_scan_run), "__call__") as call: call.return_value = scan_run.ScanRun() - client.stop_scan_run(request) # Establish that the underlying gRPC stub method was called. @@ -2370,18 +2258,18 @@ def test_stop_scan_run_field_headers(): @pytest.mark.asyncio async def test_stop_scan_run_field_headers_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.StopScanRunRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.stop_scan_run), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(scan_run.ScanRun()) - await client.stop_scan_run(request) # Establish that the underlying gRPC stub method was called. @@ -2398,7 +2286,7 @@ def test_list_crawled_urls( transport: str = "grpc", request_type=web_security_scanner.ListCrawledUrlsRequest ): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2413,19 +2301,15 @@ def test_list_crawled_urls( call.return_value = web_security_scanner.ListCrawledUrlsResponse( next_page_token="next_page_token_value", ) - response = client.list_crawled_urls(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.ListCrawledUrlsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListCrawledUrlsPager) - assert response.next_page_token == "next_page_token_value" @@ -2437,7 +2321,7 @@ def test_list_crawled_urls_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2447,7 +2331,6 @@ def test_list_crawled_urls_empty_call(): client.list_crawled_urls() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.ListCrawledUrlsRequest() @@ -2457,7 +2340,7 @@ async def test_list_crawled_urls_async( request_type=web_security_scanner.ListCrawledUrlsRequest, ): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2474,18 +2357,15 @@ async def test_list_crawled_urls_async( next_page_token="next_page_token_value", ) ) - response = await client.list_crawled_urls(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.ListCrawledUrlsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListCrawledUrlsAsyncPager) - assert response.next_page_token == "next_page_token_value" @@ -2495,11 +2375,14 @@ async def test_list_crawled_urls_async_from_dict(): def test_list_crawled_urls_field_headers(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.ListCrawledUrlsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2507,7 +2390,6 @@ def test_list_crawled_urls_field_headers(): type(client.transport.list_crawled_urls), "__call__" ) as call: call.return_value = web_security_scanner.ListCrawledUrlsResponse() - client.list_crawled_urls(request) # Establish that the underlying gRPC stub method was called. @@ -2523,12 +2405,13 @@ def test_list_crawled_urls_field_headers(): @pytest.mark.asyncio async def test_list_crawled_urls_field_headers_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.ListCrawledUrlsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2538,7 +2421,6 @@ async def test_list_crawled_urls_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( web_security_scanner.ListCrawledUrlsResponse() ) - await client.list_crawled_urls(request) # Establish that the underlying gRPC stub method was called. @@ -2552,7 +2434,7 @@ async def test_list_crawled_urls_field_headers_async(): def test_list_crawled_urls_pager(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials,) + client = WebSecurityScannerClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2594,7 +2476,7 @@ def test_list_crawled_urls_pager(): def test_list_crawled_urls_pages(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials,) + client = WebSecurityScannerClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2629,7 +2511,7 @@ def test_list_crawled_urls_pages(): @pytest.mark.asyncio async def test_list_crawled_urls_async_pager(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2672,7 +2554,7 @@ async def test_list_crawled_urls_async_pager(): @pytest.mark.asyncio async def test_list_crawled_urls_async_pages(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2713,7 +2595,7 @@ def test_get_finding( transport: str = "grpc", request_type=web_security_scanner.GetFindingRequest ): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2736,39 +2618,25 @@ def test_get_finding( final_url="final_url_value", tracking_id="tracking_id_value", ) - response = client.get_finding(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.GetFindingRequest() # Establish that the response is the type that we expect. - assert isinstance(response, finding.Finding) - assert response.name == "name_value" - assert response.finding_type == "finding_type_value" - assert response.severity == finding.Finding.Severity.CRITICAL - assert response.http_method == "http_method_value" - assert response.fuzzed_url == "fuzzed_url_value" - assert response.body == "body_value" - assert response.description == "description_value" - assert response.reproduction_url == "reproduction_url_value" - assert response.frame_url == "frame_url_value" - assert response.final_url == "final_url_value" - assert response.tracking_id == "tracking_id_value" @@ -2780,7 +2648,7 @@ def test_get_finding_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2788,7 +2656,6 @@ def test_get_finding_empty_call(): client.get_finding() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.GetFindingRequest() @@ -2797,7 +2664,7 @@ async def test_get_finding_async( transport: str = "grpc_asyncio", request_type=web_security_scanner.GetFindingRequest ): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2822,38 +2689,25 @@ async def test_get_finding_async( tracking_id="tracking_id_value", ) ) - response = await client.get_finding(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.GetFindingRequest() # Establish that the response is the type that we expect. assert isinstance(response, finding.Finding) - assert response.name == "name_value" - assert response.finding_type == "finding_type_value" - assert response.severity == finding.Finding.Severity.CRITICAL - assert response.http_method == "http_method_value" - assert response.fuzzed_url == "fuzzed_url_value" - assert response.body == "body_value" - assert response.description == "description_value" - assert response.reproduction_url == "reproduction_url_value" - assert response.frame_url == "frame_url_value" - assert response.final_url == "final_url_value" - assert response.tracking_id == "tracking_id_value" @@ -2863,17 +2717,19 @@ async def test_get_finding_async_from_dict(): def test_get_finding_field_headers(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.GetFindingRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_finding), "__call__") as call: call.return_value = finding.Finding() - client.get_finding(request) # Establish that the underlying gRPC stub method was called. @@ -2889,18 +2745,18 @@ def test_get_finding_field_headers(): @pytest.mark.asyncio async def test_get_finding_field_headers_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.GetFindingRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_finding), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(finding.Finding()) - await client.get_finding(request) # Establish that the underlying gRPC stub method was called. @@ -2917,7 +2773,7 @@ def test_list_findings( transport: str = "grpc", request_type=web_security_scanner.ListFindingsRequest ): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2930,19 +2786,15 @@ def test_list_findings( call.return_value = web_security_scanner.ListFindingsResponse( next_page_token="next_page_token_value", ) - response = client.list_findings(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.ListFindingsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListFindingsPager) - assert response.next_page_token == "next_page_token_value" @@ -2954,7 +2806,7 @@ def test_list_findings_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2962,7 +2814,6 @@ def test_list_findings_empty_call(): client.list_findings() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.ListFindingsRequest() @@ -2972,7 +2823,7 @@ async def test_list_findings_async( request_type=web_security_scanner.ListFindingsRequest, ): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2987,18 +2838,15 @@ async def test_list_findings_async( next_page_token="next_page_token_value", ) ) - response = await client.list_findings(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.ListFindingsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListFindingsAsyncPager) - assert response.next_page_token == "next_page_token_value" @@ -3008,17 +2856,19 @@ async def test_list_findings_async_from_dict(): def test_list_findings_field_headers(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.ListFindingsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_findings), "__call__") as call: call.return_value = web_security_scanner.ListFindingsResponse() - client.list_findings(request) # Establish that the underlying gRPC stub method was called. @@ -3034,12 +2884,13 @@ def test_list_findings_field_headers(): @pytest.mark.asyncio async def test_list_findings_field_headers_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.ListFindingsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -3047,7 +2898,6 @@ async def test_list_findings_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( web_security_scanner.ListFindingsResponse() ) - await client.list_findings(request) # Establish that the underlying gRPC stub method was called. @@ -3061,7 +2911,7 @@ async def test_list_findings_field_headers_async(): def test_list_findings_pager(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials,) + client = WebSecurityScannerClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_findings), "__call__") as call: @@ -3097,7 +2947,7 @@ def test_list_findings_pager(): def test_list_findings_pages(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials,) + client = WebSecurityScannerClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_findings), "__call__") as call: @@ -3126,7 +2976,7 @@ def test_list_findings_pages(): @pytest.mark.asyncio async def test_list_findings_async_pager(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3163,7 +3013,7 @@ async def test_list_findings_async_pager(): @pytest.mark.asyncio async def test_list_findings_async_pages(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3199,7 +3049,7 @@ def test_list_finding_type_stats( request_type=web_security_scanner.ListFindingTypeStatsRequest, ): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3212,17 +3062,14 @@ def test_list_finding_type_stats( ) as call: # Designate an appropriate return value for the call. call.return_value = web_security_scanner.ListFindingTypeStatsResponse() - response = client.list_finding_type_stats(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.ListFindingTypeStatsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, web_security_scanner.ListFindingTypeStatsResponse) @@ -3234,7 +3081,7 @@ def test_list_finding_type_stats_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3244,7 +3091,6 @@ def test_list_finding_type_stats_empty_call(): client.list_finding_type_stats() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.ListFindingTypeStatsRequest() @@ -3254,7 +3100,7 @@ async def test_list_finding_type_stats_async( request_type=web_security_scanner.ListFindingTypeStatsRequest, ): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3269,13 +3115,11 @@ async def test_list_finding_type_stats_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( web_security_scanner.ListFindingTypeStatsResponse() ) - response = await client.list_finding_type_stats(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.ListFindingTypeStatsRequest() # Establish that the response is the type that we expect. @@ -3288,11 +3132,14 @@ async def test_list_finding_type_stats_async_from_dict(): def test_list_finding_type_stats_field_headers(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.ListFindingTypeStatsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -3300,7 +3147,6 @@ def test_list_finding_type_stats_field_headers(): type(client.transport.list_finding_type_stats), "__call__" ) as call: call.return_value = web_security_scanner.ListFindingTypeStatsResponse() - client.list_finding_type_stats(request) # Establish that the underlying gRPC stub method was called. @@ -3316,12 +3162,13 @@ def test_list_finding_type_stats_field_headers(): @pytest.mark.asyncio async def test_list_finding_type_stats_field_headers_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.ListFindingTypeStatsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -3331,7 +3178,6 @@ async def test_list_finding_type_stats_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( web_security_scanner.ListFindingTypeStatsResponse() ) - await client.list_finding_type_stats(request) # Establish that the underlying gRPC stub method was called. @@ -3347,16 +3193,16 @@ async def test_list_finding_type_stats_field_headers_async(): def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.WebSecurityScannerGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.WebSecurityScannerGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = WebSecurityScannerClient( @@ -3366,7 +3212,7 @@ def test_credentials_transport_error(): # It is an error to provide scopes and a transport instance. transport = transports.WebSecurityScannerGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = WebSecurityScannerClient( @@ -3377,7 +3223,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.WebSecurityScannerGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) client = WebSecurityScannerClient(transport=transport) assert client.transport is transport @@ -3386,13 +3232,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.WebSecurityScannerGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel transport = transports.WebSecurityScannerGrpcAsyncIOTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel @@ -3407,23 +3253,25 @@ def test_transport_get_channel(): ) def test_transport_adc(transport_class): # Test default credentials are used if not provided. - with mock.patch.object(auth, "default") as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport_class() adc.assert_called_once() def test_transport_grpc_default(): # A client should use the gRPC transport by default. - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) assert isinstance(client.transport, transports.WebSecurityScannerGrpcTransport,) def test_web_security_scanner_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error - with pytest.raises(exceptions.DuplicateCredentialArgs): + with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.WebSecurityScannerTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), credentials_file="credentials.json", ) @@ -3435,7 +3283,7 @@ def test_web_security_scanner_base_transport(): ) as Transport: Transport.return_value = None transport = transports.WebSecurityScannerTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Every method on the transport should just blindly @@ -3460,15 +3308,37 @@ def test_web_security_scanner_base_transport(): getattr(transport, method)(request=object()) +@requires_google_auth_gte_1_25_0 def test_web_security_scanner_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( - auth, "load_credentials_from_file" + google.auth, "load_credentials_from_file", autospec=True ) as load_creds, mock.patch( "google.cloud.websecurityscanner_v1.services.web_security_scanner.transports.WebSecurityScannerTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (credentials.AnonymousCredentials(), None) + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.WebSecurityScannerTransport( + credentials_file="credentials.json", quota_project_id="octopus", + ) + load_creds.assert_called_once_with( + "credentials.json", + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", + ) + + +@requires_google_auth_lt_1_25_0 +def test_web_security_scanner_base_transport_with_credentials_file_old_google_auth(): + # Instantiate the base transport with a credentials file + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch( + "google.cloud.websecurityscanner_v1.services.web_security_scanner.transports.WebSecurityScannerTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.WebSecurityScannerTransport( credentials_file="credentials.json", quota_project_id="octopus", ) @@ -3481,19 +3351,33 @@ def test_web_security_scanner_base_transport_with_credentials_file(): def test_web_security_scanner_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(auth, "default") as adc, mock.patch( + with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( "google.cloud.websecurityscanner_v1.services.web_security_scanner.transports.WebSecurityScannerTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (credentials.AnonymousCredentials(), None) + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.WebSecurityScannerTransport() adc.assert_called_once() +@requires_google_auth_gte_1_25_0 def test_web_security_scanner_auth_adc(): # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(auth, "default") as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + WebSecurityScannerClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id=None, + ) + + +@requires_google_auth_lt_1_25_0 +def test_web_security_scanner_auth_adc_old_google_auth(): + # If no credentials are provided, we should use ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) WebSecurityScannerClient() adc.assert_called_once_with( scopes=("https://www.googleapis.com/auth/cloud-platform",), @@ -3501,20 +3385,156 @@ def test_web_security_scanner_auth_adc(): ) -def test_web_security_scanner_transport_auth_adc(): +@pytest.mark.parametrize( + "transport_class", + [ + transports.WebSecurityScannerGrpcTransport, + transports.WebSecurityScannerGrpcAsyncIOTransport, + ], +) +@requires_google_auth_gte_1_25_0 +def test_web_security_scanner_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object(auth, "default") as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) - transports.WebSecurityScannerGrpcTransport( - host="squid.clam.whelk", quota_project_id="octopus" + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + adc.assert_called_once_with( + scopes=["1", "2"], + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.WebSecurityScannerGrpcTransport, + transports.WebSecurityScannerGrpcAsyncIOTransport, + ], +) +@requires_google_auth_lt_1_25_0 +def test_web_security_scanner_transport_auth_adc_old_google_auth(transport_class): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus") adc.assert_called_once_with( scopes=("https://www.googleapis.com/auth/cloud-platform",), quota_project_id="octopus", ) +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.WebSecurityScannerGrpcTransport, grpc_helpers), + (transports.WebSecurityScannerGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_gte_1_26_0 +def test_web_security_scanner_transport_create_channel(transport_class, grpc_helpers): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + + create_channel.assert_called_with( + "websecurityscanner.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=["1", "2"], + default_host="websecurityscanner.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.WebSecurityScannerGrpcTransport, grpc_helpers), + (transports.WebSecurityScannerGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_web_security_scanner_transport_create_channel_old_api_core( + transport_class, grpc_helpers +): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class(quota_project_id="octopus") + + create_channel.assert_called_with( + "websecurityscanner.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + scopes=("https://www.googleapis.com/auth/cloud-platform",), + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.WebSecurityScannerGrpcTransport, grpc_helpers), + (transports.WebSecurityScannerGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_web_security_scanner_transport_create_channel_user_scopes( + transport_class, grpc_helpers +): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + + create_channel.assert_called_with( + "websecurityscanner.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + scopes=["1", "2"], + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + @pytest.mark.parametrize( "transport_class", [ @@ -3525,7 +3545,7 @@ def test_web_security_scanner_transport_auth_adc(): def test_web_security_scanner_grpc_transport_client_cert_source_for_mtls( transport_class, ): - cred = credentials.AnonymousCredentials() + cred = ga_credentials.AnonymousCredentials() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -3564,7 +3584,7 @@ def test_web_security_scanner_grpc_transport_client_cert_source_for_mtls( def test_web_security_scanner_host_no_port(): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="websecurityscanner.googleapis.com" ), @@ -3574,7 +3594,7 @@ def test_web_security_scanner_host_no_port(): def test_web_security_scanner_host_with_port(): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="websecurityscanner.googleapis.com:8000" ), @@ -3630,9 +3650,9 @@ def test_web_security_scanner_transport_channel_mtls_with_client_cert_source( mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = credentials.AnonymousCredentials() + cred = ga_credentials.AnonymousCredentials() with pytest.warns(DeprecationWarning): - with mock.patch.object(auth, "default") as adc: + with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) transport = transport_class( host="squid.clam.whelk", @@ -3711,7 +3731,6 @@ def test_finding_path(): scan_config = "clam" scan_run = "whelk" finding = "octopus" - expected = "projects/{project}/scanConfigs/{scan_config}/scanRuns/{scan_run}/findings/{finding}".format( project=project, scan_config=scan_config, scan_run=scan_run, finding=finding, ) @@ -3737,7 +3756,6 @@ def test_parse_finding_path(): def test_common_billing_account_path(): billing_account = "winkle" - expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -3758,7 +3776,6 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "scallop" - expected = "folders/{folder}".format(folder=folder,) actual = WebSecurityScannerClient.common_folder_path(folder) assert expected == actual @@ -3777,7 +3794,6 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "squid" - expected = "organizations/{organization}".format(organization=organization,) actual = WebSecurityScannerClient.common_organization_path(organization) assert expected == actual @@ -3796,7 +3812,6 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "whelk" - expected = "projects/{project}".format(project=project,) actual = WebSecurityScannerClient.common_project_path(project) assert expected == actual @@ -3816,7 +3831,6 @@ def test_parse_common_project_path(): def test_common_location_path(): project = "oyster" location = "nudibranch" - expected = "projects/{project}/locations/{location}".format( project=project, location=location, ) @@ -3843,7 +3857,7 @@ def test_client_withDEFAULT_CLIENT_INFO(): transports.WebSecurityScannerTransport, "_prep_wrapped_messages" ) as prep: client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -3852,6 +3866,6 @@ def test_client_withDEFAULT_CLIENT_INFO(): ) as prep: transport_class = WebSecurityScannerClient.get_transport_class() transport = transport_class( - credentials=credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) diff --git a/tests/unit/gapic/websecurityscanner_v1alpha/__init__.py b/tests/unit/gapic/websecurityscanner_v1alpha/__init__.py index 42ffdf2..4de6597 100644 --- a/tests/unit/gapic/websecurityscanner_v1alpha/__init__.py +++ b/tests/unit/gapic/websecurityscanner_v1alpha/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/unit/gapic/websecurityscanner_v1alpha/test_web_security_scanner.py b/tests/unit/gapic/websecurityscanner_v1alpha/test_web_security_scanner.py index 905949e..f8c4dd6 100644 --- a/tests/unit/gapic/websecurityscanner_v1alpha/test_web_security_scanner.py +++ b/tests/unit/gapic/websecurityscanner_v1alpha/test_web_security_scanner.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import os import mock +import packaging.version import grpc from grpc.experimental import aio @@ -24,13 +23,13 @@ import pytest from proto.marshal.rules.dates import DurationRule, TimestampRule -from google import auth + from google.api_core import client_options -from google.api_core import exceptions +from google.api_core import exceptions as core_exceptions from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async -from google.auth import credentials +from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.websecurityscanner_v1alpha.services.web_security_scanner import ( WebSecurityScannerAsyncClient, @@ -42,6 +41,12 @@ from google.cloud.websecurityscanner_v1alpha.services.web_security_scanner import ( transports, ) +from google.cloud.websecurityscanner_v1alpha.services.web_security_scanner.transports.base import ( + _API_CORE_VERSION, +) +from google.cloud.websecurityscanner_v1alpha.services.web_security_scanner.transports.base import ( + _GOOGLE_AUTH_VERSION, +) from google.cloud.websecurityscanner_v1alpha.types import crawled_url from google.cloud.websecurityscanner_v1alpha.types import finding from google.cloud.websecurityscanner_v1alpha.types import finding_addon @@ -51,8 +56,32 @@ from google.cloud.websecurityscanner_v1alpha.types import scan_run from google.cloud.websecurityscanner_v1alpha.types import web_security_scanner from google.oauth2 import service_account -from google.protobuf import field_mask_pb2 as field_mask # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +import google.auth + + +# TODO(busunkim): Once google-api-core >= 1.26.0 is required: +# - Delete all the api-core and auth "less than" test cases +# - Delete these pytest markers (Make the "greater than or equal to" tests the default). +requires_google_auth_lt_1_25_0 = pytest.mark.skipif( + packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), + reason="This test requires google-auth < 1.25.0", +) +requires_google_auth_gte_1_25_0 = pytest.mark.skipif( + packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), + reason="This test requires google-auth >= 1.25.0", +) + +requires_api_core_lt_1_26_0 = pytest.mark.skipif( + packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), + reason="This test requires google-api-core < 1.26.0", +) + +requires_api_core_gte_1_26_0 = pytest.mark.skipif( + packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), + reason="This test requires google-api-core >= 1.26.0", +) def client_cert_source_callback(): @@ -104,7 +133,7 @@ def test__get_default_mtls_endpoint(): "client_class", [WebSecurityScannerClient, WebSecurityScannerAsyncClient,] ) def test_web_security_scanner_client_from_service_account_info(client_class): - creds = credentials.AnonymousCredentials() + creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -121,7 +150,7 @@ def test_web_security_scanner_client_from_service_account_info(client_class): "client_class", [WebSecurityScannerClient, WebSecurityScannerAsyncClient,] ) def test_web_security_scanner_client_from_service_account_file(client_class): - creds = credentials.AnonymousCredentials() + creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -174,7 +203,7 @@ def test_web_security_scanner_client_client_options( ): # Check that if channel is provided we won't create a new one. with mock.patch.object(WebSecurityScannerClient, "get_transport_class") as gtc: - transport = transport_class(credentials=credentials.AnonymousCredentials()) + transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) client = client_class(transport=transport) gtc.assert_not_called() @@ -472,7 +501,7 @@ def test_create_scan_config( transport: str = "grpc", request_type=web_security_scanner.CreateScanConfigRequest ): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -493,31 +522,21 @@ def test_create_scan_config( blacklist_patterns=["blacklist_patterns_value"], target_platforms=[gcw_scan_config.ScanConfig.TargetPlatform.APP_ENGINE], ) - response = client.create_scan_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.CreateScanConfigRequest() # Establish that the response is the type that we expect. - assert isinstance(response, gcw_scan_config.ScanConfig) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.max_qps == 761 - assert response.starting_urls == ["starting_urls_value"] - assert response.user_agent == gcw_scan_config.ScanConfig.UserAgent.CHROME_LINUX - assert response.blacklist_patterns == ["blacklist_patterns_value"] - assert response.target_platforms == [ gcw_scan_config.ScanConfig.TargetPlatform.APP_ENGINE ] @@ -531,7 +550,7 @@ def test_create_scan_config_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -541,7 +560,6 @@ def test_create_scan_config_empty_call(): client.create_scan_config() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.CreateScanConfigRequest() @@ -551,7 +569,7 @@ async def test_create_scan_config_async( request_type=web_security_scanner.CreateScanConfigRequest, ): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -574,30 +592,21 @@ async def test_create_scan_config_async( target_platforms=[gcw_scan_config.ScanConfig.TargetPlatform.APP_ENGINE], ) ) - response = await client.create_scan_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.CreateScanConfigRequest() # Establish that the response is the type that we expect. assert isinstance(response, gcw_scan_config.ScanConfig) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.max_qps == 761 - assert response.starting_urls == ["starting_urls_value"] - assert response.user_agent == gcw_scan_config.ScanConfig.UserAgent.CHROME_LINUX - assert response.blacklist_patterns == ["blacklist_patterns_value"] - assert response.target_platforms == [ gcw_scan_config.ScanConfig.TargetPlatform.APP_ENGINE ] @@ -609,11 +618,14 @@ async def test_create_scan_config_async_from_dict(): def test_create_scan_config_field_headers(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.CreateScanConfigRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -621,7 +633,6 @@ def test_create_scan_config_field_headers(): type(client.transport.create_scan_config), "__call__" ) as call: call.return_value = gcw_scan_config.ScanConfig() - client.create_scan_config(request) # Establish that the underlying gRPC stub method was called. @@ -637,12 +648,13 @@ def test_create_scan_config_field_headers(): @pytest.mark.asyncio async def test_create_scan_config_field_headers_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.CreateScanConfigRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -652,7 +664,6 @@ async def test_create_scan_config_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( gcw_scan_config.ScanConfig() ) - await client.create_scan_config(request) # Establish that the underlying gRPC stub method was called. @@ -666,7 +677,9 @@ async def test_create_scan_config_field_headers_async(): def test_create_scan_config_flattened(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -674,7 +687,6 @@ def test_create_scan_config_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = gcw_scan_config.ScanConfig() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.create_scan_config( @@ -686,14 +698,14 @@ def test_create_scan_config_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].scan_config == gcw_scan_config.ScanConfig(name="name_value") def test_create_scan_config_flattened_error(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -708,7 +720,7 @@ def test_create_scan_config_flattened_error(): @pytest.mark.asyncio async def test_create_scan_config_flattened_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -732,16 +744,14 @@ async def test_create_scan_config_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].scan_config == gcw_scan_config.ScanConfig(name="name_value") @pytest.mark.asyncio async def test_create_scan_config_flattened_error_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -758,7 +768,7 @@ def test_delete_scan_config( transport: str = "grpc", request_type=web_security_scanner.DeleteScanConfigRequest ): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -771,13 +781,11 @@ def test_delete_scan_config( ) as call: # Designate an appropriate return value for the call. call.return_value = None - response = client.delete_scan_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.DeleteScanConfigRequest() # Establish that the response is the type that we expect. @@ -792,7 +800,7 @@ def test_delete_scan_config_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -802,7 +810,6 @@ def test_delete_scan_config_empty_call(): client.delete_scan_config() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.DeleteScanConfigRequest() @@ -812,7 +819,7 @@ async def test_delete_scan_config_async( request_type=web_security_scanner.DeleteScanConfigRequest, ): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -825,13 +832,11 @@ async def test_delete_scan_config_async( ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - response = await client.delete_scan_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.DeleteScanConfigRequest() # Establish that the response is the type that we expect. @@ -844,11 +849,14 @@ async def test_delete_scan_config_async_from_dict(): def test_delete_scan_config_field_headers(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.DeleteScanConfigRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -856,7 +864,6 @@ def test_delete_scan_config_field_headers(): type(client.transport.delete_scan_config), "__call__" ) as call: call.return_value = None - client.delete_scan_config(request) # Establish that the underlying gRPC stub method was called. @@ -872,12 +879,13 @@ def test_delete_scan_config_field_headers(): @pytest.mark.asyncio async def test_delete_scan_config_field_headers_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.DeleteScanConfigRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -885,7 +893,6 @@ async def test_delete_scan_config_field_headers_async(): type(client.transport.delete_scan_config), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - await client.delete_scan_config(request) # Establish that the underlying gRPC stub method was called. @@ -899,7 +906,9 @@ async def test_delete_scan_config_field_headers_async(): def test_delete_scan_config_flattened(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -907,7 +916,6 @@ def test_delete_scan_config_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = None - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.delete_scan_config(name="name_value",) @@ -916,12 +924,13 @@ def test_delete_scan_config_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_delete_scan_config_flattened_error(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -934,7 +943,7 @@ def test_delete_scan_config_flattened_error(): @pytest.mark.asyncio async def test_delete_scan_config_flattened_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -953,14 +962,13 @@ async def test_delete_scan_config_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @pytest.mark.asyncio async def test_delete_scan_config_flattened_error_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -975,7 +983,7 @@ def test_get_scan_config( transport: str = "grpc", request_type=web_security_scanner.GetScanConfigRequest ): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -994,31 +1002,21 @@ def test_get_scan_config( blacklist_patterns=["blacklist_patterns_value"], target_platforms=[scan_config.ScanConfig.TargetPlatform.APP_ENGINE], ) - response = client.get_scan_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.GetScanConfigRequest() # Establish that the response is the type that we expect. - assert isinstance(response, scan_config.ScanConfig) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.max_qps == 761 - assert response.starting_urls == ["starting_urls_value"] - assert response.user_agent == scan_config.ScanConfig.UserAgent.CHROME_LINUX - assert response.blacklist_patterns == ["blacklist_patterns_value"] - assert response.target_platforms == [ scan_config.ScanConfig.TargetPlatform.APP_ENGINE ] @@ -1032,7 +1030,7 @@ def test_get_scan_config_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1040,7 +1038,6 @@ def test_get_scan_config_empty_call(): client.get_scan_config() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.GetScanConfigRequest() @@ -1050,7 +1047,7 @@ async def test_get_scan_config_async( request_type=web_security_scanner.GetScanConfigRequest, ): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1071,30 +1068,21 @@ async def test_get_scan_config_async( target_platforms=[scan_config.ScanConfig.TargetPlatform.APP_ENGINE], ) ) - response = await client.get_scan_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.GetScanConfigRequest() # Establish that the response is the type that we expect. assert isinstance(response, scan_config.ScanConfig) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.max_qps == 761 - assert response.starting_urls == ["starting_urls_value"] - assert response.user_agent == scan_config.ScanConfig.UserAgent.CHROME_LINUX - assert response.blacklist_patterns == ["blacklist_patterns_value"] - assert response.target_platforms == [ scan_config.ScanConfig.TargetPlatform.APP_ENGINE ] @@ -1106,17 +1094,19 @@ async def test_get_scan_config_async_from_dict(): def test_get_scan_config_field_headers(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.GetScanConfigRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_scan_config), "__call__") as call: call.return_value = scan_config.ScanConfig() - client.get_scan_config(request) # Establish that the underlying gRPC stub method was called. @@ -1132,12 +1122,13 @@ def test_get_scan_config_field_headers(): @pytest.mark.asyncio async def test_get_scan_config_field_headers_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.GetScanConfigRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1145,7 +1136,6 @@ async def test_get_scan_config_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( scan_config.ScanConfig() ) - await client.get_scan_config(request) # Establish that the underlying gRPC stub method was called. @@ -1159,13 +1149,14 @@ async def test_get_scan_config_field_headers_async(): def test_get_scan_config_flattened(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_scan_config), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = scan_config.ScanConfig() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.get_scan_config(name="name_value",) @@ -1174,12 +1165,13 @@ def test_get_scan_config_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_get_scan_config_flattened_error(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1192,7 +1184,7 @@ def test_get_scan_config_flattened_error(): @pytest.mark.asyncio async def test_get_scan_config_flattened_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1211,14 +1203,13 @@ async def test_get_scan_config_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @pytest.mark.asyncio async def test_get_scan_config_flattened_error_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1233,7 +1224,7 @@ def test_list_scan_configs( transport: str = "grpc", request_type=web_security_scanner.ListScanConfigsRequest ): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1248,19 +1239,15 @@ def test_list_scan_configs( call.return_value = web_security_scanner.ListScanConfigsResponse( next_page_token="next_page_token_value", ) - response = client.list_scan_configs(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.ListScanConfigsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListScanConfigsPager) - assert response.next_page_token == "next_page_token_value" @@ -1272,7 +1259,7 @@ def test_list_scan_configs_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1282,7 +1269,6 @@ def test_list_scan_configs_empty_call(): client.list_scan_configs() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.ListScanConfigsRequest() @@ -1292,7 +1278,7 @@ async def test_list_scan_configs_async( request_type=web_security_scanner.ListScanConfigsRequest, ): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1309,18 +1295,15 @@ async def test_list_scan_configs_async( next_page_token="next_page_token_value", ) ) - response = await client.list_scan_configs(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.ListScanConfigsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListScanConfigsAsyncPager) - assert response.next_page_token == "next_page_token_value" @@ -1330,11 +1313,14 @@ async def test_list_scan_configs_async_from_dict(): def test_list_scan_configs_field_headers(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.ListScanConfigsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1342,7 +1328,6 @@ def test_list_scan_configs_field_headers(): type(client.transport.list_scan_configs), "__call__" ) as call: call.return_value = web_security_scanner.ListScanConfigsResponse() - client.list_scan_configs(request) # Establish that the underlying gRPC stub method was called. @@ -1358,12 +1343,13 @@ def test_list_scan_configs_field_headers(): @pytest.mark.asyncio async def test_list_scan_configs_field_headers_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.ListScanConfigsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1373,7 +1359,6 @@ async def test_list_scan_configs_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( web_security_scanner.ListScanConfigsResponse() ) - await client.list_scan_configs(request) # Establish that the underlying gRPC stub method was called. @@ -1387,7 +1372,9 @@ async def test_list_scan_configs_field_headers_async(): def test_list_scan_configs_flattened(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1395,7 +1382,6 @@ def test_list_scan_configs_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = web_security_scanner.ListScanConfigsResponse() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.list_scan_configs(parent="parent_value",) @@ -1404,12 +1390,13 @@ def test_list_scan_configs_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" def test_list_scan_configs_flattened_error(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1422,7 +1409,7 @@ def test_list_scan_configs_flattened_error(): @pytest.mark.asyncio async def test_list_scan_configs_flattened_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1443,14 +1430,13 @@ async def test_list_scan_configs_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" @pytest.mark.asyncio async def test_list_scan_configs_flattened_error_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1462,7 +1448,7 @@ async def test_list_scan_configs_flattened_error_async(): def test_list_scan_configs_pager(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials,) + client = WebSecurityScannerClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1504,7 +1490,7 @@ def test_list_scan_configs_pager(): def test_list_scan_configs_pages(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials,) + client = WebSecurityScannerClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1539,7 +1525,7 @@ def test_list_scan_configs_pages(): @pytest.mark.asyncio async def test_list_scan_configs_async_pager(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1582,7 +1568,7 @@ async def test_list_scan_configs_async_pager(): @pytest.mark.asyncio async def test_list_scan_configs_async_pages(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1623,7 +1609,7 @@ def test_update_scan_config( transport: str = "grpc", request_type=web_security_scanner.UpdateScanConfigRequest ): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1644,31 +1630,21 @@ def test_update_scan_config( blacklist_patterns=["blacklist_patterns_value"], target_platforms=[gcw_scan_config.ScanConfig.TargetPlatform.APP_ENGINE], ) - response = client.update_scan_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.UpdateScanConfigRequest() # Establish that the response is the type that we expect. - assert isinstance(response, gcw_scan_config.ScanConfig) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.max_qps == 761 - assert response.starting_urls == ["starting_urls_value"] - assert response.user_agent == gcw_scan_config.ScanConfig.UserAgent.CHROME_LINUX - assert response.blacklist_patterns == ["blacklist_patterns_value"] - assert response.target_platforms == [ gcw_scan_config.ScanConfig.TargetPlatform.APP_ENGINE ] @@ -1682,7 +1658,7 @@ def test_update_scan_config_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1692,7 +1668,6 @@ def test_update_scan_config_empty_call(): client.update_scan_config() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.UpdateScanConfigRequest() @@ -1702,7 +1677,7 @@ async def test_update_scan_config_async( request_type=web_security_scanner.UpdateScanConfigRequest, ): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1725,30 +1700,21 @@ async def test_update_scan_config_async( target_platforms=[gcw_scan_config.ScanConfig.TargetPlatform.APP_ENGINE], ) ) - response = await client.update_scan_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.UpdateScanConfigRequest() # Establish that the response is the type that we expect. assert isinstance(response, gcw_scan_config.ScanConfig) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.max_qps == 761 - assert response.starting_urls == ["starting_urls_value"] - assert response.user_agent == gcw_scan_config.ScanConfig.UserAgent.CHROME_LINUX - assert response.blacklist_patterns == ["blacklist_patterns_value"] - assert response.target_platforms == [ gcw_scan_config.ScanConfig.TargetPlatform.APP_ENGINE ] @@ -1760,11 +1726,14 @@ async def test_update_scan_config_async_from_dict(): def test_update_scan_config_field_headers(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.UpdateScanConfigRequest() + request.scan_config.name = "scan_config.name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1772,7 +1741,6 @@ def test_update_scan_config_field_headers(): type(client.transport.update_scan_config), "__call__" ) as call: call.return_value = gcw_scan_config.ScanConfig() - client.update_scan_config(request) # Establish that the underlying gRPC stub method was called. @@ -1790,12 +1758,13 @@ def test_update_scan_config_field_headers(): @pytest.mark.asyncio async def test_update_scan_config_field_headers_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.UpdateScanConfigRequest() + request.scan_config.name = "scan_config.name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1805,7 +1774,6 @@ async def test_update_scan_config_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( gcw_scan_config.ScanConfig() ) - await client.update_scan_config(request) # Establish that the underlying gRPC stub method was called. @@ -1821,7 +1789,9 @@ async def test_update_scan_config_field_headers_async(): def test_update_scan_config_flattened(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1829,26 +1799,25 @@ def test_update_scan_config_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = gcw_scan_config.ScanConfig() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.update_scan_config( scan_config=gcw_scan_config.ScanConfig(name="name_value"), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].scan_config == gcw_scan_config.ScanConfig(name="name_value") - - assert args[0].update_mask == field_mask.FieldMask(paths=["paths_value"]) + assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) def test_update_scan_config_flattened_error(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1856,14 +1825,14 @@ def test_update_scan_config_flattened_error(): client.update_scan_config( web_security_scanner.UpdateScanConfigRequest(), scan_config=gcw_scan_config.ScanConfig(name="name_value"), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @pytest.mark.asyncio async def test_update_scan_config_flattened_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1880,23 +1849,21 @@ async def test_update_scan_config_flattened_async(): # using the keyword arguments to the method. response = await client.update_scan_config( scan_config=gcw_scan_config.ScanConfig(name="name_value"), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].scan_config == gcw_scan_config.ScanConfig(name="name_value") - - assert args[0].update_mask == field_mask.FieldMask(paths=["paths_value"]) + assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) @pytest.mark.asyncio async def test_update_scan_config_flattened_error_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1905,7 +1872,7 @@ async def test_update_scan_config_flattened_error_async(): await client.update_scan_config( web_security_scanner.UpdateScanConfigRequest(), scan_config=gcw_scan_config.ScanConfig(name="name_value"), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @@ -1913,7 +1880,7 @@ def test_start_scan_run( transport: str = "grpc", request_type=web_security_scanner.StartScanRunRequest ): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1932,31 +1899,21 @@ def test_start_scan_run( has_vulnerabilities=True, progress_percent=1733, ) - response = client.start_scan_run(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.StartScanRunRequest() # Establish that the response is the type that we expect. - assert isinstance(response, scan_run.ScanRun) - assert response.name == "name_value" - assert response.execution_state == scan_run.ScanRun.ExecutionState.QUEUED - assert response.result_state == scan_run.ScanRun.ResultState.SUCCESS - assert response.urls_crawled_count == 1935 - assert response.urls_tested_count == 1846 - assert response.has_vulnerabilities is True - assert response.progress_percent == 1733 @@ -1968,7 +1925,7 @@ def test_start_scan_run_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1976,7 +1933,6 @@ def test_start_scan_run_empty_call(): client.start_scan_run() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.StartScanRunRequest() @@ -1986,7 +1942,7 @@ async def test_start_scan_run_async( request_type=web_security_scanner.StartScanRunRequest, ): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2007,30 +1963,21 @@ async def test_start_scan_run_async( progress_percent=1733, ) ) - response = await client.start_scan_run(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.StartScanRunRequest() # Establish that the response is the type that we expect. assert isinstance(response, scan_run.ScanRun) - assert response.name == "name_value" - assert response.execution_state == scan_run.ScanRun.ExecutionState.QUEUED - assert response.result_state == scan_run.ScanRun.ResultState.SUCCESS - assert response.urls_crawled_count == 1935 - assert response.urls_tested_count == 1846 - assert response.has_vulnerabilities is True - assert response.progress_percent == 1733 @@ -2040,17 +1987,19 @@ async def test_start_scan_run_async_from_dict(): def test_start_scan_run_field_headers(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.StartScanRunRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.start_scan_run), "__call__") as call: call.return_value = scan_run.ScanRun() - client.start_scan_run(request) # Establish that the underlying gRPC stub method was called. @@ -2066,18 +2015,18 @@ def test_start_scan_run_field_headers(): @pytest.mark.asyncio async def test_start_scan_run_field_headers_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.StartScanRunRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.start_scan_run), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(scan_run.ScanRun()) - await client.start_scan_run(request) # Establish that the underlying gRPC stub method was called. @@ -2091,13 +2040,14 @@ async def test_start_scan_run_field_headers_async(): def test_start_scan_run_flattened(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.start_scan_run), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = scan_run.ScanRun() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.start_scan_run(name="name_value",) @@ -2106,12 +2056,13 @@ def test_start_scan_run_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_start_scan_run_flattened_error(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2124,7 +2075,7 @@ def test_start_scan_run_flattened_error(): @pytest.mark.asyncio async def test_start_scan_run_flattened_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2141,14 +2092,13 @@ async def test_start_scan_run_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @pytest.mark.asyncio async def test_start_scan_run_flattened_error_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -2163,7 +2113,7 @@ def test_get_scan_run( transport: str = "grpc", request_type=web_security_scanner.GetScanRunRequest ): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2182,31 +2132,21 @@ def test_get_scan_run( has_vulnerabilities=True, progress_percent=1733, ) - response = client.get_scan_run(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.GetScanRunRequest() # Establish that the response is the type that we expect. - assert isinstance(response, scan_run.ScanRun) - assert response.name == "name_value" - assert response.execution_state == scan_run.ScanRun.ExecutionState.QUEUED - assert response.result_state == scan_run.ScanRun.ResultState.SUCCESS - assert response.urls_crawled_count == 1935 - assert response.urls_tested_count == 1846 - assert response.has_vulnerabilities is True - assert response.progress_percent == 1733 @@ -2218,7 +2158,7 @@ def test_get_scan_run_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2226,7 +2166,6 @@ def test_get_scan_run_empty_call(): client.get_scan_run() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.GetScanRunRequest() @@ -2235,7 +2174,7 @@ async def test_get_scan_run_async( transport: str = "grpc_asyncio", request_type=web_security_scanner.GetScanRunRequest ): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2256,30 +2195,21 @@ async def test_get_scan_run_async( progress_percent=1733, ) ) - response = await client.get_scan_run(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.GetScanRunRequest() # Establish that the response is the type that we expect. assert isinstance(response, scan_run.ScanRun) - assert response.name == "name_value" - assert response.execution_state == scan_run.ScanRun.ExecutionState.QUEUED - assert response.result_state == scan_run.ScanRun.ResultState.SUCCESS - assert response.urls_crawled_count == 1935 - assert response.urls_tested_count == 1846 - assert response.has_vulnerabilities is True - assert response.progress_percent == 1733 @@ -2289,17 +2219,19 @@ async def test_get_scan_run_async_from_dict(): def test_get_scan_run_field_headers(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.GetScanRunRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_scan_run), "__call__") as call: call.return_value = scan_run.ScanRun() - client.get_scan_run(request) # Establish that the underlying gRPC stub method was called. @@ -2315,18 +2247,18 @@ def test_get_scan_run_field_headers(): @pytest.mark.asyncio async def test_get_scan_run_field_headers_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.GetScanRunRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_scan_run), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(scan_run.ScanRun()) - await client.get_scan_run(request) # Establish that the underlying gRPC stub method was called. @@ -2340,13 +2272,14 @@ async def test_get_scan_run_field_headers_async(): def test_get_scan_run_flattened(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_scan_run), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = scan_run.ScanRun() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.get_scan_run(name="name_value",) @@ -2355,12 +2288,13 @@ def test_get_scan_run_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_get_scan_run_flattened_error(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2373,7 +2307,7 @@ def test_get_scan_run_flattened_error(): @pytest.mark.asyncio async def test_get_scan_run_flattened_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2390,14 +2324,13 @@ async def test_get_scan_run_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @pytest.mark.asyncio async def test_get_scan_run_flattened_error_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -2412,7 +2345,7 @@ def test_list_scan_runs( transport: str = "grpc", request_type=web_security_scanner.ListScanRunsRequest ): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2425,19 +2358,15 @@ def test_list_scan_runs( call.return_value = web_security_scanner.ListScanRunsResponse( next_page_token="next_page_token_value", ) - response = client.list_scan_runs(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.ListScanRunsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListScanRunsPager) - assert response.next_page_token == "next_page_token_value" @@ -2449,7 +2378,7 @@ def test_list_scan_runs_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2457,7 +2386,6 @@ def test_list_scan_runs_empty_call(): client.list_scan_runs() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.ListScanRunsRequest() @@ -2467,7 +2395,7 @@ async def test_list_scan_runs_async( request_type=web_security_scanner.ListScanRunsRequest, ): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2482,18 +2410,15 @@ async def test_list_scan_runs_async( next_page_token="next_page_token_value", ) ) - response = await client.list_scan_runs(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.ListScanRunsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListScanRunsAsyncPager) - assert response.next_page_token == "next_page_token_value" @@ -2503,17 +2428,19 @@ async def test_list_scan_runs_async_from_dict(): def test_list_scan_runs_field_headers(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.ListScanRunsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_scan_runs), "__call__") as call: call.return_value = web_security_scanner.ListScanRunsResponse() - client.list_scan_runs(request) # Establish that the underlying gRPC stub method was called. @@ -2529,12 +2456,13 @@ def test_list_scan_runs_field_headers(): @pytest.mark.asyncio async def test_list_scan_runs_field_headers_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.ListScanRunsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2542,7 +2470,6 @@ async def test_list_scan_runs_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( web_security_scanner.ListScanRunsResponse() ) - await client.list_scan_runs(request) # Establish that the underlying gRPC stub method was called. @@ -2556,13 +2483,14 @@ async def test_list_scan_runs_field_headers_async(): def test_list_scan_runs_flattened(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_scan_runs), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = web_security_scanner.ListScanRunsResponse() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.list_scan_runs(parent="parent_value",) @@ -2571,12 +2499,13 @@ def test_list_scan_runs_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" def test_list_scan_runs_flattened_error(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2589,7 +2518,7 @@ def test_list_scan_runs_flattened_error(): @pytest.mark.asyncio async def test_list_scan_runs_flattened_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2608,14 +2537,13 @@ async def test_list_scan_runs_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" @pytest.mark.asyncio async def test_list_scan_runs_flattened_error_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -2627,7 +2555,7 @@ async def test_list_scan_runs_flattened_error_async(): def test_list_scan_runs_pager(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials,) + client = WebSecurityScannerClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_scan_runs), "__call__") as call: @@ -2663,7 +2591,7 @@ def test_list_scan_runs_pager(): def test_list_scan_runs_pages(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials,) + client = WebSecurityScannerClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_scan_runs), "__call__") as call: @@ -2692,7 +2620,7 @@ def test_list_scan_runs_pages(): @pytest.mark.asyncio async def test_list_scan_runs_async_pager(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2729,7 +2657,7 @@ async def test_list_scan_runs_async_pager(): @pytest.mark.asyncio async def test_list_scan_runs_async_pages(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2764,7 +2692,7 @@ def test_stop_scan_run( transport: str = "grpc", request_type=web_security_scanner.StopScanRunRequest ): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2783,31 +2711,21 @@ def test_stop_scan_run( has_vulnerabilities=True, progress_percent=1733, ) - response = client.stop_scan_run(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.StopScanRunRequest() # Establish that the response is the type that we expect. - assert isinstance(response, scan_run.ScanRun) - assert response.name == "name_value" - assert response.execution_state == scan_run.ScanRun.ExecutionState.QUEUED - assert response.result_state == scan_run.ScanRun.ResultState.SUCCESS - assert response.urls_crawled_count == 1935 - assert response.urls_tested_count == 1846 - assert response.has_vulnerabilities is True - assert response.progress_percent == 1733 @@ -2819,7 +2737,7 @@ def test_stop_scan_run_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2827,7 +2745,6 @@ def test_stop_scan_run_empty_call(): client.stop_scan_run() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.StopScanRunRequest() @@ -2837,7 +2754,7 @@ async def test_stop_scan_run_async( request_type=web_security_scanner.StopScanRunRequest, ): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2858,30 +2775,21 @@ async def test_stop_scan_run_async( progress_percent=1733, ) ) - response = await client.stop_scan_run(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.StopScanRunRequest() # Establish that the response is the type that we expect. assert isinstance(response, scan_run.ScanRun) - assert response.name == "name_value" - assert response.execution_state == scan_run.ScanRun.ExecutionState.QUEUED - assert response.result_state == scan_run.ScanRun.ResultState.SUCCESS - assert response.urls_crawled_count == 1935 - assert response.urls_tested_count == 1846 - assert response.has_vulnerabilities is True - assert response.progress_percent == 1733 @@ -2891,17 +2799,19 @@ async def test_stop_scan_run_async_from_dict(): def test_stop_scan_run_field_headers(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.StopScanRunRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.stop_scan_run), "__call__") as call: call.return_value = scan_run.ScanRun() - client.stop_scan_run(request) # Establish that the underlying gRPC stub method was called. @@ -2917,18 +2827,18 @@ def test_stop_scan_run_field_headers(): @pytest.mark.asyncio async def test_stop_scan_run_field_headers_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.StopScanRunRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.stop_scan_run), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(scan_run.ScanRun()) - await client.stop_scan_run(request) # Establish that the underlying gRPC stub method was called. @@ -2942,13 +2852,14 @@ async def test_stop_scan_run_field_headers_async(): def test_stop_scan_run_flattened(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.stop_scan_run), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = scan_run.ScanRun() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.stop_scan_run(name="name_value",) @@ -2957,12 +2868,13 @@ def test_stop_scan_run_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_stop_scan_run_flattened_error(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2975,7 +2887,7 @@ def test_stop_scan_run_flattened_error(): @pytest.mark.asyncio async def test_stop_scan_run_flattened_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2992,14 +2904,13 @@ async def test_stop_scan_run_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @pytest.mark.asyncio async def test_stop_scan_run_flattened_error_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -3014,7 +2925,7 @@ def test_list_crawled_urls( transport: str = "grpc", request_type=web_security_scanner.ListCrawledUrlsRequest ): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3029,19 +2940,15 @@ def test_list_crawled_urls( call.return_value = web_security_scanner.ListCrawledUrlsResponse( next_page_token="next_page_token_value", ) - response = client.list_crawled_urls(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.ListCrawledUrlsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListCrawledUrlsPager) - assert response.next_page_token == "next_page_token_value" @@ -3053,7 +2960,7 @@ def test_list_crawled_urls_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3063,7 +2970,6 @@ def test_list_crawled_urls_empty_call(): client.list_crawled_urls() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.ListCrawledUrlsRequest() @@ -3073,7 +2979,7 @@ async def test_list_crawled_urls_async( request_type=web_security_scanner.ListCrawledUrlsRequest, ): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3090,18 +2996,15 @@ async def test_list_crawled_urls_async( next_page_token="next_page_token_value", ) ) - response = await client.list_crawled_urls(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.ListCrawledUrlsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListCrawledUrlsAsyncPager) - assert response.next_page_token == "next_page_token_value" @@ -3111,11 +3014,14 @@ async def test_list_crawled_urls_async_from_dict(): def test_list_crawled_urls_field_headers(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.ListCrawledUrlsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -3123,7 +3029,6 @@ def test_list_crawled_urls_field_headers(): type(client.transport.list_crawled_urls), "__call__" ) as call: call.return_value = web_security_scanner.ListCrawledUrlsResponse() - client.list_crawled_urls(request) # Establish that the underlying gRPC stub method was called. @@ -3139,12 +3044,13 @@ def test_list_crawled_urls_field_headers(): @pytest.mark.asyncio async def test_list_crawled_urls_field_headers_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.ListCrawledUrlsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -3154,7 +3060,6 @@ async def test_list_crawled_urls_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( web_security_scanner.ListCrawledUrlsResponse() ) - await client.list_crawled_urls(request) # Establish that the underlying gRPC stub method was called. @@ -3168,7 +3073,9 @@ async def test_list_crawled_urls_field_headers_async(): def test_list_crawled_urls_flattened(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3176,7 +3083,6 @@ def test_list_crawled_urls_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = web_security_scanner.ListCrawledUrlsResponse() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.list_crawled_urls(parent="parent_value",) @@ -3185,12 +3091,13 @@ def test_list_crawled_urls_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" def test_list_crawled_urls_flattened_error(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -3203,7 +3110,7 @@ def test_list_crawled_urls_flattened_error(): @pytest.mark.asyncio async def test_list_crawled_urls_flattened_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3224,14 +3131,13 @@ async def test_list_crawled_urls_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" @pytest.mark.asyncio async def test_list_crawled_urls_flattened_error_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -3243,7 +3149,7 @@ async def test_list_crawled_urls_flattened_error_async(): def test_list_crawled_urls_pager(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials,) + client = WebSecurityScannerClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3285,7 +3191,7 @@ def test_list_crawled_urls_pager(): def test_list_crawled_urls_pages(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials,) + client = WebSecurityScannerClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3320,7 +3226,7 @@ def test_list_crawled_urls_pages(): @pytest.mark.asyncio async def test_list_crawled_urls_async_pager(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3363,7 +3269,7 @@ async def test_list_crawled_urls_async_pager(): @pytest.mark.asyncio async def test_list_crawled_urls_async_pages(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3404,7 +3310,7 @@ def test_get_finding( transport: str = "grpc", request_type=web_security_scanner.GetFindingRequest ): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3426,37 +3332,24 @@ def test_get_finding( final_url="final_url_value", tracking_id="tracking_id_value", ) - response = client.get_finding(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.GetFindingRequest() # Establish that the response is the type that we expect. - assert isinstance(response, finding.Finding) - assert response.name == "name_value" - assert response.finding_type == finding.Finding.FindingType.MIXED_CONTENT - assert response.http_method == "http_method_value" - assert response.fuzzed_url == "fuzzed_url_value" - assert response.body == "body_value" - assert response.description == "description_value" - assert response.reproduction_url == "reproduction_url_value" - assert response.frame_url == "frame_url_value" - assert response.final_url == "final_url_value" - assert response.tracking_id == "tracking_id_value" @@ -3468,7 +3361,7 @@ def test_get_finding_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3476,7 +3369,6 @@ def test_get_finding_empty_call(): client.get_finding() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.GetFindingRequest() @@ -3485,7 +3377,7 @@ async def test_get_finding_async( transport: str = "grpc_asyncio", request_type=web_security_scanner.GetFindingRequest ): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3509,36 +3401,24 @@ async def test_get_finding_async( tracking_id="tracking_id_value", ) ) - response = await client.get_finding(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.GetFindingRequest() # Establish that the response is the type that we expect. assert isinstance(response, finding.Finding) - assert response.name == "name_value" - assert response.finding_type == finding.Finding.FindingType.MIXED_CONTENT - assert response.http_method == "http_method_value" - assert response.fuzzed_url == "fuzzed_url_value" - assert response.body == "body_value" - assert response.description == "description_value" - assert response.reproduction_url == "reproduction_url_value" - assert response.frame_url == "frame_url_value" - assert response.final_url == "final_url_value" - assert response.tracking_id == "tracking_id_value" @@ -3548,17 +3428,19 @@ async def test_get_finding_async_from_dict(): def test_get_finding_field_headers(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.GetFindingRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_finding), "__call__") as call: call.return_value = finding.Finding() - client.get_finding(request) # Establish that the underlying gRPC stub method was called. @@ -3574,18 +3456,18 @@ def test_get_finding_field_headers(): @pytest.mark.asyncio async def test_get_finding_field_headers_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.GetFindingRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_finding), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(finding.Finding()) - await client.get_finding(request) # Establish that the underlying gRPC stub method was called. @@ -3599,13 +3481,14 @@ async def test_get_finding_field_headers_async(): def test_get_finding_flattened(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_finding), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = finding.Finding() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.get_finding(name="name_value",) @@ -3614,12 +3497,13 @@ def test_get_finding_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_get_finding_flattened_error(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -3632,7 +3516,7 @@ def test_get_finding_flattened_error(): @pytest.mark.asyncio async def test_get_finding_flattened_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3649,14 +3533,13 @@ async def test_get_finding_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @pytest.mark.asyncio async def test_get_finding_flattened_error_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -3671,7 +3554,7 @@ def test_list_findings( transport: str = "grpc", request_type=web_security_scanner.ListFindingsRequest ): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3684,19 +3567,15 @@ def test_list_findings( call.return_value = web_security_scanner.ListFindingsResponse( next_page_token="next_page_token_value", ) - response = client.list_findings(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.ListFindingsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListFindingsPager) - assert response.next_page_token == "next_page_token_value" @@ -3708,7 +3587,7 @@ def test_list_findings_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3716,7 +3595,6 @@ def test_list_findings_empty_call(): client.list_findings() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.ListFindingsRequest() @@ -3726,7 +3604,7 @@ async def test_list_findings_async( request_type=web_security_scanner.ListFindingsRequest, ): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3741,18 +3619,15 @@ async def test_list_findings_async( next_page_token="next_page_token_value", ) ) - response = await client.list_findings(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.ListFindingsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListFindingsAsyncPager) - assert response.next_page_token == "next_page_token_value" @@ -3762,17 +3637,19 @@ async def test_list_findings_async_from_dict(): def test_list_findings_field_headers(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.ListFindingsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_findings), "__call__") as call: call.return_value = web_security_scanner.ListFindingsResponse() - client.list_findings(request) # Establish that the underlying gRPC stub method was called. @@ -3788,12 +3665,13 @@ def test_list_findings_field_headers(): @pytest.mark.asyncio async def test_list_findings_field_headers_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.ListFindingsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -3801,7 +3679,6 @@ async def test_list_findings_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( web_security_scanner.ListFindingsResponse() ) - await client.list_findings(request) # Establish that the underlying gRPC stub method was called. @@ -3815,13 +3692,14 @@ async def test_list_findings_field_headers_async(): def test_list_findings_flattened(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_findings), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = web_security_scanner.ListFindingsResponse() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.list_findings( @@ -3832,14 +3710,14 @@ def test_list_findings_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].filter == "filter_value" def test_list_findings_flattened_error(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -3854,7 +3732,7 @@ def test_list_findings_flattened_error(): @pytest.mark.asyncio async def test_list_findings_flattened_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3875,16 +3753,14 @@ async def test_list_findings_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].filter == "filter_value" @pytest.mark.asyncio async def test_list_findings_flattened_error_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -3898,7 +3774,7 @@ async def test_list_findings_flattened_error_async(): def test_list_findings_pager(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials,) + client = WebSecurityScannerClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_findings), "__call__") as call: @@ -3934,7 +3810,7 @@ def test_list_findings_pager(): def test_list_findings_pages(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials,) + client = WebSecurityScannerClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_findings), "__call__") as call: @@ -3963,7 +3839,7 @@ def test_list_findings_pages(): @pytest.mark.asyncio async def test_list_findings_async_pager(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4000,7 +3876,7 @@ async def test_list_findings_async_pager(): @pytest.mark.asyncio async def test_list_findings_async_pages(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4036,7 +3912,7 @@ def test_list_finding_type_stats( request_type=web_security_scanner.ListFindingTypeStatsRequest, ): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4049,17 +3925,14 @@ def test_list_finding_type_stats( ) as call: # Designate an appropriate return value for the call. call.return_value = web_security_scanner.ListFindingTypeStatsResponse() - response = client.list_finding_type_stats(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.ListFindingTypeStatsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, web_security_scanner.ListFindingTypeStatsResponse) @@ -4071,7 +3944,7 @@ def test_list_finding_type_stats_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4081,7 +3954,6 @@ def test_list_finding_type_stats_empty_call(): client.list_finding_type_stats() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.ListFindingTypeStatsRequest() @@ -4091,7 +3963,7 @@ async def test_list_finding_type_stats_async( request_type=web_security_scanner.ListFindingTypeStatsRequest, ): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4106,13 +3978,11 @@ async def test_list_finding_type_stats_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( web_security_scanner.ListFindingTypeStatsResponse() ) - response = await client.list_finding_type_stats(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.ListFindingTypeStatsRequest() # Establish that the response is the type that we expect. @@ -4125,11 +3995,14 @@ async def test_list_finding_type_stats_async_from_dict(): def test_list_finding_type_stats_field_headers(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.ListFindingTypeStatsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -4137,7 +4010,6 @@ def test_list_finding_type_stats_field_headers(): type(client.transport.list_finding_type_stats), "__call__" ) as call: call.return_value = web_security_scanner.ListFindingTypeStatsResponse() - client.list_finding_type_stats(request) # Establish that the underlying gRPC stub method was called. @@ -4153,12 +4025,13 @@ def test_list_finding_type_stats_field_headers(): @pytest.mark.asyncio async def test_list_finding_type_stats_field_headers_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.ListFindingTypeStatsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -4168,7 +4041,6 @@ async def test_list_finding_type_stats_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( web_security_scanner.ListFindingTypeStatsResponse() ) - await client.list_finding_type_stats(request) # Establish that the underlying gRPC stub method was called. @@ -4182,7 +4054,9 @@ async def test_list_finding_type_stats_field_headers_async(): def test_list_finding_type_stats_flattened(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4190,7 +4064,6 @@ def test_list_finding_type_stats_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = web_security_scanner.ListFindingTypeStatsResponse() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.list_finding_type_stats(parent="parent_value",) @@ -4199,12 +4072,13 @@ def test_list_finding_type_stats_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" def test_list_finding_type_stats_flattened_error(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -4217,7 +4091,7 @@ def test_list_finding_type_stats_flattened_error(): @pytest.mark.asyncio async def test_list_finding_type_stats_flattened_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4238,14 +4112,13 @@ async def test_list_finding_type_stats_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" @pytest.mark.asyncio async def test_list_finding_type_stats_flattened_error_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -4259,16 +4132,16 @@ async def test_list_finding_type_stats_flattened_error_async(): def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.WebSecurityScannerGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.WebSecurityScannerGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = WebSecurityScannerClient( @@ -4278,7 +4151,7 @@ def test_credentials_transport_error(): # It is an error to provide scopes and a transport instance. transport = transports.WebSecurityScannerGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = WebSecurityScannerClient( @@ -4289,7 +4162,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.WebSecurityScannerGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) client = WebSecurityScannerClient(transport=transport) assert client.transport is transport @@ -4298,13 +4171,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.WebSecurityScannerGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel transport = transports.WebSecurityScannerGrpcAsyncIOTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel @@ -4319,23 +4192,25 @@ def test_transport_get_channel(): ) def test_transport_adc(transport_class): # Test default credentials are used if not provided. - with mock.patch.object(auth, "default") as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport_class() adc.assert_called_once() def test_transport_grpc_default(): # A client should use the gRPC transport by default. - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) assert isinstance(client.transport, transports.WebSecurityScannerGrpcTransport,) def test_web_security_scanner_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error - with pytest.raises(exceptions.DuplicateCredentialArgs): + with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.WebSecurityScannerTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), credentials_file="credentials.json", ) @@ -4347,7 +4222,7 @@ def test_web_security_scanner_base_transport(): ) as Transport: Transport.return_value = None transport = transports.WebSecurityScannerTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Every method on the transport should just blindly @@ -4372,15 +4247,37 @@ def test_web_security_scanner_base_transport(): getattr(transport, method)(request=object()) +@requires_google_auth_gte_1_25_0 def test_web_security_scanner_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( - auth, "load_credentials_from_file" + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch( + "google.cloud.websecurityscanner_v1alpha.services.web_security_scanner.transports.WebSecurityScannerTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.WebSecurityScannerTransport( + credentials_file="credentials.json", quota_project_id="octopus", + ) + load_creds.assert_called_once_with( + "credentials.json", + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", + ) + + +@requires_google_auth_lt_1_25_0 +def test_web_security_scanner_base_transport_with_credentials_file_old_google_auth(): + # Instantiate the base transport with a credentials file + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True ) as load_creds, mock.patch( "google.cloud.websecurityscanner_v1alpha.services.web_security_scanner.transports.WebSecurityScannerTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (credentials.AnonymousCredentials(), None) + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.WebSecurityScannerTransport( credentials_file="credentials.json", quota_project_id="octopus", ) @@ -4393,19 +4290,33 @@ def test_web_security_scanner_base_transport_with_credentials_file(): def test_web_security_scanner_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(auth, "default") as adc, mock.patch( + with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( "google.cloud.websecurityscanner_v1alpha.services.web_security_scanner.transports.WebSecurityScannerTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (credentials.AnonymousCredentials(), None) + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.WebSecurityScannerTransport() adc.assert_called_once() +@requires_google_auth_gte_1_25_0 def test_web_security_scanner_auth_adc(): # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(auth, "default") as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + WebSecurityScannerClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id=None, + ) + + +@requires_google_auth_lt_1_25_0 +def test_web_security_scanner_auth_adc_old_google_auth(): + # If no credentials are provided, we should use ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) WebSecurityScannerClient() adc.assert_called_once_with( scopes=("https://www.googleapis.com/auth/cloud-platform",), @@ -4413,20 +4324,156 @@ def test_web_security_scanner_auth_adc(): ) -def test_web_security_scanner_transport_auth_adc(): +@pytest.mark.parametrize( + "transport_class", + [ + transports.WebSecurityScannerGrpcTransport, + transports.WebSecurityScannerGrpcAsyncIOTransport, + ], +) +@requires_google_auth_gte_1_25_0 +def test_web_security_scanner_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object(auth, "default") as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) - transports.WebSecurityScannerGrpcTransport( - host="squid.clam.whelk", quota_project_id="octopus" + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + adc.assert_called_once_with( + scopes=["1", "2"], + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.WebSecurityScannerGrpcTransport, + transports.WebSecurityScannerGrpcAsyncIOTransport, + ], +) +@requires_google_auth_lt_1_25_0 +def test_web_security_scanner_transport_auth_adc_old_google_auth(transport_class): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus") adc.assert_called_once_with( scopes=("https://www.googleapis.com/auth/cloud-platform",), quota_project_id="octopus", ) +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.WebSecurityScannerGrpcTransport, grpc_helpers), + (transports.WebSecurityScannerGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_gte_1_26_0 +def test_web_security_scanner_transport_create_channel(transport_class, grpc_helpers): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + + create_channel.assert_called_with( + "websecurityscanner.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=["1", "2"], + default_host="websecurityscanner.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.WebSecurityScannerGrpcTransport, grpc_helpers), + (transports.WebSecurityScannerGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_web_security_scanner_transport_create_channel_old_api_core( + transport_class, grpc_helpers +): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class(quota_project_id="octopus") + + create_channel.assert_called_with( + "websecurityscanner.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + scopes=("https://www.googleapis.com/auth/cloud-platform",), + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.WebSecurityScannerGrpcTransport, grpc_helpers), + (transports.WebSecurityScannerGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_web_security_scanner_transport_create_channel_user_scopes( + transport_class, grpc_helpers +): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + + create_channel.assert_called_with( + "websecurityscanner.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + scopes=["1", "2"], + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + @pytest.mark.parametrize( "transport_class", [ @@ -4437,7 +4484,7 @@ def test_web_security_scanner_transport_auth_adc(): def test_web_security_scanner_grpc_transport_client_cert_source_for_mtls( transport_class, ): - cred = credentials.AnonymousCredentials() + cred = ga_credentials.AnonymousCredentials() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -4476,7 +4523,7 @@ def test_web_security_scanner_grpc_transport_client_cert_source_for_mtls( def test_web_security_scanner_host_no_port(): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="websecurityscanner.googleapis.com" ), @@ -4486,7 +4533,7 @@ def test_web_security_scanner_host_no_port(): def test_web_security_scanner_host_with_port(): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="websecurityscanner.googleapis.com:8000" ), @@ -4542,9 +4589,9 @@ def test_web_security_scanner_transport_channel_mtls_with_client_cert_source( mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = credentials.AnonymousCredentials() + cred = ga_credentials.AnonymousCredentials() with pytest.warns(DeprecationWarning): - with mock.patch.object(auth, "default") as adc: + with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) transport = transport_class( host="squid.clam.whelk", @@ -4623,7 +4670,6 @@ def test_finding_path(): scan_config = "clam" scan_run = "whelk" finding = "octopus" - expected = "projects/{project}/scanConfigs/{scan_config}/scanRuns/{scan_run}/findings/{finding}".format( project=project, scan_config=scan_config, scan_run=scan_run, finding=finding, ) @@ -4650,7 +4696,6 @@ def test_parse_finding_path(): def test_scan_config_path(): project = "winkle" scan_config = "nautilus" - expected = "projects/{project}/scanConfigs/{scan_config}".format( project=project, scan_config=scan_config, ) @@ -4674,7 +4719,6 @@ def test_scan_run_path(): project = "squid" scan_config = "clam" scan_run = "whelk" - expected = "projects/{project}/scanConfigs/{scan_config}/scanRuns/{scan_run}".format( project=project, scan_config=scan_config, scan_run=scan_run, ) @@ -4697,7 +4741,6 @@ def test_parse_scan_run_path(): def test_common_billing_account_path(): billing_account = "cuttlefish" - expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -4718,7 +4761,6 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "winkle" - expected = "folders/{folder}".format(folder=folder,) actual = WebSecurityScannerClient.common_folder_path(folder) assert expected == actual @@ -4737,7 +4779,6 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "scallop" - expected = "organizations/{organization}".format(organization=organization,) actual = WebSecurityScannerClient.common_organization_path(organization) assert expected == actual @@ -4756,7 +4797,6 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "squid" - expected = "projects/{project}".format(project=project,) actual = WebSecurityScannerClient.common_project_path(project) assert expected == actual @@ -4776,7 +4816,6 @@ def test_parse_common_project_path(): def test_common_location_path(): project = "whelk" location = "octopus" - expected = "projects/{project}/locations/{location}".format( project=project, location=location, ) @@ -4803,7 +4842,7 @@ def test_client_withDEFAULT_CLIENT_INFO(): transports.WebSecurityScannerTransport, "_prep_wrapped_messages" ) as prep: client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -4812,6 +4851,6 @@ def test_client_withDEFAULT_CLIENT_INFO(): ) as prep: transport_class = WebSecurityScannerClient.get_transport_class() transport = transport_class( - credentials=credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) diff --git a/tests/unit/gapic/websecurityscanner_v1beta/__init__.py b/tests/unit/gapic/websecurityscanner_v1beta/__init__.py index 42ffdf2..4de6597 100644 --- a/tests/unit/gapic/websecurityscanner_v1beta/__init__.py +++ b/tests/unit/gapic/websecurityscanner_v1beta/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/unit/gapic/websecurityscanner_v1beta/test_web_security_scanner.py b/tests/unit/gapic/websecurityscanner_v1beta/test_web_security_scanner.py index 7952c4b..95af609 100644 --- a/tests/unit/gapic/websecurityscanner_v1beta/test_web_security_scanner.py +++ b/tests/unit/gapic/websecurityscanner_v1beta/test_web_security_scanner.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import os import mock +import packaging.version import grpc from grpc.experimental import aio @@ -24,13 +23,13 @@ import pytest from proto.marshal.rules.dates import DurationRule, TimestampRule -from google import auth + from google.api_core import client_options -from google.api_core import exceptions +from google.api_core import exceptions as core_exceptions from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async -from google.auth import credentials +from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.websecurityscanner_v1beta.services.web_security_scanner import ( WebSecurityScannerAsyncClient, @@ -42,6 +41,12 @@ from google.cloud.websecurityscanner_v1beta.services.web_security_scanner import ( transports, ) +from google.cloud.websecurityscanner_v1beta.services.web_security_scanner.transports.base import ( + _API_CORE_VERSION, +) +from google.cloud.websecurityscanner_v1beta.services.web_security_scanner.transports.base import ( + _GOOGLE_AUTH_VERSION, +) from google.cloud.websecurityscanner_v1beta.types import crawled_url from google.cloud.websecurityscanner_v1beta.types import finding from google.cloud.websecurityscanner_v1beta.types import finding_addon @@ -54,8 +59,32 @@ from google.cloud.websecurityscanner_v1beta.types import scan_run_warning_trace from google.cloud.websecurityscanner_v1beta.types import web_security_scanner from google.oauth2 import service_account -from google.protobuf import field_mask_pb2 as field_mask # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +import google.auth + + +# TODO(busunkim): Once google-api-core >= 1.26.0 is required: +# - Delete all the api-core and auth "less than" test cases +# - Delete these pytest markers (Make the "greater than or equal to" tests the default). +requires_google_auth_lt_1_25_0 = pytest.mark.skipif( + packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), + reason="This test requires google-auth < 1.25.0", +) +requires_google_auth_gte_1_25_0 = pytest.mark.skipif( + packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), + reason="This test requires google-auth >= 1.25.0", +) + +requires_api_core_lt_1_26_0 = pytest.mark.skipif( + packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), + reason="This test requires google-api-core < 1.26.0", +) + +requires_api_core_gte_1_26_0 = pytest.mark.skipif( + packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), + reason="This test requires google-api-core >= 1.26.0", +) def client_cert_source_callback(): @@ -107,7 +136,7 @@ def test__get_default_mtls_endpoint(): "client_class", [WebSecurityScannerClient, WebSecurityScannerAsyncClient,] ) def test_web_security_scanner_client_from_service_account_info(client_class): - creds = credentials.AnonymousCredentials() + creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -124,7 +153,7 @@ def test_web_security_scanner_client_from_service_account_info(client_class): "client_class", [WebSecurityScannerClient, WebSecurityScannerAsyncClient,] ) def test_web_security_scanner_client_from_service_account_file(client_class): - creds = credentials.AnonymousCredentials() + creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -177,7 +206,7 @@ def test_web_security_scanner_client_client_options( ): # Check that if channel is provided we won't create a new one. with mock.patch.object(WebSecurityScannerClient, "get_transport_class") as gtc: - transport = transport_class(credentials=credentials.AnonymousCredentials()) + transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) client = client_class(transport=transport) gtc.assert_not_called() @@ -475,7 +504,7 @@ def test_create_scan_config( transport: str = "grpc", request_type=web_security_scanner.CreateScanConfigRequest ): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -498,40 +527,28 @@ def test_create_scan_config( export_to_security_command_center=gcw_scan_config.ScanConfig.ExportToSecurityCommandCenter.ENABLED, risk_level=gcw_scan_config.ScanConfig.RiskLevel.NORMAL, ) - response = client.create_scan_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.CreateScanConfigRequest() # Establish that the response is the type that we expect. - assert isinstance(response, gcw_scan_config.ScanConfig) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.max_qps == 761 - assert response.starting_urls == ["starting_urls_value"] - assert response.user_agent == gcw_scan_config.ScanConfig.UserAgent.CHROME_LINUX - assert response.blacklist_patterns == ["blacklist_patterns_value"] - assert response.target_platforms == [ gcw_scan_config.ScanConfig.TargetPlatform.APP_ENGINE ] - assert ( response.export_to_security_command_center == gcw_scan_config.ScanConfig.ExportToSecurityCommandCenter.ENABLED ) - assert response.risk_level == gcw_scan_config.ScanConfig.RiskLevel.NORMAL @@ -543,7 +560,7 @@ def test_create_scan_config_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -553,7 +570,6 @@ def test_create_scan_config_empty_call(): client.create_scan_config() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.CreateScanConfigRequest() @@ -563,7 +579,7 @@ async def test_create_scan_config_async( request_type=web_security_scanner.CreateScanConfigRequest, ): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -588,39 +604,28 @@ async def test_create_scan_config_async( risk_level=gcw_scan_config.ScanConfig.RiskLevel.NORMAL, ) ) - response = await client.create_scan_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.CreateScanConfigRequest() # Establish that the response is the type that we expect. assert isinstance(response, gcw_scan_config.ScanConfig) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.max_qps == 761 - assert response.starting_urls == ["starting_urls_value"] - assert response.user_agent == gcw_scan_config.ScanConfig.UserAgent.CHROME_LINUX - assert response.blacklist_patterns == ["blacklist_patterns_value"] - assert response.target_platforms == [ gcw_scan_config.ScanConfig.TargetPlatform.APP_ENGINE ] - assert ( response.export_to_security_command_center == gcw_scan_config.ScanConfig.ExportToSecurityCommandCenter.ENABLED ) - assert response.risk_level == gcw_scan_config.ScanConfig.RiskLevel.NORMAL @@ -630,11 +635,14 @@ async def test_create_scan_config_async_from_dict(): def test_create_scan_config_field_headers(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.CreateScanConfigRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -642,7 +650,6 @@ def test_create_scan_config_field_headers(): type(client.transport.create_scan_config), "__call__" ) as call: call.return_value = gcw_scan_config.ScanConfig() - client.create_scan_config(request) # Establish that the underlying gRPC stub method was called. @@ -658,12 +665,13 @@ def test_create_scan_config_field_headers(): @pytest.mark.asyncio async def test_create_scan_config_field_headers_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.CreateScanConfigRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -673,7 +681,6 @@ async def test_create_scan_config_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( gcw_scan_config.ScanConfig() ) - await client.create_scan_config(request) # Establish that the underlying gRPC stub method was called. @@ -687,7 +694,9 @@ async def test_create_scan_config_field_headers_async(): def test_create_scan_config_flattened(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -695,7 +704,6 @@ def test_create_scan_config_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = gcw_scan_config.ScanConfig() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.create_scan_config( @@ -707,14 +715,14 @@ def test_create_scan_config_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].scan_config == gcw_scan_config.ScanConfig(name="name_value") def test_create_scan_config_flattened_error(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -729,7 +737,7 @@ def test_create_scan_config_flattened_error(): @pytest.mark.asyncio async def test_create_scan_config_flattened_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -753,16 +761,14 @@ async def test_create_scan_config_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].scan_config == gcw_scan_config.ScanConfig(name="name_value") @pytest.mark.asyncio async def test_create_scan_config_flattened_error_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -779,7 +785,7 @@ def test_delete_scan_config( transport: str = "grpc", request_type=web_security_scanner.DeleteScanConfigRequest ): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -792,13 +798,11 @@ def test_delete_scan_config( ) as call: # Designate an appropriate return value for the call. call.return_value = None - response = client.delete_scan_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.DeleteScanConfigRequest() # Establish that the response is the type that we expect. @@ -813,7 +817,7 @@ def test_delete_scan_config_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -823,7 +827,6 @@ def test_delete_scan_config_empty_call(): client.delete_scan_config() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.DeleteScanConfigRequest() @@ -833,7 +836,7 @@ async def test_delete_scan_config_async( request_type=web_security_scanner.DeleteScanConfigRequest, ): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -846,13 +849,11 @@ async def test_delete_scan_config_async( ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - response = await client.delete_scan_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.DeleteScanConfigRequest() # Establish that the response is the type that we expect. @@ -865,11 +866,14 @@ async def test_delete_scan_config_async_from_dict(): def test_delete_scan_config_field_headers(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.DeleteScanConfigRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -877,7 +881,6 @@ def test_delete_scan_config_field_headers(): type(client.transport.delete_scan_config), "__call__" ) as call: call.return_value = None - client.delete_scan_config(request) # Establish that the underlying gRPC stub method was called. @@ -893,12 +896,13 @@ def test_delete_scan_config_field_headers(): @pytest.mark.asyncio async def test_delete_scan_config_field_headers_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.DeleteScanConfigRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -906,7 +910,6 @@ async def test_delete_scan_config_field_headers_async(): type(client.transport.delete_scan_config), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - await client.delete_scan_config(request) # Establish that the underlying gRPC stub method was called. @@ -920,7 +923,9 @@ async def test_delete_scan_config_field_headers_async(): def test_delete_scan_config_flattened(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -928,7 +933,6 @@ def test_delete_scan_config_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = None - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.delete_scan_config(name="name_value",) @@ -937,12 +941,13 @@ def test_delete_scan_config_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_delete_scan_config_flattened_error(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -955,7 +960,7 @@ def test_delete_scan_config_flattened_error(): @pytest.mark.asyncio async def test_delete_scan_config_flattened_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -974,14 +979,13 @@ async def test_delete_scan_config_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @pytest.mark.asyncio async def test_delete_scan_config_flattened_error_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -996,7 +1000,7 @@ def test_get_scan_config( transport: str = "grpc", request_type=web_security_scanner.GetScanConfigRequest ): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1017,40 +1021,28 @@ def test_get_scan_config( export_to_security_command_center=scan_config.ScanConfig.ExportToSecurityCommandCenter.ENABLED, risk_level=scan_config.ScanConfig.RiskLevel.NORMAL, ) - response = client.get_scan_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.GetScanConfigRequest() # Establish that the response is the type that we expect. - assert isinstance(response, scan_config.ScanConfig) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.max_qps == 761 - assert response.starting_urls == ["starting_urls_value"] - assert response.user_agent == scan_config.ScanConfig.UserAgent.CHROME_LINUX - assert response.blacklist_patterns == ["blacklist_patterns_value"] - assert response.target_platforms == [ scan_config.ScanConfig.TargetPlatform.APP_ENGINE ] - assert ( response.export_to_security_command_center == scan_config.ScanConfig.ExportToSecurityCommandCenter.ENABLED ) - assert response.risk_level == scan_config.ScanConfig.RiskLevel.NORMAL @@ -1062,7 +1054,7 @@ def test_get_scan_config_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1070,7 +1062,6 @@ def test_get_scan_config_empty_call(): client.get_scan_config() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.GetScanConfigRequest() @@ -1080,7 +1071,7 @@ async def test_get_scan_config_async( request_type=web_security_scanner.GetScanConfigRequest, ): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1103,39 +1094,28 @@ async def test_get_scan_config_async( risk_level=scan_config.ScanConfig.RiskLevel.NORMAL, ) ) - response = await client.get_scan_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.GetScanConfigRequest() # Establish that the response is the type that we expect. assert isinstance(response, scan_config.ScanConfig) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.max_qps == 761 - assert response.starting_urls == ["starting_urls_value"] - assert response.user_agent == scan_config.ScanConfig.UserAgent.CHROME_LINUX - assert response.blacklist_patterns == ["blacklist_patterns_value"] - assert response.target_platforms == [ scan_config.ScanConfig.TargetPlatform.APP_ENGINE ] - assert ( response.export_to_security_command_center == scan_config.ScanConfig.ExportToSecurityCommandCenter.ENABLED ) - assert response.risk_level == scan_config.ScanConfig.RiskLevel.NORMAL @@ -1145,17 +1125,19 @@ async def test_get_scan_config_async_from_dict(): def test_get_scan_config_field_headers(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.GetScanConfigRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_scan_config), "__call__") as call: call.return_value = scan_config.ScanConfig() - client.get_scan_config(request) # Establish that the underlying gRPC stub method was called. @@ -1171,12 +1153,13 @@ def test_get_scan_config_field_headers(): @pytest.mark.asyncio async def test_get_scan_config_field_headers_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.GetScanConfigRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1184,7 +1167,6 @@ async def test_get_scan_config_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( scan_config.ScanConfig() ) - await client.get_scan_config(request) # Establish that the underlying gRPC stub method was called. @@ -1198,13 +1180,14 @@ async def test_get_scan_config_field_headers_async(): def test_get_scan_config_flattened(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_scan_config), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = scan_config.ScanConfig() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.get_scan_config(name="name_value",) @@ -1213,12 +1196,13 @@ def test_get_scan_config_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_get_scan_config_flattened_error(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1231,7 +1215,7 @@ def test_get_scan_config_flattened_error(): @pytest.mark.asyncio async def test_get_scan_config_flattened_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1250,14 +1234,13 @@ async def test_get_scan_config_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @pytest.mark.asyncio async def test_get_scan_config_flattened_error_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1272,7 +1255,7 @@ def test_list_scan_configs( transport: str = "grpc", request_type=web_security_scanner.ListScanConfigsRequest ): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1287,19 +1270,15 @@ def test_list_scan_configs( call.return_value = web_security_scanner.ListScanConfigsResponse( next_page_token="next_page_token_value", ) - response = client.list_scan_configs(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.ListScanConfigsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListScanConfigsPager) - assert response.next_page_token == "next_page_token_value" @@ -1311,7 +1290,7 @@ def test_list_scan_configs_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1321,7 +1300,6 @@ def test_list_scan_configs_empty_call(): client.list_scan_configs() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.ListScanConfigsRequest() @@ -1331,7 +1309,7 @@ async def test_list_scan_configs_async( request_type=web_security_scanner.ListScanConfigsRequest, ): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1348,18 +1326,15 @@ async def test_list_scan_configs_async( next_page_token="next_page_token_value", ) ) - response = await client.list_scan_configs(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.ListScanConfigsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListScanConfigsAsyncPager) - assert response.next_page_token == "next_page_token_value" @@ -1369,11 +1344,14 @@ async def test_list_scan_configs_async_from_dict(): def test_list_scan_configs_field_headers(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.ListScanConfigsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1381,7 +1359,6 @@ def test_list_scan_configs_field_headers(): type(client.transport.list_scan_configs), "__call__" ) as call: call.return_value = web_security_scanner.ListScanConfigsResponse() - client.list_scan_configs(request) # Establish that the underlying gRPC stub method was called. @@ -1397,12 +1374,13 @@ def test_list_scan_configs_field_headers(): @pytest.mark.asyncio async def test_list_scan_configs_field_headers_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.ListScanConfigsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1412,7 +1390,6 @@ async def test_list_scan_configs_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( web_security_scanner.ListScanConfigsResponse() ) - await client.list_scan_configs(request) # Establish that the underlying gRPC stub method was called. @@ -1426,7 +1403,9 @@ async def test_list_scan_configs_field_headers_async(): def test_list_scan_configs_flattened(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1434,7 +1413,6 @@ def test_list_scan_configs_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = web_security_scanner.ListScanConfigsResponse() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.list_scan_configs(parent="parent_value",) @@ -1443,12 +1421,13 @@ def test_list_scan_configs_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" def test_list_scan_configs_flattened_error(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1461,7 +1440,7 @@ def test_list_scan_configs_flattened_error(): @pytest.mark.asyncio async def test_list_scan_configs_flattened_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1482,14 +1461,13 @@ async def test_list_scan_configs_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" @pytest.mark.asyncio async def test_list_scan_configs_flattened_error_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1501,7 +1479,7 @@ async def test_list_scan_configs_flattened_error_async(): def test_list_scan_configs_pager(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials,) + client = WebSecurityScannerClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1543,7 +1521,7 @@ def test_list_scan_configs_pager(): def test_list_scan_configs_pages(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials,) + client = WebSecurityScannerClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1578,7 +1556,7 @@ def test_list_scan_configs_pages(): @pytest.mark.asyncio async def test_list_scan_configs_async_pager(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1621,7 +1599,7 @@ async def test_list_scan_configs_async_pager(): @pytest.mark.asyncio async def test_list_scan_configs_async_pages(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1662,7 +1640,7 @@ def test_update_scan_config( transport: str = "grpc", request_type=web_security_scanner.UpdateScanConfigRequest ): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1685,40 +1663,28 @@ def test_update_scan_config( export_to_security_command_center=gcw_scan_config.ScanConfig.ExportToSecurityCommandCenter.ENABLED, risk_level=gcw_scan_config.ScanConfig.RiskLevel.NORMAL, ) - response = client.update_scan_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.UpdateScanConfigRequest() # Establish that the response is the type that we expect. - assert isinstance(response, gcw_scan_config.ScanConfig) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.max_qps == 761 - assert response.starting_urls == ["starting_urls_value"] - assert response.user_agent == gcw_scan_config.ScanConfig.UserAgent.CHROME_LINUX - assert response.blacklist_patterns == ["blacklist_patterns_value"] - assert response.target_platforms == [ gcw_scan_config.ScanConfig.TargetPlatform.APP_ENGINE ] - assert ( response.export_to_security_command_center == gcw_scan_config.ScanConfig.ExportToSecurityCommandCenter.ENABLED ) - assert response.risk_level == gcw_scan_config.ScanConfig.RiskLevel.NORMAL @@ -1730,7 +1696,7 @@ def test_update_scan_config_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1740,7 +1706,6 @@ def test_update_scan_config_empty_call(): client.update_scan_config() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.UpdateScanConfigRequest() @@ -1750,7 +1715,7 @@ async def test_update_scan_config_async( request_type=web_security_scanner.UpdateScanConfigRequest, ): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1775,39 +1740,28 @@ async def test_update_scan_config_async( risk_level=gcw_scan_config.ScanConfig.RiskLevel.NORMAL, ) ) - response = await client.update_scan_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.UpdateScanConfigRequest() # Establish that the response is the type that we expect. assert isinstance(response, gcw_scan_config.ScanConfig) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.max_qps == 761 - assert response.starting_urls == ["starting_urls_value"] - assert response.user_agent == gcw_scan_config.ScanConfig.UserAgent.CHROME_LINUX - assert response.blacklist_patterns == ["blacklist_patterns_value"] - assert response.target_platforms == [ gcw_scan_config.ScanConfig.TargetPlatform.APP_ENGINE ] - assert ( response.export_to_security_command_center == gcw_scan_config.ScanConfig.ExportToSecurityCommandCenter.ENABLED ) - assert response.risk_level == gcw_scan_config.ScanConfig.RiskLevel.NORMAL @@ -1817,11 +1771,14 @@ async def test_update_scan_config_async_from_dict(): def test_update_scan_config_field_headers(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.UpdateScanConfigRequest() + request.scan_config.name = "scan_config.name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1829,7 +1786,6 @@ def test_update_scan_config_field_headers(): type(client.transport.update_scan_config), "__call__" ) as call: call.return_value = gcw_scan_config.ScanConfig() - client.update_scan_config(request) # Establish that the underlying gRPC stub method was called. @@ -1847,12 +1803,13 @@ def test_update_scan_config_field_headers(): @pytest.mark.asyncio async def test_update_scan_config_field_headers_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.UpdateScanConfigRequest() + request.scan_config.name = "scan_config.name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1862,7 +1819,6 @@ async def test_update_scan_config_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( gcw_scan_config.ScanConfig() ) - await client.update_scan_config(request) # Establish that the underlying gRPC stub method was called. @@ -1878,7 +1834,9 @@ async def test_update_scan_config_field_headers_async(): def test_update_scan_config_flattened(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1886,26 +1844,25 @@ def test_update_scan_config_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = gcw_scan_config.ScanConfig() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.update_scan_config( scan_config=gcw_scan_config.ScanConfig(name="name_value"), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].scan_config == gcw_scan_config.ScanConfig(name="name_value") - - assert args[0].update_mask == field_mask.FieldMask(paths=["paths_value"]) + assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) def test_update_scan_config_flattened_error(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1913,14 +1870,14 @@ def test_update_scan_config_flattened_error(): client.update_scan_config( web_security_scanner.UpdateScanConfigRequest(), scan_config=gcw_scan_config.ScanConfig(name="name_value"), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @pytest.mark.asyncio async def test_update_scan_config_flattened_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1937,23 +1894,21 @@ async def test_update_scan_config_flattened_async(): # using the keyword arguments to the method. response = await client.update_scan_config( scan_config=gcw_scan_config.ScanConfig(name="name_value"), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].scan_config == gcw_scan_config.ScanConfig(name="name_value") - - assert args[0].update_mask == field_mask.FieldMask(paths=["paths_value"]) + assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) @pytest.mark.asyncio async def test_update_scan_config_flattened_error_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1962,7 +1917,7 @@ async def test_update_scan_config_flattened_error_async(): await client.update_scan_config( web_security_scanner.UpdateScanConfigRequest(), scan_config=gcw_scan_config.ScanConfig(name="name_value"), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @@ -1970,7 +1925,7 @@ def test_start_scan_run( transport: str = "grpc", request_type=web_security_scanner.StartScanRunRequest ): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1989,31 +1944,21 @@ def test_start_scan_run( has_vulnerabilities=True, progress_percent=1733, ) - response = client.start_scan_run(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.StartScanRunRequest() # Establish that the response is the type that we expect. - assert isinstance(response, scan_run.ScanRun) - assert response.name == "name_value" - assert response.execution_state == scan_run.ScanRun.ExecutionState.QUEUED - assert response.result_state == scan_run.ScanRun.ResultState.SUCCESS - assert response.urls_crawled_count == 1935 - assert response.urls_tested_count == 1846 - assert response.has_vulnerabilities is True - assert response.progress_percent == 1733 @@ -2025,7 +1970,7 @@ def test_start_scan_run_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2033,7 +1978,6 @@ def test_start_scan_run_empty_call(): client.start_scan_run() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.StartScanRunRequest() @@ -2043,7 +1987,7 @@ async def test_start_scan_run_async( request_type=web_security_scanner.StartScanRunRequest, ): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2064,30 +2008,21 @@ async def test_start_scan_run_async( progress_percent=1733, ) ) - response = await client.start_scan_run(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.StartScanRunRequest() # Establish that the response is the type that we expect. assert isinstance(response, scan_run.ScanRun) - assert response.name == "name_value" - assert response.execution_state == scan_run.ScanRun.ExecutionState.QUEUED - assert response.result_state == scan_run.ScanRun.ResultState.SUCCESS - assert response.urls_crawled_count == 1935 - assert response.urls_tested_count == 1846 - assert response.has_vulnerabilities is True - assert response.progress_percent == 1733 @@ -2097,17 +2032,19 @@ async def test_start_scan_run_async_from_dict(): def test_start_scan_run_field_headers(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.StartScanRunRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.start_scan_run), "__call__") as call: call.return_value = scan_run.ScanRun() - client.start_scan_run(request) # Establish that the underlying gRPC stub method was called. @@ -2123,18 +2060,18 @@ def test_start_scan_run_field_headers(): @pytest.mark.asyncio async def test_start_scan_run_field_headers_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.StartScanRunRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.start_scan_run), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(scan_run.ScanRun()) - await client.start_scan_run(request) # Establish that the underlying gRPC stub method was called. @@ -2148,13 +2085,14 @@ async def test_start_scan_run_field_headers_async(): def test_start_scan_run_flattened(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.start_scan_run), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = scan_run.ScanRun() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.start_scan_run(name="name_value",) @@ -2163,12 +2101,13 @@ def test_start_scan_run_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_start_scan_run_flattened_error(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2181,7 +2120,7 @@ def test_start_scan_run_flattened_error(): @pytest.mark.asyncio async def test_start_scan_run_flattened_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2198,14 +2137,13 @@ async def test_start_scan_run_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @pytest.mark.asyncio async def test_start_scan_run_flattened_error_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -2220,7 +2158,7 @@ def test_get_scan_run( transport: str = "grpc", request_type=web_security_scanner.GetScanRunRequest ): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2239,31 +2177,21 @@ def test_get_scan_run( has_vulnerabilities=True, progress_percent=1733, ) - response = client.get_scan_run(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.GetScanRunRequest() # Establish that the response is the type that we expect. - assert isinstance(response, scan_run.ScanRun) - assert response.name == "name_value" - assert response.execution_state == scan_run.ScanRun.ExecutionState.QUEUED - assert response.result_state == scan_run.ScanRun.ResultState.SUCCESS - assert response.urls_crawled_count == 1935 - assert response.urls_tested_count == 1846 - assert response.has_vulnerabilities is True - assert response.progress_percent == 1733 @@ -2275,7 +2203,7 @@ def test_get_scan_run_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2283,7 +2211,6 @@ def test_get_scan_run_empty_call(): client.get_scan_run() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.GetScanRunRequest() @@ -2292,7 +2219,7 @@ async def test_get_scan_run_async( transport: str = "grpc_asyncio", request_type=web_security_scanner.GetScanRunRequest ): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2313,30 +2240,21 @@ async def test_get_scan_run_async( progress_percent=1733, ) ) - response = await client.get_scan_run(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.GetScanRunRequest() # Establish that the response is the type that we expect. assert isinstance(response, scan_run.ScanRun) - assert response.name == "name_value" - assert response.execution_state == scan_run.ScanRun.ExecutionState.QUEUED - assert response.result_state == scan_run.ScanRun.ResultState.SUCCESS - assert response.urls_crawled_count == 1935 - assert response.urls_tested_count == 1846 - assert response.has_vulnerabilities is True - assert response.progress_percent == 1733 @@ -2346,17 +2264,19 @@ async def test_get_scan_run_async_from_dict(): def test_get_scan_run_field_headers(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.GetScanRunRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_scan_run), "__call__") as call: call.return_value = scan_run.ScanRun() - client.get_scan_run(request) # Establish that the underlying gRPC stub method was called. @@ -2372,18 +2292,18 @@ def test_get_scan_run_field_headers(): @pytest.mark.asyncio async def test_get_scan_run_field_headers_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.GetScanRunRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_scan_run), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(scan_run.ScanRun()) - await client.get_scan_run(request) # Establish that the underlying gRPC stub method was called. @@ -2397,13 +2317,14 @@ async def test_get_scan_run_field_headers_async(): def test_get_scan_run_flattened(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_scan_run), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = scan_run.ScanRun() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.get_scan_run(name="name_value",) @@ -2412,12 +2333,13 @@ def test_get_scan_run_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_get_scan_run_flattened_error(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2430,7 +2352,7 @@ def test_get_scan_run_flattened_error(): @pytest.mark.asyncio async def test_get_scan_run_flattened_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2447,14 +2369,13 @@ async def test_get_scan_run_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @pytest.mark.asyncio async def test_get_scan_run_flattened_error_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -2469,7 +2390,7 @@ def test_list_scan_runs( transport: str = "grpc", request_type=web_security_scanner.ListScanRunsRequest ): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2482,19 +2403,15 @@ def test_list_scan_runs( call.return_value = web_security_scanner.ListScanRunsResponse( next_page_token="next_page_token_value", ) - response = client.list_scan_runs(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.ListScanRunsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListScanRunsPager) - assert response.next_page_token == "next_page_token_value" @@ -2506,7 +2423,7 @@ def test_list_scan_runs_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2514,7 +2431,6 @@ def test_list_scan_runs_empty_call(): client.list_scan_runs() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.ListScanRunsRequest() @@ -2524,7 +2440,7 @@ async def test_list_scan_runs_async( request_type=web_security_scanner.ListScanRunsRequest, ): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2539,18 +2455,15 @@ async def test_list_scan_runs_async( next_page_token="next_page_token_value", ) ) - response = await client.list_scan_runs(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.ListScanRunsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListScanRunsAsyncPager) - assert response.next_page_token == "next_page_token_value" @@ -2560,17 +2473,19 @@ async def test_list_scan_runs_async_from_dict(): def test_list_scan_runs_field_headers(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.ListScanRunsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_scan_runs), "__call__") as call: call.return_value = web_security_scanner.ListScanRunsResponse() - client.list_scan_runs(request) # Establish that the underlying gRPC stub method was called. @@ -2586,12 +2501,13 @@ def test_list_scan_runs_field_headers(): @pytest.mark.asyncio async def test_list_scan_runs_field_headers_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.ListScanRunsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2599,7 +2515,6 @@ async def test_list_scan_runs_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( web_security_scanner.ListScanRunsResponse() ) - await client.list_scan_runs(request) # Establish that the underlying gRPC stub method was called. @@ -2613,13 +2528,14 @@ async def test_list_scan_runs_field_headers_async(): def test_list_scan_runs_flattened(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_scan_runs), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = web_security_scanner.ListScanRunsResponse() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.list_scan_runs(parent="parent_value",) @@ -2628,12 +2544,13 @@ def test_list_scan_runs_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" def test_list_scan_runs_flattened_error(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2646,7 +2563,7 @@ def test_list_scan_runs_flattened_error(): @pytest.mark.asyncio async def test_list_scan_runs_flattened_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2665,14 +2582,13 @@ async def test_list_scan_runs_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" @pytest.mark.asyncio async def test_list_scan_runs_flattened_error_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -2684,7 +2600,7 @@ async def test_list_scan_runs_flattened_error_async(): def test_list_scan_runs_pager(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials,) + client = WebSecurityScannerClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_scan_runs), "__call__") as call: @@ -2720,7 +2636,7 @@ def test_list_scan_runs_pager(): def test_list_scan_runs_pages(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials,) + client = WebSecurityScannerClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_scan_runs), "__call__") as call: @@ -2749,7 +2665,7 @@ def test_list_scan_runs_pages(): @pytest.mark.asyncio async def test_list_scan_runs_async_pager(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2786,7 +2702,7 @@ async def test_list_scan_runs_async_pager(): @pytest.mark.asyncio async def test_list_scan_runs_async_pages(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2821,7 +2737,7 @@ def test_stop_scan_run( transport: str = "grpc", request_type=web_security_scanner.StopScanRunRequest ): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2840,31 +2756,21 @@ def test_stop_scan_run( has_vulnerabilities=True, progress_percent=1733, ) - response = client.stop_scan_run(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.StopScanRunRequest() # Establish that the response is the type that we expect. - assert isinstance(response, scan_run.ScanRun) - assert response.name == "name_value" - assert response.execution_state == scan_run.ScanRun.ExecutionState.QUEUED - assert response.result_state == scan_run.ScanRun.ResultState.SUCCESS - assert response.urls_crawled_count == 1935 - assert response.urls_tested_count == 1846 - assert response.has_vulnerabilities is True - assert response.progress_percent == 1733 @@ -2876,7 +2782,7 @@ def test_stop_scan_run_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2884,7 +2790,6 @@ def test_stop_scan_run_empty_call(): client.stop_scan_run() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.StopScanRunRequest() @@ -2894,7 +2799,7 @@ async def test_stop_scan_run_async( request_type=web_security_scanner.StopScanRunRequest, ): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2915,30 +2820,21 @@ async def test_stop_scan_run_async( progress_percent=1733, ) ) - response = await client.stop_scan_run(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.StopScanRunRequest() # Establish that the response is the type that we expect. assert isinstance(response, scan_run.ScanRun) - assert response.name == "name_value" - assert response.execution_state == scan_run.ScanRun.ExecutionState.QUEUED - assert response.result_state == scan_run.ScanRun.ResultState.SUCCESS - assert response.urls_crawled_count == 1935 - assert response.urls_tested_count == 1846 - assert response.has_vulnerabilities is True - assert response.progress_percent == 1733 @@ -2948,17 +2844,19 @@ async def test_stop_scan_run_async_from_dict(): def test_stop_scan_run_field_headers(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.StopScanRunRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.stop_scan_run), "__call__") as call: call.return_value = scan_run.ScanRun() - client.stop_scan_run(request) # Establish that the underlying gRPC stub method was called. @@ -2974,18 +2872,18 @@ def test_stop_scan_run_field_headers(): @pytest.mark.asyncio async def test_stop_scan_run_field_headers_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.StopScanRunRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.stop_scan_run), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(scan_run.ScanRun()) - await client.stop_scan_run(request) # Establish that the underlying gRPC stub method was called. @@ -2999,13 +2897,14 @@ async def test_stop_scan_run_field_headers_async(): def test_stop_scan_run_flattened(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.stop_scan_run), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = scan_run.ScanRun() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.stop_scan_run(name="name_value",) @@ -3014,12 +2913,13 @@ def test_stop_scan_run_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_stop_scan_run_flattened_error(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -3032,7 +2932,7 @@ def test_stop_scan_run_flattened_error(): @pytest.mark.asyncio async def test_stop_scan_run_flattened_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3049,14 +2949,13 @@ async def test_stop_scan_run_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @pytest.mark.asyncio async def test_stop_scan_run_flattened_error_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -3071,7 +2970,7 @@ def test_list_crawled_urls( transport: str = "grpc", request_type=web_security_scanner.ListCrawledUrlsRequest ): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3086,19 +2985,15 @@ def test_list_crawled_urls( call.return_value = web_security_scanner.ListCrawledUrlsResponse( next_page_token="next_page_token_value", ) - response = client.list_crawled_urls(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.ListCrawledUrlsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListCrawledUrlsPager) - assert response.next_page_token == "next_page_token_value" @@ -3110,7 +3005,7 @@ def test_list_crawled_urls_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3120,7 +3015,6 @@ def test_list_crawled_urls_empty_call(): client.list_crawled_urls() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.ListCrawledUrlsRequest() @@ -3130,7 +3024,7 @@ async def test_list_crawled_urls_async( request_type=web_security_scanner.ListCrawledUrlsRequest, ): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3147,18 +3041,15 @@ async def test_list_crawled_urls_async( next_page_token="next_page_token_value", ) ) - response = await client.list_crawled_urls(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.ListCrawledUrlsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListCrawledUrlsAsyncPager) - assert response.next_page_token == "next_page_token_value" @@ -3168,11 +3059,14 @@ async def test_list_crawled_urls_async_from_dict(): def test_list_crawled_urls_field_headers(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.ListCrawledUrlsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -3180,7 +3074,6 @@ def test_list_crawled_urls_field_headers(): type(client.transport.list_crawled_urls), "__call__" ) as call: call.return_value = web_security_scanner.ListCrawledUrlsResponse() - client.list_crawled_urls(request) # Establish that the underlying gRPC stub method was called. @@ -3196,12 +3089,13 @@ def test_list_crawled_urls_field_headers(): @pytest.mark.asyncio async def test_list_crawled_urls_field_headers_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.ListCrawledUrlsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -3211,7 +3105,6 @@ async def test_list_crawled_urls_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( web_security_scanner.ListCrawledUrlsResponse() ) - await client.list_crawled_urls(request) # Establish that the underlying gRPC stub method was called. @@ -3225,7 +3118,9 @@ async def test_list_crawled_urls_field_headers_async(): def test_list_crawled_urls_flattened(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3233,7 +3128,6 @@ def test_list_crawled_urls_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = web_security_scanner.ListCrawledUrlsResponse() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.list_crawled_urls(parent="parent_value",) @@ -3242,12 +3136,13 @@ def test_list_crawled_urls_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" def test_list_crawled_urls_flattened_error(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -3260,7 +3155,7 @@ def test_list_crawled_urls_flattened_error(): @pytest.mark.asyncio async def test_list_crawled_urls_flattened_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3281,14 +3176,13 @@ async def test_list_crawled_urls_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" @pytest.mark.asyncio async def test_list_crawled_urls_flattened_error_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -3300,7 +3194,7 @@ async def test_list_crawled_urls_flattened_error_async(): def test_list_crawled_urls_pager(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials,) + client = WebSecurityScannerClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3342,7 +3236,7 @@ def test_list_crawled_urls_pager(): def test_list_crawled_urls_pages(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials,) + client = WebSecurityScannerClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3377,7 +3271,7 @@ def test_list_crawled_urls_pages(): @pytest.mark.asyncio async def test_list_crawled_urls_async_pager(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3420,7 +3314,7 @@ async def test_list_crawled_urls_async_pager(): @pytest.mark.asyncio async def test_list_crawled_urls_async_pages(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3461,7 +3355,7 @@ def test_get_finding( transport: str = "grpc", request_type=web_security_scanner.GetFindingRequest ): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3483,37 +3377,24 @@ def test_get_finding( final_url="final_url_value", tracking_id="tracking_id_value", ) - response = client.get_finding(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.GetFindingRequest() # Establish that the response is the type that we expect. - assert isinstance(response, finding.Finding) - assert response.name == "name_value" - assert response.finding_type == "finding_type_value" - assert response.http_method == "http_method_value" - assert response.fuzzed_url == "fuzzed_url_value" - assert response.body == "body_value" - assert response.description == "description_value" - assert response.reproduction_url == "reproduction_url_value" - assert response.frame_url == "frame_url_value" - assert response.final_url == "final_url_value" - assert response.tracking_id == "tracking_id_value" @@ -3525,7 +3406,7 @@ def test_get_finding_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3533,7 +3414,6 @@ def test_get_finding_empty_call(): client.get_finding() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.GetFindingRequest() @@ -3542,7 +3422,7 @@ async def test_get_finding_async( transport: str = "grpc_asyncio", request_type=web_security_scanner.GetFindingRequest ): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3566,36 +3446,24 @@ async def test_get_finding_async( tracking_id="tracking_id_value", ) ) - response = await client.get_finding(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.GetFindingRequest() # Establish that the response is the type that we expect. assert isinstance(response, finding.Finding) - assert response.name == "name_value" - assert response.finding_type == "finding_type_value" - assert response.http_method == "http_method_value" - assert response.fuzzed_url == "fuzzed_url_value" - assert response.body == "body_value" - assert response.description == "description_value" - assert response.reproduction_url == "reproduction_url_value" - assert response.frame_url == "frame_url_value" - assert response.final_url == "final_url_value" - assert response.tracking_id == "tracking_id_value" @@ -3605,17 +3473,19 @@ async def test_get_finding_async_from_dict(): def test_get_finding_field_headers(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.GetFindingRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_finding), "__call__") as call: call.return_value = finding.Finding() - client.get_finding(request) # Establish that the underlying gRPC stub method was called. @@ -3631,18 +3501,18 @@ def test_get_finding_field_headers(): @pytest.mark.asyncio async def test_get_finding_field_headers_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.GetFindingRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_finding), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(finding.Finding()) - await client.get_finding(request) # Establish that the underlying gRPC stub method was called. @@ -3656,13 +3526,14 @@ async def test_get_finding_field_headers_async(): def test_get_finding_flattened(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_finding), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = finding.Finding() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.get_finding(name="name_value",) @@ -3671,12 +3542,13 @@ def test_get_finding_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_get_finding_flattened_error(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -3689,7 +3561,7 @@ def test_get_finding_flattened_error(): @pytest.mark.asyncio async def test_get_finding_flattened_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3706,14 +3578,13 @@ async def test_get_finding_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @pytest.mark.asyncio async def test_get_finding_flattened_error_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -3728,7 +3599,7 @@ def test_list_findings( transport: str = "grpc", request_type=web_security_scanner.ListFindingsRequest ): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3741,19 +3612,15 @@ def test_list_findings( call.return_value = web_security_scanner.ListFindingsResponse( next_page_token="next_page_token_value", ) - response = client.list_findings(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.ListFindingsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListFindingsPager) - assert response.next_page_token == "next_page_token_value" @@ -3765,7 +3632,7 @@ def test_list_findings_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3773,7 +3640,6 @@ def test_list_findings_empty_call(): client.list_findings() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.ListFindingsRequest() @@ -3783,7 +3649,7 @@ async def test_list_findings_async( request_type=web_security_scanner.ListFindingsRequest, ): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3798,18 +3664,15 @@ async def test_list_findings_async( next_page_token="next_page_token_value", ) ) - response = await client.list_findings(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.ListFindingsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListFindingsAsyncPager) - assert response.next_page_token == "next_page_token_value" @@ -3819,17 +3682,19 @@ async def test_list_findings_async_from_dict(): def test_list_findings_field_headers(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.ListFindingsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_findings), "__call__") as call: call.return_value = web_security_scanner.ListFindingsResponse() - client.list_findings(request) # Establish that the underlying gRPC stub method was called. @@ -3845,12 +3710,13 @@ def test_list_findings_field_headers(): @pytest.mark.asyncio async def test_list_findings_field_headers_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.ListFindingsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -3858,7 +3724,6 @@ async def test_list_findings_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( web_security_scanner.ListFindingsResponse() ) - await client.list_findings(request) # Establish that the underlying gRPC stub method was called. @@ -3872,13 +3737,14 @@ async def test_list_findings_field_headers_async(): def test_list_findings_flattened(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_findings), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = web_security_scanner.ListFindingsResponse() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.list_findings( @@ -3889,14 +3755,14 @@ def test_list_findings_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].filter == "filter_value" def test_list_findings_flattened_error(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -3911,7 +3777,7 @@ def test_list_findings_flattened_error(): @pytest.mark.asyncio async def test_list_findings_flattened_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3932,16 +3798,14 @@ async def test_list_findings_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].filter == "filter_value" @pytest.mark.asyncio async def test_list_findings_flattened_error_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -3955,7 +3819,7 @@ async def test_list_findings_flattened_error_async(): def test_list_findings_pager(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials,) + client = WebSecurityScannerClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_findings), "__call__") as call: @@ -3991,7 +3855,7 @@ def test_list_findings_pager(): def test_list_findings_pages(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials,) + client = WebSecurityScannerClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_findings), "__call__") as call: @@ -4020,7 +3884,7 @@ def test_list_findings_pages(): @pytest.mark.asyncio async def test_list_findings_async_pager(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4057,7 +3921,7 @@ async def test_list_findings_async_pager(): @pytest.mark.asyncio async def test_list_findings_async_pages(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4093,7 +3957,7 @@ def test_list_finding_type_stats( request_type=web_security_scanner.ListFindingTypeStatsRequest, ): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4106,17 +3970,14 @@ def test_list_finding_type_stats( ) as call: # Designate an appropriate return value for the call. call.return_value = web_security_scanner.ListFindingTypeStatsResponse() - response = client.list_finding_type_stats(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.ListFindingTypeStatsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, web_security_scanner.ListFindingTypeStatsResponse) @@ -4128,7 +3989,7 @@ def test_list_finding_type_stats_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4138,7 +3999,6 @@ def test_list_finding_type_stats_empty_call(): client.list_finding_type_stats() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.ListFindingTypeStatsRequest() @@ -4148,7 +4008,7 @@ async def test_list_finding_type_stats_async( request_type=web_security_scanner.ListFindingTypeStatsRequest, ): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4163,13 +4023,11 @@ async def test_list_finding_type_stats_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( web_security_scanner.ListFindingTypeStatsResponse() ) - response = await client.list_finding_type_stats(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == web_security_scanner.ListFindingTypeStatsRequest() # Establish that the response is the type that we expect. @@ -4182,11 +4040,14 @@ async def test_list_finding_type_stats_async_from_dict(): def test_list_finding_type_stats_field_headers(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.ListFindingTypeStatsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -4194,7 +4055,6 @@ def test_list_finding_type_stats_field_headers(): type(client.transport.list_finding_type_stats), "__call__" ) as call: call.return_value = web_security_scanner.ListFindingTypeStatsResponse() - client.list_finding_type_stats(request) # Establish that the underlying gRPC stub method was called. @@ -4210,12 +4070,13 @@ def test_list_finding_type_stats_field_headers(): @pytest.mark.asyncio async def test_list_finding_type_stats_field_headers_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = web_security_scanner.ListFindingTypeStatsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -4225,7 +4086,6 @@ async def test_list_finding_type_stats_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( web_security_scanner.ListFindingTypeStatsResponse() ) - await client.list_finding_type_stats(request) # Establish that the underlying gRPC stub method was called. @@ -4239,7 +4099,9 @@ async def test_list_finding_type_stats_field_headers_async(): def test_list_finding_type_stats_flattened(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4247,7 +4109,6 @@ def test_list_finding_type_stats_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = web_security_scanner.ListFindingTypeStatsResponse() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.list_finding_type_stats(parent="parent_value",) @@ -4256,12 +4117,13 @@ def test_list_finding_type_stats_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" def test_list_finding_type_stats_flattened_error(): - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -4274,7 +4136,7 @@ def test_list_finding_type_stats_flattened_error(): @pytest.mark.asyncio async def test_list_finding_type_stats_flattened_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4295,14 +4157,13 @@ async def test_list_finding_type_stats_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" @pytest.mark.asyncio async def test_list_finding_type_stats_flattened_error_async(): client = WebSecurityScannerAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -4316,16 +4177,16 @@ async def test_list_finding_type_stats_flattened_error_async(): def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.WebSecurityScannerGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.WebSecurityScannerGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = WebSecurityScannerClient( @@ -4335,7 +4196,7 @@ def test_credentials_transport_error(): # It is an error to provide scopes and a transport instance. transport = transports.WebSecurityScannerGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = WebSecurityScannerClient( @@ -4346,7 +4207,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.WebSecurityScannerGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) client = WebSecurityScannerClient(transport=transport) assert client.transport is transport @@ -4355,13 +4216,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.WebSecurityScannerGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel transport = transports.WebSecurityScannerGrpcAsyncIOTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel @@ -4376,23 +4237,25 @@ def test_transport_get_channel(): ) def test_transport_adc(transport_class): # Test default credentials are used if not provided. - with mock.patch.object(auth, "default") as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport_class() adc.assert_called_once() def test_transport_grpc_default(): # A client should use the gRPC transport by default. - client = WebSecurityScannerClient(credentials=credentials.AnonymousCredentials(),) + client = WebSecurityScannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) assert isinstance(client.transport, transports.WebSecurityScannerGrpcTransport,) def test_web_security_scanner_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error - with pytest.raises(exceptions.DuplicateCredentialArgs): + with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.WebSecurityScannerTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), credentials_file="credentials.json", ) @@ -4404,7 +4267,7 @@ def test_web_security_scanner_base_transport(): ) as Transport: Transport.return_value = None transport = transports.WebSecurityScannerTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Every method on the transport should just blindly @@ -4429,15 +4292,37 @@ def test_web_security_scanner_base_transport(): getattr(transport, method)(request=object()) +@requires_google_auth_gte_1_25_0 def test_web_security_scanner_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( - auth, "load_credentials_from_file" + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch( + "google.cloud.websecurityscanner_v1beta.services.web_security_scanner.transports.WebSecurityScannerTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.WebSecurityScannerTransport( + credentials_file="credentials.json", quota_project_id="octopus", + ) + load_creds.assert_called_once_with( + "credentials.json", + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", + ) + + +@requires_google_auth_lt_1_25_0 +def test_web_security_scanner_base_transport_with_credentials_file_old_google_auth(): + # Instantiate the base transport with a credentials file + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True ) as load_creds, mock.patch( "google.cloud.websecurityscanner_v1beta.services.web_security_scanner.transports.WebSecurityScannerTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (credentials.AnonymousCredentials(), None) + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.WebSecurityScannerTransport( credentials_file="credentials.json", quota_project_id="octopus", ) @@ -4450,19 +4335,33 @@ def test_web_security_scanner_base_transport_with_credentials_file(): def test_web_security_scanner_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(auth, "default") as adc, mock.patch( + with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( "google.cloud.websecurityscanner_v1beta.services.web_security_scanner.transports.WebSecurityScannerTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (credentials.AnonymousCredentials(), None) + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.WebSecurityScannerTransport() adc.assert_called_once() +@requires_google_auth_gte_1_25_0 def test_web_security_scanner_auth_adc(): # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(auth, "default") as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + WebSecurityScannerClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id=None, + ) + + +@requires_google_auth_lt_1_25_0 +def test_web_security_scanner_auth_adc_old_google_auth(): + # If no credentials are provided, we should use ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) WebSecurityScannerClient() adc.assert_called_once_with( scopes=("https://www.googleapis.com/auth/cloud-platform",), @@ -4470,20 +4369,156 @@ def test_web_security_scanner_auth_adc(): ) -def test_web_security_scanner_transport_auth_adc(): +@pytest.mark.parametrize( + "transport_class", + [ + transports.WebSecurityScannerGrpcTransport, + transports.WebSecurityScannerGrpcAsyncIOTransport, + ], +) +@requires_google_auth_gte_1_25_0 +def test_web_security_scanner_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object(auth, "default") as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) - transports.WebSecurityScannerGrpcTransport( - host="squid.clam.whelk", quota_project_id="octopus" + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + adc.assert_called_once_with( + scopes=["1", "2"], + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.WebSecurityScannerGrpcTransport, + transports.WebSecurityScannerGrpcAsyncIOTransport, + ], +) +@requires_google_auth_lt_1_25_0 +def test_web_security_scanner_transport_auth_adc_old_google_auth(transport_class): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus") adc.assert_called_once_with( scopes=("https://www.googleapis.com/auth/cloud-platform",), quota_project_id="octopus", ) +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.WebSecurityScannerGrpcTransport, grpc_helpers), + (transports.WebSecurityScannerGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_gte_1_26_0 +def test_web_security_scanner_transport_create_channel(transport_class, grpc_helpers): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + + create_channel.assert_called_with( + "websecurityscanner.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=["1", "2"], + default_host="websecurityscanner.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.WebSecurityScannerGrpcTransport, grpc_helpers), + (transports.WebSecurityScannerGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_web_security_scanner_transport_create_channel_old_api_core( + transport_class, grpc_helpers +): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class(quota_project_id="octopus") + + create_channel.assert_called_with( + "websecurityscanner.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + scopes=("https://www.googleapis.com/auth/cloud-platform",), + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.WebSecurityScannerGrpcTransport, grpc_helpers), + (transports.WebSecurityScannerGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_web_security_scanner_transport_create_channel_user_scopes( + transport_class, grpc_helpers +): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + + create_channel.assert_called_with( + "websecurityscanner.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + scopes=["1", "2"], + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + @pytest.mark.parametrize( "transport_class", [ @@ -4494,7 +4529,7 @@ def test_web_security_scanner_transport_auth_adc(): def test_web_security_scanner_grpc_transport_client_cert_source_for_mtls( transport_class, ): - cred = credentials.AnonymousCredentials() + cred = ga_credentials.AnonymousCredentials() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -4533,7 +4568,7 @@ def test_web_security_scanner_grpc_transport_client_cert_source_for_mtls( def test_web_security_scanner_host_no_port(): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="websecurityscanner.googleapis.com" ), @@ -4543,7 +4578,7 @@ def test_web_security_scanner_host_no_port(): def test_web_security_scanner_host_with_port(): client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="websecurityscanner.googleapis.com:8000" ), @@ -4599,9 +4634,9 @@ def test_web_security_scanner_transport_channel_mtls_with_client_cert_source( mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = credentials.AnonymousCredentials() + cred = ga_credentials.AnonymousCredentials() with pytest.warns(DeprecationWarning): - with mock.patch.object(auth, "default") as adc: + with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) transport = transport_class( host="squid.clam.whelk", @@ -4680,7 +4715,6 @@ def test_finding_path(): scan_config = "clam" scan_run = "whelk" finding = "octopus" - expected = "projects/{project}/scanConfigs/{scan_config}/scanRuns/{scan_run}/findings/{finding}".format( project=project, scan_config=scan_config, scan_run=scan_run, finding=finding, ) @@ -4707,7 +4741,6 @@ def test_parse_finding_path(): def test_scan_config_path(): project = "winkle" scan_config = "nautilus" - expected = "projects/{project}/scanConfigs/{scan_config}".format( project=project, scan_config=scan_config, ) @@ -4731,7 +4764,6 @@ def test_scan_run_path(): project = "squid" scan_config = "clam" scan_run = "whelk" - expected = "projects/{project}/scanConfigs/{scan_config}/scanRuns/{scan_run}".format( project=project, scan_config=scan_config, scan_run=scan_run, ) @@ -4754,7 +4786,6 @@ def test_parse_scan_run_path(): def test_common_billing_account_path(): billing_account = "cuttlefish" - expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -4775,7 +4806,6 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "winkle" - expected = "folders/{folder}".format(folder=folder,) actual = WebSecurityScannerClient.common_folder_path(folder) assert expected == actual @@ -4794,7 +4824,6 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "scallop" - expected = "organizations/{organization}".format(organization=organization,) actual = WebSecurityScannerClient.common_organization_path(organization) assert expected == actual @@ -4813,7 +4842,6 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "squid" - expected = "projects/{project}".format(project=project,) actual = WebSecurityScannerClient.common_project_path(project) assert expected == actual @@ -4833,7 +4861,6 @@ def test_parse_common_project_path(): def test_common_location_path(): project = "whelk" location = "octopus" - expected = "projects/{project}/locations/{location}".format( project=project, location=location, ) @@ -4860,7 +4887,7 @@ def test_client_withDEFAULT_CLIENT_INFO(): transports.WebSecurityScannerTransport, "_prep_wrapped_messages" ) as prep: client = WebSecurityScannerClient( - credentials=credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -4869,6 +4896,6 @@ def test_client_withDEFAULT_CLIENT_INFO(): ) as prep: transport_class = WebSecurityScannerClient.get_transport_class() transport = transport_class( - credentials=credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info)