This repository has been archived by the owner on Sep 5, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: move to webrisk API to python microgenerator (#27)
- Loading branch information
1 parent
c06d191
commit bbd2adf
Showing
70 changed files
with
7,347 additions
and
5,997 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
) | ||
``` |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Services for Google Cloud Webrisk v1 API | ||
======================================== | ||
|
||
.. automodule:: google.cloud.webrisk_v1.services.web_risk_service | ||
:members: | ||
:inherited-members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Types for Google Cloud Webrisk v1 API | ||
===================================== | ||
|
||
.. automodule:: google.cloud.webrisk_v1.types | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Types for Google Cloud Webrisk v1beta1 API | ||
========================================== | ||
|
||
.. automodule:: google.cloud.webrisk_v1beta1.types | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Marker file for PEP 561. | ||
# The google-cloud-webrisk package uses inline types. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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", | ||
) |
Oops, something went wrong.