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

Commit bbd2adf

Browse files
feat!: move to webrisk API to python microgenerator (#27)
1 parent c06d191 commit bbd2adf

70 files changed

Lines changed: 7347 additions & 5997 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.coveragerc‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ omit =
3232
*/gapic/*.py
3333
*/proto/*.py
3434
*/core/*.py
35-
*/site-packages/*.py
35+
*/site-packages/*.py
36+
google/cloud/webrisk/__init__.py

‎UPGRADING.MD‎

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# 2.0.0 Migration Guide
2+
3+
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.
4+
5+
If you experience issues or have questions, please file an [issue](https://github.com/googleapis/python-webrisk/issues).
6+
7+
## Supported Python Versions
8+
9+
> **WARNING**: Breaking change
10+
11+
The 2.0.0 release requires Python 3.6+.
12+
13+
14+
## Method Calls
15+
16+
> **WARNING**: Breaking change
17+
18+
Methods expect request objects. We provide a script that will convert most common use cases.
19+
20+
* Install the library
21+
22+
```py
23+
python3 -m pip install google-cloud-webrisk
24+
```
25+
26+
* The scripts `fixup_webrisk_v1_keywords.py` and `fixup_webrisk_v1beta1_keywords.py` shipped with the library. It expects
27+
an input directory (with the code to convert) and an empty destination directory.
28+
29+
```sh
30+
$ fixup_webrisk_v1_keywords.py --input-directory .samples/ --output-directory samples/
31+
```
32+
33+
**Before:**
34+
```py
35+
from google.cloud import webrisk_v1
36+
37+
client = webrisk_v1.WebRiskServiceClient()
38+
# TODO: Initialize `threat_types`:
39+
threat_types = []
40+
41+
response = client.search_hashes(threat_types)
42+
```
43+
44+
45+
**After:**
46+
```py
47+
from google.cloud import webrisk_v1
48+
49+
client = webrisk_v1.WebRiskServiceClient()
50+
51+
response = client.search_hashes(request={"threat_types": "[]"})
52+
53+
```
54+
55+
### More Details
56+
57+
In `google-cloud-webrisk<2.0.0`, parameters required by the API were positional parameters and optional parameters were keyword parameters.
58+
59+
**Before:**
60+
```py
61+
def search_hashes(
62+
self,
63+
threat_types,
64+
hash_prefix=None,
65+
retry=google.api_core.gapic_v1.method.DEFAULT,
66+
timeout=google.api_core.gapic_v1.method.DEFAULT,
67+
metadata=None,
68+
):
69+
```
70+
71+
In the 2.0.0 release, all methods have a single positional parameter `request`. Method docstrings indicate whether a parameter is required or optional.
72+
73+
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.
74+
75+
76+
**After:**
77+
```py
78+
def search_hashes(
79+
self,
80+
request: webrisk.SearchHashesRequest = None,
81+
*,
82+
hash_prefix: bytes = None,
83+
threat_types: Sequence[webrisk.ThreatType] = None,
84+
retry: retries.Retry = gapic_v1.method.DEFAULT,
85+
timeout: float = None,
86+
metadata: Sequence[Tuple[str, str]] = (),
87+
) -> webrisk.SearchHashesResponse:
88+
```
89+
90+
> **NOTE:** The `request` parameter and flattened keyword parameters for the API are mutually exclusive.
91+
> Passing both will result in an error.
92+
93+
94+
Both of these calls are valid:
95+
96+
```py
97+
response = client.search_hashes(
98+
request={
99+
"hash_prefix": hash_prefix,
100+
"threat_types": threat_types,
101+
}
102+
)
103+
```
104+
105+
```py
106+
response = client.search_hashes(
107+
hash_prefix=hash_prefix,
108+
threat_types=threat_types,
109+
)
110+
```
111+
112+
This call is invalid because it mixes `request` with a keyword argument `threat_types`. Executing this code
113+
will result in an error.
114+
115+
```py
116+
response = client.synthesize_speech(
117+
request={
118+
"hash_prefix": hash_prefix,
119+
},
120+
threat_types=threat_types
121+
)
122+
```

‎docs/gapic/v1/api.rst‎

Lines changed: 0 additions & 6 deletions
This file was deleted.

‎docs/gapic/v1/types.rst‎

Lines changed: 0 additions & 5 deletions
This file was deleted.

‎docs/gapic/v1beta1/api.rst‎

Lines changed: 0 additions & 6 deletions
This file was deleted.

‎docs/gapic/v1beta1/types.rst‎

Lines changed: 0 additions & 5 deletions
This file was deleted.

‎docs/index.rst‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ v1
77
.. toctree::
88
:maxdepth: 2
99

10-
gapic/v1/api
11-
gapic/v1/types
10+
webrisk_v1/services
11+
webrisk_v1/types
1212

1313

1414
v1beta1
1515
-------------
1616
.. toctree::
1717
:maxdepth: 2
1818

19-
gapic/v1beta1/api
20-
gapic/v1beta1/types
19+
webrisk_v1beta1/services
20+
webrisk_v1beta1/types
2121
changelog
2222

2323
Changelog

‎docs/webrisk_v1/services.rst‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Services for Google Cloud Webrisk v1 API
2+
========================================
3+
4+
.. automodule:: google.cloud.webrisk_v1.services.web_risk_service
5+
:members:
6+
:inherited-members:

‎docs/webrisk_v1/types.rst‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Types for Google Cloud Webrisk v1 API
2+
=====================================
3+
4+
.. automodule:: google.cloud.webrisk_v1.types
5+
:members:

‎docs/webrisk_v1beta1/services.rst‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Services for Google Cloud Webrisk v1beta1 API
2+
=============================================
3+
4+
.. automodule:: google.cloud.webrisk_v1beta1.services.web_risk_service_v1_beta1
5+
:members:
6+
:inherited-members:

0 commit comments

Comments
 (0)