From bbd2adf8e389e211580873b3c7793be08a034fe7 Mon Sep 17 00:00:00 2001 From: Xiaozhen Liu Date: Tue, 14 Jul 2020 15:02:37 -0700 Subject: [PATCH] feat!: move to webrisk API to python microgenerator (#27) --- .coveragerc | 3 +- UPGRADING.MD | 122 ++ docs/gapic/v1/api.rst | 6 - docs/gapic/v1/types.rst | 5 - docs/gapic/v1beta1/api.rst | 6 - docs/gapic/v1beta1/types.rst | 5 - docs/index.rst | 8 +- docs/webrisk_v1/services.rst | 6 + docs/webrisk_v1/types.rst | 5 + docs/webrisk_v1beta1/services.rst | 6 + docs/webrisk_v1beta1/types.rst | 5 + google/cloud/webrisk/__init__.py | 58 + google/cloud/webrisk/py.typed | 2 + google/cloud/webrisk_v1/__init__.py | 60 +- google/cloud/webrisk_v1/gapic/enums.py | 70 - .../web_risk_service_grpc_transport.py | 180 -- .../gapic/web_risk_service_client.py | 495 ----- .../gapic/web_risk_service_client_config.py | 62 - google/cloud/webrisk_v1/proto/__init__.py | 0 google/cloud/webrisk_v1/proto/webrisk_pb2.py | 1825 ----------------- .../webrisk_v1/proto/webrisk_pb2_grpc.py | 236 --- google/cloud/webrisk_v1/py.typed | 2 + .../{ => webrisk_v1/services}/__init__.py | 14 +- .../services/web_risk_service}/__init__.py | 18 +- .../services/web_risk_service/async_client.py | 448 ++++ .../services/web_risk_service/client.py | 571 ++++++ .../web_risk_service/transports/__init__.py | 36 + .../web_risk_service/transports/base.py | 122 ++ .../web_risk_service/transports/grpc.py | 327 +++ .../transports/grpc_asyncio.py | 325 +++ google/cloud/webrisk_v1/types.py | 48 - google/cloud/webrisk_v1/types/__init__.py | 49 + google/cloud/webrisk_v1/types/webrisk.py | 435 ++++ google/cloud/webrisk_v1beta1/__init__.py | 58 +- .../cloud/webrisk_v1beta1/gapic/__init__.py | 0 google/cloud/webrisk_v1beta1/gapic/enums.py | 70 - .../gapic/transports/__init__.py | 0 ...eb_risk_service_v1_beta1_grpc_transport.py | 153 -- .../gapic/web_risk_service_v1_beta1_client.py | 389 ---- ...web_risk_service_v1_beta1_client_config.py | 47 - .../cloud/webrisk_v1beta1/proto/__init__.py | 0 .../webrisk_v1beta1/proto/webrisk_pb2.py | 1657 --------------- .../webrisk_v1beta1/proto/webrisk_pb2_grpc.py | 178 -- google/cloud/webrisk_v1beta1/py.typed | 2 + .../webrisk_v1beta1/services/__init__.py | 16 + .../web_risk_service_v1_beta1/__init__.py} | 19 +- .../web_risk_service_v1_beta1/async_client.py | 340 +++ .../web_risk_service_v1_beta1/client.py | 464 +++++ .../transports/__init__.py | 38 + .../transports/base.py | 113 + .../transports/grpc.py | 283 +++ .../transports/grpc_asyncio.py | 281 +++ google/cloud/webrisk_v1beta1/types.py | 48 - .../cloud/webrisk_v1beta1/types/__init__.py | 45 + google/cloud/webrisk_v1beta1/types/webrisk.py | 391 ++++ mypy.ini | 3 + noxfile.py | 8 +- samples/AUTHORING_GUIDE.md | 1 + samples/CONTRIBUTING.md | 1 + scripts/fixup_webrisk_v1_keywords.py | 180 ++ scripts/fixup_webrisk_v1beta1_keywords.py | 179 ++ setup.py | 19 +- synth.metadata | 10 +- synth.py | 8 +- .../v1/test_web_risk_service_client_v1.py | 226 -- ...eb_risk_service_v1_beta1_client_v1beta1.py | 184 -- .../unit/gapic/webrisk_v1}/__init__.py | 0 .../gapic/webrisk_v1/test_web_risk_service.py | 1262 ++++++++++++ .../unit/gapic/webrisk_v1beta1}/__init__.py | 0 .../test_web_risk_service_v1_beta1.py | 1111 ++++++++++ 70 files changed, 7347 insertions(+), 5997 deletions(-) create mode 100644 UPGRADING.MD delete mode 100644 docs/gapic/v1/api.rst delete mode 100644 docs/gapic/v1/types.rst delete mode 100644 docs/gapic/v1beta1/api.rst delete mode 100644 docs/gapic/v1beta1/types.rst create mode 100644 docs/webrisk_v1/services.rst create mode 100644 docs/webrisk_v1/types.rst create mode 100644 docs/webrisk_v1beta1/services.rst create mode 100644 docs/webrisk_v1beta1/types.rst create mode 100644 google/cloud/webrisk/__init__.py create mode 100644 google/cloud/webrisk/py.typed delete mode 100644 google/cloud/webrisk_v1/gapic/enums.py delete mode 100644 google/cloud/webrisk_v1/gapic/transports/web_risk_service_grpc_transport.py delete mode 100644 google/cloud/webrisk_v1/gapic/web_risk_service_client.py delete mode 100644 google/cloud/webrisk_v1/gapic/web_risk_service_client_config.py delete mode 100644 google/cloud/webrisk_v1/proto/__init__.py delete mode 100644 google/cloud/webrisk_v1/proto/webrisk_pb2.py delete mode 100644 google/cloud/webrisk_v1/proto/webrisk_pb2_grpc.py create mode 100644 google/cloud/webrisk_v1/py.typed rename google/cloud/{ => webrisk_v1/services}/__init__.py (71%) rename google/{ => cloud/webrisk_v1/services/web_risk_service}/__init__.py (71%) create mode 100644 google/cloud/webrisk_v1/services/web_risk_service/async_client.py create mode 100644 google/cloud/webrisk_v1/services/web_risk_service/client.py create mode 100644 google/cloud/webrisk_v1/services/web_risk_service/transports/__init__.py create mode 100644 google/cloud/webrisk_v1/services/web_risk_service/transports/base.py create mode 100644 google/cloud/webrisk_v1/services/web_risk_service/transports/grpc.py create mode 100644 google/cloud/webrisk_v1/services/web_risk_service/transports/grpc_asyncio.py delete mode 100644 google/cloud/webrisk_v1/types.py create mode 100644 google/cloud/webrisk_v1/types/__init__.py create mode 100644 google/cloud/webrisk_v1/types/webrisk.py delete mode 100644 google/cloud/webrisk_v1beta1/gapic/__init__.py delete mode 100644 google/cloud/webrisk_v1beta1/gapic/enums.py delete mode 100644 google/cloud/webrisk_v1beta1/gapic/transports/__init__.py delete mode 100644 google/cloud/webrisk_v1beta1/gapic/transports/web_risk_service_v1_beta1_grpc_transport.py delete mode 100644 google/cloud/webrisk_v1beta1/gapic/web_risk_service_v1_beta1_client.py delete mode 100644 google/cloud/webrisk_v1beta1/gapic/web_risk_service_v1_beta1_client_config.py delete mode 100644 google/cloud/webrisk_v1beta1/proto/__init__.py delete mode 100644 google/cloud/webrisk_v1beta1/proto/webrisk_pb2.py delete mode 100644 google/cloud/webrisk_v1beta1/proto/webrisk_pb2_grpc.py create mode 100644 google/cloud/webrisk_v1beta1/py.typed create mode 100644 google/cloud/webrisk_v1beta1/services/__init__.py rename google/cloud/{webrisk.py => webrisk_v1beta1/services/web_risk_service_v1_beta1/__init__.py} (66%) create mode 100644 google/cloud/webrisk_v1beta1/services/web_risk_service_v1_beta1/async_client.py create mode 100644 google/cloud/webrisk_v1beta1/services/web_risk_service_v1_beta1/client.py create mode 100644 google/cloud/webrisk_v1beta1/services/web_risk_service_v1_beta1/transports/__init__.py create mode 100644 google/cloud/webrisk_v1beta1/services/web_risk_service_v1_beta1/transports/base.py create mode 100644 google/cloud/webrisk_v1beta1/services/web_risk_service_v1_beta1/transports/grpc.py create mode 100644 google/cloud/webrisk_v1beta1/services/web_risk_service_v1_beta1/transports/grpc_asyncio.py delete mode 100644 google/cloud/webrisk_v1beta1/types.py create mode 100644 google/cloud/webrisk_v1beta1/types/__init__.py create mode 100644 google/cloud/webrisk_v1beta1/types/webrisk.py create mode 100644 mypy.ini create mode 100644 samples/AUTHORING_GUIDE.md create mode 100644 samples/CONTRIBUTING.md create mode 100644 scripts/fixup_webrisk_v1_keywords.py create mode 100644 scripts/fixup_webrisk_v1beta1_keywords.py delete mode 100644 tests/unit/gapic/v1/test_web_risk_service_client_v1.py delete mode 100644 tests/unit/gapic/v1beta1/test_web_risk_service_v1_beta1_client_v1beta1.py rename {google/cloud/webrisk_v1/gapic => tests/unit/gapic/webrisk_v1}/__init__.py (100%) create mode 100644 tests/unit/gapic/webrisk_v1/test_web_risk_service.py rename {google/cloud/webrisk_v1/gapic/transports => tests/unit/gapic/webrisk_v1beta1}/__init__.py (100%) create mode 100644 tests/unit/gapic/webrisk_v1beta1/test_web_risk_service_v1_beta1.py diff --git a/.coveragerc b/.coveragerc index dd39c85..984d4c8 100644 --- a/.coveragerc +++ b/.coveragerc @@ -32,4 +32,5 @@ omit = */gapic/*.py */proto/*.py */core/*.py - */site-packages/*.py \ No newline at end of file + */site-packages/*.py + google/cloud/webrisk/__init__.py diff --git a/UPGRADING.MD b/UPGRADING.MD new file mode 100644 index 0000000..edf2153 --- /dev/null +++ b/UPGRADING.MD @@ -0,0 +1,122 @@ +# 2.0.0 Migration Guide + +The 2.0 release of the `google-cloud-webrisk` client is a significant upgrade based on a [next-gen code generator](https://github.com/googleapis/gapic-generator-python), and includes substantial interface changes. Existing code written for earlier versions of this library will likely require updates to use this version. This document describes the changes that have been made, and what you need to do to update your usage. + +If you experience issues or have questions, please file an [issue](https://github.com/googleapis/python-webrisk/issues). + +## Supported Python Versions + +> **WARNING**: Breaking change + +The 2.0.0 release requires Python 3.6+. + + +## Method Calls + +> **WARNING**: Breaking change + +Methods expect request objects. We provide a script that will convert most common use cases. + +* Install the library + +```py +python3 -m pip install google-cloud-webrisk +``` + +* The scripts `fixup_webrisk_v1_keywords.py` and `fixup_webrisk_v1beta1_keywords.py` shipped with the library. It expects +an input directory (with the code to convert) and an empty destination directory. + +```sh +$ fixup_webrisk_v1_keywords.py --input-directory .samples/ --output-directory samples/ +``` + +**Before:** +```py +from google.cloud import webrisk_v1 + +client = webrisk_v1.WebRiskServiceClient() +# TODO: Initialize `threat_types`: +threat_types = [] + +response = client.search_hashes(threat_types) +``` + + +**After:** +```py +from google.cloud import webrisk_v1 + +client = webrisk_v1.WebRiskServiceClient() + +response = client.search_hashes(request={"threat_types": "[]"}) + +``` + +### More Details + +In `google-cloud-webrisk<2.0.0`, parameters required by the API were positional parameters and optional parameters were keyword parameters. + +**Before:** +```py + def search_hashes( + self, + threat_types, + hash_prefix=None, + retry=google.api_core.gapic_v1.method.DEFAULT, + timeout=google.api_core.gapic_v1.method.DEFAULT, + metadata=None, + ): +``` + +In the 2.0.0 release, all methods have a single positional parameter `request`. Method docstrings indicate whether a parameter is required or optional. + +Some methods have additional keyword only parameters. The available parameters depend on the [`google.api.method_signature` annotation](https://github.com/googleapis/googleapis/blob/master/google/cloud/webrisk/v1/webrisk.proto#L74) specified by the API producer. + + +**After:** +```py + def search_hashes( + self, + request: webrisk.SearchHashesRequest = None, + *, + hash_prefix: bytes = None, + threat_types: Sequence[webrisk.ThreatType] = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> webrisk.SearchHashesResponse: +``` + +> **NOTE:** The `request` parameter and flattened keyword parameters for the API are mutually exclusive. +> Passing both will result in an error. + + +Both of these calls are valid: + +```py +response = client.search_hashes( + request={ + "hash_prefix": hash_prefix, + "threat_types": threat_types, + } +) +``` + +```py +response = client.search_hashes( + hash_prefix=hash_prefix, + threat_types=threat_types, +) +``` + +This call is invalid because it mixes `request` with a keyword argument `threat_types`. Executing this code +will result in an error. + +```py +response = client.synthesize_speech( + request={ + "hash_prefix": hash_prefix, + }, + threat_types=threat_types +) +``` diff --git a/docs/gapic/v1/api.rst b/docs/gapic/v1/api.rst deleted file mode 100644 index 756900a..0000000 --- a/docs/gapic/v1/api.rst +++ /dev/null @@ -1,6 +0,0 @@ -Client for Web Risk API -======================= - -.. automodule:: google.cloud.webrisk_v1 - :members: - :inherited-members: \ No newline at end of file diff --git a/docs/gapic/v1/types.rst b/docs/gapic/v1/types.rst deleted file mode 100644 index da1de57..0000000 --- a/docs/gapic/v1/types.rst +++ /dev/null @@ -1,5 +0,0 @@ -Types for Web Risk API Client -============================= - -.. automodule:: google.cloud.webrisk_v1.types - :members: \ No newline at end of file diff --git a/docs/gapic/v1beta1/api.rst b/docs/gapic/v1beta1/api.rst deleted file mode 100644 index d939a64..0000000 --- a/docs/gapic/v1beta1/api.rst +++ /dev/null @@ -1,6 +0,0 @@ -Client for Web Risk API -======================= - -.. automodule:: google.cloud.webrisk_v1beta1 - :members: - :inherited-members: \ No newline at end of file diff --git a/docs/gapic/v1beta1/types.rst b/docs/gapic/v1beta1/types.rst deleted file mode 100644 index e3d2bc8..0000000 --- a/docs/gapic/v1beta1/types.rst +++ /dev/null @@ -1,5 +0,0 @@ -Types for Web Risk API Client -============================= - -.. automodule:: google.cloud.webrisk_v1beta1.types - :members: \ No newline at end of file diff --git a/docs/index.rst b/docs/index.rst index 5bcdf54..1ae28c1 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -7,8 +7,8 @@ v1 .. toctree:: :maxdepth: 2 - gapic/v1/api - gapic/v1/types + webrisk_v1/services + webrisk_v1/types v1beta1 @@ -16,8 +16,8 @@ v1beta1 .. toctree:: :maxdepth: 2 - gapic/v1beta1/api - gapic/v1beta1/types + webrisk_v1beta1/services + webrisk_v1beta1/types changelog Changelog diff --git a/docs/webrisk_v1/services.rst b/docs/webrisk_v1/services.rst new file mode 100644 index 0000000..e11c0e7 --- /dev/null +++ b/docs/webrisk_v1/services.rst @@ -0,0 +1,6 @@ +Services for Google Cloud Webrisk v1 API +======================================== + +.. automodule:: google.cloud.webrisk_v1.services.web_risk_service + :members: + :inherited-members: diff --git a/docs/webrisk_v1/types.rst b/docs/webrisk_v1/types.rst new file mode 100644 index 0000000..a19ca60 --- /dev/null +++ b/docs/webrisk_v1/types.rst @@ -0,0 +1,5 @@ +Types for Google Cloud Webrisk v1 API +===================================== + +.. automodule:: google.cloud.webrisk_v1.types + :members: diff --git a/docs/webrisk_v1beta1/services.rst b/docs/webrisk_v1beta1/services.rst new file mode 100644 index 0000000..a658fbc --- /dev/null +++ b/docs/webrisk_v1beta1/services.rst @@ -0,0 +1,6 @@ +Services for Google Cloud Webrisk v1beta1 API +============================================= + +.. automodule:: google.cloud.webrisk_v1beta1.services.web_risk_service_v1_beta1 + :members: + :inherited-members: diff --git a/docs/webrisk_v1beta1/types.rst b/docs/webrisk_v1beta1/types.rst new file mode 100644 index 0000000..ffb6ace --- /dev/null +++ b/docs/webrisk_v1beta1/types.rst @@ -0,0 +1,5 @@ +Types for Google Cloud Webrisk v1beta1 API +========================================== + +.. automodule:: google.cloud.webrisk_v1beta1.types + :members: diff --git a/google/cloud/webrisk/__init__.py b/google/cloud/webrisk/__init__.py new file mode 100644 index 0000000..d78ab4c --- /dev/null +++ b/google/cloud/webrisk/__init__.py @@ -0,0 +1,58 @@ +# -*- 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. +# + +from google.cloud.webrisk_v1.services.web_risk_service.async_client import ( + WebRiskServiceAsyncClient, +) +from google.cloud.webrisk_v1.services.web_risk_service.client import ( + WebRiskServiceClient, +) +from google.cloud.webrisk_v1.types.webrisk import CompressionType +from google.cloud.webrisk_v1.types.webrisk import ComputeThreatListDiffRequest +from google.cloud.webrisk_v1.types.webrisk import ComputeThreatListDiffResponse +from google.cloud.webrisk_v1.types.webrisk import CreateSubmissionRequest +from google.cloud.webrisk_v1.types.webrisk import RawHashes +from google.cloud.webrisk_v1.types.webrisk import RawIndices +from google.cloud.webrisk_v1.types.webrisk import RiceDeltaEncoding +from google.cloud.webrisk_v1.types.webrisk import SearchHashesRequest +from google.cloud.webrisk_v1.types.webrisk import SearchHashesResponse +from google.cloud.webrisk_v1.types.webrisk import SearchUrisRequest +from google.cloud.webrisk_v1.types.webrisk import SearchUrisResponse +from google.cloud.webrisk_v1.types.webrisk import Submission +from google.cloud.webrisk_v1.types.webrisk import ThreatEntryAdditions +from google.cloud.webrisk_v1.types.webrisk import ThreatEntryRemovals +from google.cloud.webrisk_v1.types.webrisk import ThreatType + +__all__ = ( + "CompressionType", + "ComputeThreatListDiffRequest", + "ComputeThreatListDiffResponse", + "CreateSubmissionRequest", + "RawHashes", + "RawIndices", + "RiceDeltaEncoding", + "SearchHashesRequest", + "SearchHashesResponse", + "SearchUrisRequest", + "SearchUrisResponse", + "Submission", + "ThreatEntryAdditions", + "ThreatEntryRemovals", + "ThreatType", + "WebRiskServiceAsyncClient", + "WebRiskServiceClient", +) diff --git a/google/cloud/webrisk/py.typed b/google/cloud/webrisk/py.typed new file mode 100644 index 0000000..bef3da1 --- /dev/null +++ b/google/cloud/webrisk/py.typed @@ -0,0 +1,2 @@ +# Marker file for PEP 561. +# The google-cloud-webrisk package uses inline types. diff --git a/google/cloud/webrisk_v1/__init__.py b/google/cloud/webrisk_v1/__init__.py index e67716f..5ba2bcd 100644 --- a/google/cloud/webrisk_v1/__init__.py +++ b/google/cloud/webrisk_v1/__init__.py @@ -1,45 +1,53 @@ # -*- 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 # -# https://www.apache.org/licenses/LICENSE-2.0 +# 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. +# - -from __future__ import absolute_import -import sys -import warnings - -from google.cloud.webrisk_v1 import types -from google.cloud.webrisk_v1.gapic import enums -from google.cloud.webrisk_v1.gapic import web_risk_service_client - - -if sys.version_info[:2] == (2, 7): - message = ( - "A future version of this library will drop support for Python 2.7. " - "More details about Python 2 support for Google Cloud Client Libraries " - "can be found at https://cloud.google.com/python/docs/python2-sunset/" - ) - warnings.warn(message, DeprecationWarning) - - -class WebRiskServiceClient(web_risk_service_client.WebRiskServiceClient): - __doc__ = web_risk_service_client.WebRiskServiceClient.__doc__ - enums = enums +from .services.web_risk_service import WebRiskServiceClient +from .types.webrisk import CompressionType +from .types.webrisk import ComputeThreatListDiffRequest +from .types.webrisk import ComputeThreatListDiffResponse +from .types.webrisk import CreateSubmissionRequest +from .types.webrisk import RawHashes +from .types.webrisk import RawIndices +from .types.webrisk import RiceDeltaEncoding +from .types.webrisk import SearchHashesRequest +from .types.webrisk import SearchHashesResponse +from .types.webrisk import SearchUrisRequest +from .types.webrisk import SearchUrisResponse +from .types.webrisk import Submission +from .types.webrisk import ThreatEntryAdditions +from .types.webrisk import ThreatEntryRemovals +from .types.webrisk import ThreatType __all__ = ( - "enums", - "types", + "CompressionType", + "ComputeThreatListDiffRequest", + "ComputeThreatListDiffResponse", + "CreateSubmissionRequest", + "RawHashes", + "RawIndices", + "RiceDeltaEncoding", + "SearchHashesRequest", + "SearchHashesResponse", + "SearchUrisRequest", + "SearchUrisResponse", + "Submission", + "ThreatEntryAdditions", + "ThreatEntryRemovals", + "ThreatType", "WebRiskServiceClient", ) diff --git a/google/cloud/webrisk_v1/gapic/enums.py b/google/cloud/webrisk_v1/gapic/enums.py deleted file mode 100644 index 42fad3e..0000000 --- a/google/cloud/webrisk_v1/gapic/enums.py +++ /dev/null @@ -1,70 +0,0 @@ -# -*- 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 -# -# https://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. - -"""Wrappers for protocol buffer enum types.""" - -import enum - - -class CompressionType(enum.IntEnum): - """ - The ways in which threat entry sets can be compressed. - - Attributes: - COMPRESSION_TYPE_UNSPECIFIED (int): Unknown. - RAW (int): Raw, uncompressed data. - RICE (int): Rice-Golomb encoded data. - """ - - COMPRESSION_TYPE_UNSPECIFIED = 0 - RAW = 1 - RICE = 2 - - -class ThreatType(enum.IntEnum): - """ - The type of threat. This maps dirrectly to the threat list a threat may - belong to. - - Attributes: - THREAT_TYPE_UNSPECIFIED (int): Unknown. - MALWARE (int): Malware targeting any platform. - SOCIAL_ENGINEERING (int): Social engineering targeting any platform. - UNWANTED_SOFTWARE (int): Unwanted software targeting any platform. - """ - - THREAT_TYPE_UNSPECIFIED = 0 - MALWARE = 1 - SOCIAL_ENGINEERING = 2 - UNWANTED_SOFTWARE = 3 - - -class ComputeThreatListDiffResponse(object): - class ResponseType(enum.IntEnum): - """ - The type of response sent to the client. - - Attributes: - RESPONSE_TYPE_UNSPECIFIED (int): Unknown. - DIFF (int): Partial updates are applied to the client's existing local database. - RESET (int): Full updates resets the client's entire local database. This means - that either the client had no state, was seriously out-of-date, - or the client is believed to be corrupt. - """ - - RESPONSE_TYPE_UNSPECIFIED = 0 - DIFF = 1 - RESET = 2 diff --git a/google/cloud/webrisk_v1/gapic/transports/web_risk_service_grpc_transport.py b/google/cloud/webrisk_v1/gapic/transports/web_risk_service_grpc_transport.py deleted file mode 100644 index e0afe69..0000000 --- a/google/cloud/webrisk_v1/gapic/transports/web_risk_service_grpc_transport.py +++ /dev/null @@ -1,180 +0,0 @@ -# -*- 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 -# -# https://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. - - -import google.api_core.grpc_helpers - -from google.cloud.webrisk_v1.proto import webrisk_pb2_grpc - - -class WebRiskServiceGrpcTransport(object): - """gRPC transport class providing stubs for - google.cloud.webrisk.v1 WebRiskService API. - - The transport provides access to the raw gRPC stubs, - which can be used to take advantage of advanced - features of gRPC. - """ - - # The scopes needed to make gRPC calls to all of the methods defined - # in this service. - _OAUTH_SCOPES = ("https://www.googleapis.com/auth/cloud-platform",) - - def __init__( - self, channel=None, credentials=None, address="webrisk.googleapis.com:443" - ): - """Instantiate the transport class. - - Args: - channel (grpc.Channel): A ``Channel`` instance through - which to make calls. This argument is mutually exclusive - with ``credentials``; providing both will raise an exception. - credentials (google.auth.credentials.Credentials): The - authorization credentials to attach to requests. These - credentials identify this application to the service. If none - are specified, the client will attempt to ascertain the - credentials from the environment. - address (str): The address where the service is hosted. - """ - # If both `channel` and `credentials` are specified, raise an - # exception (channels come with credentials baked in already). - if channel is not None and credentials is not None: - raise ValueError( - "The `channel` and `credentials` arguments are mutually " "exclusive.", - ) - - # Create the channel. - if channel is None: - channel = self.create_channel( - address=address, - credentials=credentials, - options={ - "grpc.max_send_message_length": -1, - "grpc.max_receive_message_length": -1, - }.items(), - ) - - self._channel = channel - - # gRPC uses objects called "stubs" that are bound to the - # channel and provide a basic method for each RPC. - self._stubs = { - "web_risk_service_stub": webrisk_pb2_grpc.WebRiskServiceStub(channel), - } - - @classmethod - def create_channel( - cls, address="webrisk.googleapis.com:443", credentials=None, **kwargs - ): - """Create and return a gRPC channel object. - - Args: - address (str): The host for the channel to use. - credentials (~.Credentials): The - authorization credentials to attach to requests. These - credentials identify this application to the service. If - none are specified, the client will attempt to ascertain - the credentials from the environment. - kwargs (dict): Keyword arguments, which are passed to the - channel creation. - - Returns: - grpc.Channel: A gRPC channel object. - """ - return google.api_core.grpc_helpers.create_channel( - address, credentials=credentials, scopes=cls._OAUTH_SCOPES, **kwargs - ) - - @property - def channel(self): - """The gRPC channel used by the transport. - - Returns: - grpc.Channel: A gRPC channel object. - """ - return self._channel - - @property - def compute_threat_list_diff(self): - """Return the gRPC stub for :meth:`WebRiskServiceClient.compute_threat_list_diff`. - - Gets the most recent threat list diffs. These diffs should be applied to - a local database of hashes to keep it up-to-date. If the local database is - empty or excessively out-of-date, a complete snapshot of the database will - be returned. This Method only updates a single ThreatList at a time. To - update multiple ThreatList databases, this method needs to be called once - for each list. - - Returns: - Callable: A callable which accepts the appropriate - deserialized request object and returns a - deserialized response object. - """ - return self._stubs["web_risk_service_stub"].ComputeThreatListDiff - - @property - def search_uris(self): - """Return the gRPC stub for :meth:`WebRiskServiceClient.search_uris`. - - This method is used to check whether a URI is on a given threatList. - Multiple threatLists may be searched in a single query. - The response will list all requested threatLists the URI was found to - match. If the URI is not found on any of the requested ThreatList an - empty response will be returned. - - Returns: - Callable: A callable which accepts the appropriate - deserialized request object and returns a - deserialized response object. - """ - return self._stubs["web_risk_service_stub"].SearchUris - - @property - def search_hashes(self): - """Return the gRPC stub for :meth:`WebRiskServiceClient.search_hashes`. - - Gets the full hashes that match the requested hash prefix. - This is used after a hash prefix is looked up in a threatList - and there is a match. The client side threatList only holds partial hashes - so the client must query this method to determine if there is a full - hash match of a threat. - - Returns: - Callable: A callable which accepts the appropriate - deserialized request object and returns a - deserialized response object. - """ - return self._stubs["web_risk_service_stub"].SearchHashes - - @property - def create_submission(self): - """Return the gRPC stub for :meth:`WebRiskServiceClient.create_submission`. - - Creates a Submission of a URI suspected of containing phishing - content to be reviewed. If the result verifies the existence of - malicious phishing content, the site will be added to the `Google's - Social Engineering - lists `__ in - order to protect users that could get exposed to this threat in the - future. Only projects with CREATE_SUBMISSION_USERS visibility can use - this method. - - Returns: - Callable: A callable which accepts the appropriate - deserialized request object and returns a - deserialized response object. - """ - return self._stubs["web_risk_service_stub"].CreateSubmission diff --git a/google/cloud/webrisk_v1/gapic/web_risk_service_client.py b/google/cloud/webrisk_v1/gapic/web_risk_service_client.py deleted file mode 100644 index 739adfc..0000000 --- a/google/cloud/webrisk_v1/gapic/web_risk_service_client.py +++ /dev/null @@ -1,495 +0,0 @@ -# -*- 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 -# -# https://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. - -"""Accesses the google.cloud.webrisk.v1 WebRiskService API.""" - -import pkg_resources -import warnings - -from google.oauth2 import service_account -import google.api_core.client_options -import google.api_core.gapic_v1.client_info -import google.api_core.gapic_v1.config -import google.api_core.gapic_v1.method -import google.api_core.gapic_v1.routing_header -import google.api_core.grpc_helpers -import google.api_core.path_template -import grpc - -from google.cloud.webrisk_v1.gapic import enums -from google.cloud.webrisk_v1.gapic import web_risk_service_client_config -from google.cloud.webrisk_v1.gapic.transports import web_risk_service_grpc_transport -from google.cloud.webrisk_v1.proto import webrisk_pb2 -from google.cloud.webrisk_v1.proto import webrisk_pb2_grpc - - -_GAPIC_LIBRARY_VERSION = pkg_resources.get_distribution("google-cloud-webrisk",).version - - -class WebRiskServiceClient(object): - """ - Web Risk API defines an interface to detect malicious URLs on your - website and in client applications. - """ - - SERVICE_ADDRESS = "webrisk.googleapis.com:443" - """The default address of the service.""" - - # The name of the interface for this client. This is the key used to - # find the method configuration in the client_config dictionary. - _INTERFACE_NAME = "google.cloud.webrisk.v1.WebRiskService" - - @classmethod - def from_service_account_file(cls, filename, *args, **kwargs): - """Creates an instance of this client using the provided credentials - file. - - Args: - filename (str): The path to the service account private key json - file. - args: Additional arguments to pass to the constructor. - kwargs: Additional arguments to pass to the constructor. - - Returns: - WebRiskServiceClient: The constructed client. - """ - credentials = service_account.Credentials.from_service_account_file(filename) - kwargs["credentials"] = credentials - return cls(*args, **kwargs) - - from_service_account_json = from_service_account_file - - @classmethod - def project_path(cls, project): - """Return a fully-qualified project string.""" - return google.api_core.path_template.expand( - "projects/{project}", project=project, - ) - - def __init__( - self, - transport=None, - channel=None, - credentials=None, - client_config=None, - client_info=None, - client_options=None, - ): - """Constructor. - - Args: - transport (Union[~.WebRiskServiceGrpcTransport, - Callable[[~.Credentials, type], ~.WebRiskServiceGrpcTransport]): A transport - instance, responsible for actually making the API calls. - The default transport uses the gRPC protocol. - This argument may also be a callable which returns a - transport instance. Callables will be sent the credentials - as the first argument and the default transport class as - the second argument. - channel (grpc.Channel): DEPRECATED. A ``Channel`` instance - through which to make calls. This argument is mutually exclusive - with ``credentials``; providing both will raise an exception. - credentials (google.auth.credentials.Credentials): The - authorization credentials to attach to requests. These - credentials identify this application to the service. If none - are specified, the client will attempt to ascertain the - credentials from the environment. - This argument is mutually exclusive with providing a - transport instance to ``transport``; doing so will raise - an exception. - client_config (dict): DEPRECATED. A dictionary of call options for - each method. If not specified, the default configuration is used. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing - your own client library. - client_options (Union[dict, google.api_core.client_options.ClientOptions]): - Client options used to set user options on the client. API Endpoint - should be set through client_options. - """ - # Raise deprecation warnings for things we want to go away. - if client_config is not None: - warnings.warn( - "The `client_config` argument is deprecated.", - PendingDeprecationWarning, - stacklevel=2, - ) - else: - client_config = web_risk_service_client_config.config - - if channel: - warnings.warn( - "The `channel` argument is deprecated; use " "`transport` instead.", - PendingDeprecationWarning, - stacklevel=2, - ) - - api_endpoint = self.SERVICE_ADDRESS - if client_options: - if type(client_options) == dict: - client_options = google.api_core.client_options.from_dict( - client_options - ) - if client_options.api_endpoint: - api_endpoint = client_options.api_endpoint - - # Instantiate the transport. - # The transport is responsible for handling serialization and - # deserialization and actually sending data to the service. - if transport: - if callable(transport): - self.transport = transport( - credentials=credentials, - default_class=web_risk_service_grpc_transport.WebRiskServiceGrpcTransport, - address=api_endpoint, - ) - else: - if credentials: - raise ValueError( - "Received both a transport instance and " - "credentials; these are mutually exclusive." - ) - self.transport = transport - else: - self.transport = web_risk_service_grpc_transport.WebRiskServiceGrpcTransport( - address=api_endpoint, channel=channel, credentials=credentials, - ) - - if client_info is None: - client_info = google.api_core.gapic_v1.client_info.ClientInfo( - gapic_version=_GAPIC_LIBRARY_VERSION, - ) - else: - client_info.gapic_version = _GAPIC_LIBRARY_VERSION - self._client_info = client_info - - # Parse out the default settings for retry and timeout for each RPC - # from the client configuration. - # (Ordinarily, these are the defaults specified in the `*_config.py` - # file next to this one.) - self._method_configs = google.api_core.gapic_v1.config.parse_method_configs( - client_config["interfaces"][self._INTERFACE_NAME], - ) - - # Save a dictionary of cached API call functions. - # These are the actual callables which invoke the proper - # transport methods, wrapped with `wrap_method` to add retry, - # timeout, and the like. - self._inner_api_calls = {} - - # Service calls - def compute_threat_list_diff( - self, - threat_type, - constraints, - version_token=None, - retry=google.api_core.gapic_v1.method.DEFAULT, - timeout=google.api_core.gapic_v1.method.DEFAULT, - metadata=None, - ): - """ - Gets the most recent threat list diffs. These diffs should be applied to - a local database of hashes to keep it up-to-date. If the local database is - empty or excessively out-of-date, a complete snapshot of the database will - be returned. This Method only updates a single ThreatList at a time. To - update multiple ThreatList databases, this method needs to be called once - for each list. - - Example: - >>> from google.cloud import webrisk_v1 - >>> from google.cloud.webrisk_v1 import enums - >>> - >>> client = webrisk_v1.WebRiskServiceClient() - >>> - >>> # TODO: Initialize `threat_type`: - >>> threat_type = enums.ThreatType.THREAT_TYPE_UNSPECIFIED - >>> - >>> # TODO: Initialize `constraints`: - >>> constraints = {} - >>> - >>> response = client.compute_threat_list_diff(threat_type, constraints) - - Args: - threat_type (~google.cloud.webrisk_v1.types.ThreatType): Required. The threat list to update. Only a single ThreatType should be specified. - constraints (Union[dict, ~google.cloud.webrisk_v1.types.Constraints]): Required. The constraints associated with this request. - - If a dict is provided, it must be of the same form as the protobuf - message :class:`~google.cloud.webrisk_v1.types.Constraints` - version_token (bytes): The current version token of the client for the requested list (the - client version that was received from the last successful diff). - If the client does not have a version token (this is the first time calling - ComputeThreatListDiff), this may be left empty and a full database - snapshot will be returned. - retry (Optional[google.api_core.retry.Retry]): A retry object used - to retry requests. If ``None`` is specified, requests will - be retried using a default configuration. - timeout (Optional[float]): The amount of time, in seconds, to wait - for the request to complete. Note that if ``retry`` is - specified, the timeout applies to each individual attempt. - metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata - that is provided to the method. - - Returns: - A :class:`~google.cloud.webrisk_v1.types.ComputeThreatListDiffResponse` instance. - - Raises: - google.api_core.exceptions.GoogleAPICallError: If the request - failed for any reason. - google.api_core.exceptions.RetryError: If the request failed due - to a retryable error and retry attempts failed. - ValueError: If the parameters are invalid. - """ - # Wrap the transport method to add retry and timeout logic. - if "compute_threat_list_diff" not in self._inner_api_calls: - self._inner_api_calls[ - "compute_threat_list_diff" - ] = google.api_core.gapic_v1.method.wrap_method( - self.transport.compute_threat_list_diff, - default_retry=self._method_configs["ComputeThreatListDiff"].retry, - default_timeout=self._method_configs["ComputeThreatListDiff"].timeout, - client_info=self._client_info, - ) - - request = webrisk_pb2.ComputeThreatListDiffRequest( - threat_type=threat_type, - constraints=constraints, - version_token=version_token, - ) - return self._inner_api_calls["compute_threat_list_diff"]( - request, retry=retry, timeout=timeout, metadata=metadata - ) - - def search_uris( - self, - uri, - threat_types, - retry=google.api_core.gapic_v1.method.DEFAULT, - timeout=google.api_core.gapic_v1.method.DEFAULT, - metadata=None, - ): - """ - This method is used to check whether a URI is on a given threatList. - Multiple threatLists may be searched in a single query. - The response will list all requested threatLists the URI was found to - match. If the URI is not found on any of the requested ThreatList an - empty response will be returned. - - Example: - >>> from google.cloud import webrisk_v1 - >>> from google.cloud.webrisk_v1 import enums - >>> - >>> client = webrisk_v1.WebRiskServiceClient() - >>> - >>> # TODO: Initialize `uri`: - >>> uri = '' - >>> - >>> # TODO: Initialize `threat_types`: - >>> threat_types = [] - >>> - >>> response = client.search_uris(uri, threat_types) - - Args: - uri (str): Required. The URI to be checked for matches. - threat_types (list[~google.cloud.webrisk_v1.types.ThreatType]): Required. The ThreatLists to search in. Multiple ThreatLists may be specified. - retry (Optional[google.api_core.retry.Retry]): A retry object used - to retry requests. If ``None`` is specified, requests will - be retried using a default configuration. - timeout (Optional[float]): The amount of time, in seconds, to wait - for the request to complete. Note that if ``retry`` is - specified, the timeout applies to each individual attempt. - metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata - that is provided to the method. - - Returns: - A :class:`~google.cloud.webrisk_v1.types.SearchUrisResponse` instance. - - Raises: - google.api_core.exceptions.GoogleAPICallError: If the request - failed for any reason. - google.api_core.exceptions.RetryError: If the request failed due - to a retryable error and retry attempts failed. - ValueError: If the parameters are invalid. - """ - # Wrap the transport method to add retry and timeout logic. - if "search_uris" not in self._inner_api_calls: - self._inner_api_calls[ - "search_uris" - ] = google.api_core.gapic_v1.method.wrap_method( - self.transport.search_uris, - default_retry=self._method_configs["SearchUris"].retry, - default_timeout=self._method_configs["SearchUris"].timeout, - client_info=self._client_info, - ) - - request = webrisk_pb2.SearchUrisRequest(uri=uri, threat_types=threat_types,) - return self._inner_api_calls["search_uris"]( - request, retry=retry, timeout=timeout, metadata=metadata - ) - - def search_hashes( - self, - threat_types, - hash_prefix=None, - retry=google.api_core.gapic_v1.method.DEFAULT, - timeout=google.api_core.gapic_v1.method.DEFAULT, - metadata=None, - ): - """ - Gets the full hashes that match the requested hash prefix. - This is used after a hash prefix is looked up in a threatList - and there is a match. The client side threatList only holds partial hashes - so the client must query this method to determine if there is a full - hash match of a threat. - - Example: - >>> from google.cloud import webrisk_v1 - >>> from google.cloud.webrisk_v1 import enums - >>> - >>> client = webrisk_v1.WebRiskServiceClient() - >>> - >>> # TODO: Initialize `threat_types`: - >>> threat_types = [] - >>> - >>> response = client.search_hashes(threat_types) - - Args: - threat_types (list[~google.cloud.webrisk_v1.types.ThreatType]): Required. The ThreatLists to search in. Multiple ThreatLists may be specified. - hash_prefix (bytes): A hash prefix, consisting of the most significant 4-32 bytes of a SHA256 - hash. For JSON requests, this field is base64-encoded. - retry (Optional[google.api_core.retry.Retry]): A retry object used - to retry requests. If ``None`` is specified, requests will - be retried using a default configuration. - timeout (Optional[float]): The amount of time, in seconds, to wait - for the request to complete. Note that if ``retry`` is - specified, the timeout applies to each individual attempt. - metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata - that is provided to the method. - - Returns: - A :class:`~google.cloud.webrisk_v1.types.SearchHashesResponse` instance. - - Raises: - google.api_core.exceptions.GoogleAPICallError: If the request - failed for any reason. - google.api_core.exceptions.RetryError: If the request failed due - to a retryable error and retry attempts failed. - ValueError: If the parameters are invalid. - """ - # Wrap the transport method to add retry and timeout logic. - if "search_hashes" not in self._inner_api_calls: - self._inner_api_calls[ - "search_hashes" - ] = google.api_core.gapic_v1.method.wrap_method( - self.transport.search_hashes, - default_retry=self._method_configs["SearchHashes"].retry, - default_timeout=self._method_configs["SearchHashes"].timeout, - client_info=self._client_info, - ) - - request = webrisk_pb2.SearchHashesRequest( - threat_types=threat_types, hash_prefix=hash_prefix, - ) - return self._inner_api_calls["search_hashes"]( - request, retry=retry, timeout=timeout, metadata=metadata - ) - - def create_submission( - self, - parent, - submission, - retry=google.api_core.gapic_v1.method.DEFAULT, - timeout=google.api_core.gapic_v1.method.DEFAULT, - metadata=None, - ): - """ - Creates a Submission of a URI suspected of containing phishing - content to be reviewed. If the result verifies the existence of - malicious phishing content, the site will be added to the `Google's - Social Engineering - lists `__ in - order to protect users that could get exposed to this threat in the - future. Only projects with CREATE_SUBMISSION_USERS visibility can use - this method. - - Example: - >>> from google.cloud import webrisk_v1 - >>> - >>> client = webrisk_v1.WebRiskServiceClient() - >>> - >>> parent = client.project_path('[PROJECT]') - >>> - >>> # TODO: Initialize `submission`: - >>> submission = {} - >>> - >>> response = client.create_submission(parent, submission) - - Args: - parent (str): Required. The name of the project that is making the submission. - This string is in the format "projects/{project_number}". - submission (Union[dict, ~google.cloud.webrisk_v1.types.Submission]): Required. The submission that contains the content of the phishing report. - - If a dict is provided, it must be of the same form as the protobuf - message :class:`~google.cloud.webrisk_v1.types.Submission` - retry (Optional[google.api_core.retry.Retry]): A retry object used - to retry requests. If ``None`` is specified, requests will - be retried using a default configuration. - timeout (Optional[float]): The amount of time, in seconds, to wait - for the request to complete. Note that if ``retry`` is - specified, the timeout applies to each individual attempt. - metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata - that is provided to the method. - - Returns: - A :class:`~google.cloud.webrisk_v1.types.Submission` instance. - - Raises: - google.api_core.exceptions.GoogleAPICallError: If the request - failed for any reason. - google.api_core.exceptions.RetryError: If the request failed due - to a retryable error and retry attempts failed. - ValueError: If the parameters are invalid. - """ - # Wrap the transport method to add retry and timeout logic. - if "create_submission" not in self._inner_api_calls: - self._inner_api_calls[ - "create_submission" - ] = google.api_core.gapic_v1.method.wrap_method( - self.transport.create_submission, - default_retry=self._method_configs["CreateSubmission"].retry, - default_timeout=self._method_configs["CreateSubmission"].timeout, - client_info=self._client_info, - ) - - request = webrisk_pb2.CreateSubmissionRequest( - parent=parent, submission=submission, - ) - if metadata is None: - metadata = [] - metadata = list(metadata) - try: - routing_header = [("parent", parent)] - except AttributeError: - pass - else: - routing_metadata = google.api_core.gapic_v1.routing_header.to_grpc_metadata( - routing_header - ) - metadata.append(routing_metadata) - - return self._inner_api_calls["create_submission"]( - request, retry=retry, timeout=timeout, metadata=metadata - ) diff --git a/google/cloud/webrisk_v1/gapic/web_risk_service_client_config.py b/google/cloud/webrisk_v1/gapic/web_risk_service_client_config.py deleted file mode 100644 index ca541aa..0000000 --- a/google/cloud/webrisk_v1/gapic/web_risk_service_client_config.py +++ /dev/null @@ -1,62 +0,0 @@ -config = { - "interfaces": { - "google.cloud.webrisk.v1.WebRiskService": { - "retry_codes": { - "retry_policy_1_codes": ["DEADLINE_EXCEEDED", "UNAVAILABLE"], - "no_retry_codes": [], - "no_retry_1_codes": [], - }, - "retry_params": { - "retry_policy_1_params": { - "initial_retry_delay_millis": 100, - "retry_delay_multiplier": 1.3, - "max_retry_delay_millis": 60000, - "initial_rpc_timeout_millis": 600000, - "rpc_timeout_multiplier": 1.0, - "max_rpc_timeout_millis": 600000, - "total_timeout_millis": 600000, - }, - "no_retry_params": { - "initial_retry_delay_millis": 0, - "retry_delay_multiplier": 0.0, - "max_retry_delay_millis": 0, - "initial_rpc_timeout_millis": 0, - "rpc_timeout_multiplier": 1.0, - "max_rpc_timeout_millis": 0, - "total_timeout_millis": 0, - }, - "no_retry_1_params": { - "initial_retry_delay_millis": 0, - "retry_delay_multiplier": 0.0, - "max_retry_delay_millis": 0, - "initial_rpc_timeout_millis": 60000, - "rpc_timeout_multiplier": 1.0, - "max_rpc_timeout_millis": 60000, - "total_timeout_millis": 60000, - }, - }, - "methods": { - "ComputeThreatListDiff": { - "timeout_millis": 600000, - "retry_codes_name": "retry_policy_1_codes", - "retry_params_name": "retry_policy_1_params", - }, - "SearchUris": { - "timeout_millis": 600000, - "retry_codes_name": "retry_policy_1_codes", - "retry_params_name": "retry_policy_1_params", - }, - "SearchHashes": { - "timeout_millis": 600000, - "retry_codes_name": "retry_policy_1_codes", - "retry_params_name": "retry_policy_1_params", - }, - "CreateSubmission": { - "timeout_millis": 60000, - "retry_codes_name": "no_retry_1_codes", - "retry_params_name": "no_retry_1_params", - }, - }, - } - } -} diff --git a/google/cloud/webrisk_v1/proto/__init__.py b/google/cloud/webrisk_v1/proto/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/google/cloud/webrisk_v1/proto/webrisk_pb2.py b/google/cloud/webrisk_v1/proto/webrisk_pb2.py deleted file mode 100644 index 876d27e..0000000 --- a/google/cloud/webrisk_v1/proto/webrisk_pb2.py +++ /dev/null @@ -1,1825 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by the protocol buffer compiler. DO NOT EDIT! -# source: google/cloud/webrisk_v1/proto/webrisk.proto -"""Generated protocol buffer code.""" -from google.protobuf.internal import enum_type_wrapper -from google.protobuf import descriptor as _descriptor -from google.protobuf import message as _message -from google.protobuf import reflection as _reflection -from google.protobuf import symbol_database as _symbol_database - -# @@protoc_insertion_point(imports) - -_sym_db = _symbol_database.Default() - - -from google.api import annotations_pb2 as google_dot_api_dot_annotations__pb2 -from google.api import client_pb2 as google_dot_api_dot_client__pb2 -from google.api import field_behavior_pb2 as google_dot_api_dot_field__behavior__pb2 -from google.api import resource_pb2 as google_dot_api_dot_resource__pb2 -from google.protobuf import timestamp_pb2 as google_dot_protobuf_dot_timestamp__pb2 - - -DESCRIPTOR = _descriptor.FileDescriptor( - name="google/cloud/webrisk_v1/proto/webrisk.proto", - package="google.cloud.webrisk.v1", - syntax="proto3", - serialized_options=b"\n\025com.google.webrisk.v1B\014WebRiskProtoP\001Z>google.golang.org/genproto/googleapis/cloud/webrisk/v1;webrisk\242\002\004GCWR\252\002\027Google.Cloud.WebRisk.V1\312\002\027Google\\Cloud\\WebRisk\\V1\352\002\032Google::Cloud::WebRisk::V1", - create_key=_descriptor._internal_create_key, - serialized_pb=b'\n+google/cloud/webrisk_v1/proto/webrisk.proto\x12\x17google.cloud.webrisk.v1\x1a\x1cgoogle/api/annotations.proto\x1a\x17google/api/client.proto\x1a\x1fgoogle/api/field_behavior.proto\x1a\x19google/api/resource.proto\x1a\x1fgoogle/protobuf/timestamp.proto"\xe3\x02\n\x1c\x43omputeThreatListDiffRequest\x12=\n\x0bthreat_type\x18\x01 \x01(\x0e\x32#.google.cloud.webrisk.v1.ThreatTypeB\x03\xe0\x41\x02\x12\x15\n\rversion_token\x18\x02 \x01(\x0c\x12[\n\x0b\x63onstraints\x18\x03 \x01(\x0b\x32\x41.google.cloud.webrisk.v1.ComputeThreatListDiffRequest.ConstraintsB\x03\xe0\x41\x02\x1a\x8f\x01\n\x0b\x43onstraints\x12\x18\n\x10max_diff_entries\x18\x01 \x01(\x05\x12\x1c\n\x14max_database_entries\x18\x02 \x01(\x05\x12H\n\x16supported_compressions\x18\x03 \x03(\x0e\x32(.google.cloud.webrisk.v1.CompressionType"\x86\x04\n\x1d\x43omputeThreatListDiffResponse\x12Z\n\rresponse_type\x18\x04 \x01(\x0e\x32\x43.google.cloud.webrisk.v1.ComputeThreatListDiffResponse.ResponseType\x12@\n\tadditions\x18\x05 \x01(\x0b\x32-.google.cloud.webrisk.v1.ThreatEntryAdditions\x12>\n\x08removals\x18\x06 \x01(\x0b\x32,.google.cloud.webrisk.v1.ThreatEntryRemovals\x12\x19\n\x11new_version_token\x18\x07 \x01(\x0c\x12Q\n\x08\x63hecksum\x18\x08 \x01(\x0b\x32?.google.cloud.webrisk.v1.ComputeThreatListDiffResponse.Checksum\x12\x39\n\x15recommended_next_diff\x18\x02 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x1a\x1a\n\x08\x43hecksum\x12\x0e\n\x06sha256\x18\x01 \x01(\x0c"B\n\x0cResponseType\x12\x1d\n\x19RESPONSE_TYPE_UNSPECIFIED\x10\x00\x12\x08\n\x04\x44IFF\x10\x01\x12\t\n\x05RESET\x10\x02"e\n\x11SearchUrisRequest\x12\x10\n\x03uri\x18\x01 \x01(\tB\x03\xe0\x41\x02\x12>\n\x0cthreat_types\x18\x02 \x03(\x0e\x32#.google.cloud.webrisk.v1.ThreatTypeB\x03\xe0\x41\x02"\xd4\x01\n\x12SearchUrisResponse\x12\x45\n\x06threat\x18\x01 \x01(\x0b\x32\x35.google.cloud.webrisk.v1.SearchUrisResponse.ThreatUri\x1aw\n\tThreatUri\x12\x39\n\x0cthreat_types\x18\x01 \x03(\x0e\x32#.google.cloud.webrisk.v1.ThreatType\x12/\n\x0b\x65xpire_time\x18\x02 \x01(\x0b\x32\x1a.google.protobuf.Timestamp"j\n\x13SearchHashesRequest\x12\x13\n\x0bhash_prefix\x18\x01 \x01(\x0c\x12>\n\x0cthreat_types\x18\x02 \x03(\x0e\x32#.google.cloud.webrisk.v1.ThreatTypeB\x03\xe0\x41\x02"\xa4\x02\n\x14SearchHashesResponse\x12I\n\x07threats\x18\x01 \x03(\x0b\x32\x38.google.cloud.webrisk.v1.SearchHashesResponse.ThreatHash\x12\x38\n\x14negative_expire_time\x18\x02 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x1a\x86\x01\n\nThreatHash\x12\x39\n\x0cthreat_types\x18\x01 \x03(\x0e\x32#.google.cloud.webrisk.v1.ThreatType\x12\x0c\n\x04hash\x18\x02 \x01(\x0c\x12/\n\x0b\x65xpire_time\x18\x03 \x01(\x0b\x32\x1a.google.protobuf.Timestamp"\x8f\x01\n\x14ThreatEntryAdditions\x12\x36\n\nraw_hashes\x18\x01 \x03(\x0b\x32".google.cloud.webrisk.v1.RawHashes\x12?\n\x0brice_hashes\x18\x02 \x01(\x0b\x32*.google.cloud.webrisk.v1.RiceDeltaEncoding"\x91\x01\n\x13ThreatEntryRemovals\x12\x38\n\x0braw_indices\x18\x01 \x01(\x0b\x32#.google.cloud.webrisk.v1.RawIndices\x12@\n\x0crice_indices\x18\x02 \x01(\x0b\x32*.google.cloud.webrisk.v1.RiceDeltaEncoding"\x1d\n\nRawIndices\x12\x0f\n\x07indices\x18\x01 \x03(\x05"4\n\tRawHashes\x12\x13\n\x0bprefix_size\x18\x01 \x01(\x05\x12\x12\n\nraw_hashes\x18\x02 \x01(\x0c"k\n\x11RiceDeltaEncoding\x12\x13\n\x0b\x66irst_value\x18\x01 \x01(\x03\x12\x16\n\x0erice_parameter\x18\x02 \x01(\x05\x12\x13\n\x0b\x65ntry_count\x18\x03 \x01(\x05\x12\x14\n\x0c\x65ncoded_data\x18\x04 \x01(\x0c"\x1e\n\nSubmission\x12\x10\n\x03uri\x18\x01 \x01(\tB\x03\xe0\x41\x02"\x9c\x01\n\x17\x43reateSubmissionRequest\x12\x43\n\x06parent\x18\x01 \x01(\tB3\xe0\x41\x02\xfa\x41-\n+cloudresourcemanager.googleapis.com/Project\x12<\n\nsubmission\x18\x02 \x01(\x0b\x32#.google.cloud.webrisk.v1.SubmissionB\x03\xe0\x41\x02*e\n\nThreatType\x12\x1b\n\x17THREAT_TYPE_UNSPECIFIED\x10\x00\x12\x0b\n\x07MALWARE\x10\x01\x12\x16\n\x12SOCIAL_ENGINEERING\x10\x02\x12\x15\n\x11UNWANTED_SOFTWARE\x10\x03*F\n\x0f\x43ompressionType\x12 \n\x1c\x43OMPRESSION_TYPE_UNSPECIFIED\x10\x00\x12\x07\n\x03RAW\x10\x01\x12\x08\n\x04RICE\x10\x02\x32\xa3\x06\n\x0eWebRiskService\x12\xd3\x01\n\x15\x43omputeThreatListDiff\x12\x35.google.cloud.webrisk.v1.ComputeThreatListDiffRequest\x1a\x36.google.cloud.webrisk.v1.ComputeThreatListDiffResponse"K\x82\xd3\xe4\x93\x02\x1d\x12\x1b/v1/threatLists:computeDiff\xda\x41%threat_type,version_token,constraints\x12\x91\x01\n\nSearchUris\x12*.google.cloud.webrisk.v1.SearchUrisRequest\x1a+.google.cloud.webrisk.v1.SearchUrisResponse"*\x82\xd3\xe4\x93\x02\x11\x12\x0f/v1/uris:search\xda\x41\x10uri,threat_types\x12\xa1\x01\n\x0cSearchHashes\x12,.google.cloud.webrisk.v1.SearchHashesRequest\x1a-.google.cloud.webrisk.v1.SearchHashesResponse"4\x82\xd3\xe4\x93\x02\x13\x12\x11/v1/hashes:search\xda\x41\x18hash_prefix,threat_types\x12\xb6\x01\n\x10\x43reateSubmission\x12\x30.google.cloud.webrisk.v1.CreateSubmissionRequest\x1a#.google.cloud.webrisk.v1.Submission"K\x82\xd3\xe4\x93\x02\x31"#/v1/{parent=projects/*}/submissions:\nsubmission\xda\x41\x11parent,submission\x1aJ\xca\x41\x16webrisk.googleapis.com\xd2\x41.https://www.googleapis.com/auth/cloud-platformB\xbf\x01\n\x15\x63om.google.webrisk.v1B\x0cWebRiskProtoP\x01Z>google.golang.org/genproto/googleapis/cloud/webrisk/v1;webrisk\xa2\x02\x04GCWR\xaa\x02\x17Google.Cloud.WebRisk.V1\xca\x02\x17Google\\Cloud\\WebRisk\\V1\xea\x02\x1aGoogle::Cloud::WebRisk::V1b\x06proto3', - dependencies=[ - google_dot_api_dot_annotations__pb2.DESCRIPTOR, - google_dot_api_dot_client__pb2.DESCRIPTOR, - google_dot_api_dot_field__behavior__pb2.DESCRIPTOR, - google_dot_api_dot_resource__pb2.DESCRIPTOR, - google_dot_protobuf_dot_timestamp__pb2.DESCRIPTOR, - ], -) - -_THREATTYPE = _descriptor.EnumDescriptor( - name="ThreatType", - full_name="google.cloud.webrisk.v1.ThreatType", - filename=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - values=[ - _descriptor.EnumValueDescriptor( - name="THREAT_TYPE_UNSPECIFIED", - index=0, - number=0, - serialized_options=None, - type=None, - create_key=_descriptor._internal_create_key, - ), - _descriptor.EnumValueDescriptor( - name="MALWARE", - index=1, - number=1, - serialized_options=None, - type=None, - create_key=_descriptor._internal_create_key, - ), - _descriptor.EnumValueDescriptor( - name="SOCIAL_ENGINEERING", - index=2, - number=2, - serialized_options=None, - type=None, - create_key=_descriptor._internal_create_key, - ), - _descriptor.EnumValueDescriptor( - name="UNWANTED_SOFTWARE", - index=3, - number=3, - serialized_options=None, - type=None, - create_key=_descriptor._internal_create_key, - ), - ], - containing_type=None, - serialized_options=None, - serialized_start=2499, - serialized_end=2600, -) -_sym_db.RegisterEnumDescriptor(_THREATTYPE) - -ThreatType = enum_type_wrapper.EnumTypeWrapper(_THREATTYPE) -_COMPRESSIONTYPE = _descriptor.EnumDescriptor( - name="CompressionType", - full_name="google.cloud.webrisk.v1.CompressionType", - filename=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - values=[ - _descriptor.EnumValueDescriptor( - name="COMPRESSION_TYPE_UNSPECIFIED", - index=0, - number=0, - serialized_options=None, - type=None, - create_key=_descriptor._internal_create_key, - ), - _descriptor.EnumValueDescriptor( - name="RAW", - index=1, - number=1, - serialized_options=None, - type=None, - create_key=_descriptor._internal_create_key, - ), - _descriptor.EnumValueDescriptor( - name="RICE", - index=2, - number=2, - serialized_options=None, - type=None, - create_key=_descriptor._internal_create_key, - ), - ], - containing_type=None, - serialized_options=None, - serialized_start=2602, - serialized_end=2672, -) -_sym_db.RegisterEnumDescriptor(_COMPRESSIONTYPE) - -CompressionType = enum_type_wrapper.EnumTypeWrapper(_COMPRESSIONTYPE) -THREAT_TYPE_UNSPECIFIED = 0 -MALWARE = 1 -SOCIAL_ENGINEERING = 2 -UNWANTED_SOFTWARE = 3 -COMPRESSION_TYPE_UNSPECIFIED = 0 -RAW = 1 -RICE = 2 - - -_COMPUTETHREATLISTDIFFRESPONSE_RESPONSETYPE = _descriptor.EnumDescriptor( - name="ResponseType", - full_name="google.cloud.webrisk.v1.ComputeThreatListDiffResponse.ResponseType", - filename=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - values=[ - _descriptor.EnumValueDescriptor( - name="RESPONSE_TYPE_UNSPECIFIED", - index=0, - number=0, - serialized_options=None, - type=None, - create_key=_descriptor._internal_create_key, - ), - _descriptor.EnumValueDescriptor( - name="DIFF", - index=1, - number=1, - serialized_options=None, - type=None, - create_key=_descriptor._internal_create_key, - ), - _descriptor.EnumValueDescriptor( - name="RESET", - index=2, - number=2, - serialized_options=None, - type=None, - create_key=_descriptor._internal_create_key, - ), - ], - containing_type=None, - serialized_options=None, - serialized_start=1031, - serialized_end=1097, -) -_sym_db.RegisterEnumDescriptor(_COMPUTETHREATLISTDIFFRESPONSE_RESPONSETYPE) - - -_COMPUTETHREATLISTDIFFREQUEST_CONSTRAINTS = _descriptor.Descriptor( - name="Constraints", - full_name="google.cloud.webrisk.v1.ComputeThreatListDiffRequest.Constraints", - filename=None, - file=DESCRIPTOR, - containing_type=None, - create_key=_descriptor._internal_create_key, - fields=[ - _descriptor.FieldDescriptor( - name="max_diff_entries", - full_name="google.cloud.webrisk.v1.ComputeThreatListDiffRequest.Constraints.max_diff_entries", - index=0, - number=1, - type=5, - cpp_type=1, - label=1, - has_default_value=False, - default_value=0, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - _descriptor.FieldDescriptor( - name="max_database_entries", - full_name="google.cloud.webrisk.v1.ComputeThreatListDiffRequest.Constraints.max_database_entries", - index=1, - number=2, - type=5, - cpp_type=1, - label=1, - has_default_value=False, - default_value=0, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - _descriptor.FieldDescriptor( - name="supported_compressions", - full_name="google.cloud.webrisk.v1.ComputeThreatListDiffRequest.Constraints.supported_compressions", - index=2, - number=3, - type=14, - cpp_type=8, - label=3, - has_default_value=False, - default_value=[], - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - ], - extensions=[], - nested_types=[], - enum_types=[], - serialized_options=None, - is_extendable=False, - syntax="proto3", - extension_ranges=[], - oneofs=[], - serialized_start=433, - serialized_end=576, -) - -_COMPUTETHREATLISTDIFFREQUEST = _descriptor.Descriptor( - name="ComputeThreatListDiffRequest", - full_name="google.cloud.webrisk.v1.ComputeThreatListDiffRequest", - filename=None, - file=DESCRIPTOR, - containing_type=None, - create_key=_descriptor._internal_create_key, - fields=[ - _descriptor.FieldDescriptor( - name="threat_type", - full_name="google.cloud.webrisk.v1.ComputeThreatListDiffRequest.threat_type", - index=0, - number=1, - type=14, - cpp_type=8, - label=1, - has_default_value=False, - default_value=0, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=b"\340A\002", - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - _descriptor.FieldDescriptor( - name="version_token", - full_name="google.cloud.webrisk.v1.ComputeThreatListDiffRequest.version_token", - index=1, - number=2, - type=12, - cpp_type=9, - label=1, - has_default_value=False, - default_value=b"", - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - _descriptor.FieldDescriptor( - name="constraints", - full_name="google.cloud.webrisk.v1.ComputeThreatListDiffRequest.constraints", - index=2, - number=3, - type=11, - cpp_type=10, - label=1, - has_default_value=False, - default_value=None, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=b"\340A\002", - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - ], - extensions=[], - nested_types=[_COMPUTETHREATLISTDIFFREQUEST_CONSTRAINTS,], - enum_types=[], - serialized_options=None, - is_extendable=False, - syntax="proto3", - extension_ranges=[], - oneofs=[], - serialized_start=221, - serialized_end=576, -) - - -_COMPUTETHREATLISTDIFFRESPONSE_CHECKSUM = _descriptor.Descriptor( - name="Checksum", - full_name="google.cloud.webrisk.v1.ComputeThreatListDiffResponse.Checksum", - filename=None, - file=DESCRIPTOR, - containing_type=None, - create_key=_descriptor._internal_create_key, - fields=[ - _descriptor.FieldDescriptor( - name="sha256", - full_name="google.cloud.webrisk.v1.ComputeThreatListDiffResponse.Checksum.sha256", - index=0, - number=1, - type=12, - cpp_type=9, - label=1, - has_default_value=False, - default_value=b"", - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - ], - extensions=[], - nested_types=[], - enum_types=[], - serialized_options=None, - is_extendable=False, - syntax="proto3", - extension_ranges=[], - oneofs=[], - serialized_start=1003, - serialized_end=1029, -) - -_COMPUTETHREATLISTDIFFRESPONSE = _descriptor.Descriptor( - name="ComputeThreatListDiffResponse", - full_name="google.cloud.webrisk.v1.ComputeThreatListDiffResponse", - filename=None, - file=DESCRIPTOR, - containing_type=None, - create_key=_descriptor._internal_create_key, - fields=[ - _descriptor.FieldDescriptor( - name="response_type", - full_name="google.cloud.webrisk.v1.ComputeThreatListDiffResponse.response_type", - index=0, - number=4, - type=14, - cpp_type=8, - label=1, - has_default_value=False, - default_value=0, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - _descriptor.FieldDescriptor( - name="additions", - full_name="google.cloud.webrisk.v1.ComputeThreatListDiffResponse.additions", - index=1, - number=5, - type=11, - cpp_type=10, - label=1, - has_default_value=False, - default_value=None, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - _descriptor.FieldDescriptor( - name="removals", - full_name="google.cloud.webrisk.v1.ComputeThreatListDiffResponse.removals", - index=2, - number=6, - type=11, - cpp_type=10, - label=1, - has_default_value=False, - default_value=None, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - _descriptor.FieldDescriptor( - name="new_version_token", - full_name="google.cloud.webrisk.v1.ComputeThreatListDiffResponse.new_version_token", - index=3, - number=7, - type=12, - cpp_type=9, - label=1, - has_default_value=False, - default_value=b"", - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - _descriptor.FieldDescriptor( - name="checksum", - full_name="google.cloud.webrisk.v1.ComputeThreatListDiffResponse.checksum", - index=4, - number=8, - type=11, - cpp_type=10, - label=1, - has_default_value=False, - default_value=None, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - _descriptor.FieldDescriptor( - name="recommended_next_diff", - full_name="google.cloud.webrisk.v1.ComputeThreatListDiffResponse.recommended_next_diff", - index=5, - number=2, - type=11, - cpp_type=10, - label=1, - has_default_value=False, - default_value=None, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - ], - extensions=[], - nested_types=[_COMPUTETHREATLISTDIFFRESPONSE_CHECKSUM,], - enum_types=[_COMPUTETHREATLISTDIFFRESPONSE_RESPONSETYPE,], - serialized_options=None, - is_extendable=False, - syntax="proto3", - extension_ranges=[], - oneofs=[], - serialized_start=579, - serialized_end=1097, -) - - -_SEARCHURISREQUEST = _descriptor.Descriptor( - name="SearchUrisRequest", - full_name="google.cloud.webrisk.v1.SearchUrisRequest", - filename=None, - file=DESCRIPTOR, - containing_type=None, - create_key=_descriptor._internal_create_key, - fields=[ - _descriptor.FieldDescriptor( - name="uri", - full_name="google.cloud.webrisk.v1.SearchUrisRequest.uri", - index=0, - number=1, - type=9, - cpp_type=9, - label=1, - has_default_value=False, - default_value=b"".decode("utf-8"), - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=b"\340A\002", - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - _descriptor.FieldDescriptor( - name="threat_types", - full_name="google.cloud.webrisk.v1.SearchUrisRequest.threat_types", - index=1, - number=2, - type=14, - cpp_type=8, - label=3, - has_default_value=False, - default_value=[], - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=b"\340A\002", - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - ], - extensions=[], - nested_types=[], - enum_types=[], - serialized_options=None, - is_extendable=False, - syntax="proto3", - extension_ranges=[], - oneofs=[], - serialized_start=1099, - serialized_end=1200, -) - - -_SEARCHURISRESPONSE_THREATURI = _descriptor.Descriptor( - name="ThreatUri", - full_name="google.cloud.webrisk.v1.SearchUrisResponse.ThreatUri", - filename=None, - file=DESCRIPTOR, - containing_type=None, - create_key=_descriptor._internal_create_key, - fields=[ - _descriptor.FieldDescriptor( - name="threat_types", - full_name="google.cloud.webrisk.v1.SearchUrisResponse.ThreatUri.threat_types", - index=0, - number=1, - type=14, - cpp_type=8, - label=3, - has_default_value=False, - default_value=[], - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - _descriptor.FieldDescriptor( - name="expire_time", - full_name="google.cloud.webrisk.v1.SearchUrisResponse.ThreatUri.expire_time", - index=1, - number=2, - type=11, - cpp_type=10, - label=1, - has_default_value=False, - default_value=None, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - ], - extensions=[], - nested_types=[], - enum_types=[], - serialized_options=None, - is_extendable=False, - syntax="proto3", - extension_ranges=[], - oneofs=[], - serialized_start=1296, - serialized_end=1415, -) - -_SEARCHURISRESPONSE = _descriptor.Descriptor( - name="SearchUrisResponse", - full_name="google.cloud.webrisk.v1.SearchUrisResponse", - filename=None, - file=DESCRIPTOR, - containing_type=None, - create_key=_descriptor._internal_create_key, - fields=[ - _descriptor.FieldDescriptor( - name="threat", - full_name="google.cloud.webrisk.v1.SearchUrisResponse.threat", - index=0, - number=1, - type=11, - cpp_type=10, - label=1, - has_default_value=False, - default_value=None, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - ], - extensions=[], - nested_types=[_SEARCHURISRESPONSE_THREATURI,], - enum_types=[], - serialized_options=None, - is_extendable=False, - syntax="proto3", - extension_ranges=[], - oneofs=[], - serialized_start=1203, - serialized_end=1415, -) - - -_SEARCHHASHESREQUEST = _descriptor.Descriptor( - name="SearchHashesRequest", - full_name="google.cloud.webrisk.v1.SearchHashesRequest", - filename=None, - file=DESCRIPTOR, - containing_type=None, - create_key=_descriptor._internal_create_key, - fields=[ - _descriptor.FieldDescriptor( - name="hash_prefix", - full_name="google.cloud.webrisk.v1.SearchHashesRequest.hash_prefix", - index=0, - number=1, - type=12, - cpp_type=9, - label=1, - has_default_value=False, - default_value=b"", - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - _descriptor.FieldDescriptor( - name="threat_types", - full_name="google.cloud.webrisk.v1.SearchHashesRequest.threat_types", - index=1, - number=2, - type=14, - cpp_type=8, - label=3, - has_default_value=False, - default_value=[], - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=b"\340A\002", - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - ], - extensions=[], - nested_types=[], - enum_types=[], - serialized_options=None, - is_extendable=False, - syntax="proto3", - extension_ranges=[], - oneofs=[], - serialized_start=1417, - serialized_end=1523, -) - - -_SEARCHHASHESRESPONSE_THREATHASH = _descriptor.Descriptor( - name="ThreatHash", - full_name="google.cloud.webrisk.v1.SearchHashesResponse.ThreatHash", - filename=None, - file=DESCRIPTOR, - containing_type=None, - create_key=_descriptor._internal_create_key, - fields=[ - _descriptor.FieldDescriptor( - name="threat_types", - full_name="google.cloud.webrisk.v1.SearchHashesResponse.ThreatHash.threat_types", - index=0, - number=1, - type=14, - cpp_type=8, - label=3, - has_default_value=False, - default_value=[], - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - _descriptor.FieldDescriptor( - name="hash", - full_name="google.cloud.webrisk.v1.SearchHashesResponse.ThreatHash.hash", - index=1, - number=2, - type=12, - cpp_type=9, - label=1, - has_default_value=False, - default_value=b"", - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - _descriptor.FieldDescriptor( - name="expire_time", - full_name="google.cloud.webrisk.v1.SearchHashesResponse.ThreatHash.expire_time", - index=2, - number=3, - type=11, - cpp_type=10, - label=1, - has_default_value=False, - default_value=None, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - ], - extensions=[], - nested_types=[], - enum_types=[], - serialized_options=None, - is_extendable=False, - syntax="proto3", - extension_ranges=[], - oneofs=[], - serialized_start=1684, - serialized_end=1818, -) - -_SEARCHHASHESRESPONSE = _descriptor.Descriptor( - name="SearchHashesResponse", - full_name="google.cloud.webrisk.v1.SearchHashesResponse", - filename=None, - file=DESCRIPTOR, - containing_type=None, - create_key=_descriptor._internal_create_key, - fields=[ - _descriptor.FieldDescriptor( - name="threats", - full_name="google.cloud.webrisk.v1.SearchHashesResponse.threats", - index=0, - number=1, - type=11, - cpp_type=10, - label=3, - has_default_value=False, - default_value=[], - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - _descriptor.FieldDescriptor( - name="negative_expire_time", - full_name="google.cloud.webrisk.v1.SearchHashesResponse.negative_expire_time", - index=1, - number=2, - type=11, - cpp_type=10, - label=1, - has_default_value=False, - default_value=None, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - ], - extensions=[], - nested_types=[_SEARCHHASHESRESPONSE_THREATHASH,], - enum_types=[], - serialized_options=None, - is_extendable=False, - syntax="proto3", - extension_ranges=[], - oneofs=[], - serialized_start=1526, - serialized_end=1818, -) - - -_THREATENTRYADDITIONS = _descriptor.Descriptor( - name="ThreatEntryAdditions", - full_name="google.cloud.webrisk.v1.ThreatEntryAdditions", - filename=None, - file=DESCRIPTOR, - containing_type=None, - create_key=_descriptor._internal_create_key, - fields=[ - _descriptor.FieldDescriptor( - name="raw_hashes", - full_name="google.cloud.webrisk.v1.ThreatEntryAdditions.raw_hashes", - index=0, - number=1, - type=11, - cpp_type=10, - label=3, - has_default_value=False, - default_value=[], - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - _descriptor.FieldDescriptor( - name="rice_hashes", - full_name="google.cloud.webrisk.v1.ThreatEntryAdditions.rice_hashes", - index=1, - number=2, - type=11, - cpp_type=10, - label=1, - has_default_value=False, - default_value=None, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - ], - extensions=[], - nested_types=[], - enum_types=[], - serialized_options=None, - is_extendable=False, - syntax="proto3", - extension_ranges=[], - oneofs=[], - serialized_start=1821, - serialized_end=1964, -) - - -_THREATENTRYREMOVALS = _descriptor.Descriptor( - name="ThreatEntryRemovals", - full_name="google.cloud.webrisk.v1.ThreatEntryRemovals", - filename=None, - file=DESCRIPTOR, - containing_type=None, - create_key=_descriptor._internal_create_key, - fields=[ - _descriptor.FieldDescriptor( - name="raw_indices", - full_name="google.cloud.webrisk.v1.ThreatEntryRemovals.raw_indices", - index=0, - number=1, - type=11, - cpp_type=10, - label=1, - has_default_value=False, - default_value=None, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - _descriptor.FieldDescriptor( - name="rice_indices", - full_name="google.cloud.webrisk.v1.ThreatEntryRemovals.rice_indices", - index=1, - number=2, - type=11, - cpp_type=10, - label=1, - has_default_value=False, - default_value=None, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - ], - extensions=[], - nested_types=[], - enum_types=[], - serialized_options=None, - is_extendable=False, - syntax="proto3", - extension_ranges=[], - oneofs=[], - serialized_start=1967, - serialized_end=2112, -) - - -_RAWINDICES = _descriptor.Descriptor( - name="RawIndices", - full_name="google.cloud.webrisk.v1.RawIndices", - filename=None, - file=DESCRIPTOR, - containing_type=None, - create_key=_descriptor._internal_create_key, - fields=[ - _descriptor.FieldDescriptor( - name="indices", - full_name="google.cloud.webrisk.v1.RawIndices.indices", - index=0, - number=1, - type=5, - cpp_type=1, - label=3, - has_default_value=False, - default_value=[], - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - ], - extensions=[], - nested_types=[], - enum_types=[], - serialized_options=None, - is_extendable=False, - syntax="proto3", - extension_ranges=[], - oneofs=[], - serialized_start=2114, - serialized_end=2143, -) - - -_RAWHASHES = _descriptor.Descriptor( - name="RawHashes", - full_name="google.cloud.webrisk.v1.RawHashes", - filename=None, - file=DESCRIPTOR, - containing_type=None, - create_key=_descriptor._internal_create_key, - fields=[ - _descriptor.FieldDescriptor( - name="prefix_size", - full_name="google.cloud.webrisk.v1.RawHashes.prefix_size", - index=0, - number=1, - type=5, - cpp_type=1, - label=1, - has_default_value=False, - default_value=0, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - _descriptor.FieldDescriptor( - name="raw_hashes", - full_name="google.cloud.webrisk.v1.RawHashes.raw_hashes", - index=1, - number=2, - type=12, - cpp_type=9, - label=1, - has_default_value=False, - default_value=b"", - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - ], - extensions=[], - nested_types=[], - enum_types=[], - serialized_options=None, - is_extendable=False, - syntax="proto3", - extension_ranges=[], - oneofs=[], - serialized_start=2145, - serialized_end=2197, -) - - -_RICEDELTAENCODING = _descriptor.Descriptor( - name="RiceDeltaEncoding", - full_name="google.cloud.webrisk.v1.RiceDeltaEncoding", - filename=None, - file=DESCRIPTOR, - containing_type=None, - create_key=_descriptor._internal_create_key, - fields=[ - _descriptor.FieldDescriptor( - name="first_value", - full_name="google.cloud.webrisk.v1.RiceDeltaEncoding.first_value", - index=0, - number=1, - type=3, - cpp_type=2, - label=1, - has_default_value=False, - default_value=0, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - _descriptor.FieldDescriptor( - name="rice_parameter", - full_name="google.cloud.webrisk.v1.RiceDeltaEncoding.rice_parameter", - index=1, - number=2, - type=5, - cpp_type=1, - label=1, - has_default_value=False, - default_value=0, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - _descriptor.FieldDescriptor( - name="entry_count", - full_name="google.cloud.webrisk.v1.RiceDeltaEncoding.entry_count", - index=2, - number=3, - type=5, - cpp_type=1, - label=1, - has_default_value=False, - default_value=0, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - _descriptor.FieldDescriptor( - name="encoded_data", - full_name="google.cloud.webrisk.v1.RiceDeltaEncoding.encoded_data", - index=3, - number=4, - type=12, - cpp_type=9, - label=1, - has_default_value=False, - default_value=b"", - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - ], - extensions=[], - nested_types=[], - enum_types=[], - serialized_options=None, - is_extendable=False, - syntax="proto3", - extension_ranges=[], - oneofs=[], - serialized_start=2199, - serialized_end=2306, -) - - -_SUBMISSION = _descriptor.Descriptor( - name="Submission", - full_name="google.cloud.webrisk.v1.Submission", - filename=None, - file=DESCRIPTOR, - containing_type=None, - create_key=_descriptor._internal_create_key, - fields=[ - _descriptor.FieldDescriptor( - name="uri", - full_name="google.cloud.webrisk.v1.Submission.uri", - index=0, - number=1, - type=9, - cpp_type=9, - label=1, - has_default_value=False, - default_value=b"".decode("utf-8"), - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=b"\340A\002", - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - ], - extensions=[], - nested_types=[], - enum_types=[], - serialized_options=None, - is_extendable=False, - syntax="proto3", - extension_ranges=[], - oneofs=[], - serialized_start=2308, - serialized_end=2338, -) - - -_CREATESUBMISSIONREQUEST = _descriptor.Descriptor( - name="CreateSubmissionRequest", - full_name="google.cloud.webrisk.v1.CreateSubmissionRequest", - filename=None, - file=DESCRIPTOR, - containing_type=None, - create_key=_descriptor._internal_create_key, - fields=[ - _descriptor.FieldDescriptor( - name="parent", - full_name="google.cloud.webrisk.v1.CreateSubmissionRequest.parent", - index=0, - number=1, - type=9, - cpp_type=9, - label=1, - has_default_value=False, - default_value=b"".decode("utf-8"), - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=b"\340A\002\372A-\n+cloudresourcemanager.googleapis.com/Project", - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - _descriptor.FieldDescriptor( - name="submission", - full_name="google.cloud.webrisk.v1.CreateSubmissionRequest.submission", - index=1, - number=2, - type=11, - cpp_type=10, - label=1, - has_default_value=False, - default_value=None, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=b"\340A\002", - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - ], - extensions=[], - nested_types=[], - enum_types=[], - serialized_options=None, - is_extendable=False, - syntax="proto3", - extension_ranges=[], - oneofs=[], - serialized_start=2341, - serialized_end=2497, -) - -_COMPUTETHREATLISTDIFFREQUEST_CONSTRAINTS.fields_by_name[ - "supported_compressions" -].enum_type = _COMPRESSIONTYPE -_COMPUTETHREATLISTDIFFREQUEST_CONSTRAINTS.containing_type = ( - _COMPUTETHREATLISTDIFFREQUEST -) -_COMPUTETHREATLISTDIFFREQUEST.fields_by_name["threat_type"].enum_type = _THREATTYPE -_COMPUTETHREATLISTDIFFREQUEST.fields_by_name[ - "constraints" -].message_type = _COMPUTETHREATLISTDIFFREQUEST_CONSTRAINTS -_COMPUTETHREATLISTDIFFRESPONSE_CHECKSUM.containing_type = _COMPUTETHREATLISTDIFFRESPONSE -_COMPUTETHREATLISTDIFFRESPONSE.fields_by_name[ - "response_type" -].enum_type = _COMPUTETHREATLISTDIFFRESPONSE_RESPONSETYPE -_COMPUTETHREATLISTDIFFRESPONSE.fields_by_name[ - "additions" -].message_type = _THREATENTRYADDITIONS -_COMPUTETHREATLISTDIFFRESPONSE.fields_by_name[ - "removals" -].message_type = _THREATENTRYREMOVALS -_COMPUTETHREATLISTDIFFRESPONSE.fields_by_name[ - "checksum" -].message_type = _COMPUTETHREATLISTDIFFRESPONSE_CHECKSUM -_COMPUTETHREATLISTDIFFRESPONSE.fields_by_name[ - "recommended_next_diff" -].message_type = google_dot_protobuf_dot_timestamp__pb2._TIMESTAMP -_COMPUTETHREATLISTDIFFRESPONSE_RESPONSETYPE.containing_type = ( - _COMPUTETHREATLISTDIFFRESPONSE -) -_SEARCHURISREQUEST.fields_by_name["threat_types"].enum_type = _THREATTYPE -_SEARCHURISRESPONSE_THREATURI.fields_by_name["threat_types"].enum_type = _THREATTYPE -_SEARCHURISRESPONSE_THREATURI.fields_by_name[ - "expire_time" -].message_type = google_dot_protobuf_dot_timestamp__pb2._TIMESTAMP -_SEARCHURISRESPONSE_THREATURI.containing_type = _SEARCHURISRESPONSE -_SEARCHURISRESPONSE.fields_by_name[ - "threat" -].message_type = _SEARCHURISRESPONSE_THREATURI -_SEARCHHASHESREQUEST.fields_by_name["threat_types"].enum_type = _THREATTYPE -_SEARCHHASHESRESPONSE_THREATHASH.fields_by_name["threat_types"].enum_type = _THREATTYPE -_SEARCHHASHESRESPONSE_THREATHASH.fields_by_name[ - "expire_time" -].message_type = google_dot_protobuf_dot_timestamp__pb2._TIMESTAMP -_SEARCHHASHESRESPONSE_THREATHASH.containing_type = _SEARCHHASHESRESPONSE -_SEARCHHASHESRESPONSE.fields_by_name[ - "threats" -].message_type = _SEARCHHASHESRESPONSE_THREATHASH -_SEARCHHASHESRESPONSE.fields_by_name[ - "negative_expire_time" -].message_type = google_dot_protobuf_dot_timestamp__pb2._TIMESTAMP -_THREATENTRYADDITIONS.fields_by_name["raw_hashes"].message_type = _RAWHASHES -_THREATENTRYADDITIONS.fields_by_name["rice_hashes"].message_type = _RICEDELTAENCODING -_THREATENTRYREMOVALS.fields_by_name["raw_indices"].message_type = _RAWINDICES -_THREATENTRYREMOVALS.fields_by_name["rice_indices"].message_type = _RICEDELTAENCODING -_CREATESUBMISSIONREQUEST.fields_by_name["submission"].message_type = _SUBMISSION -DESCRIPTOR.message_types_by_name[ - "ComputeThreatListDiffRequest" -] = _COMPUTETHREATLISTDIFFREQUEST -DESCRIPTOR.message_types_by_name[ - "ComputeThreatListDiffResponse" -] = _COMPUTETHREATLISTDIFFRESPONSE -DESCRIPTOR.message_types_by_name["SearchUrisRequest"] = _SEARCHURISREQUEST -DESCRIPTOR.message_types_by_name["SearchUrisResponse"] = _SEARCHURISRESPONSE -DESCRIPTOR.message_types_by_name["SearchHashesRequest"] = _SEARCHHASHESREQUEST -DESCRIPTOR.message_types_by_name["SearchHashesResponse"] = _SEARCHHASHESRESPONSE -DESCRIPTOR.message_types_by_name["ThreatEntryAdditions"] = _THREATENTRYADDITIONS -DESCRIPTOR.message_types_by_name["ThreatEntryRemovals"] = _THREATENTRYREMOVALS -DESCRIPTOR.message_types_by_name["RawIndices"] = _RAWINDICES -DESCRIPTOR.message_types_by_name["RawHashes"] = _RAWHASHES -DESCRIPTOR.message_types_by_name["RiceDeltaEncoding"] = _RICEDELTAENCODING -DESCRIPTOR.message_types_by_name["Submission"] = _SUBMISSION -DESCRIPTOR.message_types_by_name["CreateSubmissionRequest"] = _CREATESUBMISSIONREQUEST -DESCRIPTOR.enum_types_by_name["ThreatType"] = _THREATTYPE -DESCRIPTOR.enum_types_by_name["CompressionType"] = _COMPRESSIONTYPE -_sym_db.RegisterFileDescriptor(DESCRIPTOR) - -ComputeThreatListDiffRequest = _reflection.GeneratedProtocolMessageType( - "ComputeThreatListDiffRequest", - (_message.Message,), - { - "Constraints": _reflection.GeneratedProtocolMessageType( - "Constraints", - (_message.Message,), - { - "DESCRIPTOR": _COMPUTETHREATLISTDIFFREQUEST_CONSTRAINTS, - "__module__": "google.cloud.webrisk_v1.proto.webrisk_pb2", - "__doc__": """The constraints for this diff. - - Attributes: - max_diff_entries: - The maximum size in number of entries. The diff will not - contain more entries than this value. This should be a power - of 2 between 2\ **10 and 2**\ 20. If zero, no diff size limit - is set. - max_database_entries: - Sets the maximum number of entries that the client is willing - to have in the local database. This should be a power of 2 - between 2\ **10 and 2**\ 20. If zero, no database size limit - is set. - supported_compressions: - The compression types supported by the client. - """, - # @@protoc_insertion_point(class_scope:google.cloud.webrisk.v1.ComputeThreatListDiffRequest.Constraints) - }, - ), - "DESCRIPTOR": _COMPUTETHREATLISTDIFFREQUEST, - "__module__": "google.cloud.webrisk_v1.proto.webrisk_pb2", - "__doc__": """Describes an API diff request. - - Attributes: - threat_type: - Required. The threat list to update. Only a single ThreatType - should be specified. - version_token: - The current version token of the client for the requested list - (the client version that was received from the last successful - diff). If the client does not have a version token (this is - the first time calling ComputeThreatListDiff), this may be - left empty and a full database snapshot will be returned. - constraints: - Required. The constraints associated with this request. - """, - # @@protoc_insertion_point(class_scope:google.cloud.webrisk.v1.ComputeThreatListDiffRequest) - }, -) -_sym_db.RegisterMessage(ComputeThreatListDiffRequest) -_sym_db.RegisterMessage(ComputeThreatListDiffRequest.Constraints) - -ComputeThreatListDiffResponse = _reflection.GeneratedProtocolMessageType( - "ComputeThreatListDiffResponse", - (_message.Message,), - { - "Checksum": _reflection.GeneratedProtocolMessageType( - "Checksum", - (_message.Message,), - { - "DESCRIPTOR": _COMPUTETHREATLISTDIFFRESPONSE_CHECKSUM, - "__module__": "google.cloud.webrisk_v1.proto.webrisk_pb2", - "__doc__": """The expected state of a client’s local database. - - Attributes: - sha256: - The SHA256 hash of the client state; that is, of the sorted - list of all hashes present in the database. - """, - # @@protoc_insertion_point(class_scope:google.cloud.webrisk.v1.ComputeThreatListDiffResponse.Checksum) - }, - ), - "DESCRIPTOR": _COMPUTETHREATLISTDIFFRESPONSE, - "__module__": "google.cloud.webrisk_v1.proto.webrisk_pb2", - "__doc__": """ - Attributes: - response_type: - The type of response. This may indicate that an action must be - taken by the client when the response is received. - additions: - A set of entries to add to a local threat type’s list. - removals: - A set of entries to remove from a local threat type’s list. - This field may be empty. - new_version_token: - The new opaque client version token. This should be retained - by the client and passed into the next call of - ComputeThreatListDiff as ‘version_token’. A separate version - token should be stored and used for each threatList. - checksum: - The expected SHA256 hash of the client state; that is, of the - sorted list of all hashes present in the database after - applying the provided diff. If the client state doesn’t match - the expected state, the client must discard this diff and - retry later. - recommended_next_diff: - The soonest the client should wait before issuing any diff - request. Querying sooner is unlikely to produce a meaningful - diff. Waiting longer is acceptable considering the use case. - If this field is not set clients may update as soon as they - want. - """, - # @@protoc_insertion_point(class_scope:google.cloud.webrisk.v1.ComputeThreatListDiffResponse) - }, -) -_sym_db.RegisterMessage(ComputeThreatListDiffResponse) -_sym_db.RegisterMessage(ComputeThreatListDiffResponse.Checksum) - -SearchUrisRequest = _reflection.GeneratedProtocolMessageType( - "SearchUrisRequest", - (_message.Message,), - { - "DESCRIPTOR": _SEARCHURISREQUEST, - "__module__": "google.cloud.webrisk_v1.proto.webrisk_pb2", - "__doc__": """Request to check URI entries against threatLists. - - Attributes: - uri: - Required. The URI to be checked for matches. - threat_types: - Required. The ThreatLists to search in. Multiple ThreatLists - may be specified. - """, - # @@protoc_insertion_point(class_scope:google.cloud.webrisk.v1.SearchUrisRequest) - }, -) -_sym_db.RegisterMessage(SearchUrisRequest) - -SearchUrisResponse = _reflection.GeneratedProtocolMessageType( - "SearchUrisResponse", - (_message.Message,), - { - "ThreatUri": _reflection.GeneratedProtocolMessageType( - "ThreatUri", - (_message.Message,), - { - "DESCRIPTOR": _SEARCHURISRESPONSE_THREATURI, - "__module__": "google.cloud.webrisk_v1.proto.webrisk_pb2", - "__doc__": """Contains threat information on a matching uri. - - Attributes: - threat_types: - The ThreatList this threat belongs to. - expire_time: - The cache lifetime for the returned match. Clients must not - cache this response past this timestamp to avoid false - positives. - """, - # @@protoc_insertion_point(class_scope:google.cloud.webrisk.v1.SearchUrisResponse.ThreatUri) - }, - ), - "DESCRIPTOR": _SEARCHURISRESPONSE, - "__module__": "google.cloud.webrisk_v1.proto.webrisk_pb2", - "__doc__": """ - Attributes: - threat: - The threat list matches. This may be empty if the URI is on no - list. - """, - # @@protoc_insertion_point(class_scope:google.cloud.webrisk.v1.SearchUrisResponse) - }, -) -_sym_db.RegisterMessage(SearchUrisResponse) -_sym_db.RegisterMessage(SearchUrisResponse.ThreatUri) - -SearchHashesRequest = _reflection.GeneratedProtocolMessageType( - "SearchHashesRequest", - (_message.Message,), - { - "DESCRIPTOR": _SEARCHHASHESREQUEST, - "__module__": "google.cloud.webrisk_v1.proto.webrisk_pb2", - "__doc__": """Request to return full hashes matched by the provided hash prefixes. - - Attributes: - hash_prefix: - A hash prefix, consisting of the most significant 4-32 bytes - of a SHA256 hash. For JSON requests, this field is - base64-encoded. - threat_types: - Required. The ThreatLists to search in. Multiple ThreatLists - may be specified. - """, - # @@protoc_insertion_point(class_scope:google.cloud.webrisk.v1.SearchHashesRequest) - }, -) -_sym_db.RegisterMessage(SearchHashesRequest) - -SearchHashesResponse = _reflection.GeneratedProtocolMessageType( - "SearchHashesResponse", - (_message.Message,), - { - "ThreatHash": _reflection.GeneratedProtocolMessageType( - "ThreatHash", - (_message.Message,), - { - "DESCRIPTOR": _SEARCHHASHESRESPONSE_THREATHASH, - "__module__": "google.cloud.webrisk_v1.proto.webrisk_pb2", - "__doc__": """Contains threat information on a matching hash. - - Attributes: - threat_types: - The ThreatList this threat belongs to. This must contain at - least one entry. - hash: - A 32 byte SHA256 hash. This field is in binary format. For - JSON requests, hashes are base64-encoded. - expire_time: - The cache lifetime for the returned match. Clients must not - cache this response past this timestamp to avoid false - positives. - """, - # @@protoc_insertion_point(class_scope:google.cloud.webrisk.v1.SearchHashesResponse.ThreatHash) - }, - ), - "DESCRIPTOR": _SEARCHHASHESRESPONSE, - "__module__": "google.cloud.webrisk_v1.proto.webrisk_pb2", - "__doc__": """ - Attributes: - threats: - The full hashes that matched the requested prefixes. The hash - will be populated in the key. - negative_expire_time: - For requested entities that did not match the threat list, how - long to cache the response until. - """, - # @@protoc_insertion_point(class_scope:google.cloud.webrisk.v1.SearchHashesResponse) - }, -) -_sym_db.RegisterMessage(SearchHashesResponse) -_sym_db.RegisterMessage(SearchHashesResponse.ThreatHash) - -ThreatEntryAdditions = _reflection.GeneratedProtocolMessageType( - "ThreatEntryAdditions", - (_message.Message,), - { - "DESCRIPTOR": _THREATENTRYADDITIONS, - "__module__": "google.cloud.webrisk_v1.proto.webrisk_pb2", - "__doc__": """Contains the set of entries to add to a local database. May contain a - combination of compressed and raw data in a single response. - - Attributes: - raw_hashes: - The raw SHA256-formatted entries. Repeated to allow returning - sets of hashes with different prefix sizes. - rice_hashes: - The encoded 4-byte prefixes of SHA256-formatted entries, using - a Golomb-Rice encoding. The hashes are converted to uint32, - sorted in ascending order, then delta encoded and stored as - encoded_data. - """, - # @@protoc_insertion_point(class_scope:google.cloud.webrisk.v1.ThreatEntryAdditions) - }, -) -_sym_db.RegisterMessage(ThreatEntryAdditions) - -ThreatEntryRemovals = _reflection.GeneratedProtocolMessageType( - "ThreatEntryRemovals", - (_message.Message,), - { - "DESCRIPTOR": _THREATENTRYREMOVALS, - "__module__": "google.cloud.webrisk_v1.proto.webrisk_pb2", - "__doc__": """Contains the set of entries to remove from a local database. - - Attributes: - raw_indices: - The raw removal indices for a local list. - rice_indices: - The encoded local, lexicographically-sorted list indices, - using a Golomb-Rice encoding. Used for sending compressed - removal indices. The removal indices (uint32) are sorted in - ascending order, then delta encoded and stored as - encoded_data. - """, - # @@protoc_insertion_point(class_scope:google.cloud.webrisk.v1.ThreatEntryRemovals) - }, -) -_sym_db.RegisterMessage(ThreatEntryRemovals) - -RawIndices = _reflection.GeneratedProtocolMessageType( - "RawIndices", - (_message.Message,), - { - "DESCRIPTOR": _RAWINDICES, - "__module__": "google.cloud.webrisk_v1.proto.webrisk_pb2", - "__doc__": """A set of raw indices to remove from a local list. - - Attributes: - indices: - The indices to remove from a lexicographically-sorted local - list. - """, - # @@protoc_insertion_point(class_scope:google.cloud.webrisk.v1.RawIndices) - }, -) -_sym_db.RegisterMessage(RawIndices) - -RawHashes = _reflection.GeneratedProtocolMessageType( - "RawHashes", - (_message.Message,), - { - "DESCRIPTOR": _RAWHASHES, - "__module__": "google.cloud.webrisk_v1.proto.webrisk_pb2", - "__doc__": """The uncompressed threat entries in hash format. Hashes can be anywhere - from 4 to 32 bytes in size. A large majority are 4 bytes, but some - hashes are lengthened if they collide with the hash of a popular URI. - Used for sending ThreatEntryAdditons to clients that do not support - compression, or when sending non-4-byte hashes to clients that do - support compression. - - Attributes: - prefix_size: - The number of bytes for each prefix encoded below. This field - can be anywhere from 4 (shortest prefix) to 32 (full SHA256 - hash). In practice this is almost always 4, except in - exceptional circumstances. - raw_hashes: - The hashes, in binary format, concatenated into one long - string. Hashes are sorted in lexicographic order. For JSON API - users, hashes are base64-encoded. - """, - # @@protoc_insertion_point(class_scope:google.cloud.webrisk.v1.RawHashes) - }, -) -_sym_db.RegisterMessage(RawHashes) - -RiceDeltaEncoding = _reflection.GeneratedProtocolMessageType( - "RiceDeltaEncoding", - (_message.Message,), - { - "DESCRIPTOR": _RICEDELTAENCODING, - "__module__": "google.cloud.webrisk_v1.proto.webrisk_pb2", - "__doc__": """The Rice-Golomb encoded data. Used for sending compressed 4-byte - hashes or compressed removal indices. - - Attributes: - first_value: - The offset of the first entry in the encoded data, or, if only - a single integer was encoded, that single integer’s value. If - the field is empty or missing, assume zero. - rice_parameter: - The Golomb-Rice parameter, which is a number between 2 and 28. - This field is missing (that is, zero) if ``num_entries`` is - zero. - entry_count: - The number of entries that are delta encoded in the encoded - data. If only a single integer was encoded, this will be zero - and the single value will be stored in ``first_value``. - encoded_data: - The encoded deltas that are encoded using the Golomb-Rice - coder. - """, - # @@protoc_insertion_point(class_scope:google.cloud.webrisk.v1.RiceDeltaEncoding) - }, -) -_sym_db.RegisterMessage(RiceDeltaEncoding) - -Submission = _reflection.GeneratedProtocolMessageType( - "Submission", - (_message.Message,), - { - "DESCRIPTOR": _SUBMISSION, - "__module__": "google.cloud.webrisk_v1.proto.webrisk_pb2", - "__doc__": """Wraps a URI that might be displaying phishing content. - - Attributes: - uri: - Required. The URI that is being reported for phishing content - to be analyzed. - """, - # @@protoc_insertion_point(class_scope:google.cloud.webrisk.v1.Submission) - }, -) -_sym_db.RegisterMessage(Submission) - -CreateSubmissionRequest = _reflection.GeneratedProtocolMessageType( - "CreateSubmissionRequest", - (_message.Message,), - { - "DESCRIPTOR": _CREATESUBMISSIONREQUEST, - "__module__": "google.cloud.webrisk_v1.proto.webrisk_pb2", - "__doc__": """Request to send a potentially phishy URI to WebRisk. - - Attributes: - parent: - Required. The name of the project that is making the - submission. This string is in the format - “projects/{project_number}”. - submission: - Required. The submission that contains the content of the - phishing report. - """, - # @@protoc_insertion_point(class_scope:google.cloud.webrisk.v1.CreateSubmissionRequest) - }, -) -_sym_db.RegisterMessage(CreateSubmissionRequest) - - -DESCRIPTOR._options = None -_COMPUTETHREATLISTDIFFREQUEST.fields_by_name["threat_type"]._options = None -_COMPUTETHREATLISTDIFFREQUEST.fields_by_name["constraints"]._options = None -_SEARCHURISREQUEST.fields_by_name["uri"]._options = None -_SEARCHURISREQUEST.fields_by_name["threat_types"]._options = None -_SEARCHHASHESREQUEST.fields_by_name["threat_types"]._options = None -_SUBMISSION.fields_by_name["uri"]._options = None -_CREATESUBMISSIONREQUEST.fields_by_name["parent"]._options = None -_CREATESUBMISSIONREQUEST.fields_by_name["submission"]._options = None - -_WEBRISKSERVICE = _descriptor.ServiceDescriptor( - name="WebRiskService", - full_name="google.cloud.webrisk.v1.WebRiskService", - file=DESCRIPTOR, - index=0, - serialized_options=b"\312A\026webrisk.googleapis.com\322A.https://www.googleapis.com/auth/cloud-platform", - create_key=_descriptor._internal_create_key, - serialized_start=2675, - serialized_end=3478, - methods=[ - _descriptor.MethodDescriptor( - name="ComputeThreatListDiff", - full_name="google.cloud.webrisk.v1.WebRiskService.ComputeThreatListDiff", - index=0, - containing_service=None, - input_type=_COMPUTETHREATLISTDIFFREQUEST, - output_type=_COMPUTETHREATLISTDIFFRESPONSE, - serialized_options=b"\202\323\344\223\002\035\022\033/v1/threatLists:computeDiff\332A%threat_type,version_token,constraints", - create_key=_descriptor._internal_create_key, - ), - _descriptor.MethodDescriptor( - name="SearchUris", - full_name="google.cloud.webrisk.v1.WebRiskService.SearchUris", - index=1, - containing_service=None, - input_type=_SEARCHURISREQUEST, - output_type=_SEARCHURISRESPONSE, - serialized_options=b"\202\323\344\223\002\021\022\017/v1/uris:search\332A\020uri,threat_types", - create_key=_descriptor._internal_create_key, - ), - _descriptor.MethodDescriptor( - name="SearchHashes", - full_name="google.cloud.webrisk.v1.WebRiskService.SearchHashes", - index=2, - containing_service=None, - input_type=_SEARCHHASHESREQUEST, - output_type=_SEARCHHASHESRESPONSE, - serialized_options=b"\202\323\344\223\002\023\022\021/v1/hashes:search\332A\030hash_prefix,threat_types", - create_key=_descriptor._internal_create_key, - ), - _descriptor.MethodDescriptor( - name="CreateSubmission", - full_name="google.cloud.webrisk.v1.WebRiskService.CreateSubmission", - index=3, - containing_service=None, - input_type=_CREATESUBMISSIONREQUEST, - output_type=_SUBMISSION, - serialized_options=b'\202\323\344\223\0021"#/v1/{parent=projects/*}/submissions:\nsubmission\332A\021parent,submission', - create_key=_descriptor._internal_create_key, - ), - ], -) -_sym_db.RegisterServiceDescriptor(_WEBRISKSERVICE) - -DESCRIPTOR.services_by_name["WebRiskService"] = _WEBRISKSERVICE - -# @@protoc_insertion_point(module_scope) diff --git a/google/cloud/webrisk_v1/proto/webrisk_pb2_grpc.py b/google/cloud/webrisk_v1/proto/webrisk_pb2_grpc.py deleted file mode 100644 index 84d12c0..0000000 --- a/google/cloud/webrisk_v1/proto/webrisk_pb2_grpc.py +++ /dev/null @@ -1,236 +0,0 @@ -# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! -"""Client and server classes corresponding to protobuf-defined services.""" -import grpc - -from google.cloud.webrisk_v1.proto import ( - webrisk_pb2 as google_dot_cloud_dot_webrisk__v1_dot_proto_dot_webrisk__pb2, -) - - -class WebRiskServiceStub(object): - """Web Risk API defines an interface to detect malicious URLs on your - website and in client applications. - """ - - def __init__(self, channel): - """Constructor. - - Args: - channel: A grpc.Channel. - """ - self.ComputeThreatListDiff = channel.unary_unary( - "/google.cloud.webrisk.v1.WebRiskService/ComputeThreatListDiff", - request_serializer=google_dot_cloud_dot_webrisk__v1_dot_proto_dot_webrisk__pb2.ComputeThreatListDiffRequest.SerializeToString, - response_deserializer=google_dot_cloud_dot_webrisk__v1_dot_proto_dot_webrisk__pb2.ComputeThreatListDiffResponse.FromString, - ) - self.SearchUris = channel.unary_unary( - "/google.cloud.webrisk.v1.WebRiskService/SearchUris", - request_serializer=google_dot_cloud_dot_webrisk__v1_dot_proto_dot_webrisk__pb2.SearchUrisRequest.SerializeToString, - response_deserializer=google_dot_cloud_dot_webrisk__v1_dot_proto_dot_webrisk__pb2.SearchUrisResponse.FromString, - ) - self.SearchHashes = channel.unary_unary( - "/google.cloud.webrisk.v1.WebRiskService/SearchHashes", - request_serializer=google_dot_cloud_dot_webrisk__v1_dot_proto_dot_webrisk__pb2.SearchHashesRequest.SerializeToString, - response_deserializer=google_dot_cloud_dot_webrisk__v1_dot_proto_dot_webrisk__pb2.SearchHashesResponse.FromString, - ) - self.CreateSubmission = channel.unary_unary( - "/google.cloud.webrisk.v1.WebRiskService/CreateSubmission", - request_serializer=google_dot_cloud_dot_webrisk__v1_dot_proto_dot_webrisk__pb2.CreateSubmissionRequest.SerializeToString, - response_deserializer=google_dot_cloud_dot_webrisk__v1_dot_proto_dot_webrisk__pb2.Submission.FromString, - ) - - -class WebRiskServiceServicer(object): - """Web Risk API defines an interface to detect malicious URLs on your - website and in client applications. - """ - - def ComputeThreatListDiff(self, request, context): - """Gets the most recent threat list diffs. These diffs should be applied to - a local database of hashes to keep it up-to-date. If the local database is - empty or excessively out-of-date, a complete snapshot of the database will - be returned. This Method only updates a single ThreatList at a time. To - update multiple ThreatList databases, this method needs to be called once - for each list. - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details("Method not implemented!") - raise NotImplementedError("Method not implemented!") - - def SearchUris(self, request, context): - """This method is used to check whether a URI is on a given threatList. - Multiple threatLists may be searched in a single query. - The response will list all requested threatLists the URI was found to - match. If the URI is not found on any of the requested ThreatList an - empty response will be returned. - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details("Method not implemented!") - raise NotImplementedError("Method not implemented!") - - def SearchHashes(self, request, context): - """Gets the full hashes that match the requested hash prefix. - This is used after a hash prefix is looked up in a threatList - and there is a match. The client side threatList only holds partial hashes - so the client must query this method to determine if there is a full - hash match of a threat. - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details("Method not implemented!") - raise NotImplementedError("Method not implemented!") - - def CreateSubmission(self, request, context): - """Creates a Submission of a URI suspected of containing phishing content to - be reviewed. If the result verifies the existence of malicious phishing - content, the site will be added to the [Google's Social Engineering - lists](https://support.google.com/webmasters/answer/6350487/) in order to - protect users that could get exposed to this threat in the future. Only - projects with CREATE_SUBMISSION_USERS visibility can use this method. - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details("Method not implemented!") - raise NotImplementedError("Method not implemented!") - - -def add_WebRiskServiceServicer_to_server(servicer, server): - rpc_method_handlers = { - "ComputeThreatListDiff": grpc.unary_unary_rpc_method_handler( - servicer.ComputeThreatListDiff, - request_deserializer=google_dot_cloud_dot_webrisk__v1_dot_proto_dot_webrisk__pb2.ComputeThreatListDiffRequest.FromString, - response_serializer=google_dot_cloud_dot_webrisk__v1_dot_proto_dot_webrisk__pb2.ComputeThreatListDiffResponse.SerializeToString, - ), - "SearchUris": grpc.unary_unary_rpc_method_handler( - servicer.SearchUris, - request_deserializer=google_dot_cloud_dot_webrisk__v1_dot_proto_dot_webrisk__pb2.SearchUrisRequest.FromString, - response_serializer=google_dot_cloud_dot_webrisk__v1_dot_proto_dot_webrisk__pb2.SearchUrisResponse.SerializeToString, - ), - "SearchHashes": grpc.unary_unary_rpc_method_handler( - servicer.SearchHashes, - request_deserializer=google_dot_cloud_dot_webrisk__v1_dot_proto_dot_webrisk__pb2.SearchHashesRequest.FromString, - response_serializer=google_dot_cloud_dot_webrisk__v1_dot_proto_dot_webrisk__pb2.SearchHashesResponse.SerializeToString, - ), - "CreateSubmission": grpc.unary_unary_rpc_method_handler( - servicer.CreateSubmission, - request_deserializer=google_dot_cloud_dot_webrisk__v1_dot_proto_dot_webrisk__pb2.CreateSubmissionRequest.FromString, - response_serializer=google_dot_cloud_dot_webrisk__v1_dot_proto_dot_webrisk__pb2.Submission.SerializeToString, - ), - } - generic_handler = grpc.method_handlers_generic_handler( - "google.cloud.webrisk.v1.WebRiskService", rpc_method_handlers - ) - server.add_generic_rpc_handlers((generic_handler,)) - - -# This class is part of an EXPERIMENTAL API. -class WebRiskService(object): - """Web Risk API defines an interface to detect malicious URLs on your - website and in client applications. - """ - - @staticmethod - def ComputeThreatListDiff( - request, - target, - options=(), - channel_credentials=None, - call_credentials=None, - compression=None, - wait_for_ready=None, - timeout=None, - metadata=None, - ): - return grpc.experimental.unary_unary( - request, - target, - "/google.cloud.webrisk.v1.WebRiskService/ComputeThreatListDiff", - google_dot_cloud_dot_webrisk__v1_dot_proto_dot_webrisk__pb2.ComputeThreatListDiffRequest.SerializeToString, - google_dot_cloud_dot_webrisk__v1_dot_proto_dot_webrisk__pb2.ComputeThreatListDiffResponse.FromString, - options, - channel_credentials, - call_credentials, - compression, - wait_for_ready, - timeout, - metadata, - ) - - @staticmethod - def SearchUris( - request, - target, - options=(), - channel_credentials=None, - call_credentials=None, - compression=None, - wait_for_ready=None, - timeout=None, - metadata=None, - ): - return grpc.experimental.unary_unary( - request, - target, - "/google.cloud.webrisk.v1.WebRiskService/SearchUris", - google_dot_cloud_dot_webrisk__v1_dot_proto_dot_webrisk__pb2.SearchUrisRequest.SerializeToString, - google_dot_cloud_dot_webrisk__v1_dot_proto_dot_webrisk__pb2.SearchUrisResponse.FromString, - options, - channel_credentials, - call_credentials, - compression, - wait_for_ready, - timeout, - metadata, - ) - - @staticmethod - def SearchHashes( - request, - target, - options=(), - channel_credentials=None, - call_credentials=None, - compression=None, - wait_for_ready=None, - timeout=None, - metadata=None, - ): - return grpc.experimental.unary_unary( - request, - target, - "/google.cloud.webrisk.v1.WebRiskService/SearchHashes", - google_dot_cloud_dot_webrisk__v1_dot_proto_dot_webrisk__pb2.SearchHashesRequest.SerializeToString, - google_dot_cloud_dot_webrisk__v1_dot_proto_dot_webrisk__pb2.SearchHashesResponse.FromString, - options, - channel_credentials, - call_credentials, - compression, - wait_for_ready, - timeout, - metadata, - ) - - @staticmethod - def CreateSubmission( - request, - target, - options=(), - channel_credentials=None, - call_credentials=None, - compression=None, - wait_for_ready=None, - timeout=None, - metadata=None, - ): - return grpc.experimental.unary_unary( - request, - target, - "/google.cloud.webrisk.v1.WebRiskService/CreateSubmission", - google_dot_cloud_dot_webrisk__v1_dot_proto_dot_webrisk__pb2.CreateSubmissionRequest.SerializeToString, - google_dot_cloud_dot_webrisk__v1_dot_proto_dot_webrisk__pb2.Submission.FromString, - options, - channel_credentials, - call_credentials, - compression, - wait_for_ready, - timeout, - metadata, - ) diff --git a/google/cloud/webrisk_v1/py.typed b/google/cloud/webrisk_v1/py.typed new file mode 100644 index 0000000..bef3da1 --- /dev/null +++ b/google/cloud/webrisk_v1/py.typed @@ -0,0 +1,2 @@ +# Marker file for PEP 561. +# The google-cloud-webrisk package uses inline types. diff --git a/google/cloud/__init__.py b/google/cloud/webrisk_v1/services/__init__.py similarity index 71% rename from google/cloud/__init__.py rename to google/cloud/webrisk_v1/services/__init__.py index 9a1b64a..42ffdf2 100644 --- a/google/cloud/__init__.py +++ b/google/cloud/webrisk_v1/services/__init__.py @@ -1,24 +1,16 @@ # -*- 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 # -# https://www.apache.org/licenses/LICENSE-2.0 +# 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. - -try: - import pkg_resources - - pkg_resources.declare_namespace(__name__) -except ImportError: - import pkgutil - - __path__ = pkgutil.extend_path(__path__, __name__) +# diff --git a/google/__init__.py b/google/cloud/webrisk_v1/services/web_risk_service/__init__.py similarity index 71% rename from google/__init__.py rename to google/cloud/webrisk_v1/services/web_risk_service/__init__.py index 9a1b64a..025193e 100644 --- a/google/__init__.py +++ b/google/cloud/webrisk_v1/services/web_risk_service/__init__.py @@ -1,24 +1,24 @@ # -*- 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 # -# https://www.apache.org/licenses/LICENSE-2.0 +# 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. +# -try: - import pkg_resources - - pkg_resources.declare_namespace(__name__) -except ImportError: - import pkgutil +from .client import WebRiskServiceClient +from .async_client import WebRiskServiceAsyncClient - __path__ = pkgutil.extend_path(__path__, __name__) +__all__ = ( + "WebRiskServiceClient", + "WebRiskServiceAsyncClient", +) diff --git a/google/cloud/webrisk_v1/services/web_risk_service/async_client.py b/google/cloud/webrisk_v1/services/web_risk_service/async_client.py new file mode 100644 index 0000000..667f71a --- /dev/null +++ b/google/cloud/webrisk_v1/services/web_risk_service/async_client.py @@ -0,0 +1,448 @@ +# -*- 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. +# + +from collections import OrderedDict +import functools +import re +from typing import Dict, Sequence, Tuple, Type, Union +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 gapic_v1 # type: ignore +from google.api_core import retry as retries # type: ignore +from google.auth import credentials # type: ignore +from google.oauth2 import service_account # type: ignore + +from google.cloud.webrisk_v1.types import webrisk +from google.protobuf import timestamp_pb2 as timestamp # type: ignore + +from .transports.base import WebRiskServiceTransport +from .transports.grpc_asyncio import WebRiskServiceGrpcAsyncIOTransport +from .client import WebRiskServiceClient + + +class WebRiskServiceAsyncClient: + """Web Risk API defines an interface to detect malicious URLs on + your website and in client applications. + """ + + _client: WebRiskServiceClient + + DEFAULT_ENDPOINT = WebRiskServiceClient.DEFAULT_ENDPOINT + DEFAULT_MTLS_ENDPOINT = WebRiskServiceClient.DEFAULT_MTLS_ENDPOINT + + from_service_account_file = WebRiskServiceClient.from_service_account_file + from_service_account_json = from_service_account_file + + get_transport_class = functools.partial( + type(WebRiskServiceClient).get_transport_class, type(WebRiskServiceClient) + ) + + def __init__( + self, + *, + credentials: credentials.Credentials = None, + transport: Union[str, WebRiskServiceTransport] = "grpc_asyncio", + client_options: ClientOptions = None, + ) -> None: + """Instantiate the web risk service client. + + Args: + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + transport (Union[str, ~.WebRiskServiceTransport]): The + transport to use. If set to None, a transport is chosen + automatically. + client_options (ClientOptions): Custom options for the client. It + won't take effect if a ``transport`` instance is provided. + (1) The ``api_endpoint`` property can be used to override the + default endpoint provided by the client. GOOGLE_API_USE_MTLS + environment variable can also be used to override the endpoint: + "always" (always use the default mTLS endpoint), "never" (always + use the default regular endpoint, this is the default value for + the environment variable) and "auto" (auto switch to the default + mTLS endpoint if client SSL credentials is present). However, + the ``api_endpoint`` property takes precedence if provided. + (2) The ``client_cert_source`` property is used to provide client + SSL credentials for mutual TLS transport. If not provided, the + default SSL credentials will be used if present. + + Raises: + google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport + creation failed for any reason. + """ + + self._client = WebRiskServiceClient( + credentials=credentials, transport=transport, client_options=client_options, + ) + + async def compute_threat_list_diff( + self, + request: webrisk.ComputeThreatListDiffRequest = None, + *, + threat_type: webrisk.ThreatType = None, + version_token: bytes = None, + constraints: webrisk.ComputeThreatListDiffRequest.Constraints = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> webrisk.ComputeThreatListDiffResponse: + r"""Gets the most recent threat list diffs. These diffs + should be applied to a local database of hashes to keep + it up-to-date. If the local database is empty or + excessively out-of-date, a complete snapshot of the + database will be returned. This Method only updates a + single ThreatList at a time. To update multiple + ThreatList databases, this method needs to be called + once for each list. + + Args: + request (:class:`~.webrisk.ComputeThreatListDiffRequest`): + The request object. Describes an API diff request. + threat_type (:class:`~.webrisk.ThreatType`): + Required. The threat list to update. + Only a single ThreatType should be + specified. + This corresponds to the ``threat_type`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + version_token (:class:`bytes`): + The current version token of the + client for the requested list (the + client version that was received from + the last successful diff). If the client + does not have a version token (this is + the first time calling + ComputeThreatListDiff), this may be left + empty and a full database snapshot will + be returned. + This corresponds to the ``version_token`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + constraints (:class:`~.webrisk.ComputeThreatListDiffRequest.Constraints`): + Required. The constraints associated + with this request. + This corresponds to the ``constraints`` 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. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.webrisk.ComputeThreatListDiffResponse: + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + if request is not None and any([threat_type, version_token, constraints]): + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = webrisk.ComputeThreatListDiffRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if threat_type is not None: + request.threat_type = threat_type + if version_token is not None: + request.version_token = version_token + if constraints is not None: + request.constraints = constraints + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.compute_threat_list_diff, + default_timeout=None, + client_info=_client_info, + ) + + # Send the request. + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + async def search_uris( + self, + request: webrisk.SearchUrisRequest = None, + *, + uri: str = None, + threat_types: Sequence[webrisk.ThreatType] = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> webrisk.SearchUrisResponse: + r"""This method is used to check whether a URI is on a + given threatList. Multiple threatLists may be searched + in a single query. The response will list all requested + threatLists the URI was found to match. If the URI is + not found on any of the requested ThreatList an empty + response will be returned. + + Args: + request (:class:`~.webrisk.SearchUrisRequest`): + The request object. Request to check URI entries against + threatLists. + uri (:class:`str`): + Required. The URI to be checked for + matches. + This corresponds to the ``uri`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + threat_types (:class:`Sequence[~.webrisk.ThreatType]`): + Required. The ThreatLists to search + in. Multiple ThreatLists may be + specified. + This corresponds to the ``threat_types`` 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. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.webrisk.SearchUrisResponse: + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + if request is not None and any([uri, threat_types]): + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = webrisk.SearchUrisRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if uri is not None: + request.uri = uri + if threat_types is not None: + request.threat_types = threat_types + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.search_uris, + default_timeout=None, + client_info=_client_info, + ) + + # Send the request. + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + async def search_hashes( + self, + request: webrisk.SearchHashesRequest = None, + *, + hash_prefix: bytes = None, + threat_types: Sequence[webrisk.ThreatType] = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> webrisk.SearchHashesResponse: + r"""Gets the full hashes that match the requested hash + prefix. This is used after a hash prefix is looked up in + a threatList and there is a match. The client side + threatList only holds partial hashes so the client must + query this method to determine if there is a full hash + match of a threat. + + Args: + request (:class:`~.webrisk.SearchHashesRequest`): + The request object. Request to return full hashes + matched by the provided hash prefixes. + hash_prefix (:class:`bytes`): + A hash prefix, consisting of the most + significant 4-32 bytes of a SHA256 hash. + For JSON requests, this field is + base64-encoded. + This corresponds to the ``hash_prefix`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + threat_types (:class:`Sequence[~.webrisk.ThreatType]`): + Required. The ThreatLists to search + in. Multiple ThreatLists may be + specified. + This corresponds to the ``threat_types`` 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. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.webrisk.SearchHashesResponse: + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + if request is not None and any([hash_prefix, threat_types]): + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = webrisk.SearchHashesRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if hash_prefix is not None: + request.hash_prefix = hash_prefix + if threat_types is not None: + request.threat_types = threat_types + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.search_hashes, + default_timeout=None, + client_info=_client_info, + ) + + # Send the request. + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + async def create_submission( + self, + request: webrisk.CreateSubmissionRequest = None, + *, + parent: str = None, + submission: webrisk.Submission = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> webrisk.Submission: + r"""Creates a Submission of a URI suspected of containing phishing + content to be reviewed. If the result verifies the existence of + malicious phishing content, the site will be added to the + `Google's Social Engineering + lists `__ + in order to protect users that could get exposed to this threat + in the future. Only projects with CREATE_SUBMISSION_USERS + visibility can use this method. + + Args: + request (:class:`~.webrisk.CreateSubmissionRequest`): + The request object. Request to send a potentially phishy + URI to WebRisk. + parent (:class:`str`): + Required. The name of the project that is making the + submission. This string is in the format + "projects/{project_number}". + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + submission (:class:`~.webrisk.Submission`): + Required. The submission that + contains the content of the phishing + report. + This corresponds to the ``submission`` 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. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.webrisk.Submission: + Wraps a URI that might be displaying + phishing content. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + if request is not None and any([parent, submission]): + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = webrisk.CreateSubmissionRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if parent is not None: + request.parent = parent + if submission is not None: + request.submission = submission + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.create_submission, + default_timeout=None, + client_info=_client_info, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), + ) + + # Send the request. + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + +try: + _client_info = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution("google-cloud-webrisk",).version, + ) +except pkg_resources.DistributionNotFound: + _client_info = gapic_v1.client_info.ClientInfo() + + +__all__ = ("WebRiskServiceAsyncClient",) diff --git a/google/cloud/webrisk_v1/services/web_risk_service/client.py b/google/cloud/webrisk_v1/services/web_risk_service/client.py new file mode 100644 index 0000000..2926404 --- /dev/null +++ b/google/cloud/webrisk_v1/services/web_risk_service/client.py @@ -0,0 +1,571 @@ +# -*- 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. +# + +from collections import OrderedDict +import os +import re +from typing import Callable, Dict, Sequence, Tuple, Type, Union +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 gapic_v1 # type: ignore +from google.api_core import retry as retries # type: ignore +from google.auth import credentials # type: ignore +from google.auth.transport import mtls # type: ignore +from google.auth.exceptions import MutualTLSChannelError # type: ignore +from google.oauth2 import service_account # type: ignore + +from google.cloud.webrisk_v1.types import webrisk +from google.protobuf import timestamp_pb2 as timestamp # type: ignore + +from .transports.base import WebRiskServiceTransport +from .transports.grpc import WebRiskServiceGrpcTransport +from .transports.grpc_asyncio import WebRiskServiceGrpcAsyncIOTransport + + +class WebRiskServiceClientMeta(type): + """Metaclass for the WebRiskService client. + + This provides class-level methods for building and retrieving + support objects (e.g. transport) without polluting the client instance + objects. + """ + + _transport_registry = ( + OrderedDict() + ) # type: Dict[str, Type[WebRiskServiceTransport]] + _transport_registry["grpc"] = WebRiskServiceGrpcTransport + _transport_registry["grpc_asyncio"] = WebRiskServiceGrpcAsyncIOTransport + + def get_transport_class(cls, label: str = None,) -> Type[WebRiskServiceTransport]: + """Return an appropriate transport class. + + Args: + label: The name of the desired transport. If none is + provided, then the first transport in the registry is used. + + Returns: + The transport class to use. + """ + # If a specific transport is requested, return that one. + if label: + return cls._transport_registry[label] + + # No transport is requested; return the default (that is, the first one + # in the dictionary). + return next(iter(cls._transport_registry.values())) + + +class WebRiskServiceClient(metaclass=WebRiskServiceClientMeta): + """Web Risk API defines an interface to detect malicious URLs on + your website and in client applications. + """ + + @staticmethod + def _get_default_mtls_endpoint(api_endpoint): + """Convert api endpoint to mTLS endpoint. + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + str: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + + m = mtls_endpoint_re.match(api_endpoint) + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + DEFAULT_ENDPOINT = "webrisk.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + @classmethod + def from_service_account_file(cls, filename: str, *args, **kwargs): + """Creates an instance of this client using the provided credentials + file. + + Args: + filename (str): The path to the service account private key json + file. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + {@api.name}: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_file(filename) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + + from_service_account_json = from_service_account_file + + def __init__( + self, + *, + credentials: credentials.Credentials = None, + transport: Union[str, WebRiskServiceTransport] = None, + client_options: ClientOptions = None, + ) -> None: + """Instantiate the web risk service client. + + Args: + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + transport (Union[str, ~.WebRiskServiceTransport]): The + transport to use. If set to None, a transport is chosen + automatically. + client_options (ClientOptions): Custom options for the client. It + won't take effect if a ``transport`` instance is provided. + (1) The ``api_endpoint`` property can be used to override the + default endpoint provided by the client. GOOGLE_API_USE_MTLS + environment variable can also be used to override the endpoint: + "always" (always use the default mTLS endpoint), "never" (always + use the default regular endpoint, this is the default value for + the environment variable) and "auto" (auto switch to the default + mTLS endpoint if client SSL credentials is present). However, + the ``api_endpoint`` property takes precedence if provided. + (2) The ``client_cert_source`` property is used to provide client + SSL credentials for mutual TLS transport. If not provided, the + default SSL credentials will be used if present. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport + creation failed for any reason. + """ + if isinstance(client_options, dict): + client_options = ClientOptions.from_dict(client_options) + if client_options is None: + client_options = ClientOptions.ClientOptions() + + if client_options.api_endpoint is None: + use_mtls_env = os.getenv("GOOGLE_API_USE_MTLS", "never") + if use_mtls_env == "never": + client_options.api_endpoint = self.DEFAULT_ENDPOINT + elif use_mtls_env == "always": + client_options.api_endpoint = self.DEFAULT_MTLS_ENDPOINT + elif use_mtls_env == "auto": + has_client_cert_source = ( + client_options.client_cert_source is not None + or mtls.has_default_client_cert_source() + ) + client_options.api_endpoint = ( + self.DEFAULT_MTLS_ENDPOINT + if has_client_cert_source + else self.DEFAULT_ENDPOINT + ) + else: + raise MutualTLSChannelError( + "Unsupported GOOGLE_API_USE_MTLS value. Accepted values: never, auto, always" + ) + + # Save or instantiate the transport. + # Ordinarily, we provide the transport, but allowing a custom transport + # instance provides an extensibility point for unusual situations. + if isinstance(transport, WebRiskServiceTransport): + # transport is a WebRiskServiceTransport instance. + if credentials or client_options.credentials_file: + raise ValueError( + "When providing a transport instance, " + "provide its credentials directly." + ) + if client_options.scopes: + raise ValueError( + "When providing a transport instance, " + "provide its scopes directly." + ) + self._transport = transport + else: + Transport = type(self).get_transport_class(transport) + self._transport = Transport( + credentials=credentials, + credentials_file=client_options.credentials_file, + host=client_options.api_endpoint, + scopes=client_options.scopes, + api_mtls_endpoint=client_options.api_endpoint, + client_cert_source=client_options.client_cert_source, + ) + + def compute_threat_list_diff( + self, + request: webrisk.ComputeThreatListDiffRequest = None, + *, + threat_type: webrisk.ThreatType = None, + version_token: bytes = None, + constraints: webrisk.ComputeThreatListDiffRequest.Constraints = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> webrisk.ComputeThreatListDiffResponse: + r"""Gets the most recent threat list diffs. These diffs + should be applied to a local database of hashes to keep + it up-to-date. If the local database is empty or + excessively out-of-date, a complete snapshot of the + database will be returned. This Method only updates a + single ThreatList at a time. To update multiple + ThreatList databases, this method needs to be called + once for each list. + + Args: + request (:class:`~.webrisk.ComputeThreatListDiffRequest`): + The request object. Describes an API diff request. + threat_type (:class:`~.webrisk.ThreatType`): + Required. The threat list to update. + Only a single ThreatType should be + specified. + This corresponds to the ``threat_type`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + version_token (:class:`bytes`): + The current version token of the + client for the requested list (the + client version that was received from + the last successful diff). If the client + does not have a version token (this is + the first time calling + ComputeThreatListDiff), this may be left + empty and a full database snapshot will + be returned. + This corresponds to the ``version_token`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + constraints (:class:`~.webrisk.ComputeThreatListDiffRequest.Constraints`): + Required. The constraints associated + with this request. + This corresponds to the ``constraints`` 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. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.webrisk.ComputeThreatListDiffResponse: + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + if request is not None and any([threat_type, version_token, constraints]): + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = webrisk.ComputeThreatListDiffRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if threat_type is not None: + request.threat_type = threat_type + if version_token is not None: + request.version_token = version_token + if constraints is not None: + request.constraints = constraints + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.compute_threat_list_diff, + default_timeout=None, + client_info=_client_info, + ) + + # Send the request. + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + def search_uris( + self, + request: webrisk.SearchUrisRequest = None, + *, + uri: str = None, + threat_types: Sequence[webrisk.ThreatType] = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> webrisk.SearchUrisResponse: + r"""This method is used to check whether a URI is on a + given threatList. Multiple threatLists may be searched + in a single query. The response will list all requested + threatLists the URI was found to match. If the URI is + not found on any of the requested ThreatList an empty + response will be returned. + + Args: + request (:class:`~.webrisk.SearchUrisRequest`): + The request object. Request to check URI entries against + threatLists. + uri (:class:`str`): + Required. The URI to be checked for + matches. + This corresponds to the ``uri`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + threat_types (:class:`Sequence[~.webrisk.ThreatType]`): + Required. The ThreatLists to search + in. Multiple ThreatLists may be + specified. + This corresponds to the ``threat_types`` 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. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.webrisk.SearchUrisResponse: + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + if request is not None and any([uri, threat_types]): + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = webrisk.SearchUrisRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if uri is not None: + request.uri = uri + if threat_types is not None: + request.threat_types = threat_types + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.search_uris, default_timeout=None, client_info=_client_info, + ) + + # Send the request. + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + def search_hashes( + self, + request: webrisk.SearchHashesRequest = None, + *, + hash_prefix: bytes = None, + threat_types: Sequence[webrisk.ThreatType] = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> webrisk.SearchHashesResponse: + r"""Gets the full hashes that match the requested hash + prefix. This is used after a hash prefix is looked up in + a threatList and there is a match. The client side + threatList only holds partial hashes so the client must + query this method to determine if there is a full hash + match of a threat. + + Args: + request (:class:`~.webrisk.SearchHashesRequest`): + The request object. Request to return full hashes + matched by the provided hash prefixes. + hash_prefix (:class:`bytes`): + A hash prefix, consisting of the most + significant 4-32 bytes of a SHA256 hash. + For JSON requests, this field is + base64-encoded. + This corresponds to the ``hash_prefix`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + threat_types (:class:`Sequence[~.webrisk.ThreatType]`): + Required. The ThreatLists to search + in. Multiple ThreatLists may be + specified. + This corresponds to the ``threat_types`` 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. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.webrisk.SearchHashesResponse: + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + if request is not None and any([hash_prefix, threat_types]): + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = webrisk.SearchHashesRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if hash_prefix is not None: + request.hash_prefix = hash_prefix + if threat_types is not None: + request.threat_types = threat_types + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.search_hashes, + default_timeout=None, + client_info=_client_info, + ) + + # Send the request. + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + def create_submission( + self, + request: webrisk.CreateSubmissionRequest = None, + *, + parent: str = None, + submission: webrisk.Submission = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> webrisk.Submission: + r"""Creates a Submission of a URI suspected of containing phishing + content to be reviewed. If the result verifies the existence of + malicious phishing content, the site will be added to the + `Google's Social Engineering + lists `__ + in order to protect users that could get exposed to this threat + in the future. Only projects with CREATE_SUBMISSION_USERS + visibility can use this method. + + Args: + request (:class:`~.webrisk.CreateSubmissionRequest`): + The request object. Request to send a potentially phishy + URI to WebRisk. + parent (:class:`str`): + Required. The name of the project that is making the + submission. This string is in the format + "projects/{project_number}". + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + submission (:class:`~.webrisk.Submission`): + Required. The submission that + contains the content of the phishing + report. + This corresponds to the ``submission`` 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. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.webrisk.Submission: + Wraps a URI that might be displaying + phishing content. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + if request is not None and any([parent, submission]): + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = webrisk.CreateSubmissionRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if parent is not None: + request.parent = parent + if submission is not None: + request.submission = submission + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.create_submission, + default_timeout=None, + client_info=_client_info, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), + ) + + # Send the request. + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + +try: + _client_info = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution("google-cloud-webrisk",).version, + ) +except pkg_resources.DistributionNotFound: + _client_info = gapic_v1.client_info.ClientInfo() + + +__all__ = ("WebRiskServiceClient",) diff --git a/google/cloud/webrisk_v1/services/web_risk_service/transports/__init__.py b/google/cloud/webrisk_v1/services/web_risk_service/transports/__init__.py new file mode 100644 index 0000000..f39de6c --- /dev/null +++ b/google/cloud/webrisk_v1/services/web_risk_service/transports/__init__.py @@ -0,0 +1,36 @@ +# -*- 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. +# + +from collections import OrderedDict +from typing import Dict, Type + +from .base import WebRiskServiceTransport +from .grpc import WebRiskServiceGrpcTransport +from .grpc_asyncio import WebRiskServiceGrpcAsyncIOTransport + + +# Compile a registry of transports. +_transport_registry = OrderedDict() # type: Dict[str, Type[WebRiskServiceTransport]] +_transport_registry["grpc"] = WebRiskServiceGrpcTransport +_transport_registry["grpc_asyncio"] = WebRiskServiceGrpcAsyncIOTransport + + +__all__ = ( + "WebRiskServiceTransport", + "WebRiskServiceGrpcTransport", + "WebRiskServiceGrpcAsyncIOTransport", +) diff --git a/google/cloud/webrisk_v1/services/web_risk_service/transports/base.py b/google/cloud/webrisk_v1/services/web_risk_service/transports/base.py new file mode 100644 index 0000000..f87e245 --- /dev/null +++ b/google/cloud/webrisk_v1/services/web_risk_service/transports/base.py @@ -0,0 +1,122 @@ +# -*- 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. +# + +import abc +import typing + +from google import auth +from google.api_core import exceptions # type: ignore +from google.auth import credentials # type: ignore + +from google.cloud.webrisk_v1.types import webrisk + + +class WebRiskServiceTransport(abc.ABC): + """Abstract transport class for WebRiskService.""" + + AUTH_SCOPES = ("https://www.googleapis.com/auth/cloud-platform",) + + def __init__( + self, + *, + host: str = "webrisk.googleapis.com", + credentials: credentials.Credentials = None, + credentials_file: typing.Optional[str] = None, + scopes: typing.Optional[typing.Sequence[str]] = AUTH_SCOPES, + **kwargs, + ) -> None: + """Instantiate the transport. + + Args: + 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 + are specified, the client will attempt to ascertain the + credentials from the environment. + 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. + """ + # Save the hostname. Default to port 443 (HTTPS) if none is specified. + if ":" not in host: + host += ":443" + self._host = host + + # If no credentials are provided, then determine the appropriate + # defaults. + if credentials and credentials_file: + raise exceptions.DuplicateCredentialArgs( + "'credentials_file' and 'credentials' are mutually exclusive" + ) + + if credentials_file is not None: + credentials, _ = auth.load_credentials_from_file( + credentials_file, scopes=scopes + ) + elif credentials is None: + credentials, _ = auth.default(scopes=scopes) + + # Save the credentials. + self._credentials = credentials + + @property + def compute_threat_list_diff( + self, + ) -> typing.Callable[ + [webrisk.ComputeThreatListDiffRequest], + typing.Union[ + webrisk.ComputeThreatListDiffResponse, + typing.Awaitable[webrisk.ComputeThreatListDiffResponse], + ], + ]: + raise NotImplementedError() + + @property + def search_uris( + self, + ) -> typing.Callable[ + [webrisk.SearchUrisRequest], + typing.Union[ + webrisk.SearchUrisResponse, typing.Awaitable[webrisk.SearchUrisResponse] + ], + ]: + raise NotImplementedError() + + @property + def search_hashes( + self, + ) -> typing.Callable[ + [webrisk.SearchHashesRequest], + typing.Union[ + webrisk.SearchHashesResponse, typing.Awaitable[webrisk.SearchHashesResponse] + ], + ]: + raise NotImplementedError() + + @property + def create_submission( + self, + ) -> typing.Callable[ + [webrisk.CreateSubmissionRequest], + typing.Union[webrisk.Submission, typing.Awaitable[webrisk.Submission]], + ]: + raise NotImplementedError() + + +__all__ = ("WebRiskServiceTransport",) diff --git a/google/cloud/webrisk_v1/services/web_risk_service/transports/grpc.py b/google/cloud/webrisk_v1/services/web_risk_service/transports/grpc.py new file mode 100644 index 0000000..8a44485 --- /dev/null +++ b/google/cloud/webrisk_v1/services/web_risk_service/transports/grpc.py @@ -0,0 +1,327 @@ +# -*- 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. +# + +from typing import Callable, Dict, Optional, Sequence, Tuple + +from google.api_core import grpc_helpers # type: ignore +from google import auth # type: ignore +from google.auth import credentials # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore + + +import grpc # type: ignore + +from google.cloud.webrisk_v1.types import webrisk + +from .base import WebRiskServiceTransport + + +class WebRiskServiceGrpcTransport(WebRiskServiceTransport): + """gRPC backend transport for WebRiskService. + + Web Risk API defines an interface to detect malicious URLs on + your website and in client applications. + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends protocol buffers over the wire using gRPC (which is built on + top of HTTP/2); the ``grpcio`` package must be installed. + """ + + _stubs: Dict[str, Callable] + + def __init__( + self, + *, + host: str = "webrisk.googleapis.com", + credentials: credentials.Credentials = None, + credentials_file: str = None, + scopes: Sequence[str] = None, + channel: grpc.Channel = None, + api_mtls_endpoint: str = None, + client_cert_source: Callable[[], Tuple[bytes, bytes]] = None + ) -> None: + """Instantiate the transport. + + Args: + 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 + are specified, the client will attempt to ascertain the + credentials from the environment. + This argument is ignored if ``channel`` is provided. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional(Sequence[str])): A list of scopes. This argument is + ignored if ``channel`` is provided. + channel (Optional[grpc.Channel]): A ``Channel`` instance through + which to make calls. + api_mtls_endpoint (Optional[str]): The mutual TLS endpoint. If + provided, it overrides the ``host`` argument and tries to create + a mutual TLS channel with client SSL credentials from + ``client_cert_source`` or applicatin default SSL credentials. + client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): A + callback to provide client SSL certificate bytes and private key + bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` + is None. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport + creation failed for any reason. + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + if channel: + # Sanity check: Ensure that channel and credentials are not both + # provided. + credentials = False + + # If a channel was explicitly provided, set it. + self._grpc_channel = channel + elif api_mtls_endpoint: + host = ( + api_mtls_endpoint + if ":" in api_mtls_endpoint + else api_mtls_endpoint + ":443" + ) + + if credentials is None: + credentials, _ = auth.default(scopes=self.AUTH_SCOPES) + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + ssl_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + ssl_credentials = SslCredentials().ssl_credentials + + # create a new channel. The provided one is ignored. + self._grpc_channel = type(self).create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + ssl_credentials=ssl_credentials, + scopes=scopes or self.AUTH_SCOPES, + ) + + # Run the base constructor. + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes or self.AUTH_SCOPES, + ) + + self._stubs = {} # type: Dict[str, Callable] + + @classmethod + def create_channel( + cls, + host: str = "webrisk.googleapis.com", + credentials: credentials.Credentials = None, + credentials_file: str = None, + scopes: Optional[Sequence[str]] = None, + **kwargs + ) -> grpc.Channel: + """Create and return a gRPC channel object. + Args: + address (Optionsl[str]): The host for the channel to use. + credentials (Optional[~.Credentials]): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If + none are specified, the client will attempt to ascertain + the credentials from the environment. + 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. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + kwargs (Optional[dict]): Keyword arguments, which are passed to the + channel creation. + Returns: + grpc.Channel: A gRPC channel object. + + Raises: + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + scopes = scopes or cls.AUTH_SCOPES + return grpc_helpers.create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + **kwargs + ) + + @property + def grpc_channel(self) -> grpc.Channel: + """Create the channel designed to connect to this service. + + This property caches on the instance; repeated calls return + the same channel. + """ + # Sanity check: Only create a new channel if we do not already + # have one. + if not hasattr(self, "_grpc_channel"): + self._grpc_channel = self.create_channel( + self._host, credentials=self._credentials, + ) + + # Return the channel from cache. + return self._grpc_channel + + @property + def compute_threat_list_diff( + self, + ) -> Callable[ + [webrisk.ComputeThreatListDiffRequest], webrisk.ComputeThreatListDiffResponse + ]: + r"""Return a callable for the compute threat list diff method over gRPC. + + Gets the most recent threat list diffs. These diffs + should be applied to a local database of hashes to keep + it up-to-date. If the local database is empty or + excessively out-of-date, a complete snapshot of the + database will be returned. This Method only updates a + single ThreatList at a time. To update multiple + ThreatList databases, this method needs to be called + once for each list. + + Returns: + Callable[[~.ComputeThreatListDiffRequest], + ~.ComputeThreatListDiffResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "compute_threat_list_diff" not in self._stubs: + self._stubs["compute_threat_list_diff"] = self.grpc_channel.unary_unary( + "/google.cloud.webrisk.v1.WebRiskService/ComputeThreatListDiff", + request_serializer=webrisk.ComputeThreatListDiffRequest.serialize, + response_deserializer=webrisk.ComputeThreatListDiffResponse.deserialize, + ) + return self._stubs["compute_threat_list_diff"] + + @property + def search_uris( + self, + ) -> Callable[[webrisk.SearchUrisRequest], webrisk.SearchUrisResponse]: + r"""Return a callable for the search uris method over gRPC. + + This method is used to check whether a URI is on a + given threatList. Multiple threatLists may be searched + in a single query. The response will list all requested + threatLists the URI was found to match. If the URI is + not found on any of the requested ThreatList an empty + response will be returned. + + Returns: + Callable[[~.SearchUrisRequest], + ~.SearchUrisResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "search_uris" not in self._stubs: + self._stubs["search_uris"] = self.grpc_channel.unary_unary( + "/google.cloud.webrisk.v1.WebRiskService/SearchUris", + request_serializer=webrisk.SearchUrisRequest.serialize, + response_deserializer=webrisk.SearchUrisResponse.deserialize, + ) + return self._stubs["search_uris"] + + @property + def search_hashes( + self, + ) -> Callable[[webrisk.SearchHashesRequest], webrisk.SearchHashesResponse]: + r"""Return a callable for the search hashes method over gRPC. + + Gets the full hashes that match the requested hash + prefix. This is used after a hash prefix is looked up in + a threatList and there is a match. The client side + threatList only holds partial hashes so the client must + query this method to determine if there is a full hash + match of a threat. + + Returns: + Callable[[~.SearchHashesRequest], + ~.SearchHashesResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "search_hashes" not in self._stubs: + self._stubs["search_hashes"] = self.grpc_channel.unary_unary( + "/google.cloud.webrisk.v1.WebRiskService/SearchHashes", + request_serializer=webrisk.SearchHashesRequest.serialize, + response_deserializer=webrisk.SearchHashesResponse.deserialize, + ) + return self._stubs["search_hashes"] + + @property + def create_submission( + self, + ) -> Callable[[webrisk.CreateSubmissionRequest], webrisk.Submission]: + r"""Return a callable for the create submission method over gRPC. + + Creates a Submission of a URI suspected of containing phishing + content to be reviewed. If the result verifies the existence of + malicious phishing content, the site will be added to the + `Google's Social Engineering + lists `__ + in order to protect users that could get exposed to this threat + in the future. Only projects with CREATE_SUBMISSION_USERS + visibility can use this method. + + Returns: + Callable[[~.CreateSubmissionRequest], + ~.Submission]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "create_submission" not in self._stubs: + self._stubs["create_submission"] = self.grpc_channel.unary_unary( + "/google.cloud.webrisk.v1.WebRiskService/CreateSubmission", + request_serializer=webrisk.CreateSubmissionRequest.serialize, + response_deserializer=webrisk.Submission.deserialize, + ) + return self._stubs["create_submission"] + + +__all__ = ("WebRiskServiceGrpcTransport",) diff --git a/google/cloud/webrisk_v1/services/web_risk_service/transports/grpc_asyncio.py b/google/cloud/webrisk_v1/services/web_risk_service/transports/grpc_asyncio.py new file mode 100644 index 0000000..1e8ae0c --- /dev/null +++ b/google/cloud/webrisk_v1/services/web_risk_service/transports/grpc_asyncio.py @@ -0,0 +1,325 @@ +# -*- 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. +# + +from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple + +from google.api_core import grpc_helpers_async # type: ignore +from google.auth import credentials # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore + +import grpc # type: ignore +from grpc.experimental import aio # type: ignore + +from google.cloud.webrisk_v1.types import webrisk + +from .base import WebRiskServiceTransport +from .grpc import WebRiskServiceGrpcTransport + + +class WebRiskServiceGrpcAsyncIOTransport(WebRiskServiceTransport): + """gRPC AsyncIO backend transport for WebRiskService. + + Web Risk API defines an interface to detect malicious URLs on + your website and in client applications. + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends protocol buffers over the wire using gRPC (which is built on + top of HTTP/2); the ``grpcio`` package must be installed. + """ + + _grpc_channel: aio.Channel + _stubs: Dict[str, Callable] = {} + + @classmethod + def create_channel( + cls, + host: str = "webrisk.googleapis.com", + credentials: credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + **kwargs + ) -> aio.Channel: + """Create and return a gRPC AsyncIO channel object. + Args: + address (Optional[str]): The host for the channel to use. + credentials (Optional[~.Credentials]): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If + none are specified, the client will attempt to ascertain + the credentials from the environment. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + kwargs (Optional[dict]): Keyword arguments, which are passed to the + channel creation. + Returns: + aio.Channel: A gRPC AsyncIO channel object. + """ + scopes = scopes or cls.AUTH_SCOPES + return grpc_helpers_async.create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + **kwargs + ) + + def __init__( + self, + *, + host: str = "webrisk.googleapis.com", + credentials: credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + channel: aio.Channel = None, + api_mtls_endpoint: str = None, + client_cert_source: Callable[[], Tuple[bytes, bytes]] = None + ) -> None: + """Instantiate the transport. + + Args: + 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 + are specified, the client will attempt to ascertain the + credentials from the environment. + This argument is ignored if ``channel`` is provided. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + channel (Optional[aio.Channel]): A ``Channel`` instance through + which to make calls. + api_mtls_endpoint (Optional[str]): The mutual TLS endpoint. If + provided, it overrides the ``host`` argument and tries to create + a mutual TLS channel with client SSL credentials from + ``client_cert_source`` or applicatin default SSL credentials. + client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): A + callback to provide client SSL certificate bytes and private key + bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` + is None. + + Raises: + google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport + creation failed for any reason. + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + if channel: + # Sanity check: Ensure that channel and credentials are not both + # provided. + credentials = False + + # If a channel was explicitly provided, set it. + self._grpc_channel = channel + elif api_mtls_endpoint: + host = ( + api_mtls_endpoint + if ":" in api_mtls_endpoint + else api_mtls_endpoint + ":443" + ) + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + ssl_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + ssl_credentials = SslCredentials().ssl_credentials + + # create a new channel. The provided one is ignored. + self._grpc_channel = type(self).create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + ssl_credentials=ssl_credentials, + scopes=scopes or self.AUTH_SCOPES, + ) + + # Run the base constructor. + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes or self.AUTH_SCOPES, + ) + + self._stubs = {} + + @property + def grpc_channel(self) -> aio.Channel: + """Create the channel designed to connect to this service. + + This property caches on the instance; repeated calls return + the same channel. + """ + # Sanity check: Only create a new channel if we do not already + # have one. + if not hasattr(self, "_grpc_channel"): + self._grpc_channel = self.create_channel( + self._host, credentials=self._credentials, + ) + + # Return the channel from cache. + return self._grpc_channel + + @property + def compute_threat_list_diff( + self, + ) -> Callable[ + [webrisk.ComputeThreatListDiffRequest], + Awaitable[webrisk.ComputeThreatListDiffResponse], + ]: + r"""Return a callable for the compute threat list diff method over gRPC. + + Gets the most recent threat list diffs. These diffs + should be applied to a local database of hashes to keep + it up-to-date. If the local database is empty or + excessively out-of-date, a complete snapshot of the + database will be returned. This Method only updates a + single ThreatList at a time. To update multiple + ThreatList databases, this method needs to be called + once for each list. + + Returns: + Callable[[~.ComputeThreatListDiffRequest], + Awaitable[~.ComputeThreatListDiffResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "compute_threat_list_diff" not in self._stubs: + self._stubs["compute_threat_list_diff"] = self.grpc_channel.unary_unary( + "/google.cloud.webrisk.v1.WebRiskService/ComputeThreatListDiff", + request_serializer=webrisk.ComputeThreatListDiffRequest.serialize, + response_deserializer=webrisk.ComputeThreatListDiffResponse.deserialize, + ) + return self._stubs["compute_threat_list_diff"] + + @property + def search_uris( + self, + ) -> Callable[[webrisk.SearchUrisRequest], Awaitable[webrisk.SearchUrisResponse]]: + r"""Return a callable for the search uris method over gRPC. + + This method is used to check whether a URI is on a + given threatList. Multiple threatLists may be searched + in a single query. The response will list all requested + threatLists the URI was found to match. If the URI is + not found on any of the requested ThreatList an empty + response will be returned. + + Returns: + Callable[[~.SearchUrisRequest], + Awaitable[~.SearchUrisResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "search_uris" not in self._stubs: + self._stubs["search_uris"] = self.grpc_channel.unary_unary( + "/google.cloud.webrisk.v1.WebRiskService/SearchUris", + request_serializer=webrisk.SearchUrisRequest.serialize, + response_deserializer=webrisk.SearchUrisResponse.deserialize, + ) + return self._stubs["search_uris"] + + @property + def search_hashes( + self, + ) -> Callable[ + [webrisk.SearchHashesRequest], Awaitable[webrisk.SearchHashesResponse] + ]: + r"""Return a callable for the search hashes method over gRPC. + + Gets the full hashes that match the requested hash + prefix. This is used after a hash prefix is looked up in + a threatList and there is a match. The client side + threatList only holds partial hashes so the client must + query this method to determine if there is a full hash + match of a threat. + + Returns: + Callable[[~.SearchHashesRequest], + Awaitable[~.SearchHashesResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "search_hashes" not in self._stubs: + self._stubs["search_hashes"] = self.grpc_channel.unary_unary( + "/google.cloud.webrisk.v1.WebRiskService/SearchHashes", + request_serializer=webrisk.SearchHashesRequest.serialize, + response_deserializer=webrisk.SearchHashesResponse.deserialize, + ) + return self._stubs["search_hashes"] + + @property + def create_submission( + self, + ) -> Callable[[webrisk.CreateSubmissionRequest], Awaitable[webrisk.Submission]]: + r"""Return a callable for the create submission method over gRPC. + + Creates a Submission of a URI suspected of containing phishing + content to be reviewed. If the result verifies the existence of + malicious phishing content, the site will be added to the + `Google's Social Engineering + lists `__ + in order to protect users that could get exposed to this threat + in the future. Only projects with CREATE_SUBMISSION_USERS + visibility can use this method. + + Returns: + Callable[[~.CreateSubmissionRequest], + Awaitable[~.Submission]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "create_submission" not in self._stubs: + self._stubs["create_submission"] = self.grpc_channel.unary_unary( + "/google.cloud.webrisk.v1.WebRiskService/CreateSubmission", + request_serializer=webrisk.CreateSubmissionRequest.serialize, + response_deserializer=webrisk.Submission.deserialize, + ) + return self._stubs["create_submission"] + + +__all__ = ("WebRiskServiceGrpcAsyncIOTransport",) diff --git a/google/cloud/webrisk_v1/types.py b/google/cloud/webrisk_v1/types.py deleted file mode 100644 index 852b9bf..0000000 --- a/google/cloud/webrisk_v1/types.py +++ /dev/null @@ -1,48 +0,0 @@ -# -*- 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 -# -# https://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. - - -from __future__ import absolute_import -import sys - -from google.api_core.protobuf_helpers import get_messages - -from google.cloud.webrisk_v1.proto import webrisk_pb2 -from google.protobuf import timestamp_pb2 - - -_shared_modules = [ - timestamp_pb2, -] - -_local_modules = [ - webrisk_pb2, -] - -names = [] - -for module in _shared_modules: # pragma: NO COVER - for name, message in get_messages(module).items(): - setattr(sys.modules[__name__], name, message) - names.append(name) -for module in _local_modules: - for name, message in get_messages(module).items(): - message.__module__ = "google.cloud.webrisk_v1.types" - setattr(sys.modules[__name__], name, message) - names.append(name) - - -__all__ = tuple(sorted(names)) diff --git a/google/cloud/webrisk_v1/types/__init__.py b/google/cloud/webrisk_v1/types/__init__.py new file mode 100644 index 0000000..07ef2cc --- /dev/null +++ b/google/cloud/webrisk_v1/types/__init__.py @@ -0,0 +1,49 @@ +# -*- 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. +# + +from .webrisk import ( + ComputeThreatListDiffRequest, + ComputeThreatListDiffResponse, + SearchUrisRequest, + SearchUrisResponse, + SearchHashesRequest, + SearchHashesResponse, + ThreatEntryAdditions, + ThreatEntryRemovals, + RawIndices, + RawHashes, + RiceDeltaEncoding, + Submission, + CreateSubmissionRequest, +) + + +__all__ = ( + "ComputeThreatListDiffRequest", + "ComputeThreatListDiffResponse", + "SearchUrisRequest", + "SearchUrisResponse", + "SearchHashesRequest", + "SearchHashesResponse", + "ThreatEntryAdditions", + "ThreatEntryRemovals", + "RawIndices", + "RawHashes", + "RiceDeltaEncoding", + "Submission", + "CreateSubmissionRequest", +) diff --git a/google/cloud/webrisk_v1/types/webrisk.py b/google/cloud/webrisk_v1/types/webrisk.py new file mode 100644 index 0000000..0c0717d --- /dev/null +++ b/google/cloud/webrisk_v1/types/webrisk.py @@ -0,0 +1,435 @@ +# -*- 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. +# + +import proto # type: ignore + + +from google.protobuf import timestamp_pb2 as timestamp # type: ignore + + +__protobuf__ = proto.module( + package="google.cloud.webrisk.v1", + manifest={ + "ThreatType", + "CompressionType", + "ComputeThreatListDiffRequest", + "ComputeThreatListDiffResponse", + "SearchUrisRequest", + "SearchUrisResponse", + "SearchHashesRequest", + "SearchHashesResponse", + "ThreatEntryAdditions", + "ThreatEntryRemovals", + "RawIndices", + "RawHashes", + "RiceDeltaEncoding", + "Submission", + "CreateSubmissionRequest", + }, +) + + +class ThreatType(proto.Enum): + r"""The type of threat. This maps dirrectly to the threat list a + threat may belong to. + """ + THREAT_TYPE_UNSPECIFIED = 0 + MALWARE = 1 + SOCIAL_ENGINEERING = 2 + UNWANTED_SOFTWARE = 3 + + +class CompressionType(proto.Enum): + r"""The ways in which threat entry sets can be compressed.""" + COMPRESSION_TYPE_UNSPECIFIED = 0 + RAW = 1 + RICE = 2 + + +class ComputeThreatListDiffRequest(proto.Message): + r"""Describes an API diff request. + + Attributes: + threat_type (~.webrisk.ThreatType): + Required. The threat list to update. Only a + single ThreatType should be specified. + version_token (bytes): + The current version token of the client for + the requested list (the client version that was + received from the last successful diff). If the + client does not have a version token (this is + the first time calling ComputeThreatListDiff), + this may be left empty and a full database + snapshot will be returned. + constraints (~.webrisk.ComputeThreatListDiffRequest.Constraints): + Required. The constraints associated with + this request. + """ + + class Constraints(proto.Message): + r"""The constraints for this diff. + + Attributes: + max_diff_entries (int): + The maximum size in number of entries. The diff will not + contain more entries than this value. This should be a power + of 2 between 2\ **10 and 2**\ 20. If zero, no diff size + limit is set. + max_database_entries (int): + Sets the maximum number of entries that the client is + willing to have in the local database. This should be a + power of 2 between 2\ **10 and 2**\ 20. If zero, no database + size limit is set. + supported_compressions (Sequence[~.webrisk.CompressionType]): + The compression types supported by the + client. + """ + + max_diff_entries = proto.Field(proto.INT32, number=1) + + max_database_entries = proto.Field(proto.INT32, number=2) + + supported_compressions = proto.RepeatedField( + proto.ENUM, number=3, enum="CompressionType", + ) + + threat_type = proto.Field(proto.ENUM, number=1, enum="ThreatType",) + + version_token = proto.Field(proto.BYTES, number=2) + + constraints = proto.Field(proto.MESSAGE, number=3, message=Constraints,) + + +class ComputeThreatListDiffResponse(proto.Message): + r""" + + Attributes: + response_type (~.webrisk.ComputeThreatListDiffResponse.ResponseType): + The type of response. This may indicate that + an action must be taken by the client when the + response is received. + additions (~.webrisk.ThreatEntryAdditions): + A set of entries to add to a local threat + type's list. + removals (~.webrisk.ThreatEntryRemovals): + A set of entries to remove from a local + threat type's list. This field may be empty. + new_version_token (bytes): + The new opaque client version token. This should be retained + by the client and passed into the next call of + ComputeThreatListDiff as 'version_token'. A separate version + token should be stored and used for each threatList. + checksum (~.webrisk.ComputeThreatListDiffResponse.Checksum): + The expected SHA256 hash of the client state; + that is, of the sorted list of all hashes + present in the database after applying the + provided diff. If the client state doesn't match + the expected state, the client must discard this + diff and retry later. + recommended_next_diff (~.timestamp.Timestamp): + The soonest the client should wait before + issuing any diff request. Querying sooner is + unlikely to produce a meaningful diff. Waiting + longer is acceptable considering the use case. + If this field is not set clients may update as + soon as they want. + """ + + class ResponseType(proto.Enum): + r"""The type of response sent to the client.""" + RESPONSE_TYPE_UNSPECIFIED = 0 + DIFF = 1 + RESET = 2 + + class Checksum(proto.Message): + r"""The expected state of a client's local database. + + Attributes: + sha256 (bytes): + The SHA256 hash of the client state; that is, + of the sorted list of all hashes present in the + database. + """ + + sha256 = proto.Field(proto.BYTES, number=1) + + response_type = proto.Field(proto.ENUM, number=4, enum=ResponseType,) + + additions = proto.Field(proto.MESSAGE, number=5, message="ThreatEntryAdditions",) + + removals = proto.Field(proto.MESSAGE, number=6, message="ThreatEntryRemovals",) + + new_version_token = proto.Field(proto.BYTES, number=7) + + checksum = proto.Field(proto.MESSAGE, number=8, message=Checksum,) + + recommended_next_diff = proto.Field( + proto.MESSAGE, number=2, message=timestamp.Timestamp, + ) + + +class SearchUrisRequest(proto.Message): + r"""Request to check URI entries against threatLists. + + Attributes: + uri (str): + Required. The URI to be checked for matches. + threat_types (Sequence[~.webrisk.ThreatType]): + Required. The ThreatLists to search in. + Multiple ThreatLists may be specified. + """ + + uri = proto.Field(proto.STRING, number=1) + + threat_types = proto.RepeatedField(proto.ENUM, number=2, enum="ThreatType",) + + +class SearchUrisResponse(proto.Message): + r""" + + Attributes: + threat (~.webrisk.SearchUrisResponse.ThreatUri): + The threat list matches. This may be empty if + the URI is on no list. + """ + + class ThreatUri(proto.Message): + r"""Contains threat information on a matching uri. + + Attributes: + threat_types (Sequence[~.webrisk.ThreatType]): + The ThreatList this threat belongs to. + expire_time (~.timestamp.Timestamp): + The cache lifetime for the returned match. + Clients must not cache this response past this + timestamp to avoid false positives. + """ + + threat_types = proto.RepeatedField(proto.ENUM, number=1, enum="ThreatType",) + + expire_time = proto.Field(proto.MESSAGE, number=2, message=timestamp.Timestamp,) + + threat = proto.Field(proto.MESSAGE, number=1, message=ThreatUri,) + + +class SearchHashesRequest(proto.Message): + r"""Request to return full hashes matched by the provided hash + prefixes. + + Attributes: + hash_prefix (bytes): + A hash prefix, consisting of the most + significant 4-32 bytes of a SHA256 hash. For + JSON requests, this field is base64-encoded. + threat_types (Sequence[~.webrisk.ThreatType]): + Required. The ThreatLists to search in. + Multiple ThreatLists may be specified. + """ + + hash_prefix = proto.Field(proto.BYTES, number=1) + + threat_types = proto.RepeatedField(proto.ENUM, number=2, enum="ThreatType",) + + +class SearchHashesResponse(proto.Message): + r""" + + Attributes: + threats (Sequence[~.webrisk.SearchHashesResponse.ThreatHash]): + The full hashes that matched the requested + prefixes. The hash will be populated in the key. + negative_expire_time (~.timestamp.Timestamp): + For requested entities that did not match the + threat list, how long to cache the response + until. + """ + + class ThreatHash(proto.Message): + r"""Contains threat information on a matching hash. + + Attributes: + threat_types (Sequence[~.webrisk.ThreatType]): + The ThreatList this threat belongs to. + This must contain at least one entry. + hash (bytes): + A 32 byte SHA256 hash. This field is in + binary format. For JSON requests, hashes are + base64-encoded. + expire_time (~.timestamp.Timestamp): + The cache lifetime for the returned match. + Clients must not cache this response past this + timestamp to avoid false positives. + """ + + threat_types = proto.RepeatedField(proto.ENUM, number=1, enum="ThreatType",) + + hash = proto.Field(proto.BYTES, number=2) + + expire_time = proto.Field(proto.MESSAGE, number=3, message=timestamp.Timestamp,) + + threats = proto.RepeatedField(proto.MESSAGE, number=1, message=ThreatHash,) + + negative_expire_time = proto.Field( + proto.MESSAGE, number=2, message=timestamp.Timestamp, + ) + + +class ThreatEntryAdditions(proto.Message): + r"""Contains the set of entries to add to a local database. + May contain a combination of compressed and raw data in a single + response. + + Attributes: + raw_hashes (Sequence[~.webrisk.RawHashes]): + The raw SHA256-formatted entries. + Repeated to allow returning sets of hashes with + different prefix sizes. + rice_hashes (~.webrisk.RiceDeltaEncoding): + The encoded 4-byte prefixes of SHA256-formatted entries, + using a Golomb-Rice encoding. The hashes are converted to + uint32, sorted in ascending order, then delta encoded and + stored as encoded_data. + """ + + raw_hashes = proto.RepeatedField(proto.MESSAGE, number=1, message="RawHashes",) + + rice_hashes = proto.Field(proto.MESSAGE, number=2, message="RiceDeltaEncoding",) + + +class ThreatEntryRemovals(proto.Message): + r"""Contains the set of entries to remove from a local database. + + Attributes: + raw_indices (~.webrisk.RawIndices): + The raw removal indices for a local list. + rice_indices (~.webrisk.RiceDeltaEncoding): + The encoded local, lexicographically-sorted list indices, + using a Golomb-Rice encoding. Used for sending compressed + removal indices. The removal indices (uint32) are sorted in + ascending order, then delta encoded and stored as + encoded_data. + """ + + raw_indices = proto.Field(proto.MESSAGE, number=1, message="RawIndices",) + + rice_indices = proto.Field(proto.MESSAGE, number=2, message="RiceDeltaEncoding",) + + +class RawIndices(proto.Message): + r"""A set of raw indices to remove from a local list. + + Attributes: + indices (Sequence[int]): + The indices to remove from a + lexicographically-sorted local list. + """ + + indices = proto.RepeatedField(proto.INT32, number=1) + + +class RawHashes(proto.Message): + r"""The uncompressed threat entries in hash format. + Hashes can be anywhere from 4 to 32 bytes in size. A large + majority are 4 bytes, but some hashes are lengthened if they + collide with the hash of a popular URI. + + Used for sending ThreatEntryAdditons to clients that do not + support compression, or when sending non-4-byte hashes to + clients that do support compression. + + Attributes: + prefix_size (int): + The number of bytes for each prefix encoded + below. This field can be anywhere from 4 + (shortest prefix) to 32 (full SHA256 hash). In + practice this is almost always 4, except in + exceptional circumstances. + raw_hashes (bytes): + The hashes, in binary format, concatenated + into one long string. Hashes are sorted in + lexicographic order. For JSON API users, hashes + are base64-encoded. + """ + + prefix_size = proto.Field(proto.INT32, number=1) + + raw_hashes = proto.Field(proto.BYTES, number=2) + + +class RiceDeltaEncoding(proto.Message): + r"""The Rice-Golomb encoded data. Used for sending compressed + 4-byte hashes or compressed removal indices. + + Attributes: + first_value (int): + The offset of the first entry in the encoded + data, or, if only a single integer was encoded, + that single integer's value. If the field is + empty or missing, assume zero. + rice_parameter (int): + The Golomb-Rice parameter, which is a number between 2 and + 28. This field is missing (that is, zero) if ``num_entries`` + is zero. + entry_count (int): + The number of entries that are delta encoded in the encoded + data. If only a single integer was encoded, this will be + zero and the single value will be stored in ``first_value``. + encoded_data (bytes): + The encoded deltas that are encoded using the + Golomb-Rice coder. + """ + + first_value = proto.Field(proto.INT64, number=1) + + rice_parameter = proto.Field(proto.INT32, number=2) + + entry_count = proto.Field(proto.INT32, number=3) + + encoded_data = proto.Field(proto.BYTES, number=4) + + +class Submission(proto.Message): + r"""Wraps a URI that might be displaying phishing content. + + Attributes: + uri (str): + Required. The URI that is being reported for + phishing content to be analyzed. + """ + + uri = proto.Field(proto.STRING, number=1) + + +class CreateSubmissionRequest(proto.Message): + r"""Request to send a potentially phishy URI to WebRisk. + + Attributes: + parent (str): + Required. The name of the project that is making the + submission. This string is in the format + "projects/{project_number}". + submission (~.webrisk.Submission): + Required. The submission that contains the + content of the phishing report. + """ + + parent = proto.Field(proto.STRING, number=1) + + submission = proto.Field(proto.MESSAGE, number=2, message=Submission,) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/webrisk_v1beta1/__init__.py b/google/cloud/webrisk_v1beta1/__init__.py index deb723c..3128dd4 100644 --- a/google/cloud/webrisk_v1beta1/__init__.py +++ b/google/cloud/webrisk_v1beta1/__init__.py @@ -1,47 +1,49 @@ # -*- 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 # -# https://www.apache.org/licenses/LICENSE-2.0 +# 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. +# - -from __future__ import absolute_import -import sys -import warnings - -from google.cloud.webrisk_v1beta1 import types -from google.cloud.webrisk_v1beta1.gapic import enums -from google.cloud.webrisk_v1beta1.gapic import web_risk_service_v1_beta1_client - - -if sys.version_info[:2] == (2, 7): - message = ( - "A future version of this library will drop support for Python 2.7. " - "More details about Python 2 support for Google Cloud Client Libraries " - "can be found at https://cloud.google.com/python/docs/python2-sunset/" - ) - warnings.warn(message, DeprecationWarning) - - -class WebRiskServiceV1Beta1Client( - web_risk_service_v1_beta1_client.WebRiskServiceV1Beta1Client -): - __doc__ = web_risk_service_v1_beta1_client.WebRiskServiceV1Beta1Client.__doc__ - enums = enums +from .services.web_risk_service_v1_beta1 import WebRiskServiceV1Beta1Client +from .types.webrisk import CompressionType +from .types.webrisk import ComputeThreatListDiffRequest +from .types.webrisk import ComputeThreatListDiffResponse +from .types.webrisk import RawHashes +from .types.webrisk import RawIndices +from .types.webrisk import RiceDeltaEncoding +from .types.webrisk import SearchHashesRequest +from .types.webrisk import SearchHashesResponse +from .types.webrisk import SearchUrisRequest +from .types.webrisk import SearchUrisResponse +from .types.webrisk import ThreatEntryAdditions +from .types.webrisk import ThreatEntryRemovals +from .types.webrisk import ThreatType __all__ = ( - "enums", - "types", + "CompressionType", + "ComputeThreatListDiffRequest", + "ComputeThreatListDiffResponse", + "RawHashes", + "RawIndices", + "RiceDeltaEncoding", + "SearchHashesRequest", + "SearchHashesResponse", + "SearchUrisRequest", + "SearchUrisResponse", + "ThreatEntryAdditions", + "ThreatEntryRemovals", + "ThreatType", "WebRiskServiceV1Beta1Client", ) diff --git a/google/cloud/webrisk_v1beta1/gapic/__init__.py b/google/cloud/webrisk_v1beta1/gapic/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/google/cloud/webrisk_v1beta1/gapic/enums.py b/google/cloud/webrisk_v1beta1/gapic/enums.py deleted file mode 100644 index 42fad3e..0000000 --- a/google/cloud/webrisk_v1beta1/gapic/enums.py +++ /dev/null @@ -1,70 +0,0 @@ -# -*- 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 -# -# https://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. - -"""Wrappers for protocol buffer enum types.""" - -import enum - - -class CompressionType(enum.IntEnum): - """ - The ways in which threat entry sets can be compressed. - - Attributes: - COMPRESSION_TYPE_UNSPECIFIED (int): Unknown. - RAW (int): Raw, uncompressed data. - RICE (int): Rice-Golomb encoded data. - """ - - COMPRESSION_TYPE_UNSPECIFIED = 0 - RAW = 1 - RICE = 2 - - -class ThreatType(enum.IntEnum): - """ - The type of threat. This maps dirrectly to the threat list a threat may - belong to. - - Attributes: - THREAT_TYPE_UNSPECIFIED (int): Unknown. - MALWARE (int): Malware targeting any platform. - SOCIAL_ENGINEERING (int): Social engineering targeting any platform. - UNWANTED_SOFTWARE (int): Unwanted software targeting any platform. - """ - - THREAT_TYPE_UNSPECIFIED = 0 - MALWARE = 1 - SOCIAL_ENGINEERING = 2 - UNWANTED_SOFTWARE = 3 - - -class ComputeThreatListDiffResponse(object): - class ResponseType(enum.IntEnum): - """ - The type of response sent to the client. - - Attributes: - RESPONSE_TYPE_UNSPECIFIED (int): Unknown. - DIFF (int): Partial updates are applied to the client's existing local database. - RESET (int): Full updates resets the client's entire local database. This means - that either the client had no state, was seriously out-of-date, - or the client is believed to be corrupt. - """ - - RESPONSE_TYPE_UNSPECIFIED = 0 - DIFF = 1 - RESET = 2 diff --git a/google/cloud/webrisk_v1beta1/gapic/transports/__init__.py b/google/cloud/webrisk_v1beta1/gapic/transports/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/google/cloud/webrisk_v1beta1/gapic/transports/web_risk_service_v1_beta1_grpc_transport.py b/google/cloud/webrisk_v1beta1/gapic/transports/web_risk_service_v1_beta1_grpc_transport.py deleted file mode 100644 index 70e1b3e..0000000 --- a/google/cloud/webrisk_v1beta1/gapic/transports/web_risk_service_v1_beta1_grpc_transport.py +++ /dev/null @@ -1,153 +0,0 @@ -# -*- 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 -# -# https://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. - - -import google.api_core.grpc_helpers - -from google.cloud.webrisk_v1beta1.proto import webrisk_pb2_grpc - - -class WebRiskServiceV1Beta1GrpcTransport(object): - """gRPC transport class providing stubs for - google.cloud.webrisk.v1beta1 WebRiskServiceV1Beta1 API. - - The transport provides access to the raw gRPC stubs, - which can be used to take advantage of advanced - features of gRPC. - """ - - # The scopes needed to make gRPC calls to all of the methods defined - # in this service. - _OAUTH_SCOPES = ("https://www.googleapis.com/auth/cloud-platform",) - - def __init__( - self, channel=None, credentials=None, address="webrisk.googleapis.com:443" - ): - """Instantiate the transport class. - - Args: - channel (grpc.Channel): A ``Channel`` instance through - which to make calls. This argument is mutually exclusive - with ``credentials``; providing both will raise an exception. - credentials (google.auth.credentials.Credentials): The - authorization credentials to attach to requests. These - credentials identify this application to the service. If none - are specified, the client will attempt to ascertain the - credentials from the environment. - address (str): The address where the service is hosted. - """ - # If both `channel` and `credentials` are specified, raise an - # exception (channels come with credentials baked in already). - if channel is not None and credentials is not None: - raise ValueError( - "The `channel` and `credentials` arguments are mutually " "exclusive.", - ) - - # Create the channel. - if channel is None: - channel = self.create_channel( - address=address, - credentials=credentials, - options={ - "grpc.max_send_message_length": -1, - "grpc.max_receive_message_length": -1, - }.items(), - ) - - self._channel = channel - - # gRPC uses objects called "stubs" that are bound to the - # channel and provide a basic method for each RPC. - self._stubs = { - "web_risk_service_v1_beta1_stub": webrisk_pb2_grpc.WebRiskServiceV1Beta1Stub( - channel - ), - } - - @classmethod - def create_channel( - cls, address="webrisk.googleapis.com:443", credentials=None, **kwargs - ): - """Create and return a gRPC channel object. - - Args: - address (str): The host for the channel to use. - credentials (~.Credentials): The - authorization credentials to attach to requests. These - credentials identify this application to the service. If - none are specified, the client will attempt to ascertain - the credentials from the environment. - kwargs (dict): Keyword arguments, which are passed to the - channel creation. - - Returns: - grpc.Channel: A gRPC channel object. - """ - return google.api_core.grpc_helpers.create_channel( - address, credentials=credentials, scopes=cls._OAUTH_SCOPES, **kwargs - ) - - @property - def channel(self): - """The gRPC channel used by the transport. - - Returns: - grpc.Channel: A gRPC channel object. - """ - return self._channel - - @property - def compute_threat_list_diff(self): - """Return the gRPC stub for :meth:`WebRiskServiceV1Beta1Client.compute_threat_list_diff`. - - Gets the most recent threat list diffs. - - Returns: - Callable: A callable which accepts the appropriate - deserialized request object and returns a - deserialized response object. - """ - return self._stubs["web_risk_service_v1_beta1_stub"].ComputeThreatListDiff - - @property - def search_uris(self): - """Return the gRPC stub for :meth:`WebRiskServiceV1Beta1Client.search_uris`. - - This method is used to check whether a URI is on a given threatList. - - Returns: - Callable: A callable which accepts the appropriate - deserialized request object and returns a - deserialized response object. - """ - return self._stubs["web_risk_service_v1_beta1_stub"].SearchUris - - @property - def search_hashes(self): - """Return the gRPC stub for :meth:`WebRiskServiceV1Beta1Client.search_hashes`. - - Gets the full hashes that match the requested hash prefix. - This is used after a hash prefix is looked up in a threatList - and there is a match. The client side threatList only holds partial hashes - so the client must query this method to determine if there is a full - hash match of a threat. - - Returns: - Callable: A callable which accepts the appropriate - deserialized request object and returns a - deserialized response object. - """ - return self._stubs["web_risk_service_v1_beta1_stub"].SearchHashes diff --git a/google/cloud/webrisk_v1beta1/gapic/web_risk_service_v1_beta1_client.py b/google/cloud/webrisk_v1beta1/gapic/web_risk_service_v1_beta1_client.py deleted file mode 100644 index 2bb2413..0000000 --- a/google/cloud/webrisk_v1beta1/gapic/web_risk_service_v1_beta1_client.py +++ /dev/null @@ -1,389 +0,0 @@ -# -*- 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 -# -# https://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. - -"""Accesses the google.cloud.webrisk.v1beta1 WebRiskServiceV1Beta1 API.""" - -import pkg_resources -import warnings - -from google.oauth2 import service_account -import google.api_core.client_options -import google.api_core.gapic_v1.client_info -import google.api_core.gapic_v1.config -import google.api_core.gapic_v1.method -import google.api_core.grpc_helpers -import grpc - -from google.cloud.webrisk_v1beta1.gapic import enums -from google.cloud.webrisk_v1beta1.gapic import web_risk_service_v1_beta1_client_config -from google.cloud.webrisk_v1beta1.gapic.transports import ( - web_risk_service_v1_beta1_grpc_transport, -) -from google.cloud.webrisk_v1beta1.proto import webrisk_pb2 -from google.cloud.webrisk_v1beta1.proto import webrisk_pb2_grpc - - -_GAPIC_LIBRARY_VERSION = pkg_resources.get_distribution("google-cloud-webrisk",).version - - -class WebRiskServiceV1Beta1Client(object): - """ - Web Risk v1beta1 API defines an interface to detect malicious URLs on your - website and in client applications. - """ - - SERVICE_ADDRESS = "webrisk.googleapis.com:443" - """The default address of the service.""" - - # The name of the interface for this client. This is the key used to - # find the method configuration in the client_config dictionary. - _INTERFACE_NAME = "google.cloud.webrisk.v1beta1.WebRiskServiceV1Beta1" - - @classmethod - def from_service_account_file(cls, filename, *args, **kwargs): - """Creates an instance of this client using the provided credentials - file. - - Args: - filename (str): The path to the service account private key json - file. - args: Additional arguments to pass to the constructor. - kwargs: Additional arguments to pass to the constructor. - - Returns: - WebRiskServiceV1Beta1Client: The constructed client. - """ - credentials = service_account.Credentials.from_service_account_file(filename) - kwargs["credentials"] = credentials - return cls(*args, **kwargs) - - from_service_account_json = from_service_account_file - - def __init__( - self, - transport=None, - channel=None, - credentials=None, - client_config=None, - client_info=None, - client_options=None, - ): - """Constructor. - - Args: - transport (Union[~.WebRiskServiceV1Beta1GrpcTransport, - Callable[[~.Credentials, type], ~.WebRiskServiceV1Beta1GrpcTransport]): A transport - instance, responsible for actually making the API calls. - The default transport uses the gRPC protocol. - This argument may also be a callable which returns a - transport instance. Callables will be sent the credentials - as the first argument and the default transport class as - the second argument. - channel (grpc.Channel): DEPRECATED. A ``Channel`` instance - through which to make calls. This argument is mutually exclusive - with ``credentials``; providing both will raise an exception. - credentials (google.auth.credentials.Credentials): The - authorization credentials to attach to requests. These - credentials identify this application to the service. If none - are specified, the client will attempt to ascertain the - credentials from the environment. - This argument is mutually exclusive with providing a - transport instance to ``transport``; doing so will raise - an exception. - client_config (dict): DEPRECATED. A dictionary of call options for - each method. If not specified, the default configuration is used. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing - your own client library. - client_options (Union[dict, google.api_core.client_options.ClientOptions]): - Client options used to set user options on the client. API Endpoint - should be set through client_options. - """ - # Raise deprecation warnings for things we want to go away. - if client_config is not None: - warnings.warn( - "The `client_config` argument is deprecated.", - PendingDeprecationWarning, - stacklevel=2, - ) - else: - client_config = web_risk_service_v1_beta1_client_config.config - - if channel: - warnings.warn( - "The `channel` argument is deprecated; use " "`transport` instead.", - PendingDeprecationWarning, - stacklevel=2, - ) - - api_endpoint = self.SERVICE_ADDRESS - if client_options: - if type(client_options) == dict: - client_options = google.api_core.client_options.from_dict( - client_options - ) - if client_options.api_endpoint: - api_endpoint = client_options.api_endpoint - - # Instantiate the transport. - # The transport is responsible for handling serialization and - # deserialization and actually sending data to the service. - if transport: - if callable(transport): - self.transport = transport( - credentials=credentials, - default_class=web_risk_service_v1_beta1_grpc_transport.WebRiskServiceV1Beta1GrpcTransport, - address=api_endpoint, - ) - else: - if credentials: - raise ValueError( - "Received both a transport instance and " - "credentials; these are mutually exclusive." - ) - self.transport = transport - else: - self.transport = web_risk_service_v1_beta1_grpc_transport.WebRiskServiceV1Beta1GrpcTransport( - address=api_endpoint, channel=channel, credentials=credentials, - ) - - if client_info is None: - client_info = google.api_core.gapic_v1.client_info.ClientInfo( - gapic_version=_GAPIC_LIBRARY_VERSION, - ) - else: - client_info.gapic_version = _GAPIC_LIBRARY_VERSION - self._client_info = client_info - - # Parse out the default settings for retry and timeout for each RPC - # from the client configuration. - # (Ordinarily, these are the defaults specified in the `*_config.py` - # file next to this one.) - self._method_configs = google.api_core.gapic_v1.config.parse_method_configs( - client_config["interfaces"][self._INTERFACE_NAME], - ) - - # Save a dictionary of cached API call functions. - # These are the actual callables which invoke the proper - # transport methods, wrapped with `wrap_method` to add retry, - # timeout, and the like. - self._inner_api_calls = {} - - # Service calls - def compute_threat_list_diff( - self, - threat_type, - constraints, - version_token=None, - retry=google.api_core.gapic_v1.method.DEFAULT, - timeout=google.api_core.gapic_v1.method.DEFAULT, - metadata=None, - ): - """ - Gets the most recent threat list diffs. - - Example: - >>> from google.cloud import webrisk_v1beta1 - >>> from google.cloud.webrisk_v1beta1 import enums - >>> - >>> client = webrisk_v1beta1.WebRiskServiceV1Beta1Client() - >>> - >>> # TODO: Initialize `threat_type`: - >>> threat_type = enums.ThreatType.THREAT_TYPE_UNSPECIFIED - >>> - >>> # TODO: Initialize `constraints`: - >>> constraints = {} - >>> - >>> response = client.compute_threat_list_diff(threat_type, constraints) - - Args: - threat_type (~google.cloud.webrisk_v1beta1.types.ThreatType): The ThreatList to update. - constraints (Union[dict, ~google.cloud.webrisk_v1beta1.types.Constraints]): Required. The constraints associated with this request. - - If a dict is provided, it must be of the same form as the protobuf - message :class:`~google.cloud.webrisk_v1beta1.types.Constraints` - version_token (bytes): The current version token of the client for the requested list (the - client version that was received from the last successful diff). - retry (Optional[google.api_core.retry.Retry]): A retry object used - to retry requests. If ``None`` is specified, requests will - be retried using a default configuration. - timeout (Optional[float]): The amount of time, in seconds, to wait - for the request to complete. Note that if ``retry`` is - specified, the timeout applies to each individual attempt. - metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata - that is provided to the method. - - Returns: - A :class:`~google.cloud.webrisk_v1beta1.types.ComputeThreatListDiffResponse` instance. - - Raises: - google.api_core.exceptions.GoogleAPICallError: If the request - failed for any reason. - google.api_core.exceptions.RetryError: If the request failed due - to a retryable error and retry attempts failed. - ValueError: If the parameters are invalid. - """ - # Wrap the transport method to add retry and timeout logic. - if "compute_threat_list_diff" not in self._inner_api_calls: - self._inner_api_calls[ - "compute_threat_list_diff" - ] = google.api_core.gapic_v1.method.wrap_method( - self.transport.compute_threat_list_diff, - default_retry=self._method_configs["ComputeThreatListDiff"].retry, - default_timeout=self._method_configs["ComputeThreatListDiff"].timeout, - client_info=self._client_info, - ) - - request = webrisk_pb2.ComputeThreatListDiffRequest( - threat_type=threat_type, - constraints=constraints, - version_token=version_token, - ) - return self._inner_api_calls["compute_threat_list_diff"]( - request, retry=retry, timeout=timeout, metadata=metadata - ) - - def search_uris( - self, - uri, - threat_types, - retry=google.api_core.gapic_v1.method.DEFAULT, - timeout=google.api_core.gapic_v1.method.DEFAULT, - metadata=None, - ): - """ - This method is used to check whether a URI is on a given threatList. - - Example: - >>> from google.cloud import webrisk_v1beta1 - >>> from google.cloud.webrisk_v1beta1 import enums - >>> - >>> client = webrisk_v1beta1.WebRiskServiceV1Beta1Client() - >>> - >>> # TODO: Initialize `uri`: - >>> uri = '' - >>> - >>> # TODO: Initialize `threat_types`: - >>> threat_types = [] - >>> - >>> response = client.search_uris(uri, threat_types) - - Args: - uri (str): Required. The URI to be checked for matches. - threat_types (list[~google.cloud.webrisk_v1beta1.types.ThreatType]): Required. The ThreatLists to search in. - retry (Optional[google.api_core.retry.Retry]): A retry object used - to retry requests. If ``None`` is specified, requests will - be retried using a default configuration. - timeout (Optional[float]): The amount of time, in seconds, to wait - for the request to complete. Note that if ``retry`` is - specified, the timeout applies to each individual attempt. - metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata - that is provided to the method. - - Returns: - A :class:`~google.cloud.webrisk_v1beta1.types.SearchUrisResponse` instance. - - Raises: - google.api_core.exceptions.GoogleAPICallError: If the request - failed for any reason. - google.api_core.exceptions.RetryError: If the request failed due - to a retryable error and retry attempts failed. - ValueError: If the parameters are invalid. - """ - # Wrap the transport method to add retry and timeout logic. - if "search_uris" not in self._inner_api_calls: - self._inner_api_calls[ - "search_uris" - ] = google.api_core.gapic_v1.method.wrap_method( - self.transport.search_uris, - default_retry=self._method_configs["SearchUris"].retry, - default_timeout=self._method_configs["SearchUris"].timeout, - client_info=self._client_info, - ) - - request = webrisk_pb2.SearchUrisRequest(uri=uri, threat_types=threat_types,) - return self._inner_api_calls["search_uris"]( - request, retry=retry, timeout=timeout, metadata=metadata - ) - - def search_hashes( - self, - threat_types, - hash_prefix=None, - retry=google.api_core.gapic_v1.method.DEFAULT, - timeout=google.api_core.gapic_v1.method.DEFAULT, - metadata=None, - ): - """ - Gets the full hashes that match the requested hash prefix. - This is used after a hash prefix is looked up in a threatList - and there is a match. The client side threatList only holds partial hashes - so the client must query this method to determine if there is a full - hash match of a threat. - - Example: - >>> from google.cloud import webrisk_v1beta1 - >>> from google.cloud.webrisk_v1beta1 import enums - >>> - >>> client = webrisk_v1beta1.WebRiskServiceV1Beta1Client() - >>> - >>> # TODO: Initialize `threat_types`: - >>> threat_types = [] - >>> - >>> response = client.search_hashes(threat_types) - - Args: - threat_types (list[~google.cloud.webrisk_v1beta1.types.ThreatType]): Required. The ThreatLists to search in. - hash_prefix (bytes): A hash prefix, consisting of the most significant 4-32 bytes of a SHA256 - hash. For JSON requests, this field is base64-encoded. - retry (Optional[google.api_core.retry.Retry]): A retry object used - to retry requests. If ``None`` is specified, requests will - be retried using a default configuration. - timeout (Optional[float]): The amount of time, in seconds, to wait - for the request to complete. Note that if ``retry`` is - specified, the timeout applies to each individual attempt. - metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata - that is provided to the method. - - Returns: - A :class:`~google.cloud.webrisk_v1beta1.types.SearchHashesResponse` instance. - - Raises: - google.api_core.exceptions.GoogleAPICallError: If the request - failed for any reason. - google.api_core.exceptions.RetryError: If the request failed due - to a retryable error and retry attempts failed. - ValueError: If the parameters are invalid. - """ - # Wrap the transport method to add retry and timeout logic. - if "search_hashes" not in self._inner_api_calls: - self._inner_api_calls[ - "search_hashes" - ] = google.api_core.gapic_v1.method.wrap_method( - self.transport.search_hashes, - default_retry=self._method_configs["SearchHashes"].retry, - default_timeout=self._method_configs["SearchHashes"].timeout, - client_info=self._client_info, - ) - - request = webrisk_pb2.SearchHashesRequest( - threat_types=threat_types, hash_prefix=hash_prefix, - ) - return self._inner_api_calls["search_hashes"]( - request, retry=retry, timeout=timeout, metadata=metadata - ) diff --git a/google/cloud/webrisk_v1beta1/gapic/web_risk_service_v1_beta1_client_config.py b/google/cloud/webrisk_v1beta1/gapic/web_risk_service_v1_beta1_client_config.py deleted file mode 100644 index f2d199b..0000000 --- a/google/cloud/webrisk_v1beta1/gapic/web_risk_service_v1_beta1_client_config.py +++ /dev/null @@ -1,47 +0,0 @@ -config = { - "interfaces": { - "google.cloud.webrisk.v1beta1.WebRiskServiceV1Beta1": { - "retry_codes": { - "retry_policy_1_codes": ["DEADLINE_EXCEEDED", "UNAVAILABLE"], - "no_retry_codes": [], - }, - "retry_params": { - "retry_policy_1_params": { - "initial_retry_delay_millis": 100, - "retry_delay_multiplier": 1.3, - "max_retry_delay_millis": 60000, - "initial_rpc_timeout_millis": 600000, - "rpc_timeout_multiplier": 1.0, - "max_rpc_timeout_millis": 600000, - "total_timeout_millis": 600000, - }, - "no_retry_params": { - "initial_retry_delay_millis": 0, - "retry_delay_multiplier": 0.0, - "max_retry_delay_millis": 0, - "initial_rpc_timeout_millis": 0, - "rpc_timeout_multiplier": 1.0, - "max_rpc_timeout_millis": 0, - "total_timeout_millis": 0, - }, - }, - "methods": { - "ComputeThreatListDiff": { - "timeout_millis": 600000, - "retry_codes_name": "retry_policy_1_codes", - "retry_params_name": "retry_policy_1_params", - }, - "SearchUris": { - "timeout_millis": 600000, - "retry_codes_name": "retry_policy_1_codes", - "retry_params_name": "retry_policy_1_params", - }, - "SearchHashes": { - "timeout_millis": 600000, - "retry_codes_name": "retry_policy_1_codes", - "retry_params_name": "retry_policy_1_params", - }, - }, - } - } -} diff --git a/google/cloud/webrisk_v1beta1/proto/__init__.py b/google/cloud/webrisk_v1beta1/proto/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/google/cloud/webrisk_v1beta1/proto/webrisk_pb2.py b/google/cloud/webrisk_v1beta1/proto/webrisk_pb2.py deleted file mode 100644 index 3bf7f58..0000000 --- a/google/cloud/webrisk_v1beta1/proto/webrisk_pb2.py +++ /dev/null @@ -1,1657 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by the protocol buffer compiler. DO NOT EDIT! -# source: google/cloud/webrisk_v1beta1/proto/webrisk.proto -"""Generated protocol buffer code.""" -from google.protobuf.internal import enum_type_wrapper -from google.protobuf import descriptor as _descriptor -from google.protobuf import message as _message -from google.protobuf import reflection as _reflection -from google.protobuf import symbol_database as _symbol_database - -# @@protoc_insertion_point(imports) - -_sym_db = _symbol_database.Default() - - -from google.api import annotations_pb2 as google_dot_api_dot_annotations__pb2 -from google.api import client_pb2 as google_dot_api_dot_client__pb2 -from google.api import field_behavior_pb2 as google_dot_api_dot_field__behavior__pb2 -from google.protobuf import timestamp_pb2 as google_dot_protobuf_dot_timestamp__pb2 - - -DESCRIPTOR = _descriptor.FileDescriptor( - name="google/cloud/webrisk_v1beta1/proto/webrisk.proto", - package="google.cloud.webrisk.v1beta1", - syntax="proto3", - serialized_options=b"\n\032com.google.webrisk.v1beta1B\014WebRiskProtoP\001ZCgoogle.golang.org/genproto/googleapis/cloud/webrisk/v1beta1;webrisk\242\002\004GCWR\252\002\034Google.Cloud.WebRisk.V1Beta1\312\002\034Google\\Cloud\\WebRisk\\V1beta1\352\002\037Google::Cloud::WebRisk::V1beta1", - create_key=_descriptor._internal_create_key, - serialized_pb=b'\n0google/cloud/webrisk_v1beta1/proto/webrisk.proto\x12\x1cgoogle.cloud.webrisk.v1beta1\x1a\x1cgoogle/api/annotations.proto\x1a\x17google/api/client.proto\x1a\x1fgoogle/api/field_behavior.proto\x1a\x1fgoogle/protobuf/timestamp.proto"\xf2\x02\n\x1c\x43omputeThreatListDiffRequest\x12\x42\n\x0bthreat_type\x18\x01 \x01(\x0e\x32(.google.cloud.webrisk.v1beta1.ThreatTypeB\x03\xe0\x41\x02\x12\x15\n\rversion_token\x18\x02 \x01(\x0c\x12`\n\x0b\x63onstraints\x18\x03 \x01(\x0b\x32\x46.google.cloud.webrisk.v1beta1.ComputeThreatListDiffRequest.ConstraintsB\x03\xe0\x41\x02\x1a\x94\x01\n\x0b\x43onstraints\x12\x18\n\x10max_diff_entries\x18\x01 \x01(\x05\x12\x1c\n\x14max_database_entries\x18\x02 \x01(\x05\x12M\n\x16supported_compressions\x18\x03 \x03(\x0e\x32-.google.cloud.webrisk.v1beta1.CompressionType"\x9a\x04\n\x1d\x43omputeThreatListDiffResponse\x12_\n\rresponse_type\x18\x04 \x01(\x0e\x32H.google.cloud.webrisk.v1beta1.ComputeThreatListDiffResponse.ResponseType\x12\x45\n\tadditions\x18\x05 \x01(\x0b\x32\x32.google.cloud.webrisk.v1beta1.ThreatEntryAdditions\x12\x43\n\x08removals\x18\x06 \x01(\x0b\x32\x31.google.cloud.webrisk.v1beta1.ThreatEntryRemovals\x12\x19\n\x11new_version_token\x18\x07 \x01(\x0c\x12V\n\x08\x63hecksum\x18\x08 \x01(\x0b\x32\x44.google.cloud.webrisk.v1beta1.ComputeThreatListDiffResponse.Checksum\x12\x39\n\x15recommended_next_diff\x18\x02 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x1a\x1a\n\x08\x43hecksum\x12\x0e\n\x06sha256\x18\x01 \x01(\x0c"B\n\x0cResponseType\x12\x1d\n\x19RESPONSE_TYPE_UNSPECIFIED\x10\x00\x12\x08\n\x04\x44IFF\x10\x01\x12\t\n\x05RESET\x10\x02"j\n\x11SearchUrisRequest\x12\x10\n\x03uri\x18\x01 \x01(\tB\x03\xe0\x41\x02\x12\x43\n\x0cthreat_types\x18\x02 \x03(\x0e\x32(.google.cloud.webrisk.v1beta1.ThreatTypeB\x03\xe0\x41\x02"\xde\x01\n\x12SearchUrisResponse\x12J\n\x06threat\x18\x01 \x01(\x0b\x32:.google.cloud.webrisk.v1beta1.SearchUrisResponse.ThreatUri\x1a|\n\tThreatUri\x12>\n\x0cthreat_types\x18\x01 \x03(\x0e\x32(.google.cloud.webrisk.v1beta1.ThreatType\x12/\n\x0b\x65xpire_time\x18\x02 \x01(\x0b\x32\x1a.google.protobuf.Timestamp"o\n\x13SearchHashesRequest\x12\x13\n\x0bhash_prefix\x18\x01 \x01(\x0c\x12\x43\n\x0cthreat_types\x18\x02 \x03(\x0e\x32(.google.cloud.webrisk.v1beta1.ThreatTypeB\x03\xe0\x41\x02"\xae\x02\n\x14SearchHashesResponse\x12N\n\x07threats\x18\x01 \x03(\x0b\x32=.google.cloud.webrisk.v1beta1.SearchHashesResponse.ThreatHash\x12\x38\n\x14negative_expire_time\x18\x02 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x1a\x8b\x01\n\nThreatHash\x12>\n\x0cthreat_types\x18\x01 \x03(\x0e\x32(.google.cloud.webrisk.v1beta1.ThreatType\x12\x0c\n\x04hash\x18\x02 \x01(\x0c\x12/\n\x0b\x65xpire_time\x18\x03 \x01(\x0b\x32\x1a.google.protobuf.Timestamp"\x99\x01\n\x14ThreatEntryAdditions\x12;\n\nraw_hashes\x18\x01 \x03(\x0b\x32\'.google.cloud.webrisk.v1beta1.RawHashes\x12\x44\n\x0brice_hashes\x18\x02 \x01(\x0b\x32/.google.cloud.webrisk.v1beta1.RiceDeltaEncoding"\x9b\x01\n\x13ThreatEntryRemovals\x12=\n\x0braw_indices\x18\x01 \x01(\x0b\x32(.google.cloud.webrisk.v1beta1.RawIndices\x12\x45\n\x0crice_indices\x18\x02 \x01(\x0b\x32/.google.cloud.webrisk.v1beta1.RiceDeltaEncoding"\x1d\n\nRawIndices\x12\x0f\n\x07indices\x18\x01 \x03(\x05"4\n\tRawHashes\x12\x13\n\x0bprefix_size\x18\x01 \x01(\x05\x12\x12\n\nraw_hashes\x18\x02 \x01(\x0c"k\n\x11RiceDeltaEncoding\x12\x13\n\x0b\x66irst_value\x18\x01 \x01(\x03\x12\x16\n\x0erice_parameter\x18\x02 \x01(\x05\x12\x13\n\x0b\x65ntry_count\x18\x03 \x01(\x05\x12\x14\n\x0c\x65ncoded_data\x18\x04 \x01(\x0c*e\n\nThreatType\x12\x1b\n\x17THREAT_TYPE_UNSPECIFIED\x10\x00\x12\x0b\n\x07MALWARE\x10\x01\x12\x16\n\x12SOCIAL_ENGINEERING\x10\x02\x12\x15\n\x11UNWANTED_SOFTWARE\x10\x03*F\n\x0f\x43ompressionType\x12 \n\x1c\x43OMPRESSION_TYPE_UNSPECIFIED\x10\x00\x12\x07\n\x03RAW\x10\x01\x12\x08\n\x04RICE\x10\x02\x32\x9e\x05\n\x15WebRiskServiceV1Beta1\x12\xe2\x01\n\x15\x43omputeThreatListDiff\x12:.google.cloud.webrisk.v1beta1.ComputeThreatListDiffRequest\x1a;.google.cloud.webrisk.v1beta1.ComputeThreatListDiffResponse"P\x82\xd3\xe4\x93\x02"\x12 /v1beta1/threatLists:computeDiff\xda\x41%threat_type,version_token,constraints\x12\xa0\x01\n\nSearchUris\x12/.google.cloud.webrisk.v1beta1.SearchUrisRequest\x1a\x30.google.cloud.webrisk.v1beta1.SearchUrisResponse"/\x82\xd3\xe4\x93\x02\x16\x12\x14/v1beta1/uris:search\xda\x41\x10uri,threat_types\x12\xb0\x01\n\x0cSearchHashes\x12\x31.google.cloud.webrisk.v1beta1.SearchHashesRequest\x1a\x32.google.cloud.webrisk.v1beta1.SearchHashesResponse"9\x82\xd3\xe4\x93\x02\x18\x12\x16/v1beta1/hashes:search\xda\x41\x18hash_prefix,threat_types\x1aJ\xca\x41\x16webrisk.googleapis.com\xd2\x41.https://www.googleapis.com/auth/cloud-platformB\xd8\x01\n\x1a\x63om.google.webrisk.v1beta1B\x0cWebRiskProtoP\x01ZCgoogle.golang.org/genproto/googleapis/cloud/webrisk/v1beta1;webrisk\xa2\x02\x04GCWR\xaa\x02\x1cGoogle.Cloud.WebRisk.V1Beta1\xca\x02\x1cGoogle\\Cloud\\WebRisk\\V1beta1\xea\x02\x1fGoogle::Cloud::WebRisk::V1beta1b\x06proto3', - dependencies=[ - google_dot_api_dot_annotations__pb2.DESCRIPTOR, - google_dot_api_dot_client__pb2.DESCRIPTOR, - google_dot_api_dot_field__behavior__pb2.DESCRIPTOR, - google_dot_protobuf_dot_timestamp__pb2.DESCRIPTOR, - ], -) - -_THREATTYPE = _descriptor.EnumDescriptor( - name="ThreatType", - full_name="google.cloud.webrisk.v1beta1.ThreatType", - filename=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - values=[ - _descriptor.EnumValueDescriptor( - name="THREAT_TYPE_UNSPECIFIED", - index=0, - number=0, - serialized_options=None, - type=None, - create_key=_descriptor._internal_create_key, - ), - _descriptor.EnumValueDescriptor( - name="MALWARE", - index=1, - number=1, - serialized_options=None, - type=None, - create_key=_descriptor._internal_create_key, - ), - _descriptor.EnumValueDescriptor( - name="SOCIAL_ENGINEERING", - index=2, - number=2, - serialized_options=None, - type=None, - create_key=_descriptor._internal_create_key, - ), - _descriptor.EnumValueDescriptor( - name="UNWANTED_SOFTWARE", - index=3, - number=3, - serialized_options=None, - type=None, - create_key=_descriptor._internal_create_key, - ), - ], - containing_type=None, - serialized_options=None, - serialized_start=2376, - serialized_end=2477, -) -_sym_db.RegisterEnumDescriptor(_THREATTYPE) - -ThreatType = enum_type_wrapper.EnumTypeWrapper(_THREATTYPE) -_COMPRESSIONTYPE = _descriptor.EnumDescriptor( - name="CompressionType", - full_name="google.cloud.webrisk.v1beta1.CompressionType", - filename=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - values=[ - _descriptor.EnumValueDescriptor( - name="COMPRESSION_TYPE_UNSPECIFIED", - index=0, - number=0, - serialized_options=None, - type=None, - create_key=_descriptor._internal_create_key, - ), - _descriptor.EnumValueDescriptor( - name="RAW", - index=1, - number=1, - serialized_options=None, - type=None, - create_key=_descriptor._internal_create_key, - ), - _descriptor.EnumValueDescriptor( - name="RICE", - index=2, - number=2, - serialized_options=None, - type=None, - create_key=_descriptor._internal_create_key, - ), - ], - containing_type=None, - serialized_options=None, - serialized_start=2479, - serialized_end=2549, -) -_sym_db.RegisterEnumDescriptor(_COMPRESSIONTYPE) - -CompressionType = enum_type_wrapper.EnumTypeWrapper(_COMPRESSIONTYPE) -THREAT_TYPE_UNSPECIFIED = 0 -MALWARE = 1 -SOCIAL_ENGINEERING = 2 -UNWANTED_SOFTWARE = 3 -COMPRESSION_TYPE_UNSPECIFIED = 0 -RAW = 1 -RICE = 2 - - -_COMPUTETHREATLISTDIFFRESPONSE_RESPONSETYPE = _descriptor.EnumDescriptor( - name="ResponseType", - full_name="google.cloud.webrisk.v1beta1.ComputeThreatListDiffResponse.ResponseType", - filename=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - values=[ - _descriptor.EnumValueDescriptor( - name="RESPONSE_TYPE_UNSPECIFIED", - index=0, - number=0, - serialized_options=None, - type=None, - create_key=_descriptor._internal_create_key, - ), - _descriptor.EnumValueDescriptor( - name="DIFF", - index=1, - number=1, - serialized_options=None, - type=None, - create_key=_descriptor._internal_create_key, - ), - _descriptor.EnumValueDescriptor( - name="RESET", - index=2, - number=2, - serialized_options=None, - type=None, - create_key=_descriptor._internal_create_key, - ), - ], - containing_type=None, - serialized_options=None, - serialized_start=1049, - serialized_end=1115, -) -_sym_db.RegisterEnumDescriptor(_COMPUTETHREATLISTDIFFRESPONSE_RESPONSETYPE) - - -_COMPUTETHREATLISTDIFFREQUEST_CONSTRAINTS = _descriptor.Descriptor( - name="Constraints", - full_name="google.cloud.webrisk.v1beta1.ComputeThreatListDiffRequest.Constraints", - filename=None, - file=DESCRIPTOR, - containing_type=None, - create_key=_descriptor._internal_create_key, - fields=[ - _descriptor.FieldDescriptor( - name="max_diff_entries", - full_name="google.cloud.webrisk.v1beta1.ComputeThreatListDiffRequest.Constraints.max_diff_entries", - index=0, - number=1, - type=5, - cpp_type=1, - label=1, - has_default_value=False, - default_value=0, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - _descriptor.FieldDescriptor( - name="max_database_entries", - full_name="google.cloud.webrisk.v1beta1.ComputeThreatListDiffRequest.Constraints.max_database_entries", - index=1, - number=2, - type=5, - cpp_type=1, - label=1, - has_default_value=False, - default_value=0, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - _descriptor.FieldDescriptor( - name="supported_compressions", - full_name="google.cloud.webrisk.v1beta1.ComputeThreatListDiffRequest.Constraints.supported_compressions", - index=2, - number=3, - type=14, - cpp_type=8, - label=3, - has_default_value=False, - default_value=[], - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - ], - extensions=[], - nested_types=[], - enum_types=[], - serialized_options=None, - is_extendable=False, - syntax="proto3", - extension_ranges=[], - oneofs=[], - serialized_start=426, - serialized_end=574, -) - -_COMPUTETHREATLISTDIFFREQUEST = _descriptor.Descriptor( - name="ComputeThreatListDiffRequest", - full_name="google.cloud.webrisk.v1beta1.ComputeThreatListDiffRequest", - filename=None, - file=DESCRIPTOR, - containing_type=None, - create_key=_descriptor._internal_create_key, - fields=[ - _descriptor.FieldDescriptor( - name="threat_type", - full_name="google.cloud.webrisk.v1beta1.ComputeThreatListDiffRequest.threat_type", - index=0, - number=1, - type=14, - cpp_type=8, - label=1, - has_default_value=False, - default_value=0, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=b"\340A\002", - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - _descriptor.FieldDescriptor( - name="version_token", - full_name="google.cloud.webrisk.v1beta1.ComputeThreatListDiffRequest.version_token", - index=1, - number=2, - type=12, - cpp_type=9, - label=1, - has_default_value=False, - default_value=b"", - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - _descriptor.FieldDescriptor( - name="constraints", - full_name="google.cloud.webrisk.v1beta1.ComputeThreatListDiffRequest.constraints", - index=2, - number=3, - type=11, - cpp_type=10, - label=1, - has_default_value=False, - default_value=None, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=b"\340A\002", - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - ], - extensions=[], - nested_types=[_COMPUTETHREATLISTDIFFREQUEST_CONSTRAINTS,], - enum_types=[], - serialized_options=None, - is_extendable=False, - syntax="proto3", - extension_ranges=[], - oneofs=[], - serialized_start=204, - serialized_end=574, -) - - -_COMPUTETHREATLISTDIFFRESPONSE_CHECKSUM = _descriptor.Descriptor( - name="Checksum", - full_name="google.cloud.webrisk.v1beta1.ComputeThreatListDiffResponse.Checksum", - filename=None, - file=DESCRIPTOR, - containing_type=None, - create_key=_descriptor._internal_create_key, - fields=[ - _descriptor.FieldDescriptor( - name="sha256", - full_name="google.cloud.webrisk.v1beta1.ComputeThreatListDiffResponse.Checksum.sha256", - index=0, - number=1, - type=12, - cpp_type=9, - label=1, - has_default_value=False, - default_value=b"", - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - ], - extensions=[], - nested_types=[], - enum_types=[], - serialized_options=None, - is_extendable=False, - syntax="proto3", - extension_ranges=[], - oneofs=[], - serialized_start=1021, - serialized_end=1047, -) - -_COMPUTETHREATLISTDIFFRESPONSE = _descriptor.Descriptor( - name="ComputeThreatListDiffResponse", - full_name="google.cloud.webrisk.v1beta1.ComputeThreatListDiffResponse", - filename=None, - file=DESCRIPTOR, - containing_type=None, - create_key=_descriptor._internal_create_key, - fields=[ - _descriptor.FieldDescriptor( - name="response_type", - full_name="google.cloud.webrisk.v1beta1.ComputeThreatListDiffResponse.response_type", - index=0, - number=4, - type=14, - cpp_type=8, - label=1, - has_default_value=False, - default_value=0, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - _descriptor.FieldDescriptor( - name="additions", - full_name="google.cloud.webrisk.v1beta1.ComputeThreatListDiffResponse.additions", - index=1, - number=5, - type=11, - cpp_type=10, - label=1, - has_default_value=False, - default_value=None, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - _descriptor.FieldDescriptor( - name="removals", - full_name="google.cloud.webrisk.v1beta1.ComputeThreatListDiffResponse.removals", - index=2, - number=6, - type=11, - cpp_type=10, - label=1, - has_default_value=False, - default_value=None, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - _descriptor.FieldDescriptor( - name="new_version_token", - full_name="google.cloud.webrisk.v1beta1.ComputeThreatListDiffResponse.new_version_token", - index=3, - number=7, - type=12, - cpp_type=9, - label=1, - has_default_value=False, - default_value=b"", - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - _descriptor.FieldDescriptor( - name="checksum", - full_name="google.cloud.webrisk.v1beta1.ComputeThreatListDiffResponse.checksum", - index=4, - number=8, - type=11, - cpp_type=10, - label=1, - has_default_value=False, - default_value=None, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - _descriptor.FieldDescriptor( - name="recommended_next_diff", - full_name="google.cloud.webrisk.v1beta1.ComputeThreatListDiffResponse.recommended_next_diff", - index=5, - number=2, - type=11, - cpp_type=10, - label=1, - has_default_value=False, - default_value=None, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - ], - extensions=[], - nested_types=[_COMPUTETHREATLISTDIFFRESPONSE_CHECKSUM,], - enum_types=[_COMPUTETHREATLISTDIFFRESPONSE_RESPONSETYPE,], - serialized_options=None, - is_extendable=False, - syntax="proto3", - extension_ranges=[], - oneofs=[], - serialized_start=577, - serialized_end=1115, -) - - -_SEARCHURISREQUEST = _descriptor.Descriptor( - name="SearchUrisRequest", - full_name="google.cloud.webrisk.v1beta1.SearchUrisRequest", - filename=None, - file=DESCRIPTOR, - containing_type=None, - create_key=_descriptor._internal_create_key, - fields=[ - _descriptor.FieldDescriptor( - name="uri", - full_name="google.cloud.webrisk.v1beta1.SearchUrisRequest.uri", - index=0, - number=1, - type=9, - cpp_type=9, - label=1, - has_default_value=False, - default_value=b"".decode("utf-8"), - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=b"\340A\002", - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - _descriptor.FieldDescriptor( - name="threat_types", - full_name="google.cloud.webrisk.v1beta1.SearchUrisRequest.threat_types", - index=1, - number=2, - type=14, - cpp_type=8, - label=3, - has_default_value=False, - default_value=[], - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=b"\340A\002", - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - ], - extensions=[], - nested_types=[], - enum_types=[], - serialized_options=None, - is_extendable=False, - syntax="proto3", - extension_ranges=[], - oneofs=[], - serialized_start=1117, - serialized_end=1223, -) - - -_SEARCHURISRESPONSE_THREATURI = _descriptor.Descriptor( - name="ThreatUri", - full_name="google.cloud.webrisk.v1beta1.SearchUrisResponse.ThreatUri", - filename=None, - file=DESCRIPTOR, - containing_type=None, - create_key=_descriptor._internal_create_key, - fields=[ - _descriptor.FieldDescriptor( - name="threat_types", - full_name="google.cloud.webrisk.v1beta1.SearchUrisResponse.ThreatUri.threat_types", - index=0, - number=1, - type=14, - cpp_type=8, - label=3, - has_default_value=False, - default_value=[], - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - _descriptor.FieldDescriptor( - name="expire_time", - full_name="google.cloud.webrisk.v1beta1.SearchUrisResponse.ThreatUri.expire_time", - index=1, - number=2, - type=11, - cpp_type=10, - label=1, - has_default_value=False, - default_value=None, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - ], - extensions=[], - nested_types=[], - enum_types=[], - serialized_options=None, - is_extendable=False, - syntax="proto3", - extension_ranges=[], - oneofs=[], - serialized_start=1324, - serialized_end=1448, -) - -_SEARCHURISRESPONSE = _descriptor.Descriptor( - name="SearchUrisResponse", - full_name="google.cloud.webrisk.v1beta1.SearchUrisResponse", - filename=None, - file=DESCRIPTOR, - containing_type=None, - create_key=_descriptor._internal_create_key, - fields=[ - _descriptor.FieldDescriptor( - name="threat", - full_name="google.cloud.webrisk.v1beta1.SearchUrisResponse.threat", - index=0, - number=1, - type=11, - cpp_type=10, - label=1, - has_default_value=False, - default_value=None, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - ], - extensions=[], - nested_types=[_SEARCHURISRESPONSE_THREATURI,], - enum_types=[], - serialized_options=None, - is_extendable=False, - syntax="proto3", - extension_ranges=[], - oneofs=[], - serialized_start=1226, - serialized_end=1448, -) - - -_SEARCHHASHESREQUEST = _descriptor.Descriptor( - name="SearchHashesRequest", - full_name="google.cloud.webrisk.v1beta1.SearchHashesRequest", - filename=None, - file=DESCRIPTOR, - containing_type=None, - create_key=_descriptor._internal_create_key, - fields=[ - _descriptor.FieldDescriptor( - name="hash_prefix", - full_name="google.cloud.webrisk.v1beta1.SearchHashesRequest.hash_prefix", - index=0, - number=1, - type=12, - cpp_type=9, - label=1, - has_default_value=False, - default_value=b"", - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - _descriptor.FieldDescriptor( - name="threat_types", - full_name="google.cloud.webrisk.v1beta1.SearchHashesRequest.threat_types", - index=1, - number=2, - type=14, - cpp_type=8, - label=3, - has_default_value=False, - default_value=[], - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=b"\340A\002", - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - ], - extensions=[], - nested_types=[], - enum_types=[], - serialized_options=None, - is_extendable=False, - syntax="proto3", - extension_ranges=[], - oneofs=[], - serialized_start=1450, - serialized_end=1561, -) - - -_SEARCHHASHESRESPONSE_THREATHASH = _descriptor.Descriptor( - name="ThreatHash", - full_name="google.cloud.webrisk.v1beta1.SearchHashesResponse.ThreatHash", - filename=None, - file=DESCRIPTOR, - containing_type=None, - create_key=_descriptor._internal_create_key, - fields=[ - _descriptor.FieldDescriptor( - name="threat_types", - full_name="google.cloud.webrisk.v1beta1.SearchHashesResponse.ThreatHash.threat_types", - index=0, - number=1, - type=14, - cpp_type=8, - label=3, - has_default_value=False, - default_value=[], - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - _descriptor.FieldDescriptor( - name="hash", - full_name="google.cloud.webrisk.v1beta1.SearchHashesResponse.ThreatHash.hash", - index=1, - number=2, - type=12, - cpp_type=9, - label=1, - has_default_value=False, - default_value=b"", - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - _descriptor.FieldDescriptor( - name="expire_time", - full_name="google.cloud.webrisk.v1beta1.SearchHashesResponse.ThreatHash.expire_time", - index=2, - number=3, - type=11, - cpp_type=10, - label=1, - has_default_value=False, - default_value=None, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - ], - extensions=[], - nested_types=[], - enum_types=[], - serialized_options=None, - is_extendable=False, - syntax="proto3", - extension_ranges=[], - oneofs=[], - serialized_start=1727, - serialized_end=1866, -) - -_SEARCHHASHESRESPONSE = _descriptor.Descriptor( - name="SearchHashesResponse", - full_name="google.cloud.webrisk.v1beta1.SearchHashesResponse", - filename=None, - file=DESCRIPTOR, - containing_type=None, - create_key=_descriptor._internal_create_key, - fields=[ - _descriptor.FieldDescriptor( - name="threats", - full_name="google.cloud.webrisk.v1beta1.SearchHashesResponse.threats", - index=0, - number=1, - type=11, - cpp_type=10, - label=3, - has_default_value=False, - default_value=[], - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - _descriptor.FieldDescriptor( - name="negative_expire_time", - full_name="google.cloud.webrisk.v1beta1.SearchHashesResponse.negative_expire_time", - index=1, - number=2, - type=11, - cpp_type=10, - label=1, - has_default_value=False, - default_value=None, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - ], - extensions=[], - nested_types=[_SEARCHHASHESRESPONSE_THREATHASH,], - enum_types=[], - serialized_options=None, - is_extendable=False, - syntax="proto3", - extension_ranges=[], - oneofs=[], - serialized_start=1564, - serialized_end=1866, -) - - -_THREATENTRYADDITIONS = _descriptor.Descriptor( - name="ThreatEntryAdditions", - full_name="google.cloud.webrisk.v1beta1.ThreatEntryAdditions", - filename=None, - file=DESCRIPTOR, - containing_type=None, - create_key=_descriptor._internal_create_key, - fields=[ - _descriptor.FieldDescriptor( - name="raw_hashes", - full_name="google.cloud.webrisk.v1beta1.ThreatEntryAdditions.raw_hashes", - index=0, - number=1, - type=11, - cpp_type=10, - label=3, - has_default_value=False, - default_value=[], - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - _descriptor.FieldDescriptor( - name="rice_hashes", - full_name="google.cloud.webrisk.v1beta1.ThreatEntryAdditions.rice_hashes", - index=1, - number=2, - type=11, - cpp_type=10, - label=1, - has_default_value=False, - default_value=None, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - ], - extensions=[], - nested_types=[], - enum_types=[], - serialized_options=None, - is_extendable=False, - syntax="proto3", - extension_ranges=[], - oneofs=[], - serialized_start=1869, - serialized_end=2022, -) - - -_THREATENTRYREMOVALS = _descriptor.Descriptor( - name="ThreatEntryRemovals", - full_name="google.cloud.webrisk.v1beta1.ThreatEntryRemovals", - filename=None, - file=DESCRIPTOR, - containing_type=None, - create_key=_descriptor._internal_create_key, - fields=[ - _descriptor.FieldDescriptor( - name="raw_indices", - full_name="google.cloud.webrisk.v1beta1.ThreatEntryRemovals.raw_indices", - index=0, - number=1, - type=11, - cpp_type=10, - label=1, - has_default_value=False, - default_value=None, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - _descriptor.FieldDescriptor( - name="rice_indices", - full_name="google.cloud.webrisk.v1beta1.ThreatEntryRemovals.rice_indices", - index=1, - number=2, - type=11, - cpp_type=10, - label=1, - has_default_value=False, - default_value=None, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - ], - extensions=[], - nested_types=[], - enum_types=[], - serialized_options=None, - is_extendable=False, - syntax="proto3", - extension_ranges=[], - oneofs=[], - serialized_start=2025, - serialized_end=2180, -) - - -_RAWINDICES = _descriptor.Descriptor( - name="RawIndices", - full_name="google.cloud.webrisk.v1beta1.RawIndices", - filename=None, - file=DESCRIPTOR, - containing_type=None, - create_key=_descriptor._internal_create_key, - fields=[ - _descriptor.FieldDescriptor( - name="indices", - full_name="google.cloud.webrisk.v1beta1.RawIndices.indices", - index=0, - number=1, - type=5, - cpp_type=1, - label=3, - has_default_value=False, - default_value=[], - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - ], - extensions=[], - nested_types=[], - enum_types=[], - serialized_options=None, - is_extendable=False, - syntax="proto3", - extension_ranges=[], - oneofs=[], - serialized_start=2182, - serialized_end=2211, -) - - -_RAWHASHES = _descriptor.Descriptor( - name="RawHashes", - full_name="google.cloud.webrisk.v1beta1.RawHashes", - filename=None, - file=DESCRIPTOR, - containing_type=None, - create_key=_descriptor._internal_create_key, - fields=[ - _descriptor.FieldDescriptor( - name="prefix_size", - full_name="google.cloud.webrisk.v1beta1.RawHashes.prefix_size", - index=0, - number=1, - type=5, - cpp_type=1, - label=1, - has_default_value=False, - default_value=0, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - _descriptor.FieldDescriptor( - name="raw_hashes", - full_name="google.cloud.webrisk.v1beta1.RawHashes.raw_hashes", - index=1, - number=2, - type=12, - cpp_type=9, - label=1, - has_default_value=False, - default_value=b"", - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - ], - extensions=[], - nested_types=[], - enum_types=[], - serialized_options=None, - is_extendable=False, - syntax="proto3", - extension_ranges=[], - oneofs=[], - serialized_start=2213, - serialized_end=2265, -) - - -_RICEDELTAENCODING = _descriptor.Descriptor( - name="RiceDeltaEncoding", - full_name="google.cloud.webrisk.v1beta1.RiceDeltaEncoding", - filename=None, - file=DESCRIPTOR, - containing_type=None, - create_key=_descriptor._internal_create_key, - fields=[ - _descriptor.FieldDescriptor( - name="first_value", - full_name="google.cloud.webrisk.v1beta1.RiceDeltaEncoding.first_value", - index=0, - number=1, - type=3, - cpp_type=2, - label=1, - has_default_value=False, - default_value=0, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - _descriptor.FieldDescriptor( - name="rice_parameter", - full_name="google.cloud.webrisk.v1beta1.RiceDeltaEncoding.rice_parameter", - index=1, - number=2, - type=5, - cpp_type=1, - label=1, - has_default_value=False, - default_value=0, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - _descriptor.FieldDescriptor( - name="entry_count", - full_name="google.cloud.webrisk.v1beta1.RiceDeltaEncoding.entry_count", - index=2, - number=3, - type=5, - cpp_type=1, - label=1, - has_default_value=False, - default_value=0, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - _descriptor.FieldDescriptor( - name="encoded_data", - full_name="google.cloud.webrisk.v1beta1.RiceDeltaEncoding.encoded_data", - index=3, - number=4, - type=12, - cpp_type=9, - label=1, - has_default_value=False, - default_value=b"", - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, - ), - ], - extensions=[], - nested_types=[], - enum_types=[], - serialized_options=None, - is_extendable=False, - syntax="proto3", - extension_ranges=[], - oneofs=[], - serialized_start=2267, - serialized_end=2374, -) - -_COMPUTETHREATLISTDIFFREQUEST_CONSTRAINTS.fields_by_name[ - "supported_compressions" -].enum_type = _COMPRESSIONTYPE -_COMPUTETHREATLISTDIFFREQUEST_CONSTRAINTS.containing_type = ( - _COMPUTETHREATLISTDIFFREQUEST -) -_COMPUTETHREATLISTDIFFREQUEST.fields_by_name["threat_type"].enum_type = _THREATTYPE -_COMPUTETHREATLISTDIFFREQUEST.fields_by_name[ - "constraints" -].message_type = _COMPUTETHREATLISTDIFFREQUEST_CONSTRAINTS -_COMPUTETHREATLISTDIFFRESPONSE_CHECKSUM.containing_type = _COMPUTETHREATLISTDIFFRESPONSE -_COMPUTETHREATLISTDIFFRESPONSE.fields_by_name[ - "response_type" -].enum_type = _COMPUTETHREATLISTDIFFRESPONSE_RESPONSETYPE -_COMPUTETHREATLISTDIFFRESPONSE.fields_by_name[ - "additions" -].message_type = _THREATENTRYADDITIONS -_COMPUTETHREATLISTDIFFRESPONSE.fields_by_name[ - "removals" -].message_type = _THREATENTRYREMOVALS -_COMPUTETHREATLISTDIFFRESPONSE.fields_by_name[ - "checksum" -].message_type = _COMPUTETHREATLISTDIFFRESPONSE_CHECKSUM -_COMPUTETHREATLISTDIFFRESPONSE.fields_by_name[ - "recommended_next_diff" -].message_type = google_dot_protobuf_dot_timestamp__pb2._TIMESTAMP -_COMPUTETHREATLISTDIFFRESPONSE_RESPONSETYPE.containing_type = ( - _COMPUTETHREATLISTDIFFRESPONSE -) -_SEARCHURISREQUEST.fields_by_name["threat_types"].enum_type = _THREATTYPE -_SEARCHURISRESPONSE_THREATURI.fields_by_name["threat_types"].enum_type = _THREATTYPE -_SEARCHURISRESPONSE_THREATURI.fields_by_name[ - "expire_time" -].message_type = google_dot_protobuf_dot_timestamp__pb2._TIMESTAMP -_SEARCHURISRESPONSE_THREATURI.containing_type = _SEARCHURISRESPONSE -_SEARCHURISRESPONSE.fields_by_name[ - "threat" -].message_type = _SEARCHURISRESPONSE_THREATURI -_SEARCHHASHESREQUEST.fields_by_name["threat_types"].enum_type = _THREATTYPE -_SEARCHHASHESRESPONSE_THREATHASH.fields_by_name["threat_types"].enum_type = _THREATTYPE -_SEARCHHASHESRESPONSE_THREATHASH.fields_by_name[ - "expire_time" -].message_type = google_dot_protobuf_dot_timestamp__pb2._TIMESTAMP -_SEARCHHASHESRESPONSE_THREATHASH.containing_type = _SEARCHHASHESRESPONSE -_SEARCHHASHESRESPONSE.fields_by_name[ - "threats" -].message_type = _SEARCHHASHESRESPONSE_THREATHASH -_SEARCHHASHESRESPONSE.fields_by_name[ - "negative_expire_time" -].message_type = google_dot_protobuf_dot_timestamp__pb2._TIMESTAMP -_THREATENTRYADDITIONS.fields_by_name["raw_hashes"].message_type = _RAWHASHES -_THREATENTRYADDITIONS.fields_by_name["rice_hashes"].message_type = _RICEDELTAENCODING -_THREATENTRYREMOVALS.fields_by_name["raw_indices"].message_type = _RAWINDICES -_THREATENTRYREMOVALS.fields_by_name["rice_indices"].message_type = _RICEDELTAENCODING -DESCRIPTOR.message_types_by_name[ - "ComputeThreatListDiffRequest" -] = _COMPUTETHREATLISTDIFFREQUEST -DESCRIPTOR.message_types_by_name[ - "ComputeThreatListDiffResponse" -] = _COMPUTETHREATLISTDIFFRESPONSE -DESCRIPTOR.message_types_by_name["SearchUrisRequest"] = _SEARCHURISREQUEST -DESCRIPTOR.message_types_by_name["SearchUrisResponse"] = _SEARCHURISRESPONSE -DESCRIPTOR.message_types_by_name["SearchHashesRequest"] = _SEARCHHASHESREQUEST -DESCRIPTOR.message_types_by_name["SearchHashesResponse"] = _SEARCHHASHESRESPONSE -DESCRIPTOR.message_types_by_name["ThreatEntryAdditions"] = _THREATENTRYADDITIONS -DESCRIPTOR.message_types_by_name["ThreatEntryRemovals"] = _THREATENTRYREMOVALS -DESCRIPTOR.message_types_by_name["RawIndices"] = _RAWINDICES -DESCRIPTOR.message_types_by_name["RawHashes"] = _RAWHASHES -DESCRIPTOR.message_types_by_name["RiceDeltaEncoding"] = _RICEDELTAENCODING -DESCRIPTOR.enum_types_by_name["ThreatType"] = _THREATTYPE -DESCRIPTOR.enum_types_by_name["CompressionType"] = _COMPRESSIONTYPE -_sym_db.RegisterFileDescriptor(DESCRIPTOR) - -ComputeThreatListDiffRequest = _reflection.GeneratedProtocolMessageType( - "ComputeThreatListDiffRequest", - (_message.Message,), - { - "Constraints": _reflection.GeneratedProtocolMessageType( - "Constraints", - (_message.Message,), - { - "DESCRIPTOR": _COMPUTETHREATLISTDIFFREQUEST_CONSTRAINTS, - "__module__": "google.cloud.webrisk_v1beta1.proto.webrisk_pb2", - "__doc__": """The constraints for this diff. - - Attributes: - max_diff_entries: - The maximum size in number of entries. The diff will not - contain more entries than this value. This should be a power - of 2 between 2\ **10 and 2**\ 20. If zero, no diff size limit - is set. - max_database_entries: - Sets the maximum number of entries that the client is willing - to have in the local database. This should be a power of 2 - between 2\ **10 and 2**\ 20. If zero, no database size limit - is set. - supported_compressions: - The compression types supported by the client. - """, - # @@protoc_insertion_point(class_scope:google.cloud.webrisk.v1beta1.ComputeThreatListDiffRequest.Constraints) - }, - ), - "DESCRIPTOR": _COMPUTETHREATLISTDIFFREQUEST, - "__module__": "google.cloud.webrisk_v1beta1.proto.webrisk_pb2", - "__doc__": """Describes an API diff request. - - Attributes: - threat_type: - The ThreatList to update. - version_token: - The current version token of the client for the requested list - (the client version that was received from the last successful - diff). - constraints: - Required. The constraints associated with this request. - """, - # @@protoc_insertion_point(class_scope:google.cloud.webrisk.v1beta1.ComputeThreatListDiffRequest) - }, -) -_sym_db.RegisterMessage(ComputeThreatListDiffRequest) -_sym_db.RegisterMessage(ComputeThreatListDiffRequest.Constraints) - -ComputeThreatListDiffResponse = _reflection.GeneratedProtocolMessageType( - "ComputeThreatListDiffResponse", - (_message.Message,), - { - "Checksum": _reflection.GeneratedProtocolMessageType( - "Checksum", - (_message.Message,), - { - "DESCRIPTOR": _COMPUTETHREATLISTDIFFRESPONSE_CHECKSUM, - "__module__": "google.cloud.webrisk_v1beta1.proto.webrisk_pb2", - "__doc__": """The expected state of a client’s local database. - - Attributes: - sha256: - The SHA256 hash of the client state; that is, of the sorted - list of all hashes present in the database. - """, - # @@protoc_insertion_point(class_scope:google.cloud.webrisk.v1beta1.ComputeThreatListDiffResponse.Checksum) - }, - ), - "DESCRIPTOR": _COMPUTETHREATLISTDIFFRESPONSE, - "__module__": "google.cloud.webrisk_v1beta1.proto.webrisk_pb2", - "__doc__": """ - Attributes: - response_type: - The type of response. This may indicate that an action must be - taken by the client when the response is received. - additions: - A set of entries to add to a local threat type’s list. - removals: - A set of entries to remove from a local threat type’s list. - This field may be empty. - new_version_token: - The new opaque client version token. - checksum: - The expected SHA256 hash of the client state; that is, of the - sorted list of all hashes present in the database after - applying the provided diff. If the client state doesn’t match - the expected state, the client must disregard this diff and - retry later. - recommended_next_diff: - The soonest the client should wait before issuing any diff - request. Querying sooner is unlikely to produce a meaningful - diff. Waiting longer is acceptable considering the use case. - If this field is not set clients may update as soon as they - want. - """, - # @@protoc_insertion_point(class_scope:google.cloud.webrisk.v1beta1.ComputeThreatListDiffResponse) - }, -) -_sym_db.RegisterMessage(ComputeThreatListDiffResponse) -_sym_db.RegisterMessage(ComputeThreatListDiffResponse.Checksum) - -SearchUrisRequest = _reflection.GeneratedProtocolMessageType( - "SearchUrisRequest", - (_message.Message,), - { - "DESCRIPTOR": _SEARCHURISREQUEST, - "__module__": "google.cloud.webrisk_v1beta1.proto.webrisk_pb2", - "__doc__": """Request to check URI entries against threatLists. - - Attributes: - uri: - Required. The URI to be checked for matches. - threat_types: - Required. The ThreatLists to search in. - """, - # @@protoc_insertion_point(class_scope:google.cloud.webrisk.v1beta1.SearchUrisRequest) - }, -) -_sym_db.RegisterMessage(SearchUrisRequest) - -SearchUrisResponse = _reflection.GeneratedProtocolMessageType( - "SearchUrisResponse", - (_message.Message,), - { - "ThreatUri": _reflection.GeneratedProtocolMessageType( - "ThreatUri", - (_message.Message,), - { - "DESCRIPTOR": _SEARCHURISRESPONSE_THREATURI, - "__module__": "google.cloud.webrisk_v1beta1.proto.webrisk_pb2", - "__doc__": """Contains threat information on a matching uri. - - Attributes: - threat_types: - The ThreatList this threat belongs to. - expire_time: - The cache lifetime for the returned match. Clients must not - cache this response past this timestamp to avoid false - positives. - """, - # @@protoc_insertion_point(class_scope:google.cloud.webrisk.v1beta1.SearchUrisResponse.ThreatUri) - }, - ), - "DESCRIPTOR": _SEARCHURISRESPONSE, - "__module__": "google.cloud.webrisk_v1beta1.proto.webrisk_pb2", - "__doc__": """ - Attributes: - threat: - The threat list matches. This may be empty if the URI is on no - list. - """, - # @@protoc_insertion_point(class_scope:google.cloud.webrisk.v1beta1.SearchUrisResponse) - }, -) -_sym_db.RegisterMessage(SearchUrisResponse) -_sym_db.RegisterMessage(SearchUrisResponse.ThreatUri) - -SearchHashesRequest = _reflection.GeneratedProtocolMessageType( - "SearchHashesRequest", - (_message.Message,), - { - "DESCRIPTOR": _SEARCHHASHESREQUEST, - "__module__": "google.cloud.webrisk_v1beta1.proto.webrisk_pb2", - "__doc__": """Request to return full hashes matched by the provided hash prefixes. - - Attributes: - hash_prefix: - A hash prefix, consisting of the most significant 4-32 bytes - of a SHA256 hash. For JSON requests, this field is - base64-encoded. - threat_types: - Required. The ThreatLists to search in. - """, - # @@protoc_insertion_point(class_scope:google.cloud.webrisk.v1beta1.SearchHashesRequest) - }, -) -_sym_db.RegisterMessage(SearchHashesRequest) - -SearchHashesResponse = _reflection.GeneratedProtocolMessageType( - "SearchHashesResponse", - (_message.Message,), - { - "ThreatHash": _reflection.GeneratedProtocolMessageType( - "ThreatHash", - (_message.Message,), - { - "DESCRIPTOR": _SEARCHHASHESRESPONSE_THREATHASH, - "__module__": "google.cloud.webrisk_v1beta1.proto.webrisk_pb2", - "__doc__": """Contains threat information on a matching hash. - - Attributes: - threat_types: - The ThreatList this threat belongs to. This must contain at - least one entry. - hash: - A 32 byte SHA256 hash. This field is in binary format. For - JSON requests, hashes are base64-encoded. - expire_time: - The cache lifetime for the returned match. Clients must not - cache this response past this timestamp to avoid false - positives. - """, - # @@protoc_insertion_point(class_scope:google.cloud.webrisk.v1beta1.SearchHashesResponse.ThreatHash) - }, - ), - "DESCRIPTOR": _SEARCHHASHESRESPONSE, - "__module__": "google.cloud.webrisk_v1beta1.proto.webrisk_pb2", - "__doc__": """ - Attributes: - threats: - The full hashes that matched the requested prefixes. The hash - will be populated in the key. - negative_expire_time: - For requested entities that did not match the threat list, how - long to cache the response until. - """, - # @@protoc_insertion_point(class_scope:google.cloud.webrisk.v1beta1.SearchHashesResponse) - }, -) -_sym_db.RegisterMessage(SearchHashesResponse) -_sym_db.RegisterMessage(SearchHashesResponse.ThreatHash) - -ThreatEntryAdditions = _reflection.GeneratedProtocolMessageType( - "ThreatEntryAdditions", - (_message.Message,), - { - "DESCRIPTOR": _THREATENTRYADDITIONS, - "__module__": "google.cloud.webrisk_v1beta1.proto.webrisk_pb2", - "__doc__": """Contains the set of entries to add to a local database. May contain a - combination of compressed and raw data in a single response. - - Attributes: - raw_hashes: - The raw SHA256-formatted entries. Repeated to allow returning - sets of hashes with different prefix sizes. - rice_hashes: - The encoded 4-byte prefixes of SHA256-formatted entries, using - a Golomb-Rice encoding. The hashes are converted to uint32, - sorted in ascending order, then delta encoded and stored as - encoded_data. - """, - # @@protoc_insertion_point(class_scope:google.cloud.webrisk.v1beta1.ThreatEntryAdditions) - }, -) -_sym_db.RegisterMessage(ThreatEntryAdditions) - -ThreatEntryRemovals = _reflection.GeneratedProtocolMessageType( - "ThreatEntryRemovals", - (_message.Message,), - { - "DESCRIPTOR": _THREATENTRYREMOVALS, - "__module__": "google.cloud.webrisk_v1beta1.proto.webrisk_pb2", - "__doc__": """Contains the set of entries to remove from a local database. - - Attributes: - raw_indices: - The raw removal indices for a local list. - rice_indices: - The encoded local, lexicographically-sorted list indices, - using a Golomb-Rice encoding. Used for sending compressed - removal indices. The removal indices (uint32) are sorted in - ascending order, then delta encoded and stored as - encoded_data. - """, - # @@protoc_insertion_point(class_scope:google.cloud.webrisk.v1beta1.ThreatEntryRemovals) - }, -) -_sym_db.RegisterMessage(ThreatEntryRemovals) - -RawIndices = _reflection.GeneratedProtocolMessageType( - "RawIndices", - (_message.Message,), - { - "DESCRIPTOR": _RAWINDICES, - "__module__": "google.cloud.webrisk_v1beta1.proto.webrisk_pb2", - "__doc__": """A set of raw indices to remove from a local list. - - Attributes: - indices: - The indices to remove from a lexicographically-sorted local - list. - """, - # @@protoc_insertion_point(class_scope:google.cloud.webrisk.v1beta1.RawIndices) - }, -) -_sym_db.RegisterMessage(RawIndices) - -RawHashes = _reflection.GeneratedProtocolMessageType( - "RawHashes", - (_message.Message,), - { - "DESCRIPTOR": _RAWHASHES, - "__module__": "google.cloud.webrisk_v1beta1.proto.webrisk_pb2", - "__doc__": """The uncompressed threat entries in hash format. Hashes can be anywhere - from 4 to 32 bytes in size. A large majority are 4 bytes, but some - hashes are lengthened if they collide with the hash of a popular URI. - Used for sending ThreatEntryAdditons to clients that do not support - compression, or when sending non-4-byte hashes to clients that do - support compression. - - Attributes: - prefix_size: - The number of bytes for each prefix encoded below. This field - can be anywhere from 4 (shortest prefix) to 32 (full SHA256 - hash). - raw_hashes: - The hashes, in binary format, concatenated into one long - string. Hashes are sorted in lexicographic order. For JSON API - users, hashes are base64-encoded. - """, - # @@protoc_insertion_point(class_scope:google.cloud.webrisk.v1beta1.RawHashes) - }, -) -_sym_db.RegisterMessage(RawHashes) - -RiceDeltaEncoding = _reflection.GeneratedProtocolMessageType( - "RiceDeltaEncoding", - (_message.Message,), - { - "DESCRIPTOR": _RICEDELTAENCODING, - "__module__": "google.cloud.webrisk_v1beta1.proto.webrisk_pb2", - "__doc__": """The Rice-Golomb encoded data. Used for sending compressed 4-byte - hashes or compressed removal indices. - - Attributes: - first_value: - The offset of the first entry in the encoded data, or, if only - a single integer was encoded, that single integer’s value. If - the field is empty or missing, assume zero. - rice_parameter: - The Golomb-Rice parameter, which is a number between 2 and 28. - This field is missing (that is, zero) if ``num_entries`` is - zero. - entry_count: - The number of entries that are delta encoded in the encoded - data. If only a single integer was encoded, this will be zero - and the single value will be stored in ``first_value``. - encoded_data: - The encoded deltas that are encoded using the Golomb-Rice - coder. - """, - # @@protoc_insertion_point(class_scope:google.cloud.webrisk.v1beta1.RiceDeltaEncoding) - }, -) -_sym_db.RegisterMessage(RiceDeltaEncoding) - - -DESCRIPTOR._options = None -_COMPUTETHREATLISTDIFFREQUEST.fields_by_name["threat_type"]._options = None -_COMPUTETHREATLISTDIFFREQUEST.fields_by_name["constraints"]._options = None -_SEARCHURISREQUEST.fields_by_name["uri"]._options = None -_SEARCHURISREQUEST.fields_by_name["threat_types"]._options = None -_SEARCHHASHESREQUEST.fields_by_name["threat_types"]._options = None - -_WEBRISKSERVICEV1BETA1 = _descriptor.ServiceDescriptor( - name="WebRiskServiceV1Beta1", - full_name="google.cloud.webrisk.v1beta1.WebRiskServiceV1Beta1", - file=DESCRIPTOR, - index=0, - serialized_options=b"\312A\026webrisk.googleapis.com\322A.https://www.googleapis.com/auth/cloud-platform", - create_key=_descriptor._internal_create_key, - serialized_start=2552, - serialized_end=3222, - methods=[ - _descriptor.MethodDescriptor( - name="ComputeThreatListDiff", - full_name="google.cloud.webrisk.v1beta1.WebRiskServiceV1Beta1.ComputeThreatListDiff", - index=0, - containing_service=None, - input_type=_COMPUTETHREATLISTDIFFREQUEST, - output_type=_COMPUTETHREATLISTDIFFRESPONSE, - serialized_options=b'\202\323\344\223\002"\022 /v1beta1/threatLists:computeDiff\332A%threat_type,version_token,constraints', - create_key=_descriptor._internal_create_key, - ), - _descriptor.MethodDescriptor( - name="SearchUris", - full_name="google.cloud.webrisk.v1beta1.WebRiskServiceV1Beta1.SearchUris", - index=1, - containing_service=None, - input_type=_SEARCHURISREQUEST, - output_type=_SEARCHURISRESPONSE, - serialized_options=b"\202\323\344\223\002\026\022\024/v1beta1/uris:search\332A\020uri,threat_types", - create_key=_descriptor._internal_create_key, - ), - _descriptor.MethodDescriptor( - name="SearchHashes", - full_name="google.cloud.webrisk.v1beta1.WebRiskServiceV1Beta1.SearchHashes", - index=2, - containing_service=None, - input_type=_SEARCHHASHESREQUEST, - output_type=_SEARCHHASHESRESPONSE, - serialized_options=b"\202\323\344\223\002\030\022\026/v1beta1/hashes:search\332A\030hash_prefix,threat_types", - create_key=_descriptor._internal_create_key, - ), - ], -) -_sym_db.RegisterServiceDescriptor(_WEBRISKSERVICEV1BETA1) - -DESCRIPTOR.services_by_name["WebRiskServiceV1Beta1"] = _WEBRISKSERVICEV1BETA1 - -# @@protoc_insertion_point(module_scope) diff --git a/google/cloud/webrisk_v1beta1/proto/webrisk_pb2_grpc.py b/google/cloud/webrisk_v1beta1/proto/webrisk_pb2_grpc.py deleted file mode 100644 index 6458d2f..0000000 --- a/google/cloud/webrisk_v1beta1/proto/webrisk_pb2_grpc.py +++ /dev/null @@ -1,178 +0,0 @@ -# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! -"""Client and server classes corresponding to protobuf-defined services.""" -import grpc - -from google.cloud.webrisk_v1beta1.proto import ( - webrisk_pb2 as google_dot_cloud_dot_webrisk__v1beta1_dot_proto_dot_webrisk__pb2, -) - - -class WebRiskServiceV1Beta1Stub(object): - """Web Risk v1beta1 API defines an interface to detect malicious URLs on your - website and in client applications. - """ - - def __init__(self, channel): - """Constructor. - - Args: - channel: A grpc.Channel. - """ - self.ComputeThreatListDiff = channel.unary_unary( - "/google.cloud.webrisk.v1beta1.WebRiskServiceV1Beta1/ComputeThreatListDiff", - request_serializer=google_dot_cloud_dot_webrisk__v1beta1_dot_proto_dot_webrisk__pb2.ComputeThreatListDiffRequest.SerializeToString, - response_deserializer=google_dot_cloud_dot_webrisk__v1beta1_dot_proto_dot_webrisk__pb2.ComputeThreatListDiffResponse.FromString, - ) - self.SearchUris = channel.unary_unary( - "/google.cloud.webrisk.v1beta1.WebRiskServiceV1Beta1/SearchUris", - request_serializer=google_dot_cloud_dot_webrisk__v1beta1_dot_proto_dot_webrisk__pb2.SearchUrisRequest.SerializeToString, - response_deserializer=google_dot_cloud_dot_webrisk__v1beta1_dot_proto_dot_webrisk__pb2.SearchUrisResponse.FromString, - ) - self.SearchHashes = channel.unary_unary( - "/google.cloud.webrisk.v1beta1.WebRiskServiceV1Beta1/SearchHashes", - request_serializer=google_dot_cloud_dot_webrisk__v1beta1_dot_proto_dot_webrisk__pb2.SearchHashesRequest.SerializeToString, - response_deserializer=google_dot_cloud_dot_webrisk__v1beta1_dot_proto_dot_webrisk__pb2.SearchHashesResponse.FromString, - ) - - -class WebRiskServiceV1Beta1Servicer(object): - """Web Risk v1beta1 API defines an interface to detect malicious URLs on your - website and in client applications. - """ - - def ComputeThreatListDiff(self, request, context): - """Gets the most recent threat list diffs. - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details("Method not implemented!") - raise NotImplementedError("Method not implemented!") - - def SearchUris(self, request, context): - """This method is used to check whether a URI is on a given threatList. - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details("Method not implemented!") - raise NotImplementedError("Method not implemented!") - - def SearchHashes(self, request, context): - """Gets the full hashes that match the requested hash prefix. - This is used after a hash prefix is looked up in a threatList - and there is a match. The client side threatList only holds partial hashes - so the client must query this method to determine if there is a full - hash match of a threat. - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details("Method not implemented!") - raise NotImplementedError("Method not implemented!") - - -def add_WebRiskServiceV1Beta1Servicer_to_server(servicer, server): - rpc_method_handlers = { - "ComputeThreatListDiff": grpc.unary_unary_rpc_method_handler( - servicer.ComputeThreatListDiff, - request_deserializer=google_dot_cloud_dot_webrisk__v1beta1_dot_proto_dot_webrisk__pb2.ComputeThreatListDiffRequest.FromString, - response_serializer=google_dot_cloud_dot_webrisk__v1beta1_dot_proto_dot_webrisk__pb2.ComputeThreatListDiffResponse.SerializeToString, - ), - "SearchUris": grpc.unary_unary_rpc_method_handler( - servicer.SearchUris, - request_deserializer=google_dot_cloud_dot_webrisk__v1beta1_dot_proto_dot_webrisk__pb2.SearchUrisRequest.FromString, - response_serializer=google_dot_cloud_dot_webrisk__v1beta1_dot_proto_dot_webrisk__pb2.SearchUrisResponse.SerializeToString, - ), - "SearchHashes": grpc.unary_unary_rpc_method_handler( - servicer.SearchHashes, - request_deserializer=google_dot_cloud_dot_webrisk__v1beta1_dot_proto_dot_webrisk__pb2.SearchHashesRequest.FromString, - response_serializer=google_dot_cloud_dot_webrisk__v1beta1_dot_proto_dot_webrisk__pb2.SearchHashesResponse.SerializeToString, - ), - } - generic_handler = grpc.method_handlers_generic_handler( - "google.cloud.webrisk.v1beta1.WebRiskServiceV1Beta1", rpc_method_handlers - ) - server.add_generic_rpc_handlers((generic_handler,)) - - -# This class is part of an EXPERIMENTAL API. -class WebRiskServiceV1Beta1(object): - """Web Risk v1beta1 API defines an interface to detect malicious URLs on your - website and in client applications. - """ - - @staticmethod - def ComputeThreatListDiff( - request, - target, - options=(), - channel_credentials=None, - call_credentials=None, - compression=None, - wait_for_ready=None, - timeout=None, - metadata=None, - ): - return grpc.experimental.unary_unary( - request, - target, - "/google.cloud.webrisk.v1beta1.WebRiskServiceV1Beta1/ComputeThreatListDiff", - google_dot_cloud_dot_webrisk__v1beta1_dot_proto_dot_webrisk__pb2.ComputeThreatListDiffRequest.SerializeToString, - google_dot_cloud_dot_webrisk__v1beta1_dot_proto_dot_webrisk__pb2.ComputeThreatListDiffResponse.FromString, - options, - channel_credentials, - call_credentials, - compression, - wait_for_ready, - timeout, - metadata, - ) - - @staticmethod - def SearchUris( - request, - target, - options=(), - channel_credentials=None, - call_credentials=None, - compression=None, - wait_for_ready=None, - timeout=None, - metadata=None, - ): - return grpc.experimental.unary_unary( - request, - target, - "/google.cloud.webrisk.v1beta1.WebRiskServiceV1Beta1/SearchUris", - google_dot_cloud_dot_webrisk__v1beta1_dot_proto_dot_webrisk__pb2.SearchUrisRequest.SerializeToString, - google_dot_cloud_dot_webrisk__v1beta1_dot_proto_dot_webrisk__pb2.SearchUrisResponse.FromString, - options, - channel_credentials, - call_credentials, - compression, - wait_for_ready, - timeout, - metadata, - ) - - @staticmethod - def SearchHashes( - request, - target, - options=(), - channel_credentials=None, - call_credentials=None, - compression=None, - wait_for_ready=None, - timeout=None, - metadata=None, - ): - return grpc.experimental.unary_unary( - request, - target, - "/google.cloud.webrisk.v1beta1.WebRiskServiceV1Beta1/SearchHashes", - google_dot_cloud_dot_webrisk__v1beta1_dot_proto_dot_webrisk__pb2.SearchHashesRequest.SerializeToString, - google_dot_cloud_dot_webrisk__v1beta1_dot_proto_dot_webrisk__pb2.SearchHashesResponse.FromString, - options, - channel_credentials, - call_credentials, - compression, - wait_for_ready, - timeout, - metadata, - ) diff --git a/google/cloud/webrisk_v1beta1/py.typed b/google/cloud/webrisk_v1beta1/py.typed new file mode 100644 index 0000000..bef3da1 --- /dev/null +++ b/google/cloud/webrisk_v1beta1/py.typed @@ -0,0 +1,2 @@ +# Marker file for PEP 561. +# The google-cloud-webrisk package uses inline types. diff --git a/google/cloud/webrisk_v1beta1/services/__init__.py b/google/cloud/webrisk_v1beta1/services/__init__.py new file mode 100644 index 0000000..42ffdf2 --- /dev/null +++ b/google/cloud/webrisk_v1beta1/services/__init__.py @@ -0,0 +1,16 @@ +# -*- 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/google/cloud/webrisk.py b/google/cloud/webrisk_v1beta1/services/web_risk_service_v1_beta1/__init__.py similarity index 66% rename from google/cloud/webrisk.py rename to google/cloud/webrisk_v1beta1/services/web_risk_service_v1_beta1/__init__.py index c457e09..2c81da5 100644 --- a/google/cloud/webrisk.py +++ b/google/cloud/webrisk_v1beta1/services/web_risk_service_v1_beta1/__init__.py @@ -1,29 +1,24 @@ # -*- 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 # -# https://www.apache.org/licenses/LICENSE-2.0 +# 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. +# - -from __future__ import absolute_import - -from google.cloud.webrisk_v1 import WebRiskServiceClient -from google.cloud.webrisk_v1 import enums -from google.cloud.webrisk_v1 import types - +from .client import WebRiskServiceV1Beta1Client +from .async_client import WebRiskServiceV1Beta1AsyncClient __all__ = ( - "enums", - "types", - "WebRiskServiceClient", + "WebRiskServiceV1Beta1Client", + "WebRiskServiceV1Beta1AsyncClient", ) diff --git a/google/cloud/webrisk_v1beta1/services/web_risk_service_v1_beta1/async_client.py b/google/cloud/webrisk_v1beta1/services/web_risk_service_v1_beta1/async_client.py new file mode 100644 index 0000000..b56c370 --- /dev/null +++ b/google/cloud/webrisk_v1beta1/services/web_risk_service_v1_beta1/async_client.py @@ -0,0 +1,340 @@ +# -*- 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. +# + +from collections import OrderedDict +import functools +import re +from typing import Dict, Sequence, Tuple, Type, Union +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 gapic_v1 # type: ignore +from google.api_core import retry as retries # type: ignore +from google.auth import credentials # type: ignore +from google.oauth2 import service_account # type: ignore + +from google.cloud.webrisk_v1beta1.types import webrisk +from google.protobuf import timestamp_pb2 as timestamp # type: ignore + +from .transports.base import WebRiskServiceV1Beta1Transport +from .transports.grpc_asyncio import WebRiskServiceV1Beta1GrpcAsyncIOTransport +from .client import WebRiskServiceV1Beta1Client + + +class WebRiskServiceV1Beta1AsyncClient: + """Web Risk v1beta1 API defines an interface to detect malicious + URLs on your website and in client applications. + """ + + _client: WebRiskServiceV1Beta1Client + + DEFAULT_ENDPOINT = WebRiskServiceV1Beta1Client.DEFAULT_ENDPOINT + DEFAULT_MTLS_ENDPOINT = WebRiskServiceV1Beta1Client.DEFAULT_MTLS_ENDPOINT + + from_service_account_file = WebRiskServiceV1Beta1Client.from_service_account_file + from_service_account_json = from_service_account_file + + get_transport_class = functools.partial( + type(WebRiskServiceV1Beta1Client).get_transport_class, + type(WebRiskServiceV1Beta1Client), + ) + + def __init__( + self, + *, + credentials: credentials.Credentials = None, + transport: Union[str, WebRiskServiceV1Beta1Transport] = "grpc_asyncio", + client_options: ClientOptions = None, + ) -> None: + """Instantiate the web risk service v1 beta1 client. + + Args: + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + transport (Union[str, ~.WebRiskServiceV1Beta1Transport]): The + transport to use. If set to None, a transport is chosen + automatically. + client_options (ClientOptions): Custom options for the client. It + won't take effect if a ``transport`` instance is provided. + (1) The ``api_endpoint`` property can be used to override the + default endpoint provided by the client. GOOGLE_API_USE_MTLS + environment variable can also be used to override the endpoint: + "always" (always use the default mTLS endpoint), "never" (always + use the default regular endpoint, this is the default value for + the environment variable) and "auto" (auto switch to the default + mTLS endpoint if client SSL credentials is present). However, + the ``api_endpoint`` property takes precedence if provided. + (2) The ``client_cert_source`` property is used to provide client + SSL credentials for mutual TLS transport. If not provided, the + default SSL credentials will be used if present. + + Raises: + google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport + creation failed for any reason. + """ + + self._client = WebRiskServiceV1Beta1Client( + credentials=credentials, transport=transport, client_options=client_options, + ) + + async def compute_threat_list_diff( + self, + request: webrisk.ComputeThreatListDiffRequest = None, + *, + threat_type: webrisk.ThreatType = None, + version_token: bytes = None, + constraints: webrisk.ComputeThreatListDiffRequest.Constraints = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> webrisk.ComputeThreatListDiffResponse: + r"""Gets the most recent threat list diffs. + + Args: + request (:class:`~.webrisk.ComputeThreatListDiffRequest`): + The request object. Describes an API diff request. + threat_type (:class:`~.webrisk.ThreatType`): + The ThreatList to update. + This corresponds to the ``threat_type`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + version_token (:class:`bytes`): + The current version token of the + client for the requested list (the + client version that was received from + the last successful diff). + This corresponds to the ``version_token`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + constraints (:class:`~.webrisk.ComputeThreatListDiffRequest.Constraints`): + Required. The constraints associated + with this request. + This corresponds to the ``constraints`` 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. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.webrisk.ComputeThreatListDiffResponse: + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + if request is not None and any([threat_type, version_token, constraints]): + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = webrisk.ComputeThreatListDiffRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if threat_type is not None: + request.threat_type = threat_type + if version_token is not None: + request.version_token = version_token + if constraints is not None: + request.constraints = constraints + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.compute_threat_list_diff, + default_timeout=None, + client_info=_client_info, + ) + + # Send the request. + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + async def search_uris( + self, + request: webrisk.SearchUrisRequest = None, + *, + uri: str = None, + threat_types: Sequence[webrisk.ThreatType] = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> webrisk.SearchUrisResponse: + r"""This method is used to check whether a URI is on a + given threatList. + + Args: + request (:class:`~.webrisk.SearchUrisRequest`): + The request object. Request to check URI entries against + threatLists. + uri (:class:`str`): + Required. The URI to be checked for + matches. + This corresponds to the ``uri`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + threat_types (:class:`Sequence[~.webrisk.ThreatType]`): + Required. The ThreatLists to search + in. + This corresponds to the ``threat_types`` 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. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.webrisk.SearchUrisResponse: + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + if request is not None and any([uri, threat_types]): + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = webrisk.SearchUrisRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if uri is not None: + request.uri = uri + if threat_types is not None: + request.threat_types = threat_types + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.search_uris, + default_timeout=None, + client_info=_client_info, + ) + + # Send the request. + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + async def search_hashes( + self, + request: webrisk.SearchHashesRequest = None, + *, + hash_prefix: bytes = None, + threat_types: Sequence[webrisk.ThreatType] = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> webrisk.SearchHashesResponse: + r"""Gets the full hashes that match the requested hash + prefix. This is used after a hash prefix is looked up in + a threatList and there is a match. The client side + threatList only holds partial hashes so the client must + query this method to determine if there is a full hash + match of a threat. + + Args: + request (:class:`~.webrisk.SearchHashesRequest`): + The request object. Request to return full hashes + matched by the provided hash prefixes. + hash_prefix (:class:`bytes`): + A hash prefix, consisting of the most + significant 4-32 bytes of a SHA256 hash. + For JSON requests, this field is + base64-encoded. + This corresponds to the ``hash_prefix`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + threat_types (:class:`Sequence[~.webrisk.ThreatType]`): + Required. The ThreatLists to search + in. + This corresponds to the ``threat_types`` 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. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.webrisk.SearchHashesResponse: + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + if request is not None and any([hash_prefix, threat_types]): + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = webrisk.SearchHashesRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if hash_prefix is not None: + request.hash_prefix = hash_prefix + if threat_types is not None: + request.threat_types = threat_types + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.search_hashes, + default_timeout=None, + client_info=_client_info, + ) + + # Send the request. + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + +try: + _client_info = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution("google-cloud-webrisk",).version, + ) +except pkg_resources.DistributionNotFound: + _client_info = gapic_v1.client_info.ClientInfo() + + +__all__ = ("WebRiskServiceV1Beta1AsyncClient",) diff --git a/google/cloud/webrisk_v1beta1/services/web_risk_service_v1_beta1/client.py b/google/cloud/webrisk_v1beta1/services/web_risk_service_v1_beta1/client.py new file mode 100644 index 0000000..527db93 --- /dev/null +++ b/google/cloud/webrisk_v1beta1/services/web_risk_service_v1_beta1/client.py @@ -0,0 +1,464 @@ +# -*- 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. +# + +from collections import OrderedDict +import os +import re +from typing import Callable, Dict, Sequence, Tuple, Type, Union +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 gapic_v1 # type: ignore +from google.api_core import retry as retries # type: ignore +from google.auth import credentials # type: ignore +from google.auth.transport import mtls # type: ignore +from google.auth.exceptions import MutualTLSChannelError # type: ignore +from google.oauth2 import service_account # type: ignore + +from google.cloud.webrisk_v1beta1.types import webrisk +from google.protobuf import timestamp_pb2 as timestamp # type: ignore + +from .transports.base import WebRiskServiceV1Beta1Transport +from .transports.grpc import WebRiskServiceV1Beta1GrpcTransport +from .transports.grpc_asyncio import WebRiskServiceV1Beta1GrpcAsyncIOTransport + + +class WebRiskServiceV1Beta1ClientMeta(type): + """Metaclass for the WebRiskServiceV1Beta1 client. + + This provides class-level methods for building and retrieving + support objects (e.g. transport) without polluting the client instance + objects. + """ + + _transport_registry = ( + OrderedDict() + ) # type: Dict[str, Type[WebRiskServiceV1Beta1Transport]] + _transport_registry["grpc"] = WebRiskServiceV1Beta1GrpcTransport + _transport_registry["grpc_asyncio"] = WebRiskServiceV1Beta1GrpcAsyncIOTransport + + def get_transport_class( + cls, label: str = None, + ) -> Type[WebRiskServiceV1Beta1Transport]: + """Return an appropriate transport class. + + Args: + label: The name of the desired transport. If none is + provided, then the first transport in the registry is used. + + Returns: + The transport class to use. + """ + # If a specific transport is requested, return that one. + if label: + return cls._transport_registry[label] + + # No transport is requested; return the default (that is, the first one + # in the dictionary). + return next(iter(cls._transport_registry.values())) + + +class WebRiskServiceV1Beta1Client(metaclass=WebRiskServiceV1Beta1ClientMeta): + """Web Risk v1beta1 API defines an interface to detect malicious + URLs on your website and in client applications. + """ + + @staticmethod + def _get_default_mtls_endpoint(api_endpoint): + """Convert api endpoint to mTLS endpoint. + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + str: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + + m = mtls_endpoint_re.match(api_endpoint) + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + DEFAULT_ENDPOINT = "webrisk.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + @classmethod + def from_service_account_file(cls, filename: str, *args, **kwargs): + """Creates an instance of this client using the provided credentials + file. + + Args: + filename (str): The path to the service account private key json + file. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + {@api.name}: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_file(filename) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + + from_service_account_json = from_service_account_file + + def __init__( + self, + *, + credentials: credentials.Credentials = None, + transport: Union[str, WebRiskServiceV1Beta1Transport] = None, + client_options: ClientOptions = None, + ) -> None: + """Instantiate the web risk service v1 beta1 client. + + Args: + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + transport (Union[str, ~.WebRiskServiceV1Beta1Transport]): The + transport to use. If set to None, a transport is chosen + automatically. + client_options (ClientOptions): Custom options for the client. It + won't take effect if a ``transport`` instance is provided. + (1) The ``api_endpoint`` property can be used to override the + default endpoint provided by the client. GOOGLE_API_USE_MTLS + environment variable can also be used to override the endpoint: + "always" (always use the default mTLS endpoint), "never" (always + use the default regular endpoint, this is the default value for + the environment variable) and "auto" (auto switch to the default + mTLS endpoint if client SSL credentials is present). However, + the ``api_endpoint`` property takes precedence if provided. + (2) The ``client_cert_source`` property is used to provide client + SSL credentials for mutual TLS transport. If not provided, the + default SSL credentials will be used if present. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport + creation failed for any reason. + """ + if isinstance(client_options, dict): + client_options = ClientOptions.from_dict(client_options) + if client_options is None: + client_options = ClientOptions.ClientOptions() + + if client_options.api_endpoint is None: + use_mtls_env = os.getenv("GOOGLE_API_USE_MTLS", "never") + if use_mtls_env == "never": + client_options.api_endpoint = self.DEFAULT_ENDPOINT + elif use_mtls_env == "always": + client_options.api_endpoint = self.DEFAULT_MTLS_ENDPOINT + elif use_mtls_env == "auto": + has_client_cert_source = ( + client_options.client_cert_source is not None + or mtls.has_default_client_cert_source() + ) + client_options.api_endpoint = ( + self.DEFAULT_MTLS_ENDPOINT + if has_client_cert_source + else self.DEFAULT_ENDPOINT + ) + else: + raise MutualTLSChannelError( + "Unsupported GOOGLE_API_USE_MTLS value. Accepted values: never, auto, always" + ) + + # Save or instantiate the transport. + # Ordinarily, we provide the transport, but allowing a custom transport + # instance provides an extensibility point for unusual situations. + if isinstance(transport, WebRiskServiceV1Beta1Transport): + # transport is a WebRiskServiceV1Beta1Transport instance. + if credentials or client_options.credentials_file: + raise ValueError( + "When providing a transport instance, " + "provide its credentials directly." + ) + if client_options.scopes: + raise ValueError( + "When providing a transport instance, " + "provide its scopes directly." + ) + self._transport = transport + else: + Transport = type(self).get_transport_class(transport) + self._transport = Transport( + credentials=credentials, + credentials_file=client_options.credentials_file, + host=client_options.api_endpoint, + scopes=client_options.scopes, + api_mtls_endpoint=client_options.api_endpoint, + client_cert_source=client_options.client_cert_source, + ) + + def compute_threat_list_diff( + self, + request: webrisk.ComputeThreatListDiffRequest = None, + *, + threat_type: webrisk.ThreatType = None, + version_token: bytes = None, + constraints: webrisk.ComputeThreatListDiffRequest.Constraints = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> webrisk.ComputeThreatListDiffResponse: + r"""Gets the most recent threat list diffs. + + Args: + request (:class:`~.webrisk.ComputeThreatListDiffRequest`): + The request object. Describes an API diff request. + threat_type (:class:`~.webrisk.ThreatType`): + The ThreatList to update. + This corresponds to the ``threat_type`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + version_token (:class:`bytes`): + The current version token of the + client for the requested list (the + client version that was received from + the last successful diff). + This corresponds to the ``version_token`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + constraints (:class:`~.webrisk.ComputeThreatListDiffRequest.Constraints`): + Required. The constraints associated + with this request. + This corresponds to the ``constraints`` 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. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.webrisk.ComputeThreatListDiffResponse: + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + if request is not None and any([threat_type, version_token, constraints]): + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = webrisk.ComputeThreatListDiffRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if threat_type is not None: + request.threat_type = threat_type + if version_token is not None: + request.version_token = version_token + if constraints is not None: + request.constraints = constraints + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.compute_threat_list_diff, + default_timeout=None, + client_info=_client_info, + ) + + # Send the request. + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + def search_uris( + self, + request: webrisk.SearchUrisRequest = None, + *, + uri: str = None, + threat_types: Sequence[webrisk.ThreatType] = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> webrisk.SearchUrisResponse: + r"""This method is used to check whether a URI is on a + given threatList. + + Args: + request (:class:`~.webrisk.SearchUrisRequest`): + The request object. Request to check URI entries against + threatLists. + uri (:class:`str`): + Required. The URI to be checked for + matches. + This corresponds to the ``uri`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + threat_types (:class:`Sequence[~.webrisk.ThreatType]`): + Required. The ThreatLists to search + in. + This corresponds to the ``threat_types`` 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. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.webrisk.SearchUrisResponse: + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + if request is not None and any([uri, threat_types]): + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = webrisk.SearchUrisRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if uri is not None: + request.uri = uri + if threat_types is not None: + request.threat_types = threat_types + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.search_uris, default_timeout=None, client_info=_client_info, + ) + + # Send the request. + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + def search_hashes( + self, + request: webrisk.SearchHashesRequest = None, + *, + hash_prefix: bytes = None, + threat_types: Sequence[webrisk.ThreatType] = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> webrisk.SearchHashesResponse: + r"""Gets the full hashes that match the requested hash + prefix. This is used after a hash prefix is looked up in + a threatList and there is a match. The client side + threatList only holds partial hashes so the client must + query this method to determine if there is a full hash + match of a threat. + + Args: + request (:class:`~.webrisk.SearchHashesRequest`): + The request object. Request to return full hashes + matched by the provided hash prefixes. + hash_prefix (:class:`bytes`): + A hash prefix, consisting of the most + significant 4-32 bytes of a SHA256 hash. + For JSON requests, this field is + base64-encoded. + This corresponds to the ``hash_prefix`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + threat_types (:class:`Sequence[~.webrisk.ThreatType]`): + Required. The ThreatLists to search + in. + This corresponds to the ``threat_types`` 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. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.webrisk.SearchHashesResponse: + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + if request is not None and any([hash_prefix, threat_types]): + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = webrisk.SearchHashesRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if hash_prefix is not None: + request.hash_prefix = hash_prefix + if threat_types is not None: + request.threat_types = threat_types + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.search_hashes, + default_timeout=None, + client_info=_client_info, + ) + + # Send the request. + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + +try: + _client_info = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution("google-cloud-webrisk",).version, + ) +except pkg_resources.DistributionNotFound: + _client_info = gapic_v1.client_info.ClientInfo() + + +__all__ = ("WebRiskServiceV1Beta1Client",) diff --git a/google/cloud/webrisk_v1beta1/services/web_risk_service_v1_beta1/transports/__init__.py b/google/cloud/webrisk_v1beta1/services/web_risk_service_v1_beta1/transports/__init__.py new file mode 100644 index 0000000..ff1b518 --- /dev/null +++ b/google/cloud/webrisk_v1beta1/services/web_risk_service_v1_beta1/transports/__init__.py @@ -0,0 +1,38 @@ +# -*- 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. +# + +from collections import OrderedDict +from typing import Dict, Type + +from .base import WebRiskServiceV1Beta1Transport +from .grpc import WebRiskServiceV1Beta1GrpcTransport +from .grpc_asyncio import WebRiskServiceV1Beta1GrpcAsyncIOTransport + + +# Compile a registry of transports. +_transport_registry = ( + OrderedDict() +) # type: Dict[str, Type[WebRiskServiceV1Beta1Transport]] +_transport_registry["grpc"] = WebRiskServiceV1Beta1GrpcTransport +_transport_registry["grpc_asyncio"] = WebRiskServiceV1Beta1GrpcAsyncIOTransport + + +__all__ = ( + "WebRiskServiceV1Beta1Transport", + "WebRiskServiceV1Beta1GrpcTransport", + "WebRiskServiceV1Beta1GrpcAsyncIOTransport", +) diff --git a/google/cloud/webrisk_v1beta1/services/web_risk_service_v1_beta1/transports/base.py b/google/cloud/webrisk_v1beta1/services/web_risk_service_v1_beta1/transports/base.py new file mode 100644 index 0000000..5bb1c49 --- /dev/null +++ b/google/cloud/webrisk_v1beta1/services/web_risk_service_v1_beta1/transports/base.py @@ -0,0 +1,113 @@ +# -*- 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. +# + +import abc +import typing + +from google import auth +from google.api_core import exceptions # type: ignore +from google.auth import credentials # type: ignore + +from google.cloud.webrisk_v1beta1.types import webrisk + + +class WebRiskServiceV1Beta1Transport(abc.ABC): + """Abstract transport class for WebRiskServiceV1Beta1.""" + + AUTH_SCOPES = ("https://www.googleapis.com/auth/cloud-platform",) + + def __init__( + self, + *, + host: str = "webrisk.googleapis.com", + credentials: credentials.Credentials = None, + credentials_file: typing.Optional[str] = None, + scopes: typing.Optional[typing.Sequence[str]] = AUTH_SCOPES, + **kwargs, + ) -> None: + """Instantiate the transport. + + Args: + 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 + are specified, the client will attempt to ascertain the + credentials from the environment. + 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. + """ + # Save the hostname. Default to port 443 (HTTPS) if none is specified. + if ":" not in host: + host += ":443" + self._host = host + + # If no credentials are provided, then determine the appropriate + # defaults. + if credentials and credentials_file: + raise exceptions.DuplicateCredentialArgs( + "'credentials_file' and 'credentials' are mutually exclusive" + ) + + if credentials_file is not None: + credentials, _ = auth.load_credentials_from_file( + credentials_file, scopes=scopes + ) + elif credentials is None: + credentials, _ = auth.default(scopes=scopes) + + # Save the credentials. + self._credentials = credentials + + @property + def compute_threat_list_diff( + self, + ) -> typing.Callable[ + [webrisk.ComputeThreatListDiffRequest], + typing.Union[ + webrisk.ComputeThreatListDiffResponse, + typing.Awaitable[webrisk.ComputeThreatListDiffResponse], + ], + ]: + raise NotImplementedError() + + @property + def search_uris( + self, + ) -> typing.Callable[ + [webrisk.SearchUrisRequest], + typing.Union[ + webrisk.SearchUrisResponse, typing.Awaitable[webrisk.SearchUrisResponse] + ], + ]: + raise NotImplementedError() + + @property + def search_hashes( + self, + ) -> typing.Callable[ + [webrisk.SearchHashesRequest], + typing.Union[ + webrisk.SearchHashesResponse, typing.Awaitable[webrisk.SearchHashesResponse] + ], + ]: + raise NotImplementedError() + + +__all__ = ("WebRiskServiceV1Beta1Transport",) diff --git a/google/cloud/webrisk_v1beta1/services/web_risk_service_v1_beta1/transports/grpc.py b/google/cloud/webrisk_v1beta1/services/web_risk_service_v1_beta1/transports/grpc.py new file mode 100644 index 0000000..a585953 --- /dev/null +++ b/google/cloud/webrisk_v1beta1/services/web_risk_service_v1_beta1/transports/grpc.py @@ -0,0 +1,283 @@ +# -*- 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. +# + +from typing import Callable, Dict, Optional, Sequence, Tuple + +from google.api_core import grpc_helpers # type: ignore +from google import auth # type: ignore +from google.auth import credentials # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore + + +import grpc # type: ignore + +from google.cloud.webrisk_v1beta1.types import webrisk + +from .base import WebRiskServiceV1Beta1Transport + + +class WebRiskServiceV1Beta1GrpcTransport(WebRiskServiceV1Beta1Transport): + """gRPC backend transport for WebRiskServiceV1Beta1. + + Web Risk v1beta1 API defines an interface to detect malicious + URLs on your website and in client applications. + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends protocol buffers over the wire using gRPC (which is built on + top of HTTP/2); the ``grpcio`` package must be installed. + """ + + _stubs: Dict[str, Callable] + + def __init__( + self, + *, + host: str = "webrisk.googleapis.com", + credentials: credentials.Credentials = None, + credentials_file: str = None, + scopes: Sequence[str] = None, + channel: grpc.Channel = None, + api_mtls_endpoint: str = None, + client_cert_source: Callable[[], Tuple[bytes, bytes]] = None + ) -> None: + """Instantiate the transport. + + Args: + 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 + are specified, the client will attempt to ascertain the + credentials from the environment. + This argument is ignored if ``channel`` is provided. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional(Sequence[str])): A list of scopes. This argument is + ignored if ``channel`` is provided. + channel (Optional[grpc.Channel]): A ``Channel`` instance through + which to make calls. + api_mtls_endpoint (Optional[str]): The mutual TLS endpoint. If + provided, it overrides the ``host`` argument and tries to create + a mutual TLS channel with client SSL credentials from + ``client_cert_source`` or applicatin default SSL credentials. + client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): A + callback to provide client SSL certificate bytes and private key + bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` + is None. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport + creation failed for any reason. + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + if channel: + # Sanity check: Ensure that channel and credentials are not both + # provided. + credentials = False + + # If a channel was explicitly provided, set it. + self._grpc_channel = channel + elif api_mtls_endpoint: + host = ( + api_mtls_endpoint + if ":" in api_mtls_endpoint + else api_mtls_endpoint + ":443" + ) + + if credentials is None: + credentials, _ = auth.default(scopes=self.AUTH_SCOPES) + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + ssl_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + ssl_credentials = SslCredentials().ssl_credentials + + # create a new channel. The provided one is ignored. + self._grpc_channel = type(self).create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + ssl_credentials=ssl_credentials, + scopes=scopes or self.AUTH_SCOPES, + ) + + # Run the base constructor. + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes or self.AUTH_SCOPES, + ) + + self._stubs = {} # type: Dict[str, Callable] + + @classmethod + def create_channel( + cls, + host: str = "webrisk.googleapis.com", + credentials: credentials.Credentials = None, + credentials_file: str = None, + scopes: Optional[Sequence[str]] = None, + **kwargs + ) -> grpc.Channel: + """Create and return a gRPC channel object. + Args: + address (Optionsl[str]): The host for the channel to use. + credentials (Optional[~.Credentials]): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If + none are specified, the client will attempt to ascertain + the credentials from the environment. + 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. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + kwargs (Optional[dict]): Keyword arguments, which are passed to the + channel creation. + Returns: + grpc.Channel: A gRPC channel object. + + Raises: + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + scopes = scopes or cls.AUTH_SCOPES + return grpc_helpers.create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + **kwargs + ) + + @property + def grpc_channel(self) -> grpc.Channel: + """Create the channel designed to connect to this service. + + This property caches on the instance; repeated calls return + the same channel. + """ + # Sanity check: Only create a new channel if we do not already + # have one. + if not hasattr(self, "_grpc_channel"): + self._grpc_channel = self.create_channel( + self._host, credentials=self._credentials, + ) + + # Return the channel from cache. + return self._grpc_channel + + @property + def compute_threat_list_diff( + self, + ) -> Callable[ + [webrisk.ComputeThreatListDiffRequest], webrisk.ComputeThreatListDiffResponse + ]: + r"""Return a callable for the compute threat list diff method over gRPC. + + Gets the most recent threat list diffs. + + Returns: + Callable[[~.ComputeThreatListDiffRequest], + ~.ComputeThreatListDiffResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "compute_threat_list_diff" not in self._stubs: + self._stubs["compute_threat_list_diff"] = self.grpc_channel.unary_unary( + "/google.cloud.webrisk.v1beta1.WebRiskServiceV1Beta1/ComputeThreatListDiff", + request_serializer=webrisk.ComputeThreatListDiffRequest.serialize, + response_deserializer=webrisk.ComputeThreatListDiffResponse.deserialize, + ) + return self._stubs["compute_threat_list_diff"] + + @property + def search_uris( + self, + ) -> Callable[[webrisk.SearchUrisRequest], webrisk.SearchUrisResponse]: + r"""Return a callable for the search uris method over gRPC. + + This method is used to check whether a URI is on a + given threatList. + + Returns: + Callable[[~.SearchUrisRequest], + ~.SearchUrisResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "search_uris" not in self._stubs: + self._stubs["search_uris"] = self.grpc_channel.unary_unary( + "/google.cloud.webrisk.v1beta1.WebRiskServiceV1Beta1/SearchUris", + request_serializer=webrisk.SearchUrisRequest.serialize, + response_deserializer=webrisk.SearchUrisResponse.deserialize, + ) + return self._stubs["search_uris"] + + @property + def search_hashes( + self, + ) -> Callable[[webrisk.SearchHashesRequest], webrisk.SearchHashesResponse]: + r"""Return a callable for the search hashes method over gRPC. + + Gets the full hashes that match the requested hash + prefix. This is used after a hash prefix is looked up in + a threatList and there is a match. The client side + threatList only holds partial hashes so the client must + query this method to determine if there is a full hash + match of a threat. + + Returns: + Callable[[~.SearchHashesRequest], + ~.SearchHashesResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "search_hashes" not in self._stubs: + self._stubs["search_hashes"] = self.grpc_channel.unary_unary( + "/google.cloud.webrisk.v1beta1.WebRiskServiceV1Beta1/SearchHashes", + request_serializer=webrisk.SearchHashesRequest.serialize, + response_deserializer=webrisk.SearchHashesResponse.deserialize, + ) + return self._stubs["search_hashes"] + + +__all__ = ("WebRiskServiceV1Beta1GrpcTransport",) diff --git a/google/cloud/webrisk_v1beta1/services/web_risk_service_v1_beta1/transports/grpc_asyncio.py b/google/cloud/webrisk_v1beta1/services/web_risk_service_v1_beta1/transports/grpc_asyncio.py new file mode 100644 index 0000000..b8c81d6 --- /dev/null +++ b/google/cloud/webrisk_v1beta1/services/web_risk_service_v1_beta1/transports/grpc_asyncio.py @@ -0,0 +1,281 @@ +# -*- 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. +# + +from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple + +from google.api_core import grpc_helpers_async # type: ignore +from google.auth import credentials # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore + +import grpc # type: ignore +from grpc.experimental import aio # type: ignore + +from google.cloud.webrisk_v1beta1.types import webrisk + +from .base import WebRiskServiceV1Beta1Transport +from .grpc import WebRiskServiceV1Beta1GrpcTransport + + +class WebRiskServiceV1Beta1GrpcAsyncIOTransport(WebRiskServiceV1Beta1Transport): + """gRPC AsyncIO backend transport for WebRiskServiceV1Beta1. + + Web Risk v1beta1 API defines an interface to detect malicious + URLs on your website and in client applications. + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends protocol buffers over the wire using gRPC (which is built on + top of HTTP/2); the ``grpcio`` package must be installed. + """ + + _grpc_channel: aio.Channel + _stubs: Dict[str, Callable] = {} + + @classmethod + def create_channel( + cls, + host: str = "webrisk.googleapis.com", + credentials: credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + **kwargs + ) -> aio.Channel: + """Create and return a gRPC AsyncIO channel object. + Args: + address (Optional[str]): The host for the channel to use. + credentials (Optional[~.Credentials]): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If + none are specified, the client will attempt to ascertain + the credentials from the environment. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + kwargs (Optional[dict]): Keyword arguments, which are passed to the + channel creation. + Returns: + aio.Channel: A gRPC AsyncIO channel object. + """ + scopes = scopes or cls.AUTH_SCOPES + return grpc_helpers_async.create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + **kwargs + ) + + def __init__( + self, + *, + host: str = "webrisk.googleapis.com", + credentials: credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + channel: aio.Channel = None, + api_mtls_endpoint: str = None, + client_cert_source: Callable[[], Tuple[bytes, bytes]] = None + ) -> None: + """Instantiate the transport. + + Args: + 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 + are specified, the client will attempt to ascertain the + credentials from the environment. + This argument is ignored if ``channel`` is provided. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + channel (Optional[aio.Channel]): A ``Channel`` instance through + which to make calls. + api_mtls_endpoint (Optional[str]): The mutual TLS endpoint. If + provided, it overrides the ``host`` argument and tries to create + a mutual TLS channel with client SSL credentials from + ``client_cert_source`` or applicatin default SSL credentials. + client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): A + callback to provide client SSL certificate bytes and private key + bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` + is None. + + Raises: + google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport + creation failed for any reason. + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + if channel: + # Sanity check: Ensure that channel and credentials are not both + # provided. + credentials = False + + # If a channel was explicitly provided, set it. + self._grpc_channel = channel + elif api_mtls_endpoint: + host = ( + api_mtls_endpoint + if ":" in api_mtls_endpoint + else api_mtls_endpoint + ":443" + ) + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + ssl_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + ssl_credentials = SslCredentials().ssl_credentials + + # create a new channel. The provided one is ignored. + self._grpc_channel = type(self).create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + ssl_credentials=ssl_credentials, + scopes=scopes or self.AUTH_SCOPES, + ) + + # Run the base constructor. + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes or self.AUTH_SCOPES, + ) + + self._stubs = {} + + @property + def grpc_channel(self) -> aio.Channel: + """Create the channel designed to connect to this service. + + This property caches on the instance; repeated calls return + the same channel. + """ + # Sanity check: Only create a new channel if we do not already + # have one. + if not hasattr(self, "_grpc_channel"): + self._grpc_channel = self.create_channel( + self._host, credentials=self._credentials, + ) + + # Return the channel from cache. + return self._grpc_channel + + @property + def compute_threat_list_diff( + self, + ) -> Callable[ + [webrisk.ComputeThreatListDiffRequest], + Awaitable[webrisk.ComputeThreatListDiffResponse], + ]: + r"""Return a callable for the compute threat list diff method over gRPC. + + Gets the most recent threat list diffs. + + Returns: + Callable[[~.ComputeThreatListDiffRequest], + Awaitable[~.ComputeThreatListDiffResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "compute_threat_list_diff" not in self._stubs: + self._stubs["compute_threat_list_diff"] = self.grpc_channel.unary_unary( + "/google.cloud.webrisk.v1beta1.WebRiskServiceV1Beta1/ComputeThreatListDiff", + request_serializer=webrisk.ComputeThreatListDiffRequest.serialize, + response_deserializer=webrisk.ComputeThreatListDiffResponse.deserialize, + ) + return self._stubs["compute_threat_list_diff"] + + @property + def search_uris( + self, + ) -> Callable[[webrisk.SearchUrisRequest], Awaitable[webrisk.SearchUrisResponse]]: + r"""Return a callable for the search uris method over gRPC. + + This method is used to check whether a URI is on a + given threatList. + + Returns: + Callable[[~.SearchUrisRequest], + Awaitable[~.SearchUrisResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "search_uris" not in self._stubs: + self._stubs["search_uris"] = self.grpc_channel.unary_unary( + "/google.cloud.webrisk.v1beta1.WebRiskServiceV1Beta1/SearchUris", + request_serializer=webrisk.SearchUrisRequest.serialize, + response_deserializer=webrisk.SearchUrisResponse.deserialize, + ) + return self._stubs["search_uris"] + + @property + def search_hashes( + self, + ) -> Callable[ + [webrisk.SearchHashesRequest], Awaitable[webrisk.SearchHashesResponse] + ]: + r"""Return a callable for the search hashes method over gRPC. + + Gets the full hashes that match the requested hash + prefix. This is used after a hash prefix is looked up in + a threatList and there is a match. The client side + threatList only holds partial hashes so the client must + query this method to determine if there is a full hash + match of a threat. + + Returns: + Callable[[~.SearchHashesRequest], + Awaitable[~.SearchHashesResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "search_hashes" not in self._stubs: + self._stubs["search_hashes"] = self.grpc_channel.unary_unary( + "/google.cloud.webrisk.v1beta1.WebRiskServiceV1Beta1/SearchHashes", + request_serializer=webrisk.SearchHashesRequest.serialize, + response_deserializer=webrisk.SearchHashesResponse.deserialize, + ) + return self._stubs["search_hashes"] + + +__all__ = ("WebRiskServiceV1Beta1GrpcAsyncIOTransport",) diff --git a/google/cloud/webrisk_v1beta1/types.py b/google/cloud/webrisk_v1beta1/types.py deleted file mode 100644 index 410776a..0000000 --- a/google/cloud/webrisk_v1beta1/types.py +++ /dev/null @@ -1,48 +0,0 @@ -# -*- 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 -# -# https://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. - - -from __future__ import absolute_import -import sys - -from google.api_core.protobuf_helpers import get_messages - -from google.cloud.webrisk_v1beta1.proto import webrisk_pb2 -from google.protobuf import timestamp_pb2 - - -_shared_modules = [ - timestamp_pb2, -] - -_local_modules = [ - webrisk_pb2, -] - -names = [] - -for module in _shared_modules: # pragma: NO COVER - for name, message in get_messages(module).items(): - setattr(sys.modules[__name__], name, message) - names.append(name) -for module in _local_modules: - for name, message in get_messages(module).items(): - message.__module__ = "google.cloud.webrisk_v1beta1.types" - setattr(sys.modules[__name__], name, message) - names.append(name) - - -__all__ = tuple(sorted(names)) diff --git a/google/cloud/webrisk_v1beta1/types/__init__.py b/google/cloud/webrisk_v1beta1/types/__init__.py new file mode 100644 index 0000000..5a964ca --- /dev/null +++ b/google/cloud/webrisk_v1beta1/types/__init__.py @@ -0,0 +1,45 @@ +# -*- 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. +# + +from .webrisk import ( + ComputeThreatListDiffRequest, + ComputeThreatListDiffResponse, + SearchUrisRequest, + SearchUrisResponse, + SearchHashesRequest, + SearchHashesResponse, + ThreatEntryAdditions, + ThreatEntryRemovals, + RawIndices, + RawHashes, + RiceDeltaEncoding, +) + + +__all__ = ( + "ComputeThreatListDiffRequest", + "ComputeThreatListDiffResponse", + "SearchUrisRequest", + "SearchUrisResponse", + "SearchHashesRequest", + "SearchHashesResponse", + "ThreatEntryAdditions", + "ThreatEntryRemovals", + "RawIndices", + "RawHashes", + "RiceDeltaEncoding", +) diff --git a/google/cloud/webrisk_v1beta1/types/webrisk.py b/google/cloud/webrisk_v1beta1/types/webrisk.py new file mode 100644 index 0000000..1f660fd --- /dev/null +++ b/google/cloud/webrisk_v1beta1/types/webrisk.py @@ -0,0 +1,391 @@ +# -*- 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. +# + +import proto # type: ignore + + +from google.protobuf import timestamp_pb2 as timestamp # type: ignore + + +__protobuf__ = proto.module( + package="google.cloud.webrisk.v1beta1", + manifest={ + "ThreatType", + "CompressionType", + "ComputeThreatListDiffRequest", + "ComputeThreatListDiffResponse", + "SearchUrisRequest", + "SearchUrisResponse", + "SearchHashesRequest", + "SearchHashesResponse", + "ThreatEntryAdditions", + "ThreatEntryRemovals", + "RawIndices", + "RawHashes", + "RiceDeltaEncoding", + }, +) + + +class ThreatType(proto.Enum): + r"""The type of threat. This maps dirrectly to the threat list a + threat may belong to. + """ + THREAT_TYPE_UNSPECIFIED = 0 + MALWARE = 1 + SOCIAL_ENGINEERING = 2 + UNWANTED_SOFTWARE = 3 + + +class CompressionType(proto.Enum): + r"""The ways in which threat entry sets can be compressed.""" + COMPRESSION_TYPE_UNSPECIFIED = 0 + RAW = 1 + RICE = 2 + + +class ComputeThreatListDiffRequest(proto.Message): + r"""Describes an API diff request. + + Attributes: + threat_type (~.webrisk.ThreatType): + The ThreatList to update. + version_token (bytes): + The current version token of the client for + the requested list (the client version that was + received from the last successful diff). + constraints (~.webrisk.ComputeThreatListDiffRequest.Constraints): + Required. The constraints associated with + this request. + """ + + class Constraints(proto.Message): + r"""The constraints for this diff. + + Attributes: + max_diff_entries (int): + The maximum size in number of entries. The diff will not + contain more entries than this value. This should be a power + of 2 between 2\ **10 and 2**\ 20. If zero, no diff size + limit is set. + max_database_entries (int): + Sets the maximum number of entries that the client is + willing to have in the local database. This should be a + power of 2 between 2\ **10 and 2**\ 20. If zero, no database + size limit is set. + supported_compressions (Sequence[~.webrisk.CompressionType]): + The compression types supported by the + client. + """ + + max_diff_entries = proto.Field(proto.INT32, number=1) + + max_database_entries = proto.Field(proto.INT32, number=2) + + supported_compressions = proto.RepeatedField( + proto.ENUM, number=3, enum="CompressionType", + ) + + threat_type = proto.Field(proto.ENUM, number=1, enum="ThreatType",) + + version_token = proto.Field(proto.BYTES, number=2) + + constraints = proto.Field(proto.MESSAGE, number=3, message=Constraints,) + + +class ComputeThreatListDiffResponse(proto.Message): + r""" + + Attributes: + response_type (~.webrisk.ComputeThreatListDiffResponse.ResponseType): + The type of response. This may indicate that + an action must be taken by the client when the + response is received. + additions (~.webrisk.ThreatEntryAdditions): + A set of entries to add to a local threat + type's list. + removals (~.webrisk.ThreatEntryRemovals): + A set of entries to remove from a local + threat type's list. This field may be empty. + new_version_token (bytes): + The new opaque client version token. + checksum (~.webrisk.ComputeThreatListDiffResponse.Checksum): + The expected SHA256 hash of the client state; + that is, of the sorted list of all hashes + present in the database after applying the + provided diff. If the client state doesn't match + the expected state, the client must disregard + this diff and retry later. + recommended_next_diff (~.timestamp.Timestamp): + The soonest the client should wait before + issuing any diff request. Querying sooner is + unlikely to produce a meaningful diff. Waiting + longer is acceptable considering the use case. + If this field is not set clients may update as + soon as they want. + """ + + class ResponseType(proto.Enum): + r"""The type of response sent to the client.""" + RESPONSE_TYPE_UNSPECIFIED = 0 + DIFF = 1 + RESET = 2 + + class Checksum(proto.Message): + r"""The expected state of a client's local database. + + Attributes: + sha256 (bytes): + The SHA256 hash of the client state; that is, + of the sorted list of all hashes present in the + database. + """ + + sha256 = proto.Field(proto.BYTES, number=1) + + response_type = proto.Field(proto.ENUM, number=4, enum=ResponseType,) + + additions = proto.Field(proto.MESSAGE, number=5, message="ThreatEntryAdditions",) + + removals = proto.Field(proto.MESSAGE, number=6, message="ThreatEntryRemovals",) + + new_version_token = proto.Field(proto.BYTES, number=7) + + checksum = proto.Field(proto.MESSAGE, number=8, message=Checksum,) + + recommended_next_diff = proto.Field( + proto.MESSAGE, number=2, message=timestamp.Timestamp, + ) + + +class SearchUrisRequest(proto.Message): + r"""Request to check URI entries against threatLists. + + Attributes: + uri (str): + Required. The URI to be checked for matches. + threat_types (Sequence[~.webrisk.ThreatType]): + Required. The ThreatLists to search in. + """ + + uri = proto.Field(proto.STRING, number=1) + + threat_types = proto.RepeatedField(proto.ENUM, number=2, enum="ThreatType",) + + +class SearchUrisResponse(proto.Message): + r""" + + Attributes: + threat (~.webrisk.SearchUrisResponse.ThreatUri): + The threat list matches. This may be empty if + the URI is on no list. + """ + + class ThreatUri(proto.Message): + r"""Contains threat information on a matching uri. + + Attributes: + threat_types (Sequence[~.webrisk.ThreatType]): + The ThreatList this threat belongs to. + expire_time (~.timestamp.Timestamp): + The cache lifetime for the returned match. + Clients must not cache this response past this + timestamp to avoid false positives. + """ + + threat_types = proto.RepeatedField(proto.ENUM, number=1, enum="ThreatType",) + + expire_time = proto.Field(proto.MESSAGE, number=2, message=timestamp.Timestamp,) + + threat = proto.Field(proto.MESSAGE, number=1, message=ThreatUri,) + + +class SearchHashesRequest(proto.Message): + r"""Request to return full hashes matched by the provided hash + prefixes. + + Attributes: + hash_prefix (bytes): + A hash prefix, consisting of the most + significant 4-32 bytes of a SHA256 hash. For + JSON requests, this field is base64-encoded. + threat_types (Sequence[~.webrisk.ThreatType]): + Required. The ThreatLists to search in. + """ + + hash_prefix = proto.Field(proto.BYTES, number=1) + + threat_types = proto.RepeatedField(proto.ENUM, number=2, enum="ThreatType",) + + +class SearchHashesResponse(proto.Message): + r""" + + Attributes: + threats (Sequence[~.webrisk.SearchHashesResponse.ThreatHash]): + The full hashes that matched the requested + prefixes. The hash will be populated in the key. + negative_expire_time (~.timestamp.Timestamp): + For requested entities that did not match the + threat list, how long to cache the response + until. + """ + + class ThreatHash(proto.Message): + r"""Contains threat information on a matching hash. + + Attributes: + threat_types (Sequence[~.webrisk.ThreatType]): + The ThreatList this threat belongs to. + This must contain at least one entry. + hash (bytes): + A 32 byte SHA256 hash. This field is in + binary format. For JSON requests, hashes are + base64-encoded. + expire_time (~.timestamp.Timestamp): + The cache lifetime for the returned match. + Clients must not cache this response past this + timestamp to avoid false positives. + """ + + threat_types = proto.RepeatedField(proto.ENUM, number=1, enum="ThreatType",) + + hash = proto.Field(proto.BYTES, number=2) + + expire_time = proto.Field(proto.MESSAGE, number=3, message=timestamp.Timestamp,) + + threats = proto.RepeatedField(proto.MESSAGE, number=1, message=ThreatHash,) + + negative_expire_time = proto.Field( + proto.MESSAGE, number=2, message=timestamp.Timestamp, + ) + + +class ThreatEntryAdditions(proto.Message): + r"""Contains the set of entries to add to a local database. + May contain a combination of compressed and raw data in a single + response. + + Attributes: + raw_hashes (Sequence[~.webrisk.RawHashes]): + The raw SHA256-formatted entries. + Repeated to allow returning sets of hashes with + different prefix sizes. + rice_hashes (~.webrisk.RiceDeltaEncoding): + The encoded 4-byte prefixes of SHA256-formatted entries, + using a Golomb-Rice encoding. The hashes are converted to + uint32, sorted in ascending order, then delta encoded and + stored as encoded_data. + """ + + raw_hashes = proto.RepeatedField(proto.MESSAGE, number=1, message="RawHashes",) + + rice_hashes = proto.Field(proto.MESSAGE, number=2, message="RiceDeltaEncoding",) + + +class ThreatEntryRemovals(proto.Message): + r"""Contains the set of entries to remove from a local database. + + Attributes: + raw_indices (~.webrisk.RawIndices): + The raw removal indices for a local list. + rice_indices (~.webrisk.RiceDeltaEncoding): + The encoded local, lexicographically-sorted list indices, + using a Golomb-Rice encoding. Used for sending compressed + removal indices. The removal indices (uint32) are sorted in + ascending order, then delta encoded and stored as + encoded_data. + """ + + raw_indices = proto.Field(proto.MESSAGE, number=1, message="RawIndices",) + + rice_indices = proto.Field(proto.MESSAGE, number=2, message="RiceDeltaEncoding",) + + +class RawIndices(proto.Message): + r"""A set of raw indices to remove from a local list. + + Attributes: + indices (Sequence[int]): + The indices to remove from a + lexicographically-sorted local list. + """ + + indices = proto.RepeatedField(proto.INT32, number=1) + + +class RawHashes(proto.Message): + r"""The uncompressed threat entries in hash format. + Hashes can be anywhere from 4 to 32 bytes in size. A large + majority are 4 bytes, but some hashes are lengthened if they + collide with the hash of a popular URI. + + Used for sending ThreatEntryAdditons to clients that do not + support compression, or when sending non-4-byte hashes to + clients that do support compression. + + Attributes: + prefix_size (int): + The number of bytes for each prefix encoded + below. This field can be anywhere from 4 + (shortest prefix) to 32 (full SHA256 hash). + raw_hashes (bytes): + The hashes, in binary format, concatenated + into one long string. Hashes are sorted in + lexicographic order. For JSON API users, hashes + are base64-encoded. + """ + + prefix_size = proto.Field(proto.INT32, number=1) + + raw_hashes = proto.Field(proto.BYTES, number=2) + + +class RiceDeltaEncoding(proto.Message): + r"""The Rice-Golomb encoded data. Used for sending compressed + 4-byte hashes or compressed removal indices. + + Attributes: + first_value (int): + The offset of the first entry in the encoded + data, or, if only a single integer was encoded, + that single integer's value. If the field is + empty or missing, assume zero. + rice_parameter (int): + The Golomb-Rice parameter, which is a number between 2 and + 28. This field is missing (that is, zero) if ``num_entries`` + is zero. + entry_count (int): + The number of entries that are delta encoded in the encoded + data. If only a single integer was encoded, this will be + zero and the single value will be stored in ``first_value``. + encoded_data (bytes): + The encoded deltas that are encoded using the + Golomb-Rice coder. + """ + + first_value = proto.Field(proto.INT64, number=1) + + rice_parameter = proto.Field(proto.INT32, number=2) + + entry_count = proto.Field(proto.INT32, number=3) + + encoded_data = proto.Field(proto.BYTES, number=4) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/mypy.ini b/mypy.ini new file mode 100644 index 0000000..4505b48 --- /dev/null +++ b/mypy.ini @@ -0,0 +1,3 @@ +[mypy] +python_version = 3.6 +namespace_packages = True diff --git a/noxfile.py b/noxfile.py index 0516d80..cabecdd 100644 --- a/noxfile.py +++ b/noxfile.py @@ -27,8 +27,8 @@ BLACK_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"] DEFAULT_PYTHON_VERSION = "3.8" -SYSTEM_TEST_PYTHON_VERSIONS = ["2.7", "3.8"] -UNIT_TEST_PYTHON_VERSIONS = ["2.7", "3.5", "3.6", "3.7", "3.8"] +SYSTEM_TEST_PYTHON_VERSIONS = ["3.8"] +UNIT_TEST_PYTHON_VERSIONS = ["3.6", "3.7", "3.8"] @nox.session(python=DEFAULT_PYTHON_VERSION) @@ -70,6 +70,8 @@ def lint_setup_py(session): def default(session): # Install all test dependencies, then install this package in-place. + session.install("asyncmock", "pytest-asyncio") + session.install("mock", "pytest", "pytest-cov") session.install("-e", ".") @@ -135,7 +137,7 @@ def cover(session): test runs (not system test runs), and then erases coverage data. """ session.install("coverage", "pytest-cov") - session.run("coverage", "report", "--show-missing", "--fail-under=75") + session.run("coverage", "report", "--show-missing", "--fail-under=99") session.run("coverage", "erase") diff --git a/samples/AUTHORING_GUIDE.md b/samples/AUTHORING_GUIDE.md new file mode 100644 index 0000000..55c97b3 --- /dev/null +++ b/samples/AUTHORING_GUIDE.md @@ -0,0 +1 @@ +See https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/AUTHORING_GUIDE.md \ No newline at end of file diff --git a/samples/CONTRIBUTING.md b/samples/CONTRIBUTING.md new file mode 100644 index 0000000..34c882b --- /dev/null +++ b/samples/CONTRIBUTING.md @@ -0,0 +1 @@ +See https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/CONTRIBUTING.md \ No newline at end of file diff --git a/scripts/fixup_webrisk_v1_keywords.py b/scripts/fixup_webrisk_v1_keywords.py new file mode 100644 index 0000000..3b554e2 --- /dev/null +++ b/scripts/fixup_webrisk_v1_keywords.py @@ -0,0 +1,180 @@ +# -*- 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. +# + +import argparse +import os +import libcst as cst +import pathlib +import sys +from typing import (Any, Callable, Dict, List, Sequence, Tuple) + + +def partition( + predicate: Callable[[Any], bool], + iterator: Sequence[Any] +) -> Tuple[List[Any], List[Any]]: + """A stable, out-of-place partition.""" + results = ([], []) + + for i in iterator: + results[int(predicate(i))].append(i) + + # Returns trueList, falseList + return results[1], results[0] + + +class webriskCallTransformer(cst.CSTTransformer): + CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') + METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { + 'compute_threat_list_diff': ('threat_type', 'constraints', 'version_token', ), + 'create_submission': ('parent', 'submission', ), + 'search_hashes': ('threat_types', 'hash_prefix', ), + 'search_uris': ('uri', 'threat_types', ), + } + + def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: + try: + key = original.func.attr.value + kword_params = self.METHOD_TO_PARAMS[key] + except (AttributeError, KeyError): + # Either not a method from the API or too convoluted to be sure. + return updated + + # If the existing code is valid, keyword args come after positional args. + # Therefore, all positional args must map to the first parameters. + args, kwargs = partition(lambda a: not bool(a.keyword), updated.args) + if any(k.keyword.value == "request" for k in kwargs): + # We've already fixed this file, don't fix it again. + return updated + + kwargs, ctrl_kwargs = partition( + lambda a: not a.keyword.value in self.CTRL_PARAMS, + kwargs + ) + + args, ctrl_args = args[:len(kword_params)], args[len(kword_params):] + ctrl_kwargs.extend(cst.Arg(value=a.value, keyword=cst.Name(value=ctrl)) + for a, ctrl in zip(ctrl_args, self.CTRL_PARAMS)) + + request_arg = cst.Arg( + value=cst.Dict([ + cst.DictElement( + cst.SimpleString("'{}'".format(name)), + 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 + # those could have been passed positionally or by keyword. + for name, arg in zip(kword_params, args + kwargs)]), + keyword=cst.Name("request") + ) + + return updated.with_changes( + args=[request_arg] + ctrl_kwargs + ) + + +def fix_files( + in_dir: pathlib.Path, + out_dir: pathlib.Path, + *, + transformer=webriskCallTransformer(), +): + """Duplicate the input dir to the output dir, fixing file method calls. + + Preconditions: + * in_dir is a real directory + * out_dir is a real, empty directory + """ + pyfile_gen = ( + pathlib.Path(os.path.join(root, f)) + for root, _, files in os.walk(in_dir) + for f in files if os.path.splitext(f)[1] == ".py" + ) + + for fpath in pyfile_gen: + with open(fpath, 'r') as f: + src = f.read() + + # Parse the code and insert method call fixes. + tree = cst.parse_module(src) + updated = tree.visit(transformer) + + # Create the path and directory structure for the new file. + updated_path = out_dir.joinpath(fpath.relative_to(in_dir)) + updated_path.parent.mkdir(parents=True, exist_ok=True) + + # Generate the updated source file at the corresponding path. + with open(updated_path, 'w') as f: + f.write(updated.code) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser( + description="""Fix up source that uses the webrisk client library. + +The existing sources are NOT overwritten but are copied to output_dir with changes made. + +Note: This tool operates at a best-effort level at converting positional + parameters in client method calls to keyword based parameters. + Cases where it WILL FAIL include + A) * or ** expansion in a method call. + B) Calls via function or method alias (includes free function calls) + C) Indirect or dispatched calls (e.g. the method is looked up dynamically) + + These all constitute false negatives. The tool will also detect false + positives when an API method shares a name with another method. +""") + parser.add_argument( + '-d', + '--input-directory', + required=True, + dest='input_dir', + help='the input directory to walk for python files to fix up', + ) + parser.add_argument( + '-o', + '--output-directory', + required=True, + dest='output_dir', + help='the directory to output files fixed via un-flattening', + ) + args = parser.parse_args() + input_dir = pathlib.Path(args.input_dir) + output_dir = pathlib.Path(args.output_dir) + if not input_dir.is_dir(): + print( + f"input directory '{input_dir}' does not exist or is not a directory", + file=sys.stderr, + ) + sys.exit(-1) + + if not output_dir.is_dir(): + print( + f"output directory '{output_dir}' does not exist or is not a directory", + file=sys.stderr, + ) + sys.exit(-1) + + if os.listdir(output_dir): + print( + f"output directory '{output_dir}' is not empty", + file=sys.stderr, + ) + sys.exit(-1) + + fix_files(input_dir, output_dir) diff --git a/scripts/fixup_webrisk_v1beta1_keywords.py b/scripts/fixup_webrisk_v1beta1_keywords.py new file mode 100644 index 0000000..0b3a191 --- /dev/null +++ b/scripts/fixup_webrisk_v1beta1_keywords.py @@ -0,0 +1,179 @@ +# -*- 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. +# + +import argparse +import os +import libcst as cst +import pathlib +import sys +from typing import (Any, Callable, Dict, List, Sequence, Tuple) + + +def partition( + predicate: Callable[[Any], bool], + iterator: Sequence[Any] +) -> Tuple[List[Any], List[Any]]: + """A stable, out-of-place partition.""" + results = ([], []) + + for i in iterator: + results[int(predicate(i))].append(i) + + # Returns trueList, falseList + return results[1], results[0] + + +class webriskCallTransformer(cst.CSTTransformer): + CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') + METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { + 'compute_threat_list_diff': ('threat_type', 'constraints', 'version_token', ), + 'search_hashes': ('threat_types', 'hash_prefix', ), + 'search_uris': ('uri', 'threat_types', ), + } + + def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: + try: + key = original.func.attr.value + kword_params = self.METHOD_TO_PARAMS[key] + except (AttributeError, KeyError): + # Either not a method from the API or too convoluted to be sure. + return updated + + # If the existing code is valid, keyword args come after positional args. + # Therefore, all positional args must map to the first parameters. + args, kwargs = partition(lambda a: not bool(a.keyword), updated.args) + if any(k.keyword.value == "request" for k in kwargs): + # We've already fixed this file, don't fix it again. + return updated + + kwargs, ctrl_kwargs = partition( + lambda a: not a.keyword.value in self.CTRL_PARAMS, + kwargs + ) + + args, ctrl_args = args[:len(kword_params)], args[len(kword_params):] + ctrl_kwargs.extend(cst.Arg(value=a.value, keyword=cst.Name(value=ctrl)) + for a, ctrl in zip(ctrl_args, self.CTRL_PARAMS)) + + request_arg = cst.Arg( + value=cst.Dict([ + cst.DictElement( + cst.SimpleString("'{}'".format(name)), + 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 + # those could have been passed positionally or by keyword. + for name, arg in zip(kword_params, args + kwargs)]), + keyword=cst.Name("request") + ) + + return updated.with_changes( + args=[request_arg] + ctrl_kwargs + ) + + +def fix_files( + in_dir: pathlib.Path, + out_dir: pathlib.Path, + *, + transformer=webriskCallTransformer(), +): + """Duplicate the input dir to the output dir, fixing file method calls. + + Preconditions: + * in_dir is a real directory + * out_dir is a real, empty directory + """ + pyfile_gen = ( + pathlib.Path(os.path.join(root, f)) + for root, _, files in os.walk(in_dir) + for f in files if os.path.splitext(f)[1] == ".py" + ) + + for fpath in pyfile_gen: + with open(fpath, 'r') as f: + src = f.read() + + # Parse the code and insert method call fixes. + tree = cst.parse_module(src) + updated = tree.visit(transformer) + + # Create the path and directory structure for the new file. + updated_path = out_dir.joinpath(fpath.relative_to(in_dir)) + updated_path.parent.mkdir(parents=True, exist_ok=True) + + # Generate the updated source file at the corresponding path. + with open(updated_path, 'w') as f: + f.write(updated.code) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser( + description="""Fix up source that uses the webrisk client library. + +The existing sources are NOT overwritten but are copied to output_dir with changes made. + +Note: This tool operates at a best-effort level at converting positional + parameters in client method calls to keyword based parameters. + Cases where it WILL FAIL include + A) * or ** expansion in a method call. + B) Calls via function or method alias (includes free function calls) + C) Indirect or dispatched calls (e.g. the method is looked up dynamically) + + These all constitute false negatives. The tool will also detect false + positives when an API method shares a name with another method. +""") + parser.add_argument( + '-d', + '--input-directory', + required=True, + dest='input_dir', + help='the input directory to walk for python files to fix up', + ) + parser.add_argument( + '-o', + '--output-directory', + required=True, + dest='output_dir', + help='the directory to output files fixed via un-flattening', + ) + args = parser.parse_args() + input_dir = pathlib.Path(args.input_dir) + output_dir = pathlib.Path(args.output_dir) + if not input_dir.is_dir(): + print( + f"input directory '{input_dir}' does not exist or is not a directory", + file=sys.stderr, + ) + sys.exit(-1) + + if not output_dir.is_dir(): + print( + f"output directory '{output_dir}' does not exist or is not a directory", + file=sys.stderr, + ) + sys.exit(-1) + + if os.listdir(output_dir): + print( + f"output directory '{output_dir}' is not empty", + file=sys.stderr, + ) + sys.exit(-1) + + fix_files(input_dir, output_dir) diff --git a/setup.py b/setup.py index ab00d6c..7a9dff0 100644 --- a/setup.py +++ b/setup.py @@ -28,7 +28,11 @@ # 'Development Status :: 4 - Beta' # 'Development Status :: 5 - Production/Stable' release_status = "Development Status :: 3 - Alpha" -dependencies = ["google-api-core[grpc] >= 1.14.0, < 2.0.0dev"] +dependencies = [ + "google-api-core[grpc] >= 1.21.0, < 2.0.0dev", + "proto-plus >= 0.4.0", + "libcst >= 0.2.5", +] extras = {} @@ -43,7 +47,9 @@ # Only include packages under the 'google' namespace. Do not include tests, # benchmarks, etc. packages = [ - package for package in setuptools.find_packages() if package.startswith("google") + package + for package in setuptools.PEP420PackageFinder.find() + if package.startswith("google") ] # Determine which namespaces are needed. @@ -66,10 +72,7 @@ "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", - "Programming Language :: Python :: 2", - "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Operating System :: OS Independent", @@ -80,7 +83,11 @@ namespace_packages=namespaces, install_requires=dependencies, extras_require=extras, - python_requires=">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*", + python_requires=">=3.6", + scripts=[ + "scripts/fixup_webrisk_v1_keywords.py", + "scripts/fixup_webrisk_v1beta1_keywords.py", + ], include_package_data=True, zip_safe=False, ) diff --git a/synth.metadata b/synth.metadata index 57882aa..b038f38 100644 --- a/synth.metadata +++ b/synth.metadata @@ -3,23 +3,23 @@ { "git": { "name": ".", - "remote": "https://github.com/googleapis/python-webrisk.git", - "sha": "6cda9039c6601fdb5e06870ae282480dc03590f0" + "remote": "git@github.com:googleapis/python-webrisk.git", + "sha": "da0eeec144adf5ba1b41aef2aea856cdf07ea5cd" } }, { "git": { "name": "googleapis", "remote": "https://github.com/googleapis/googleapis.git", - "sha": "b882b8e6bfcd708042ff00f7adc67ce750817dd0", - "internalRef": "318028816" + "sha": "50ae1c72fd94a3ae4269394b09e4b7fbb9251146", + "internalRef": "320484049" } }, { "git": { "name": "synthtool", "remote": "https://github.com/googleapis/synthtool.git", - "sha": "303271797a360f8a439203413f13a160f2f5b3b4" + "sha": "799d8e6522c1ef7cb55a70d9ea0b15e045c3d00b" } } ], diff --git a/synth.py b/synth.py index 2e51818..b60cc84 100644 --- a/synth.py +++ b/synth.py @@ -46,8 +46,12 @@ # ---------------------------------------------------------------------------- # Add templated files # ---------------------------------------------------------------------------- -templated_files = common.py_library(cov_level=75) -s.move(templated_files) +templated_files = common.py_library( + samples=False, # set to True only if there are samples + microgenerator=True, + cov_level=99, +) +s.move(templated_files, excludes=[".coveragerc"]) # microgenerator has a good .coveragerc file # TODO(busunkim): Use latest sphinx after microgenerator transition s.replace("noxfile.py", """['"]sphinx['"]""", '"sphinx<3.0.0"') diff --git a/tests/unit/gapic/v1/test_web_risk_service_client_v1.py b/tests/unit/gapic/v1/test_web_risk_service_client_v1.py deleted file mode 100644 index 4b45a55..0000000 --- a/tests/unit/gapic/v1/test_web_risk_service_client_v1.py +++ /dev/null @@ -1,226 +0,0 @@ -# -*- 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 -# -# https://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. - -"""Unit tests.""" - -import mock -import pytest - -from google.cloud import webrisk_v1 -from google.cloud.webrisk_v1 import enums -from google.cloud.webrisk_v1.proto import webrisk_pb2 - - -class MultiCallableStub(object): - """Stub for the grpc.UnaryUnaryMultiCallable interface.""" - - def __init__(self, method, channel_stub): - self.method = method - self.channel_stub = channel_stub - - def __call__(self, request, timeout=None, metadata=None, credentials=None): - self.channel_stub.requests.append((self.method, request)) - - response = None - if self.channel_stub.responses: - response = self.channel_stub.responses.pop() - - if isinstance(response, Exception): - raise response - - if response: - return response - - -class ChannelStub(object): - """Stub for the grpc.Channel interface.""" - - def __init__(self, responses=[]): - self.responses = responses - self.requests = [] - - def unary_unary(self, method, request_serializer=None, response_deserializer=None): - return MultiCallableStub(method, self) - - -class CustomException(Exception): - pass - - -class TestWebRiskServiceClient(object): - def test_compute_threat_list_diff(self): - # Setup Expected Response - new_version_token = b"115" - expected_response = {"new_version_token": new_version_token} - expected_response = webrisk_pb2.ComputeThreatListDiffResponse( - **expected_response - ) - - # Mock the API response - channel = ChannelStub(responses=[expected_response]) - patch = mock.patch("google.api_core.grpc_helpers.create_channel") - with patch as create_channel: - create_channel.return_value = channel - client = webrisk_v1.WebRiskServiceClient() - - # Setup Request - threat_type = enums.ThreatType.THREAT_TYPE_UNSPECIFIED - constraints = {} - - response = client.compute_threat_list_diff(threat_type, constraints) - assert expected_response == response - - assert len(channel.requests) == 1 - expected_request = webrisk_pb2.ComputeThreatListDiffRequest( - threat_type=threat_type, constraints=constraints - ) - actual_request = channel.requests[0][1] - assert expected_request == actual_request - - def test_compute_threat_list_diff_exception(self): - # Mock the API response - channel = ChannelStub(responses=[CustomException()]) - patch = mock.patch("google.api_core.grpc_helpers.create_channel") - with patch as create_channel: - create_channel.return_value = channel - client = webrisk_v1.WebRiskServiceClient() - - # Setup request - threat_type = enums.ThreatType.THREAT_TYPE_UNSPECIFIED - constraints = {} - - with pytest.raises(CustomException): - client.compute_threat_list_diff(threat_type, constraints) - - def test_search_uris(self): - # Setup Expected Response - expected_response = {} - expected_response = webrisk_pb2.SearchUrisResponse(**expected_response) - - # Mock the API response - channel = ChannelStub(responses=[expected_response]) - patch = mock.patch("google.api_core.grpc_helpers.create_channel") - with patch as create_channel: - create_channel.return_value = channel - client = webrisk_v1.WebRiskServiceClient() - - # Setup Request - uri = "uri116076" - threat_types = [] - - response = client.search_uris(uri, threat_types) - assert expected_response == response - - assert len(channel.requests) == 1 - expected_request = webrisk_pb2.SearchUrisRequest( - uri=uri, threat_types=threat_types - ) - actual_request = channel.requests[0][1] - assert expected_request == actual_request - - def test_search_uris_exception(self): - # Mock the API response - channel = ChannelStub(responses=[CustomException()]) - patch = mock.patch("google.api_core.grpc_helpers.create_channel") - with patch as create_channel: - create_channel.return_value = channel - client = webrisk_v1.WebRiskServiceClient() - - # Setup request - uri = "uri116076" - threat_types = [] - - with pytest.raises(CustomException): - client.search_uris(uri, threat_types) - - def test_search_hashes(self): - # Setup Expected Response - expected_response = {} - expected_response = webrisk_pb2.SearchHashesResponse(**expected_response) - - # Mock the API response - channel = ChannelStub(responses=[expected_response]) - patch = mock.patch("google.api_core.grpc_helpers.create_channel") - with patch as create_channel: - create_channel.return_value = channel - client = webrisk_v1.WebRiskServiceClient() - - # Setup Request - threat_types = [] - - response = client.search_hashes(threat_types) - assert expected_response == response - - assert len(channel.requests) == 1 - expected_request = webrisk_pb2.SearchHashesRequest(threat_types=threat_types) - actual_request = channel.requests[0][1] - assert expected_request == actual_request - - def test_search_hashes_exception(self): - # Mock the API response - channel = ChannelStub(responses=[CustomException()]) - patch = mock.patch("google.api_core.grpc_helpers.create_channel") - with patch as create_channel: - create_channel.return_value = channel - client = webrisk_v1.WebRiskServiceClient() - - # Setup request - threat_types = [] - - with pytest.raises(CustomException): - client.search_hashes(threat_types) - - def test_create_submission(self): - # Setup Expected Response - uri = "uri116076" - expected_response = {"uri": uri} - expected_response = webrisk_pb2.Submission(**expected_response) - - # Mock the API response - channel = ChannelStub(responses=[expected_response]) - patch = mock.patch("google.api_core.grpc_helpers.create_channel") - with patch as create_channel: - create_channel.return_value = channel - client = webrisk_v1.WebRiskServiceClient() - - # Setup Request - parent = client.project_path("[PROJECT]") - submission = {} - - response = client.create_submission(parent, submission) - assert expected_response == response - - assert len(channel.requests) == 1 - expected_request = webrisk_pb2.CreateSubmissionRequest( - parent=parent, submission=submission - ) - actual_request = channel.requests[0][1] - assert expected_request == actual_request - - def test_create_submission_exception(self): - # Mock the API response - channel = ChannelStub(responses=[CustomException()]) - patch = mock.patch("google.api_core.grpc_helpers.create_channel") - with patch as create_channel: - create_channel.return_value = channel - client = webrisk_v1.WebRiskServiceClient() - - # Setup request - parent = client.project_path("[PROJECT]") - submission = {} - - with pytest.raises(CustomException): - client.create_submission(parent, submission) diff --git a/tests/unit/gapic/v1beta1/test_web_risk_service_v1_beta1_client_v1beta1.py b/tests/unit/gapic/v1beta1/test_web_risk_service_v1_beta1_client_v1beta1.py deleted file mode 100644 index 3e8ec68..0000000 --- a/tests/unit/gapic/v1beta1/test_web_risk_service_v1_beta1_client_v1beta1.py +++ /dev/null @@ -1,184 +0,0 @@ -# -*- 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 -# -# https://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. - -"""Unit tests.""" - -import mock -import pytest - -from google.cloud import webrisk_v1beta1 -from google.cloud.webrisk_v1beta1 import enums -from google.cloud.webrisk_v1beta1.proto import webrisk_pb2 - - -class MultiCallableStub(object): - """Stub for the grpc.UnaryUnaryMultiCallable interface.""" - - def __init__(self, method, channel_stub): - self.method = method - self.channel_stub = channel_stub - - def __call__(self, request, timeout=None, metadata=None, credentials=None): - self.channel_stub.requests.append((self.method, request)) - - response = None - if self.channel_stub.responses: - response = self.channel_stub.responses.pop() - - if isinstance(response, Exception): - raise response - - if response: - return response - - -class ChannelStub(object): - """Stub for the grpc.Channel interface.""" - - def __init__(self, responses=[]): - self.responses = responses - self.requests = [] - - def unary_unary(self, method, request_serializer=None, response_deserializer=None): - return MultiCallableStub(method, self) - - -class CustomException(Exception): - pass - - -class TestWebRiskServiceV1Beta1Client(object): - def test_compute_threat_list_diff(self): - # Setup Expected Response - new_version_token = b"115" - expected_response = {"new_version_token": new_version_token} - expected_response = webrisk_pb2.ComputeThreatListDiffResponse( - **expected_response - ) - - # Mock the API response - channel = ChannelStub(responses=[expected_response]) - patch = mock.patch("google.api_core.grpc_helpers.create_channel") - with patch as create_channel: - create_channel.return_value = channel - client = webrisk_v1beta1.WebRiskServiceV1Beta1Client() - - # Setup Request - threat_type = enums.ThreatType.THREAT_TYPE_UNSPECIFIED - constraints = {} - - response = client.compute_threat_list_diff(threat_type, constraints) - assert expected_response == response - - assert len(channel.requests) == 1 - expected_request = webrisk_pb2.ComputeThreatListDiffRequest( - threat_type=threat_type, constraints=constraints - ) - actual_request = channel.requests[0][1] - assert expected_request == actual_request - - def test_compute_threat_list_diff_exception(self): - # Mock the API response - channel = ChannelStub(responses=[CustomException()]) - patch = mock.patch("google.api_core.grpc_helpers.create_channel") - with patch as create_channel: - create_channel.return_value = channel - client = webrisk_v1beta1.WebRiskServiceV1Beta1Client() - - # Setup request - threat_type = enums.ThreatType.THREAT_TYPE_UNSPECIFIED - constraints = {} - - with pytest.raises(CustomException): - client.compute_threat_list_diff(threat_type, constraints) - - def test_search_uris(self): - # Setup Expected Response - expected_response = {} - expected_response = webrisk_pb2.SearchUrisResponse(**expected_response) - - # Mock the API response - channel = ChannelStub(responses=[expected_response]) - patch = mock.patch("google.api_core.grpc_helpers.create_channel") - with patch as create_channel: - create_channel.return_value = channel - client = webrisk_v1beta1.WebRiskServiceV1Beta1Client() - - # Setup Request - uri = "uri116076" - threat_types = [] - - response = client.search_uris(uri, threat_types) - assert expected_response == response - - assert len(channel.requests) == 1 - expected_request = webrisk_pb2.SearchUrisRequest( - uri=uri, threat_types=threat_types - ) - actual_request = channel.requests[0][1] - assert expected_request == actual_request - - def test_search_uris_exception(self): - # Mock the API response - channel = ChannelStub(responses=[CustomException()]) - patch = mock.patch("google.api_core.grpc_helpers.create_channel") - with patch as create_channel: - create_channel.return_value = channel - client = webrisk_v1beta1.WebRiskServiceV1Beta1Client() - - # Setup request - uri = "uri116076" - threat_types = [] - - with pytest.raises(CustomException): - client.search_uris(uri, threat_types) - - def test_search_hashes(self): - # Setup Expected Response - expected_response = {} - expected_response = webrisk_pb2.SearchHashesResponse(**expected_response) - - # Mock the API response - channel = ChannelStub(responses=[expected_response]) - patch = mock.patch("google.api_core.grpc_helpers.create_channel") - with patch as create_channel: - create_channel.return_value = channel - client = webrisk_v1beta1.WebRiskServiceV1Beta1Client() - - # Setup Request - threat_types = [] - - response = client.search_hashes(threat_types) - assert expected_response == response - - assert len(channel.requests) == 1 - expected_request = webrisk_pb2.SearchHashesRequest(threat_types=threat_types) - actual_request = channel.requests[0][1] - assert expected_request == actual_request - - def test_search_hashes_exception(self): - # Mock the API response - channel = ChannelStub(responses=[CustomException()]) - patch = mock.patch("google.api_core.grpc_helpers.create_channel") - with patch as create_channel: - create_channel.return_value = channel - client = webrisk_v1beta1.WebRiskServiceV1Beta1Client() - - # Setup request - threat_types = [] - - with pytest.raises(CustomException): - client.search_hashes(threat_types) diff --git a/google/cloud/webrisk_v1/gapic/__init__.py b/tests/unit/gapic/webrisk_v1/__init__.py similarity index 100% rename from google/cloud/webrisk_v1/gapic/__init__.py rename to tests/unit/gapic/webrisk_v1/__init__.py diff --git a/tests/unit/gapic/webrisk_v1/test_web_risk_service.py b/tests/unit/gapic/webrisk_v1/test_web_risk_service.py new file mode 100644 index 0000000..5bf8bb6 --- /dev/null +++ b/tests/unit/gapic/webrisk_v1/test_web_risk_service.py @@ -0,0 +1,1262 @@ +# -*- 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. +# + +import os +import mock + +import grpc +from grpc.experimental import aio +import math +import pytest + +from google import auth +from google.api_core import client_options +from google.api_core import exceptions +from google.api_core import grpc_helpers +from google.api_core import grpc_helpers_async +from google.auth import credentials +from google.auth.exceptions import MutualTLSChannelError +from google.cloud.webrisk_v1.services.web_risk_service import WebRiskServiceAsyncClient +from google.cloud.webrisk_v1.services.web_risk_service import WebRiskServiceClient +from google.cloud.webrisk_v1.services.web_risk_service import transports +from google.cloud.webrisk_v1.types import webrisk +from google.oauth2 import service_account +from google.protobuf import timestamp_pb2 as timestamp # type: ignore + + +def client_cert_source_callback(): + return b"cert bytes", b"key bytes" + + +def test__get_default_mtls_endpoint(): + api_endpoint = "example.googleapis.com" + api_mtls_endpoint = "example.mtls.googleapis.com" + sandbox_endpoint = "example.sandbox.googleapis.com" + sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" + non_googleapi = "api.example.com" + + assert WebRiskServiceClient._get_default_mtls_endpoint(None) is None + assert ( + WebRiskServiceClient._get_default_mtls_endpoint(api_endpoint) + == api_mtls_endpoint + ) + assert ( + WebRiskServiceClient._get_default_mtls_endpoint(api_mtls_endpoint) + == api_mtls_endpoint + ) + assert ( + WebRiskServiceClient._get_default_mtls_endpoint(sandbox_endpoint) + == sandbox_mtls_endpoint + ) + assert ( + WebRiskServiceClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) + == sandbox_mtls_endpoint + ) + assert ( + WebRiskServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + ) + + +@pytest.mark.parametrize( + "client_class", [WebRiskServiceClient, WebRiskServiceAsyncClient] +) +def test_web_risk_service_client_from_service_account_file(client_class): + creds = credentials.AnonymousCredentials() + with mock.patch.object( + service_account.Credentials, "from_service_account_file" + ) as factory: + factory.return_value = creds + client = client_class.from_service_account_file("dummy/file/path.json") + assert client._transport._credentials == creds + + client = client_class.from_service_account_json("dummy/file/path.json") + assert client._transport._credentials == creds + + assert client._transport._host == "webrisk.googleapis.com:443" + + +def test_web_risk_service_client_get_transport_class(): + transport = WebRiskServiceClient.get_transport_class() + assert transport == transports.WebRiskServiceGrpcTransport + + transport = WebRiskServiceClient.get_transport_class("grpc") + assert transport == transports.WebRiskServiceGrpcTransport + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (WebRiskServiceClient, transports.WebRiskServiceGrpcTransport, "grpc"), + ( + WebRiskServiceAsyncClient, + transports.WebRiskServiceGrpcAsyncIOTransport, + "grpc_asyncio", + ), + ], +) +def test_web_risk_service_client_client_options( + client_class, transport_class, transport_name +): + # Check that if channel is provided we won't create a new one. + with mock.patch.object(WebRiskServiceClient, "get_transport_class") as gtc: + transport = transport_class(credentials=credentials.AnonymousCredentials()) + client = client_class(transport=transport) + gtc.assert_not_called() + + # Check that if channel is provided via str we will create a new one. + with mock.patch.object(WebRiskServiceClient, "get_transport_class") as gtc: + client = client_class(transport=transport_name) + gtc.assert_called() + + # Check the case api_endpoint is provided. + options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host="squid.clam.whelk", + scopes=None, + api_mtls_endpoint="squid.clam.whelk", + client_cert_source=None, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS is + # "never". + os.environ["GOOGLE_API_USE_MTLS"] = "never" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class() + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + api_mtls_endpoint=client.DEFAULT_ENDPOINT, + client_cert_source=None, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS is + # "always". + os.environ["GOOGLE_API_USE_MTLS"] = "always" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class() + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_MTLS_ENDPOINT, + scopes=None, + api_mtls_endpoint=client.DEFAULT_MTLS_ENDPOINT, + client_cert_source=None, + ) + + # Check the case api_endpoint is not provided, GOOGLE_API_USE_MTLS is + # "auto", and client_cert_source is provided. + os.environ["GOOGLE_API_USE_MTLS"] = "auto" + options = client_options.ClientOptions( + client_cert_source=client_cert_source_callback + ) + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_MTLS_ENDPOINT, + scopes=None, + api_mtls_endpoint=client.DEFAULT_MTLS_ENDPOINT, + client_cert_source=client_cert_source_callback, + ) + + # Check the case api_endpoint is not provided, GOOGLE_API_USE_MTLS is + # "auto", and default_client_cert_source is provided. + os.environ["GOOGLE_API_USE_MTLS"] = "auto" + with mock.patch.object(transport_class, "__init__") as patched: + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + patched.return_value = None + client = client_class() + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_MTLS_ENDPOINT, + scopes=None, + api_mtls_endpoint=client.DEFAULT_MTLS_ENDPOINT, + client_cert_source=None, + ) + + # Check the case api_endpoint is not provided, GOOGLE_API_USE_MTLS is + # "auto", but client_cert_source and default_client_cert_source are None. + os.environ["GOOGLE_API_USE_MTLS"] = "auto" + with mock.patch.object(transport_class, "__init__") as patched: + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + patched.return_value = None + client = client_class() + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + api_mtls_endpoint=client.DEFAULT_ENDPOINT, + client_cert_source=None, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS has + # unsupported value. + os.environ["GOOGLE_API_USE_MTLS"] = "Unsupported" + with pytest.raises(MutualTLSChannelError): + client = client_class() + + del os.environ["GOOGLE_API_USE_MTLS"] + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (WebRiskServiceClient, transports.WebRiskServiceGrpcTransport, "grpc"), + ( + WebRiskServiceAsyncClient, + transports.WebRiskServiceGrpcAsyncIOTransport, + "grpc_asyncio", + ), + ], +) +def test_web_risk_service_client_client_options_scopes( + client_class, transport_class, transport_name +): + # Check the case scopes are provided. + options = client_options.ClientOptions(scopes=["1", "2"],) + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=["1", "2"], + api_mtls_endpoint=client.DEFAULT_ENDPOINT, + client_cert_source=None, + ) + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (WebRiskServiceClient, transports.WebRiskServiceGrpcTransport, "grpc"), + ( + WebRiskServiceAsyncClient, + transports.WebRiskServiceGrpcAsyncIOTransport, + "grpc_asyncio", + ), + ], +) +def test_web_risk_service_client_client_options_credentials_file( + client_class, transport_class, transport_name +): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + api_mtls_endpoint=client.DEFAULT_ENDPOINT, + client_cert_source=None, + ) + + +def test_web_risk_service_client_client_options_from_dict(): + with mock.patch( + "google.cloud.webrisk_v1.services.web_risk_service.transports.WebRiskServiceGrpcTransport.__init__" + ) as grpc_transport: + grpc_transport.return_value = None + client = WebRiskServiceClient( + client_options={"api_endpoint": "squid.clam.whelk"} + ) + grpc_transport.assert_called_once_with( + credentials=None, + credentials_file=None, + host="squid.clam.whelk", + scopes=None, + api_mtls_endpoint="squid.clam.whelk", + client_cert_source=None, + ) + + +def test_compute_threat_list_diff(transport: str = "grpc"): + client = WebRiskServiceClient( + credentials=credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = webrisk.ComputeThreatListDiffRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client._transport.compute_threat_list_diff), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = webrisk.ComputeThreatListDiffResponse( + response_type=webrisk.ComputeThreatListDiffResponse.ResponseType.DIFF, + new_version_token=b"new_version_token_blob", + ) + + response = client.compute_threat_list_diff(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, webrisk.ComputeThreatListDiffResponse) + + assert ( + response.response_type + == webrisk.ComputeThreatListDiffResponse.ResponseType.DIFF + ) + + assert response.new_version_token == b"new_version_token_blob" + + +@pytest.mark.asyncio +async def test_compute_threat_list_diff_async(transport: str = "grpc_asyncio"): + client = WebRiskServiceAsyncClient( + credentials=credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = webrisk.ComputeThreatListDiffRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client._client._transport.compute_threat_list_diff), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + webrisk.ComputeThreatListDiffResponse( + response_type=webrisk.ComputeThreatListDiffResponse.ResponseType.DIFF, + new_version_token=b"new_version_token_blob", + ) + ) + + response = await client.compute_threat_list_diff(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, webrisk.ComputeThreatListDiffResponse) + + assert ( + response.response_type + == webrisk.ComputeThreatListDiffResponse.ResponseType.DIFF + ) + + assert response.new_version_token == b"new_version_token_blob" + + +def test_compute_threat_list_diff_flattened(): + client = WebRiskServiceClient(credentials=credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client._transport.compute_threat_list_diff), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = webrisk.ComputeThreatListDiffResponse() + + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.compute_threat_list_diff( + threat_type=webrisk.ThreatType.MALWARE, + version_token=b"version_token_blob", + constraints=webrisk.ComputeThreatListDiffRequest.Constraints( + max_diff_entries=1687 + ), + ) + + # 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].threat_type == webrisk.ThreatType.MALWARE + assert args[0].version_token == b"version_token_blob" + assert args[0].constraints == webrisk.ComputeThreatListDiffRequest.Constraints( + max_diff_entries=1687 + ) + + +def test_compute_threat_list_diff_flattened_error(): + client = WebRiskServiceClient(credentials=credentials.AnonymousCredentials(),) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.compute_threat_list_diff( + webrisk.ComputeThreatListDiffRequest(), + threat_type=webrisk.ThreatType.MALWARE, + version_token=b"version_token_blob", + constraints=webrisk.ComputeThreatListDiffRequest.Constraints( + max_diff_entries=1687 + ), + ) + + +@pytest.mark.asyncio +async def test_compute_threat_list_diff_flattened_async(): + client = WebRiskServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client._client._transport.compute_threat_list_diff), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = webrisk.ComputeThreatListDiffResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + webrisk.ComputeThreatListDiffResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.compute_threat_list_diff( + threat_type=webrisk.ThreatType.MALWARE, + version_token=b"version_token_blob", + constraints=webrisk.ComputeThreatListDiffRequest.Constraints( + max_diff_entries=1687 + ), + ) + + # 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].threat_type == webrisk.ThreatType.MALWARE + assert args[0].version_token == b"version_token_blob" + assert args[0].constraints == webrisk.ComputeThreatListDiffRequest.Constraints( + max_diff_entries=1687 + ) + + +@pytest.mark.asyncio +async def test_compute_threat_list_diff_flattened_error_async(): + client = WebRiskServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.compute_threat_list_diff( + webrisk.ComputeThreatListDiffRequest(), + threat_type=webrisk.ThreatType.MALWARE, + version_token=b"version_token_blob", + constraints=webrisk.ComputeThreatListDiffRequest.Constraints( + max_diff_entries=1687 + ), + ) + + +def test_search_uris(transport: str = "grpc"): + client = WebRiskServiceClient( + credentials=credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = webrisk.SearchUrisRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client._transport.search_uris), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = webrisk.SearchUrisResponse() + + response = client.search_uris(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, webrisk.SearchUrisResponse) + + +@pytest.mark.asyncio +async def test_search_uris_async(transport: str = "grpc_asyncio"): + client = WebRiskServiceAsyncClient( + credentials=credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = webrisk.SearchUrisRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client._client._transport.search_uris), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + webrisk.SearchUrisResponse() + ) + + response = await client.search_uris(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, webrisk.SearchUrisResponse) + + +def test_search_uris_flattened(): + client = WebRiskServiceClient(credentials=credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client._transport.search_uris), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = webrisk.SearchUrisResponse() + + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.search_uris( + uri="uri_value", threat_types=[webrisk.ThreatType.MALWARE], + ) + + # 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].uri == "uri_value" + assert args[0].threat_types == [webrisk.ThreatType.MALWARE] + + +def test_search_uris_flattened_error(): + client = WebRiskServiceClient(credentials=credentials.AnonymousCredentials(),) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.search_uris( + webrisk.SearchUrisRequest(), + uri="uri_value", + threat_types=[webrisk.ThreatType.MALWARE], + ) + + +@pytest.mark.asyncio +async def test_search_uris_flattened_async(): + client = WebRiskServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client._client._transport.search_uris), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = webrisk.SearchUrisResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + webrisk.SearchUrisResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.search_uris( + uri="uri_value", threat_types=[webrisk.ThreatType.MALWARE], + ) + + # 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].uri == "uri_value" + assert args[0].threat_types == [webrisk.ThreatType.MALWARE] + + +@pytest.mark.asyncio +async def test_search_uris_flattened_error_async(): + client = WebRiskServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.search_uris( + webrisk.SearchUrisRequest(), + uri="uri_value", + threat_types=[webrisk.ThreatType.MALWARE], + ) + + +def test_search_hashes(transport: str = "grpc"): + client = WebRiskServiceClient( + credentials=credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = webrisk.SearchHashesRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client._transport.search_hashes), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = webrisk.SearchHashesResponse() + + response = client.search_hashes(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, webrisk.SearchHashesResponse) + + +@pytest.mark.asyncio +async def test_search_hashes_async(transport: str = "grpc_asyncio"): + client = WebRiskServiceAsyncClient( + credentials=credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = webrisk.SearchHashesRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client._client._transport.search_hashes), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + webrisk.SearchHashesResponse() + ) + + response = await client.search_hashes(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, webrisk.SearchHashesResponse) + + +def test_search_hashes_flattened(): + client = WebRiskServiceClient(credentials=credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client._transport.search_hashes), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = webrisk.SearchHashesResponse() + + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.search_hashes( + hash_prefix=b"hash_prefix_blob", threat_types=[webrisk.ThreatType.MALWARE], + ) + + # 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].hash_prefix == b"hash_prefix_blob" + assert args[0].threat_types == [webrisk.ThreatType.MALWARE] + + +def test_search_hashes_flattened_error(): + client = WebRiskServiceClient(credentials=credentials.AnonymousCredentials(),) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.search_hashes( + webrisk.SearchHashesRequest(), + hash_prefix=b"hash_prefix_blob", + threat_types=[webrisk.ThreatType.MALWARE], + ) + + +@pytest.mark.asyncio +async def test_search_hashes_flattened_async(): + client = WebRiskServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client._client._transport.search_hashes), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = webrisk.SearchHashesResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + webrisk.SearchHashesResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.search_hashes( + hash_prefix=b"hash_prefix_blob", threat_types=[webrisk.ThreatType.MALWARE], + ) + + # 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].hash_prefix == b"hash_prefix_blob" + assert args[0].threat_types == [webrisk.ThreatType.MALWARE] + + +@pytest.mark.asyncio +async def test_search_hashes_flattened_error_async(): + client = WebRiskServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.search_hashes( + webrisk.SearchHashesRequest(), + hash_prefix=b"hash_prefix_blob", + threat_types=[webrisk.ThreatType.MALWARE], + ) + + +def test_create_submission(transport: str = "grpc"): + client = WebRiskServiceClient( + credentials=credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = webrisk.CreateSubmissionRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client._transport.create_submission), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = webrisk.Submission(uri="uri_value",) + + response = client.create_submission(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, webrisk.Submission) + + assert response.uri == "uri_value" + + +@pytest.mark.asyncio +async def test_create_submission_async(transport: str = "grpc_asyncio"): + client = WebRiskServiceAsyncClient( + credentials=credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = webrisk.CreateSubmissionRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client._client._transport.create_submission), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + webrisk.Submission(uri="uri_value",) + ) + + response = await client.create_submission(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, webrisk.Submission) + + assert response.uri == "uri_value" + + +def test_create_submission_field_headers(): + client = WebRiskServiceClient(credentials=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 = webrisk.CreateSubmissionRequest() + request.parent = "parent/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client._transport.create_submission), "__call__" + ) as call: + call.return_value = webrisk.Submission() + + client.create_submission(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_create_submission_field_headers_async(): + client = WebRiskServiceAsyncClient(credentials=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 = webrisk.CreateSubmissionRequest() + request.parent = "parent/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client._client._transport.create_submission), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(webrisk.Submission()) + + await client.create_submission(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + + +def test_create_submission_flattened(): + client = WebRiskServiceClient(credentials=credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client._transport.create_submission), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = webrisk.Submission() + + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.create_submission( + parent="parent_value", submission=webrisk.Submission(uri="uri_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].parent == "parent_value" + assert args[0].submission == webrisk.Submission(uri="uri_value") + + +def test_create_submission_flattened_error(): + client = WebRiskServiceClient(credentials=credentials.AnonymousCredentials(),) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_submission( + webrisk.CreateSubmissionRequest(), + parent="parent_value", + submission=webrisk.Submission(uri="uri_value"), + ) + + +@pytest.mark.asyncio +async def test_create_submission_flattened_async(): + client = WebRiskServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client._client._transport.create_submission), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = webrisk.Submission() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(webrisk.Submission()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.create_submission( + parent="parent_value", submission=webrisk.Submission(uri="uri_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].parent == "parent_value" + assert args[0].submission == webrisk.Submission(uri="uri_value") + + +@pytest.mark.asyncio +async def test_create_submission_flattened_error_async(): + client = WebRiskServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.create_submission( + webrisk.CreateSubmissionRequest(), + parent="parent_value", + submission=webrisk.Submission(uri="uri_value"), + ) + + +def test_credentials_transport_error(): + # It is an error to provide credentials and a transport instance. + transport = transports.WebRiskServiceGrpcTransport( + credentials=credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = WebRiskServiceClient( + credentials=credentials.AnonymousCredentials(), transport=transport, + ) + + # It is an error to provide a credentials file and a transport instance. + transport = transports.WebRiskServiceGrpcTransport( + credentials=credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = WebRiskServiceClient( + client_options={"credentials_file": "credentials.json"}, + transport=transport, + ) + + # It is an error to provide scopes and a transport instance. + transport = transports.WebRiskServiceGrpcTransport( + credentials=credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = WebRiskServiceClient( + client_options={"scopes": ["1", "2"]}, transport=transport, + ) + + +def test_transport_instance(): + # A client may be instantiated with a custom transport instance. + transport = transports.WebRiskServiceGrpcTransport( + credentials=credentials.AnonymousCredentials(), + ) + client = WebRiskServiceClient(transport=transport) + assert client._transport is transport + + +def test_transport_get_channel(): + # A client may be instantiated with a custom transport instance. + transport = transports.WebRiskServiceGrpcTransport( + credentials=credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + transport = transports.WebRiskServiceGrpcAsyncIOTransport( + credentials=credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + +def test_transport_grpc_default(): + # A client should use the gRPC transport by default. + client = WebRiskServiceClient(credentials=credentials.AnonymousCredentials(),) + assert isinstance(client._transport, transports.WebRiskServiceGrpcTransport,) + + +def test_web_risk_service_base_transport_error(): + # Passing both a credentials object and credentials_file should raise an error + with pytest.raises(exceptions.DuplicateCredentialArgs): + transport = transports.WebRiskServiceTransport( + credentials=credentials.AnonymousCredentials(), + credentials_file="credentials.json", + ) + + +def test_web_risk_service_base_transport(): + # Instantiate the base transport. + transport = transports.WebRiskServiceTransport( + credentials=credentials.AnonymousCredentials(), + ) + + # Every method on the transport should just blindly + # raise NotImplementedError. + methods = ( + "compute_threat_list_diff", + "search_uris", + "search_hashes", + "create_submission", + ) + for method in methods: + with pytest.raises(NotImplementedError): + getattr(transport, method)(request=object()) + + +def test_web_risk_service_base_transport_with_credentials_file(): + # Instantiate the base transport with a credentials file + with mock.patch.object(auth, "load_credentials_from_file") as load_creds: + load_creds.return_value = (credentials.AnonymousCredentials(), None) + transport = transports.WebRiskServiceTransport( + credentials_file="credentials.json", + ) + load_creds.assert_called_once_with( + "credentials.json", + scopes=("https://www.googleapis.com/auth/cloud-platform",), + ) + + +def test_web_risk_service_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) + WebRiskServiceClient() + adc.assert_called_once_with( + scopes=("https://www.googleapis.com/auth/cloud-platform",) + ) + + +def test_web_risk_service_transport_auth_adc(): + # 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.WebRiskServiceGrpcTransport(host="squid.clam.whelk") + adc.assert_called_once_with( + scopes=("https://www.googleapis.com/auth/cloud-platform",) + ) + + +def test_web_risk_service_host_no_port(): + client = WebRiskServiceClient( + credentials=credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions( + api_endpoint="webrisk.googleapis.com" + ), + ) + assert client._transport._host == "webrisk.googleapis.com:443" + + +def test_web_risk_service_host_with_port(): + client = WebRiskServiceClient( + credentials=credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions( + api_endpoint="webrisk.googleapis.com:8000" + ), + ) + assert client._transport._host == "webrisk.googleapis.com:8000" + + +def test_web_risk_service_grpc_transport_channel(): + channel = grpc.insecure_channel("http://localhost/") + + # Check that if channel is provided, mtls endpoint and client_cert_source + # won't be used. + callback = mock.MagicMock() + transport = transports.WebRiskServiceGrpcTransport( + host="squid.clam.whelk", + channel=channel, + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=callback, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert not callback.called + + +def test_web_risk_service_grpc_asyncio_transport_channel(): + channel = aio.insecure_channel("http://localhost/") + + # Check that if channel is provided, mtls endpoint and client_cert_source + # won't be used. + callback = mock.MagicMock() + transport = transports.WebRiskServiceGrpcAsyncIOTransport( + host="squid.clam.whelk", + channel=channel, + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=callback, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert not callback.called + + +@mock.patch("grpc.ssl_channel_credentials", autospec=True) +@mock.patch("google.api_core.grpc_helpers.create_channel", autospec=True) +def test_web_risk_service_grpc_transport_channel_mtls_with_client_cert_source( + grpc_create_channel, grpc_ssl_channel_cred +): + # Check that if channel is None, but api_mtls_endpoint and client_cert_source + # are provided, then a mTLS channel will be created. + mock_cred = mock.Mock() + + mock_ssl_cred = mock.Mock() + grpc_ssl_channel_cred.return_value = mock_ssl_cred + + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + + transport = transports.WebRiskServiceGrpcTransport( + host="squid.clam.whelk", + credentials=mock_cred, + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=client_cert_source_callback, + ) + grpc_ssl_channel_cred.assert_called_once_with( + certificate_chain=b"cert bytes", private_key=b"key bytes" + ) + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=mock_cred, + credentials_file=None, + scopes=("https://www.googleapis.com/auth/cloud-platform",), + ssl_credentials=mock_ssl_cred, + ) + assert transport.grpc_channel == mock_grpc_channel + + +@mock.patch("grpc.ssl_channel_credentials", autospec=True) +@mock.patch("google.api_core.grpc_helpers_async.create_channel", autospec=True) +def test_web_risk_service_grpc_asyncio_transport_channel_mtls_with_client_cert_source( + grpc_create_channel, grpc_ssl_channel_cred +): + # Check that if channel is None, but api_mtls_endpoint and client_cert_source + # are provided, then a mTLS channel will be created. + mock_cred = mock.Mock() + + mock_ssl_cred = mock.Mock() + grpc_ssl_channel_cred.return_value = mock_ssl_cred + + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + + transport = transports.WebRiskServiceGrpcAsyncIOTransport( + host="squid.clam.whelk", + credentials=mock_cred, + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=client_cert_source_callback, + ) + grpc_ssl_channel_cred.assert_called_once_with( + certificate_chain=b"cert bytes", private_key=b"key bytes" + ) + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=mock_cred, + credentials_file=None, + scopes=("https://www.googleapis.com/auth/cloud-platform",), + ssl_credentials=mock_ssl_cred, + ) + assert transport.grpc_channel == mock_grpc_channel + + +@pytest.mark.parametrize( + "api_mtls_endpoint", ["mtls.squid.clam.whelk", "mtls.squid.clam.whelk:443"] +) +@mock.patch("google.api_core.grpc_helpers.create_channel", autospec=True) +def test_web_risk_service_grpc_transport_channel_mtls_with_adc( + grpc_create_channel, api_mtls_endpoint +): + # Check that if channel and client_cert_source are None, but api_mtls_endpoint + # is provided, then a mTLS channel will be created with SSL ADC. + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + + # Mock google.auth.transport.grpc.SslCredentials class. + mock_ssl_cred = mock.Mock() + with mock.patch.multiple( + "google.auth.transport.grpc.SslCredentials", + __init__=mock.Mock(return_value=None), + ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), + ): + mock_cred = mock.Mock() + transport = transports.WebRiskServiceGrpcTransport( + host="squid.clam.whelk", + credentials=mock_cred, + api_mtls_endpoint=api_mtls_endpoint, + client_cert_source=None, + ) + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=mock_cred, + credentials_file=None, + scopes=("https://www.googleapis.com/auth/cloud-platform",), + ssl_credentials=mock_ssl_cred, + ) + assert transport.grpc_channel == mock_grpc_channel + + +@pytest.mark.parametrize( + "api_mtls_endpoint", ["mtls.squid.clam.whelk", "mtls.squid.clam.whelk:443"] +) +@mock.patch("google.api_core.grpc_helpers_async.create_channel", autospec=True) +def test_web_risk_service_grpc_asyncio_transport_channel_mtls_with_adc( + grpc_create_channel, api_mtls_endpoint +): + # Check that if channel and client_cert_source are None, but api_mtls_endpoint + # is provided, then a mTLS channel will be created with SSL ADC. + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + + # Mock google.auth.transport.grpc.SslCredentials class. + mock_ssl_cred = mock.Mock() + with mock.patch.multiple( + "google.auth.transport.grpc.SslCredentials", + __init__=mock.Mock(return_value=None), + ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), + ): + mock_cred = mock.Mock() + transport = transports.WebRiskServiceGrpcAsyncIOTransport( + host="squid.clam.whelk", + credentials=mock_cred, + api_mtls_endpoint=api_mtls_endpoint, + client_cert_source=None, + ) + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=mock_cred, + credentials_file=None, + scopes=("https://www.googleapis.com/auth/cloud-platform",), + ssl_credentials=mock_ssl_cred, + ) + assert transport.grpc_channel == mock_grpc_channel diff --git a/google/cloud/webrisk_v1/gapic/transports/__init__.py b/tests/unit/gapic/webrisk_v1beta1/__init__.py similarity index 100% rename from google/cloud/webrisk_v1/gapic/transports/__init__.py rename to tests/unit/gapic/webrisk_v1beta1/__init__.py diff --git a/tests/unit/gapic/webrisk_v1beta1/test_web_risk_service_v1_beta1.py b/tests/unit/gapic/webrisk_v1beta1/test_web_risk_service_v1_beta1.py new file mode 100644 index 0000000..4840ecd --- /dev/null +++ b/tests/unit/gapic/webrisk_v1beta1/test_web_risk_service_v1_beta1.py @@ -0,0 +1,1111 @@ +# -*- 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. +# + +import os +import mock + +import grpc +from grpc.experimental import aio +import math +import pytest + +from google import auth +from google.api_core import client_options +from google.api_core import exceptions +from google.api_core import grpc_helpers +from google.api_core import grpc_helpers_async +from google.auth import credentials +from google.auth.exceptions import MutualTLSChannelError +from google.cloud.webrisk_v1beta1.services.web_risk_service_v1_beta1 import ( + WebRiskServiceV1Beta1AsyncClient, +) +from google.cloud.webrisk_v1beta1.services.web_risk_service_v1_beta1 import ( + WebRiskServiceV1Beta1Client, +) +from google.cloud.webrisk_v1beta1.services.web_risk_service_v1_beta1 import transports +from google.cloud.webrisk_v1beta1.types import webrisk +from google.oauth2 import service_account +from google.protobuf import timestamp_pb2 as timestamp # type: ignore + + +def client_cert_source_callback(): + return b"cert bytes", b"key bytes" + + +def test__get_default_mtls_endpoint(): + api_endpoint = "example.googleapis.com" + api_mtls_endpoint = "example.mtls.googleapis.com" + sandbox_endpoint = "example.sandbox.googleapis.com" + sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" + non_googleapi = "api.example.com" + + assert WebRiskServiceV1Beta1Client._get_default_mtls_endpoint(None) is None + assert ( + WebRiskServiceV1Beta1Client._get_default_mtls_endpoint(api_endpoint) + == api_mtls_endpoint + ) + assert ( + WebRiskServiceV1Beta1Client._get_default_mtls_endpoint(api_mtls_endpoint) + == api_mtls_endpoint + ) + assert ( + WebRiskServiceV1Beta1Client._get_default_mtls_endpoint(sandbox_endpoint) + == sandbox_mtls_endpoint + ) + assert ( + WebRiskServiceV1Beta1Client._get_default_mtls_endpoint(sandbox_mtls_endpoint) + == sandbox_mtls_endpoint + ) + assert ( + WebRiskServiceV1Beta1Client._get_default_mtls_endpoint(non_googleapi) + == non_googleapi + ) + + +@pytest.mark.parametrize( + "client_class", [WebRiskServiceV1Beta1Client, WebRiskServiceV1Beta1AsyncClient] +) +def test_web_risk_service_v1_beta1_client_from_service_account_file(client_class): + creds = credentials.AnonymousCredentials() + with mock.patch.object( + service_account.Credentials, "from_service_account_file" + ) as factory: + factory.return_value = creds + client = client_class.from_service_account_file("dummy/file/path.json") + assert client._transport._credentials == creds + + client = client_class.from_service_account_json("dummy/file/path.json") + assert client._transport._credentials == creds + + assert client._transport._host == "webrisk.googleapis.com:443" + + +def test_web_risk_service_v1_beta1_client_get_transport_class(): + transport = WebRiskServiceV1Beta1Client.get_transport_class() + assert transport == transports.WebRiskServiceV1Beta1GrpcTransport + + transport = WebRiskServiceV1Beta1Client.get_transport_class("grpc") + assert transport == transports.WebRiskServiceV1Beta1GrpcTransport + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + ( + WebRiskServiceV1Beta1Client, + transports.WebRiskServiceV1Beta1GrpcTransport, + "grpc", + ), + ( + WebRiskServiceV1Beta1AsyncClient, + transports.WebRiskServiceV1Beta1GrpcAsyncIOTransport, + "grpc_asyncio", + ), + ], +) +def test_web_risk_service_v1_beta1_client_client_options( + client_class, transport_class, transport_name +): + # Check that if channel is provided we won't create a new one. + with mock.patch.object(WebRiskServiceV1Beta1Client, "get_transport_class") as gtc: + transport = transport_class(credentials=credentials.AnonymousCredentials()) + client = client_class(transport=transport) + gtc.assert_not_called() + + # Check that if channel is provided via str we will create a new one. + with mock.patch.object(WebRiskServiceV1Beta1Client, "get_transport_class") as gtc: + client = client_class(transport=transport_name) + gtc.assert_called() + + # Check the case api_endpoint is provided. + options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host="squid.clam.whelk", + scopes=None, + api_mtls_endpoint="squid.clam.whelk", + client_cert_source=None, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS is + # "never". + os.environ["GOOGLE_API_USE_MTLS"] = "never" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class() + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + api_mtls_endpoint=client.DEFAULT_ENDPOINT, + client_cert_source=None, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS is + # "always". + os.environ["GOOGLE_API_USE_MTLS"] = "always" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class() + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_MTLS_ENDPOINT, + scopes=None, + api_mtls_endpoint=client.DEFAULT_MTLS_ENDPOINT, + client_cert_source=None, + ) + + # Check the case api_endpoint is not provided, GOOGLE_API_USE_MTLS is + # "auto", and client_cert_source is provided. + os.environ["GOOGLE_API_USE_MTLS"] = "auto" + options = client_options.ClientOptions( + client_cert_source=client_cert_source_callback + ) + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_MTLS_ENDPOINT, + scopes=None, + api_mtls_endpoint=client.DEFAULT_MTLS_ENDPOINT, + client_cert_source=client_cert_source_callback, + ) + + # Check the case api_endpoint is not provided, GOOGLE_API_USE_MTLS is + # "auto", and default_client_cert_source is provided. + os.environ["GOOGLE_API_USE_MTLS"] = "auto" + with mock.patch.object(transport_class, "__init__") as patched: + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + patched.return_value = None + client = client_class() + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_MTLS_ENDPOINT, + scopes=None, + api_mtls_endpoint=client.DEFAULT_MTLS_ENDPOINT, + client_cert_source=None, + ) + + # Check the case api_endpoint is not provided, GOOGLE_API_USE_MTLS is + # "auto", but client_cert_source and default_client_cert_source are None. + os.environ["GOOGLE_API_USE_MTLS"] = "auto" + with mock.patch.object(transport_class, "__init__") as patched: + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + patched.return_value = None + client = client_class() + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + api_mtls_endpoint=client.DEFAULT_ENDPOINT, + client_cert_source=None, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS has + # unsupported value. + os.environ["GOOGLE_API_USE_MTLS"] = "Unsupported" + with pytest.raises(MutualTLSChannelError): + client = client_class() + + del os.environ["GOOGLE_API_USE_MTLS"] + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + ( + WebRiskServiceV1Beta1Client, + transports.WebRiskServiceV1Beta1GrpcTransport, + "grpc", + ), + ( + WebRiskServiceV1Beta1AsyncClient, + transports.WebRiskServiceV1Beta1GrpcAsyncIOTransport, + "grpc_asyncio", + ), + ], +) +def test_web_risk_service_v1_beta1_client_client_options_scopes( + client_class, transport_class, transport_name +): + # Check the case scopes are provided. + options = client_options.ClientOptions(scopes=["1", "2"],) + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=["1", "2"], + api_mtls_endpoint=client.DEFAULT_ENDPOINT, + client_cert_source=None, + ) + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + ( + WebRiskServiceV1Beta1Client, + transports.WebRiskServiceV1Beta1GrpcTransport, + "grpc", + ), + ( + WebRiskServiceV1Beta1AsyncClient, + transports.WebRiskServiceV1Beta1GrpcAsyncIOTransport, + "grpc_asyncio", + ), + ], +) +def test_web_risk_service_v1_beta1_client_client_options_credentials_file( + client_class, transport_class, transport_name +): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + api_mtls_endpoint=client.DEFAULT_ENDPOINT, + client_cert_source=None, + ) + + +def test_web_risk_service_v1_beta1_client_client_options_from_dict(): + with mock.patch( + "google.cloud.webrisk_v1beta1.services.web_risk_service_v1_beta1.transports.WebRiskServiceV1Beta1GrpcTransport.__init__" + ) as grpc_transport: + grpc_transport.return_value = None + client = WebRiskServiceV1Beta1Client( + client_options={"api_endpoint": "squid.clam.whelk"} + ) + grpc_transport.assert_called_once_with( + credentials=None, + credentials_file=None, + host="squid.clam.whelk", + scopes=None, + api_mtls_endpoint="squid.clam.whelk", + client_cert_source=None, + ) + + +def test_compute_threat_list_diff(transport: str = "grpc"): + client = WebRiskServiceV1Beta1Client( + credentials=credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = webrisk.ComputeThreatListDiffRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client._transport.compute_threat_list_diff), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = webrisk.ComputeThreatListDiffResponse( + response_type=webrisk.ComputeThreatListDiffResponse.ResponseType.DIFF, + new_version_token=b"new_version_token_blob", + ) + + response = client.compute_threat_list_diff(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, webrisk.ComputeThreatListDiffResponse) + + assert ( + response.response_type + == webrisk.ComputeThreatListDiffResponse.ResponseType.DIFF + ) + + assert response.new_version_token == b"new_version_token_blob" + + +@pytest.mark.asyncio +async def test_compute_threat_list_diff_async(transport: str = "grpc_asyncio"): + client = WebRiskServiceV1Beta1AsyncClient( + credentials=credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = webrisk.ComputeThreatListDiffRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client._client._transport.compute_threat_list_diff), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + webrisk.ComputeThreatListDiffResponse( + response_type=webrisk.ComputeThreatListDiffResponse.ResponseType.DIFF, + new_version_token=b"new_version_token_blob", + ) + ) + + response = await client.compute_threat_list_diff(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, webrisk.ComputeThreatListDiffResponse) + + assert ( + response.response_type + == webrisk.ComputeThreatListDiffResponse.ResponseType.DIFF + ) + + assert response.new_version_token == b"new_version_token_blob" + + +def test_compute_threat_list_diff_flattened(): + client = WebRiskServiceV1Beta1Client( + credentials=credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client._transport.compute_threat_list_diff), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = webrisk.ComputeThreatListDiffResponse() + + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.compute_threat_list_diff( + threat_type=webrisk.ThreatType.MALWARE, + version_token=b"version_token_blob", + constraints=webrisk.ComputeThreatListDiffRequest.Constraints( + max_diff_entries=1687 + ), + ) + + # 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].threat_type == webrisk.ThreatType.MALWARE + assert args[0].version_token == b"version_token_blob" + assert args[0].constraints == webrisk.ComputeThreatListDiffRequest.Constraints( + max_diff_entries=1687 + ) + + +def test_compute_threat_list_diff_flattened_error(): + client = WebRiskServiceV1Beta1Client( + credentials=credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.compute_threat_list_diff( + webrisk.ComputeThreatListDiffRequest(), + threat_type=webrisk.ThreatType.MALWARE, + version_token=b"version_token_blob", + constraints=webrisk.ComputeThreatListDiffRequest.Constraints( + max_diff_entries=1687 + ), + ) + + +@pytest.mark.asyncio +async def test_compute_threat_list_diff_flattened_async(): + client = WebRiskServiceV1Beta1AsyncClient( + credentials=credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client._client._transport.compute_threat_list_diff), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = webrisk.ComputeThreatListDiffResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + webrisk.ComputeThreatListDiffResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.compute_threat_list_diff( + threat_type=webrisk.ThreatType.MALWARE, + version_token=b"version_token_blob", + constraints=webrisk.ComputeThreatListDiffRequest.Constraints( + max_diff_entries=1687 + ), + ) + + # 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].threat_type == webrisk.ThreatType.MALWARE + assert args[0].version_token == b"version_token_blob" + assert args[0].constraints == webrisk.ComputeThreatListDiffRequest.Constraints( + max_diff_entries=1687 + ) + + +@pytest.mark.asyncio +async def test_compute_threat_list_diff_flattened_error_async(): + client = WebRiskServiceV1Beta1AsyncClient( + credentials=credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.compute_threat_list_diff( + webrisk.ComputeThreatListDiffRequest(), + threat_type=webrisk.ThreatType.MALWARE, + version_token=b"version_token_blob", + constraints=webrisk.ComputeThreatListDiffRequest.Constraints( + max_diff_entries=1687 + ), + ) + + +def test_search_uris(transport: str = "grpc"): + client = WebRiskServiceV1Beta1Client( + credentials=credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = webrisk.SearchUrisRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client._transport.search_uris), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = webrisk.SearchUrisResponse() + + response = client.search_uris(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, webrisk.SearchUrisResponse) + + +@pytest.mark.asyncio +async def test_search_uris_async(transport: str = "grpc_asyncio"): + client = WebRiskServiceV1Beta1AsyncClient( + credentials=credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = webrisk.SearchUrisRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client._client._transport.search_uris), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + webrisk.SearchUrisResponse() + ) + + response = await client.search_uris(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, webrisk.SearchUrisResponse) + + +def test_search_uris_flattened(): + client = WebRiskServiceV1Beta1Client( + credentials=credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client._transport.search_uris), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = webrisk.SearchUrisResponse() + + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.search_uris( + uri="uri_value", threat_types=[webrisk.ThreatType.MALWARE], + ) + + # 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].uri == "uri_value" + assert args[0].threat_types == [webrisk.ThreatType.MALWARE] + + +def test_search_uris_flattened_error(): + client = WebRiskServiceV1Beta1Client( + credentials=credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.search_uris( + webrisk.SearchUrisRequest(), + uri="uri_value", + threat_types=[webrisk.ThreatType.MALWARE], + ) + + +@pytest.mark.asyncio +async def test_search_uris_flattened_async(): + client = WebRiskServiceV1Beta1AsyncClient( + credentials=credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client._client._transport.search_uris), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = webrisk.SearchUrisResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + webrisk.SearchUrisResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.search_uris( + uri="uri_value", threat_types=[webrisk.ThreatType.MALWARE], + ) + + # 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].uri == "uri_value" + assert args[0].threat_types == [webrisk.ThreatType.MALWARE] + + +@pytest.mark.asyncio +async def test_search_uris_flattened_error_async(): + client = WebRiskServiceV1Beta1AsyncClient( + credentials=credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.search_uris( + webrisk.SearchUrisRequest(), + uri="uri_value", + threat_types=[webrisk.ThreatType.MALWARE], + ) + + +def test_search_hashes(transport: str = "grpc"): + client = WebRiskServiceV1Beta1Client( + credentials=credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = webrisk.SearchHashesRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client._transport.search_hashes), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = webrisk.SearchHashesResponse() + + response = client.search_hashes(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, webrisk.SearchHashesResponse) + + +@pytest.mark.asyncio +async def test_search_hashes_async(transport: str = "grpc_asyncio"): + client = WebRiskServiceV1Beta1AsyncClient( + credentials=credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = webrisk.SearchHashesRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client._client._transport.search_hashes), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + webrisk.SearchHashesResponse() + ) + + response = await client.search_hashes(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, webrisk.SearchHashesResponse) + + +def test_search_hashes_flattened(): + client = WebRiskServiceV1Beta1Client( + credentials=credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client._transport.search_hashes), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = webrisk.SearchHashesResponse() + + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.search_hashes( + hash_prefix=b"hash_prefix_blob", threat_types=[webrisk.ThreatType.MALWARE], + ) + + # 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].hash_prefix == b"hash_prefix_blob" + assert args[0].threat_types == [webrisk.ThreatType.MALWARE] + + +def test_search_hashes_flattened_error(): + client = WebRiskServiceV1Beta1Client( + credentials=credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.search_hashes( + webrisk.SearchHashesRequest(), + hash_prefix=b"hash_prefix_blob", + threat_types=[webrisk.ThreatType.MALWARE], + ) + + +@pytest.mark.asyncio +async def test_search_hashes_flattened_async(): + client = WebRiskServiceV1Beta1AsyncClient( + credentials=credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client._client._transport.search_hashes), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = webrisk.SearchHashesResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + webrisk.SearchHashesResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.search_hashes( + hash_prefix=b"hash_prefix_blob", threat_types=[webrisk.ThreatType.MALWARE], + ) + + # 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].hash_prefix == b"hash_prefix_blob" + assert args[0].threat_types == [webrisk.ThreatType.MALWARE] + + +@pytest.mark.asyncio +async def test_search_hashes_flattened_error_async(): + client = WebRiskServiceV1Beta1AsyncClient( + credentials=credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.search_hashes( + webrisk.SearchHashesRequest(), + hash_prefix=b"hash_prefix_blob", + threat_types=[webrisk.ThreatType.MALWARE], + ) + + +def test_credentials_transport_error(): + # It is an error to provide credentials and a transport instance. + transport = transports.WebRiskServiceV1Beta1GrpcTransport( + credentials=credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = WebRiskServiceV1Beta1Client( + credentials=credentials.AnonymousCredentials(), transport=transport, + ) + + # It is an error to provide a credentials file and a transport instance. + transport = transports.WebRiskServiceV1Beta1GrpcTransport( + credentials=credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = WebRiskServiceV1Beta1Client( + client_options={"credentials_file": "credentials.json"}, + transport=transport, + ) + + # It is an error to provide scopes and a transport instance. + transport = transports.WebRiskServiceV1Beta1GrpcTransport( + credentials=credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = WebRiskServiceV1Beta1Client( + client_options={"scopes": ["1", "2"]}, transport=transport, + ) + + +def test_transport_instance(): + # A client may be instantiated with a custom transport instance. + transport = transports.WebRiskServiceV1Beta1GrpcTransport( + credentials=credentials.AnonymousCredentials(), + ) + client = WebRiskServiceV1Beta1Client(transport=transport) + assert client._transport is transport + + +def test_transport_get_channel(): + # A client may be instantiated with a custom transport instance. + transport = transports.WebRiskServiceV1Beta1GrpcTransport( + credentials=credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + transport = transports.WebRiskServiceV1Beta1GrpcAsyncIOTransport( + credentials=credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + +def test_transport_grpc_default(): + # A client should use the gRPC transport by default. + client = WebRiskServiceV1Beta1Client( + credentials=credentials.AnonymousCredentials(), + ) + assert isinstance(client._transport, transports.WebRiskServiceV1Beta1GrpcTransport,) + + +def test_web_risk_service_v1_beta1_base_transport_error(): + # Passing both a credentials object and credentials_file should raise an error + with pytest.raises(exceptions.DuplicateCredentialArgs): + transport = transports.WebRiskServiceV1Beta1Transport( + credentials=credentials.AnonymousCredentials(), + credentials_file="credentials.json", + ) + + +def test_web_risk_service_v1_beta1_base_transport(): + # Instantiate the base transport. + transport = transports.WebRiskServiceV1Beta1Transport( + credentials=credentials.AnonymousCredentials(), + ) + + # Every method on the transport should just blindly + # raise NotImplementedError. + methods = ( + "compute_threat_list_diff", + "search_uris", + "search_hashes", + ) + for method in methods: + with pytest.raises(NotImplementedError): + getattr(transport, method)(request=object()) + + +def test_web_risk_service_v1_beta1_base_transport_with_credentials_file(): + # Instantiate the base transport with a credentials file + with mock.patch.object(auth, "load_credentials_from_file") as load_creds: + load_creds.return_value = (credentials.AnonymousCredentials(), None) + transport = transports.WebRiskServiceV1Beta1Transport( + credentials_file="credentials.json", + ) + load_creds.assert_called_once_with( + "credentials.json", + scopes=("https://www.googleapis.com/auth/cloud-platform",), + ) + + +def test_web_risk_service_v1_beta1_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) + WebRiskServiceV1Beta1Client() + adc.assert_called_once_with( + scopes=("https://www.googleapis.com/auth/cloud-platform",) + ) + + +def test_web_risk_service_v1_beta1_transport_auth_adc(): + # 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.WebRiskServiceV1Beta1GrpcTransport(host="squid.clam.whelk") + adc.assert_called_once_with( + scopes=("https://www.googleapis.com/auth/cloud-platform",) + ) + + +def test_web_risk_service_v1_beta1_host_no_port(): + client = WebRiskServiceV1Beta1Client( + credentials=credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions( + api_endpoint="webrisk.googleapis.com" + ), + ) + assert client._transport._host == "webrisk.googleapis.com:443" + + +def test_web_risk_service_v1_beta1_host_with_port(): + client = WebRiskServiceV1Beta1Client( + credentials=credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions( + api_endpoint="webrisk.googleapis.com:8000" + ), + ) + assert client._transport._host == "webrisk.googleapis.com:8000" + + +def test_web_risk_service_v1_beta1_grpc_transport_channel(): + channel = grpc.insecure_channel("http://localhost/") + + # Check that if channel is provided, mtls endpoint and client_cert_source + # won't be used. + callback = mock.MagicMock() + transport = transports.WebRiskServiceV1Beta1GrpcTransport( + host="squid.clam.whelk", + channel=channel, + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=callback, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert not callback.called + + +def test_web_risk_service_v1_beta1_grpc_asyncio_transport_channel(): + channel = aio.insecure_channel("http://localhost/") + + # Check that if channel is provided, mtls endpoint and client_cert_source + # won't be used. + callback = mock.MagicMock() + transport = transports.WebRiskServiceV1Beta1GrpcAsyncIOTransport( + host="squid.clam.whelk", + channel=channel, + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=callback, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert not callback.called + + +@mock.patch("grpc.ssl_channel_credentials", autospec=True) +@mock.patch("google.api_core.grpc_helpers.create_channel", autospec=True) +def test_web_risk_service_v1_beta1_grpc_transport_channel_mtls_with_client_cert_source( + grpc_create_channel, grpc_ssl_channel_cred +): + # Check that if channel is None, but api_mtls_endpoint and client_cert_source + # are provided, then a mTLS channel will be created. + mock_cred = mock.Mock() + + mock_ssl_cred = mock.Mock() + grpc_ssl_channel_cred.return_value = mock_ssl_cred + + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + + transport = transports.WebRiskServiceV1Beta1GrpcTransport( + host="squid.clam.whelk", + credentials=mock_cred, + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=client_cert_source_callback, + ) + grpc_ssl_channel_cred.assert_called_once_with( + certificate_chain=b"cert bytes", private_key=b"key bytes" + ) + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=mock_cred, + credentials_file=None, + scopes=("https://www.googleapis.com/auth/cloud-platform",), + ssl_credentials=mock_ssl_cred, + ) + assert transport.grpc_channel == mock_grpc_channel + + +@mock.patch("grpc.ssl_channel_credentials", autospec=True) +@mock.patch("google.api_core.grpc_helpers_async.create_channel", autospec=True) +def test_web_risk_service_v1_beta1_grpc_asyncio_transport_channel_mtls_with_client_cert_source( + grpc_create_channel, grpc_ssl_channel_cred +): + # Check that if channel is None, but api_mtls_endpoint and client_cert_source + # are provided, then a mTLS channel will be created. + mock_cred = mock.Mock() + + mock_ssl_cred = mock.Mock() + grpc_ssl_channel_cred.return_value = mock_ssl_cred + + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + + transport = transports.WebRiskServiceV1Beta1GrpcAsyncIOTransport( + host="squid.clam.whelk", + credentials=mock_cred, + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=client_cert_source_callback, + ) + grpc_ssl_channel_cred.assert_called_once_with( + certificate_chain=b"cert bytes", private_key=b"key bytes" + ) + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=mock_cred, + credentials_file=None, + scopes=("https://www.googleapis.com/auth/cloud-platform",), + ssl_credentials=mock_ssl_cred, + ) + assert transport.grpc_channel == mock_grpc_channel + + +@pytest.mark.parametrize( + "api_mtls_endpoint", ["mtls.squid.clam.whelk", "mtls.squid.clam.whelk:443"] +) +@mock.patch("google.api_core.grpc_helpers.create_channel", autospec=True) +def test_web_risk_service_v1_beta1_grpc_transport_channel_mtls_with_adc( + grpc_create_channel, api_mtls_endpoint +): + # Check that if channel and client_cert_source are None, but api_mtls_endpoint + # is provided, then a mTLS channel will be created with SSL ADC. + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + + # Mock google.auth.transport.grpc.SslCredentials class. + mock_ssl_cred = mock.Mock() + with mock.patch.multiple( + "google.auth.transport.grpc.SslCredentials", + __init__=mock.Mock(return_value=None), + ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), + ): + mock_cred = mock.Mock() + transport = transports.WebRiskServiceV1Beta1GrpcTransport( + host="squid.clam.whelk", + credentials=mock_cred, + api_mtls_endpoint=api_mtls_endpoint, + client_cert_source=None, + ) + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=mock_cred, + credentials_file=None, + scopes=("https://www.googleapis.com/auth/cloud-platform",), + ssl_credentials=mock_ssl_cred, + ) + assert transport.grpc_channel == mock_grpc_channel + + +@pytest.mark.parametrize( + "api_mtls_endpoint", ["mtls.squid.clam.whelk", "mtls.squid.clam.whelk:443"] +) +@mock.patch("google.api_core.grpc_helpers_async.create_channel", autospec=True) +def test_web_risk_service_v1_beta1_grpc_asyncio_transport_channel_mtls_with_adc( + grpc_create_channel, api_mtls_endpoint +): + # Check that if channel and client_cert_source are None, but api_mtls_endpoint + # is provided, then a mTLS channel will be created with SSL ADC. + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + + # Mock google.auth.transport.grpc.SslCredentials class. + mock_ssl_cred = mock.Mock() + with mock.patch.multiple( + "google.auth.transport.grpc.SslCredentials", + __init__=mock.Mock(return_value=None), + ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), + ): + mock_cred = mock.Mock() + transport = transports.WebRiskServiceV1Beta1GrpcAsyncIOTransport( + host="squid.clam.whelk", + credentials=mock_cred, + api_mtls_endpoint=api_mtls_endpoint, + client_cert_source=None, + ) + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=mock_cred, + credentials_file=None, + scopes=("https://www.googleapis.com/auth/cloud-platform",), + ssl_credentials=mock_ssl_cred, + ) + assert transport.grpc_channel == mock_grpc_channel