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

Commit

Permalink
feat: add common resource helpers; expose client transport; remove gR…
Browse files Browse the repository at this point in the history
…PC send/recv limits (#40)

* changes without context

        autosynth cannot find the source of changes triggered by earlier changes in this
        repository, or by version upgrades to tools such as linters.

* chore: use gapic-generator-python 0.28.1

Also re-adds the grpc_service_config to all the Python libraries that have been moved to the microgenerator.

PiperOrigin-RevId: 321807443

Source-Author: Google APIs <noreply@google.com>
Source-Date: Fri Jul 17 10:39:39 2020 -0700
Source-Repo: googleapis/googleapis
Source-Sha: abb30a02aa8583950595ca92b6fb4a3c2a3e9f03
Source-Link: googleapis/googleapis@abb30a0

* fix: Fix Java and PHP bazel builds on Mac

Specifically it should resolve the broken tar.gz archives issue on mac.

PiperOrigin-RevId: 321904251

Source-Author: Google APIs <noreply@google.com>
Source-Date: Fri Jul 17 20:57:58 2020 -0700
Source-Repo: googleapis/googleapis
Source-Sha: 5340d28e386f4a70b6e9da146858b3f129b790a7
Source-Link: googleapis/googleapis@5340d28

* fix!: Remove fields for un-available feature.

PiperOrigin-RevId: 322174882

Source-Author: Google APIs <noreply@google.com>
Source-Date: Mon Jul 20 10:35:53 2020 -0700
Source-Repo: googleapis/googleapis
Source-Sha: 4ceb9b6ff45b5665d85a164cc59941e17f827d85
Source-Link: googleapis/googleapis@4ceb9b6

* chore: upgrade to gapic-generator-python v0.29.0

Also enables the 'add-iam-method' option for KMS and Pub/Sub.

https://github.com/googleapis/gapic-generator-python/releases/tag/v0.29.0

PiperOrigin-RevId: 322659285

Source-Author: Google APIs <noreply@google.com>
Source-Date: Wed Jul 22 14:44:27 2020 -0700
Source-Repo: googleapis/googleapis
Source-Sha: 5d0eacc7ba0d9199ef1fcd7c542dd4b53949c285
Source-Link: googleapis/googleapis@5d0eacc

* chore: upgrade to gapic-generator-python 0.29.1

PiperOrigin-RevId: 322700241

Source-Author: Google APIs <noreply@google.com>
Source-Date: Wed Jul 22 18:41:34 2020 -0700
Source-Repo: googleapis/googleapis
Source-Sha: a1c9dba23852947c0232f7c13dd1e92108f92153
Source-Link: googleapis/googleapis@a1c9dba

* chore: migrate securitycenter to python microgenerator

PiperOrigin-RevId: 323472217

Source-Author: Google APIs <noreply@google.com>
Source-Date: Mon Jul 27 17:03:43 2020 -0700
Source-Repo: googleapis/googleapis
Source-Sha: 6a813acf535e4746fa4a135ce23547bb6425c26d
Source-Link: googleapis/googleapis@6a813ac

* Add/correct PHP namespace for BigQuery connection/reservation

PiperOrigin-RevId: 323605868

Source-Author: Google APIs <noreply@google.com>
Source-Date: Tue Jul 28 10:47:24 2020 -0700
Source-Repo: googleapis/googleapis
Source-Sha: 0c6a73081373ff3ff3d470efe554f2f1efd64041
Source-Link: googleapis/googleapis@0c6a730

* chore: upgrade to gapic-generator-python 0.30.0

PiperOrigin-RevId: 323630732

Source-Author: Google APIs <noreply@google.com>
Source-Date: Tue Jul 28 12:37:10 2020 -0700
Source-Repo: googleapis/googleapis
Source-Sha: 74e8cf85f23d3cef04fcc75b4f59a21a2b41886c
Source-Link: googleapis/googleapis@74e8cf8

* migrate cloud asset BUILD.bazel to python microgen

PiperOrigin-RevId: 323858574

Source-Author: Google APIs <noreply@google.com>
Source-Date: Wed Jul 29 13:40:36 2020 -0700
Source-Repo: googleapis/googleapis
Source-Sha: c8fc4b79cc54749520e6fc7726deee7a22d1f988
Source-Link: googleapis/googleapis@c8fc4b7

* update python micro-gen version

PiperOrigin-RevId: 324035013

Source-Author: Google APIs <noreply@google.com>
Source-Date: Thu Jul 30 10:46:03 2020 -0700
Source-Repo: googleapis/googleapis
Source-Sha: 8cda089accaead072caea33c5081be8a4b8f9ea7
Source-Link: googleapis/googleapis@8cda089

* chore: cleaning up unnecessary comment block in WORKSPACE file.

PiperOrigin-RevId: 324046932

Source-Author: Google APIs <noreply@google.com>
Source-Date: Thu Jul 30 11:38:24 2020 -0700
Source-Repo: googleapis/googleapis
Source-Sha: 26e80fe6cffa4963139373b9a8300bddad606daa
Source-Link: googleapis/googleapis@26e80fe

* Update protobuf workspace dependency to v3.13.0.

PiperOrigin-RevId: 327026955

Source-Author: Google APIs <noreply@google.com>
Source-Date: Mon Aug 17 08:40:22 2020 -0700
Source-Repo: googleapis/googleapis
Source-Sha: 0dc0a6c0f1a9f979bc0690f0caa5fbafa3000c2c
Source-Link: googleapis/googleapis@0dc0a6c

* chore: upgrade to gapic-generator-python 0.32.0

PiperOrigin-RevId: 327246996

Source-Author: Google APIs <noreply@google.com>
Source-Date: Tue Aug 18 09:48:39 2020 -0700
Source-Repo: googleapis/googleapis
Source-Sha: 09c2579cfa9f37eb91e21ba53c0eaca1481a13cf
Source-Link: googleapis/googleapis@09c2579

* Updates the gapic-generator-ruby import to the latest version using bundler.

PiperOrigin-RevId: 327261444

Source-Author: Google APIs <noreply@google.com>
Source-Date: Tue Aug 18 10:51:33 2020 -0700
Source-Repo: googleapis/googleapis
Source-Sha: 18ffeb71f9433cb6f82b2ddccb9e11d553be4cdc
Source-Link: googleapis/googleapis@18ffeb7

* feat: (a) Add additional binding for session with environment. (b) Allow force delete entity types and webhooks.

PiperOrigin-RevId: 327289448

Source-Author: Google APIs <noreply@google.com>
Source-Date: Tue Aug 18 13:00:19 2020 -0700
Source-Repo: googleapis/googleapis
Source-Sha: 6ee93932840fb3ccbaaa1527d549ddc04e4812fc
Source-Link: googleapis/googleapis@6ee9393

* chore: upgrade gapic-generator-python to 0.32.2

PiperOrigin-RevId: 328157915

Source-Author: Google APIs <noreply@google.com>
Source-Date: Mon Aug 24 09:54:09 2020 -0700
Source-Repo: googleapis/googleapis
Source-Sha: f75a734e2c257765764074562f191f0e130c34e5
Source-Link: googleapis/googleapis@f75a734

* feat: add media translation v1alpha1 API

PiperOrigin-RevId: 328476173

Source-Author: Google APIs <noreply@google.com>
Source-Date: Tue Aug 25 23:29:03 2020 -0700
Source-Repo: googleapis/googleapis
Source-Sha: 1a85976e6bcecdaee1242f6e7fd8b3db81904f56
Source-Link: googleapis/googleapis@1a85976

* fix: revert removal of WorkerPool API

PiperOrigin-RevId: 330974505

Source-Author: Google APIs <noreply@google.com>
Source-Date: Thu Sep 10 11:08:18 2020 -0700
Source-Repo: googleapis/googleapis
Source-Sha: 3257ba52160dd8a9c7f83c34d13793de843bdb4a
Source-Link: googleapis/googleapis@3257ba5

* chore: update python microgen version to 0.33.0

PiperOrigin-RevId: 331031262

Source-Author: Google APIs <noreply@google.com>
Source-Date: Thu Sep 10 15:35:17 2020 -0700
Source-Repo: googleapis/googleapis
Source-Sha: 6a18a3c50ffd62de53dd2e44f599d6696580f90b
Source-Link: googleapis/googleapis@6a18a3c

* feat: use https://github.com/googleapis/gapic-generator-csharp for generating C# libraries.

PiperOrigin-RevId: 331104099

Source-Author: Google APIs <noreply@google.com>
Source-Date: Fri Sep 11 01:15:53 2020 -0700
Source-Repo: googleapis/googleapis
Source-Sha: b821f320473c8ec05a1c7fb9a496c958b1ab9834
Source-Link: googleapis/googleapis@b821f32

* Update gapic-generator-python pin to 0.33.4

PiperOrigin-RevId: 333159182

Source-Author: Google APIs <noreply@google.com>
Source-Date: Tue Sep 22 14:22:59 2020 -0700
Source-Repo: googleapis/googleapis
Source-Sha: 3dbeac0d54125b123c8dfd39c774b37473c36944
Source-Link: googleapis/googleapis@3dbeac0

* chore: use Python microgenerator rules for aiplatform

PiperOrigin-RevId: 333302099

Source-Author: Google APIs <noreply@google.com>
Source-Date: Wed Sep 23 08:58:22 2020 -0700
Source-Repo: googleapis/googleapis
Source-Sha: acd4aabf1c1e3e5bf7db0e81f323003fb317fdaa
Source-Link: googleapis/googleapis@acd4aab

* chore: use gapic-generator-python 0.33.6

PiperOrigin-RevId: 333323660

Source-Author: Google APIs <noreply@google.com>
Source-Date: Wed Sep 23 10:41:17 2020 -0700
Source-Repo: googleapis/googleapis
Source-Sha: 7e377ce8f06ced48a79b45d97eebccb8a51f1e28
Source-Link: googleapis/googleapis@7e377ce

* chore: move talent v4 to python microgenerator rules

PiperOrigin-RevId: 333372432

Source-Author: Google APIs <noreply@google.com>
Source-Date: Wed Sep 23 14:23:38 2020 -0700
Source-Repo: googleapis/googleapis
Source-Sha: 0fd468f90d1236193ee4cbdfb22265b674de121f
Source-Link: googleapis/googleapis@0fd468f

* fix: naming style updates

Source-Author: Mira Leung <miraleung@google.com>
Source-Date: Wed Sep 23 16:33:18 2020 -0700
Source-Repo: googleapis/googleapis
Source-Sha: 3737889dafd012d7f7f724fa04390d42db496e6c
Source-Link: googleapis/googleapis@3737889

* Add Service Direcotry v1 protos and configs

PiperOrigin-RevId: 333502684

Source-Author: Google APIs <noreply@google.com>
Source-Date: Thu Sep 24 06:33:53 2020 -0700
Source-Repo: googleapis/googleapis
Source-Sha: d3697d47929f34c43bcc4de16c7c761a80e97cf1
Source-Link: googleapis/googleapis@d3697d4

* GA launch for PersonDetection and FaceDetection features.

PiperOrigin-RevId: 334093713

Source-Author: Google APIs <noreply@google.com>
Source-Date: Sun Sep 27 23:41:00 2020 -0700
Source-Repo: googleapis/googleapis
Source-Sha: e7375a91e7942c562c61495a908f4f6d50b4ea3f
Source-Link: googleapis/googleapis@e7375a9

* migrate monitoring_v3 python part to use microgen

PiperOrigin-RevId: 335029068

Source-Author: Google APIs <noreply@google.com>
Source-Date: Fri Oct 2 08:16:35 2020 -0700
Source-Repo: googleapis/googleapis
Source-Sha: 4f2a18a10e89afa485f4023bf31f2bb120a2d54d
Source-Link: googleapis/googleapis@4f2a18a

* chore: upgrade to gapic-generator 0.35.9

PiperOrigin-RevId: 339292950

Source-Author: Google APIs <noreply@google.com>
Source-Date: Tue Oct 27 11:32:46 2020 -0700
Source-Repo: googleapis/googleapis
Source-Sha: 07d41a7e5cade45aba6f0d277c89722b48f2c956
Source-Link: googleapis/googleapis@07d41a7

* fix: remove client recv msg limit fix: add enums to `types/__init__.py`

PiperOrigin-RevId: 347055288

Source-Author: Google APIs <noreply@google.com>
Source-Date: Fri Dec 11 12:44:37 2020 -0800
Source-Repo: googleapis/googleapis
Source-Sha: dd372aa22ded7a8ba6f0e03a80e06358a3fa0907
Source-Link: googleapis/googleapis@dd372aa

* chore: Fix C# and PHP namespaces and Ruby package

This is a breaking change for anyone generating C#, PHP or Ruby themselves, but Google Cloud Client Libraries have not been published in those languages. This is effectively a no-op (modulo protobuf reflection) in other languages.

PiperOrigin-RevId: 348813319

Source-Author: Google APIs <noreply@google.com>
Source-Date: Wed Dec 23 10:18:11 2020 -0800
Source-Repo: googleapis/googleapis
Source-Sha: 57fc4a8a94a5bd015a83fb0f0a1707f62254b2cd
Source-Link: googleapis/googleapis@57fc4a8

* chore: clean up dependencies

Co-authored-by: Bu Sun Kim <busunkim@google.com>
Co-authored-by: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com>
  • Loading branch information
3 people committed Dec 23, 2020
1 parent bda3c4b commit 3f09199
Show file tree
Hide file tree
Showing 29 changed files with 2,196 additions and 880 deletions.
4 changes: 2 additions & 2 deletions UPGRADING.MD
Expand Up @@ -17,10 +17,10 @@ The 2.0.0 release requires Python 3.6+.
Methods expect request objects. We provide a script that will convert most common use cases.

* Install the library
* Install the library and `libcst >= 0.2.5`.

```py
python3 -m pip install google-cloud-webrisk
python3 -m pip install google-cloud-webrisk libcst >= 0.2.5
```

* The scripts `fixup_webrisk_v1_keywords.py` and `fixup_webrisk_v1beta1_keywords.py` shipped with the library. It expects
Expand Down
1 change: 1 addition & 0 deletions docs/webrisk_v1/types.rst
Expand Up @@ -3,3 +3,4 @@ Types for Google Cloud Webrisk v1 API

.. automodule:: google.cloud.webrisk_v1.types
:members:
:show-inheritance:
1 change: 1 addition & 0 deletions docs/webrisk_v1beta1/types.rst
Expand Up @@ -3,3 +3,4 @@ Types for Google Cloud Webrisk v1beta1 API

.. automodule:: google.cloud.webrisk_v1beta1.types
:members:
:show-inheritance:
131 changes: 103 additions & 28 deletions google/cloud/webrisk_v1/services/web_risk_service/async_client.py
Expand Up @@ -31,7 +31,7 @@
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.base import WebRiskServiceTransport, DEFAULT_CLIENT_INFO
from .transports.grpc_asyncio import WebRiskServiceGrpcAsyncIOTransport
from .client import WebRiskServiceClient

Expand All @@ -46,9 +46,47 @@ class WebRiskServiceAsyncClient:
DEFAULT_ENDPOINT = WebRiskServiceClient.DEFAULT_ENDPOINT
DEFAULT_MTLS_ENDPOINT = WebRiskServiceClient.DEFAULT_MTLS_ENDPOINT

common_billing_account_path = staticmethod(
WebRiskServiceClient.common_billing_account_path
)
parse_common_billing_account_path = staticmethod(
WebRiskServiceClient.parse_common_billing_account_path
)

common_folder_path = staticmethod(WebRiskServiceClient.common_folder_path)
parse_common_folder_path = staticmethod(
WebRiskServiceClient.parse_common_folder_path
)

common_organization_path = staticmethod(
WebRiskServiceClient.common_organization_path
)
parse_common_organization_path = staticmethod(
WebRiskServiceClient.parse_common_organization_path
)

common_project_path = staticmethod(WebRiskServiceClient.common_project_path)
parse_common_project_path = staticmethod(
WebRiskServiceClient.parse_common_project_path
)

common_location_path = staticmethod(WebRiskServiceClient.common_location_path)
parse_common_location_path = staticmethod(
WebRiskServiceClient.parse_common_location_path
)

from_service_account_file = WebRiskServiceClient.from_service_account_file
from_service_account_json = from_service_account_file

@property
def transport(self) -> WebRiskServiceTransport:
"""Return the transport used by the client instance.
Returns:
WebRiskServiceTransport: The transport used by the client instance.
"""
return self._client.transport

get_transport_class = functools.partial(
type(WebRiskServiceClient).get_transport_class, type(WebRiskServiceClient)
)
Expand All @@ -59,6 +97,7 @@ def __init__(
credentials: credentials.Credentials = None,
transport: Union[str, WebRiskServiceTransport] = "grpc_asyncio",
client_options: ClientOptions = None,
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
) -> None:
"""Instantiate the web risk service client.
Expand All @@ -74,24 +113,30 @@ def __init__(
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
default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT
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.
use the default regular endpoint) and "auto" (auto switch to the
default mTLS endpoint if client certificate is present, this is
the default value). However, the ``api_endpoint`` property takes
precedence if provided.
(2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable
is "true", then the ``client_cert_source`` property can be used
to provide client certificate for mutual TLS transport. If
not provided, the default SSL client certificate will be used if
present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not
set, no client certificate will be used.
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,
credentials=credentials,
transport=transport,
client_options=client_options,
client_info=client_info,
)

async def compute_threat_list_diff(
Expand Down Expand Up @@ -157,7 +202,8 @@ async def compute_threat_list_diff(
# 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]):
has_flattened_params = any([threat_type, version_token, constraints])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
"the individual field arguments should be set."
Expand All @@ -179,8 +225,16 @@ async def compute_threat_list_diff(
# 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,
default_retry=retries.Retry(
initial=0.1,
maximum=60.0,
multiplier=1.3,
predicate=retries.if_exception_type(
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
),
),
default_timeout=600.0,
client_info=DEFAULT_CLIENT_INFO,
)

# Send the request.
Expand Down Expand Up @@ -237,7 +291,8 @@ async def search_uris(
# 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]):
has_flattened_params = any([uri, threat_types])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
"the individual field arguments should be set."
Expand All @@ -250,15 +305,24 @@ async def search_uris(

if uri is not None:
request.uri = uri
if threat_types is not None:
request.threat_types = threat_types

if threat_types:
request.threat_types.extend(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,
default_retry=retries.Retry(
initial=0.1,
maximum=60.0,
multiplier=1.3,
predicate=retries.if_exception_type(
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
),
),
default_timeout=600.0,
client_info=DEFAULT_CLIENT_INFO,
)

# Send the request.
Expand Down Expand Up @@ -317,7 +381,8 @@ async def search_hashes(
# 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]):
has_flattened_params = any([hash_prefix, threat_types])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
"the individual field arguments should be set."
Expand All @@ -330,15 +395,24 @@ async def search_hashes(

if hash_prefix is not None:
request.hash_prefix = hash_prefix
if threat_types is not None:
request.threat_types = threat_types

if threat_types:
request.threat_types.extend(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,
default_retry=retries.Retry(
initial=0.1,
maximum=60.0,
multiplier=1.3,
predicate=retries.if_exception_type(
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
),
),
default_timeout=600.0,
client_info=DEFAULT_CLIENT_INFO,
)

# Send the request.
Expand Down Expand Up @@ -400,7 +474,8 @@ async def create_submission(
# 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]):
has_flattened_params = any([parent, submission])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
"the individual field arguments should be set."
Expand All @@ -420,8 +495,8 @@ async def create_submission(
# and friendly error handling.
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.create_submission,
default_timeout=None,
client_info=_client_info,
default_timeout=60.0,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
Expand All @@ -438,11 +513,11 @@ async def create_submission(


try:
_client_info = gapic_v1.client_info.ClientInfo(
DEFAULT_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()
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo()


__all__ = ("WebRiskServiceAsyncClient",)

0 comments on commit 3f09199

Please sign in to comment.