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

Commit

Permalink
feat: add GetMetrics and MigrateKey methods to reCAPTCHA enterprise A…
Browse files Browse the repository at this point in the history
…PI (#119)

* feat: add GetMetrics and MigrateKey methods to reCAPTCHA enterprise API

PiperOrigin-RevId: 396937887

Source-Link: googleapis/googleapis@020672e

Source-Link: googleapis/googleapis-gen@a584790
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYTU4NDc5MDdlYjM2MDc4MzdmMTBmOTNlOTVmZGZjYzBhOThlNmYyMSJ9

* 🦉 Updates from OwlBot

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
gcf-owl-bot[bot] and gcf-owl-bot[bot] committed Sep 16, 2021
1 parent fa6d90b commit 6c8bf2f
Show file tree
Hide file tree
Showing 12 changed files with 1,069 additions and 33 deletions.
22 changes: 22 additions & 0 deletions google/cloud/recaptchaenterprise/__init__.py
Expand Up @@ -31,6 +31,9 @@
AnnotateAssessmentResponse,
)
from google.cloud.recaptchaenterprise_v1.types.recaptchaenterprise import Assessment
from google.cloud.recaptchaenterprise_v1.types.recaptchaenterprise import (
ChallengeMetrics,
)
from google.cloud.recaptchaenterprise_v1.types.recaptchaenterprise import (
CreateAssessmentRequest,
)
Expand All @@ -42,6 +45,9 @@
)
from google.cloud.recaptchaenterprise_v1.types.recaptchaenterprise import Event
from google.cloud.recaptchaenterprise_v1.types.recaptchaenterprise import GetKeyRequest
from google.cloud.recaptchaenterprise_v1.types.recaptchaenterprise import (
GetMetricsRequest,
)
from google.cloud.recaptchaenterprise_v1.types.recaptchaenterprise import IOSKeySettings
from google.cloud.recaptchaenterprise_v1.types.recaptchaenterprise import Key
from google.cloud.recaptchaenterprise_v1.types.recaptchaenterprise import (
Expand All @@ -50,7 +56,16 @@
from google.cloud.recaptchaenterprise_v1.types.recaptchaenterprise import (
ListKeysResponse,
)
from google.cloud.recaptchaenterprise_v1.types.recaptchaenterprise import Metrics
from google.cloud.recaptchaenterprise_v1.types.recaptchaenterprise import (
MigrateKeyRequest,
)
from google.cloud.recaptchaenterprise_v1.types.recaptchaenterprise import RiskAnalysis
from google.cloud.recaptchaenterprise_v1.types.recaptchaenterprise import (
ScoreDistribution,
)
from google.cloud.recaptchaenterprise_v1.types.recaptchaenterprise import ScoreMetrics
from google.cloud.recaptchaenterprise_v1.types.recaptchaenterprise import TestingOptions
from google.cloud.recaptchaenterprise_v1.types.recaptchaenterprise import (
TokenProperties,
)
Expand All @@ -66,16 +81,23 @@
"AnnotateAssessmentRequest",
"AnnotateAssessmentResponse",
"Assessment",
"ChallengeMetrics",
"CreateAssessmentRequest",
"CreateKeyRequest",
"DeleteKeyRequest",
"Event",
"GetKeyRequest",
"GetMetricsRequest",
"IOSKeySettings",
"Key",
"ListKeysRequest",
"ListKeysResponse",
"Metrics",
"MigrateKeyRequest",
"RiskAnalysis",
"ScoreDistribution",
"ScoreMetrics",
"TestingOptions",
"TokenProperties",
"UpdateKeyRequest",
"WebKeySettings",
Expand Down
14 changes: 14 additions & 0 deletions google/cloud/recaptchaenterprise_v1/__init__.py
Expand Up @@ -21,16 +21,23 @@
from .types.recaptchaenterprise import AnnotateAssessmentRequest
from .types.recaptchaenterprise import AnnotateAssessmentResponse
from .types.recaptchaenterprise import Assessment
from .types.recaptchaenterprise import ChallengeMetrics
from .types.recaptchaenterprise import CreateAssessmentRequest
from .types.recaptchaenterprise import CreateKeyRequest
from .types.recaptchaenterprise import DeleteKeyRequest
from .types.recaptchaenterprise import Event
from .types.recaptchaenterprise import GetKeyRequest
from .types.recaptchaenterprise import GetMetricsRequest
from .types.recaptchaenterprise import IOSKeySettings
from .types.recaptchaenterprise import Key
from .types.recaptchaenterprise import ListKeysRequest
from .types.recaptchaenterprise import ListKeysResponse
from .types.recaptchaenterprise import Metrics
from .types.recaptchaenterprise import MigrateKeyRequest
from .types.recaptchaenterprise import RiskAnalysis
from .types.recaptchaenterprise import ScoreDistribution
from .types.recaptchaenterprise import ScoreMetrics
from .types.recaptchaenterprise import TestingOptions
from .types.recaptchaenterprise import TokenProperties
from .types.recaptchaenterprise import UpdateKeyRequest
from .types.recaptchaenterprise import WebKeySettings
Expand All @@ -41,17 +48,24 @@
"AnnotateAssessmentRequest",
"AnnotateAssessmentResponse",
"Assessment",
"ChallengeMetrics",
"CreateAssessmentRequest",
"CreateKeyRequest",
"DeleteKeyRequest",
"Event",
"GetKeyRequest",
"GetMetricsRequest",
"IOSKeySettings",
"Key",
"ListKeysRequest",
"ListKeysResponse",
"Metrics",
"MigrateKeyRequest",
"RecaptchaEnterpriseServiceClient",
"RiskAnalysis",
"ScoreDistribution",
"ScoreMetrics",
"TestingOptions",
"TokenProperties",
"UpdateKeyRequest",
"WebKeySettings",
Expand Down
20 changes: 20 additions & 0 deletions google/cloud/recaptchaenterprise_v1/gapic_metadata.json
Expand Up @@ -35,11 +35,21 @@
"get_key"
]
},
"GetMetrics": {
"methods": [
"get_metrics"
]
},
"ListKeys": {
"methods": [
"list_keys"
]
},
"MigrateKey": {
"methods": [
"migrate_key"
]
},
"UpdateKey": {
"methods": [
"update_key"
Expand Down Expand Up @@ -75,11 +85,21 @@
"get_key"
]
},
"GetMetrics": {
"methods": [
"get_metrics"
]
},
"ListKeys": {
"methods": [
"list_keys"
]
},
"MigrateKey": {
"methods": [
"migrate_key"
]
},
"UpdateKey": {
"methods": [
"update_key"
Expand Down
Expand Up @@ -50,6 +50,10 @@ class RecaptchaEnterpriseServiceAsyncClient:
)
key_path = staticmethod(RecaptchaEnterpriseServiceClient.key_path)
parse_key_path = staticmethod(RecaptchaEnterpriseServiceClient.parse_key_path)
metrics_path = staticmethod(RecaptchaEnterpriseServiceClient.metrics_path)
parse_metrics_path = staticmethod(
RecaptchaEnterpriseServiceClient.parse_metrics_path
)
common_billing_account_path = staticmethod(
RecaptchaEnterpriseServiceClient.common_billing_account_path
)
Expand Down Expand Up @@ -266,7 +270,7 @@ async def annotate_assessment(
) -> recaptchaenterprise.AnnotateAssessmentResponse:
r"""Annotates a previously created Assessment to provide
additional information on whether the event turned out
to be authentic or fradulent.
to be authentic or fraudulent.
Args:
request (:class:`google.cloud.recaptchaenterprise_v1.types.AnnotateAssessmentRequest`):
Expand All @@ -281,8 +285,11 @@ async def annotate_assessment(
on the ``request`` instance; if ``request`` is provided, this
should not be set.
annotation (:class:`google.cloud.recaptchaenterprise_v1.types.AnnotateAssessmentRequest.Annotation`):
Required. The annotation that will be
assigned to the Event.
Optional. The annotation that will be
assigned to the Event. This field can be
left empty to provide reasons that apply
to an event without concluding whether
the event is legitimate or fraudulent.
This corresponds to the ``annotation`` field
on the ``request`` instance; if ``request`` is provided, this
Expand Down Expand Up @@ -584,6 +591,131 @@ async def delete_key(
request, retry=retry, timeout=timeout, metadata=metadata,
)

async def migrate_key(
self,
request: recaptchaenterprise.MigrateKeyRequest = None,
*,
retry: retries.Retry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> recaptchaenterprise.Key:
r"""Migrates an existing key from reCAPTCHA to reCAPTCHA
Enterprise. Once a key is migrated, it can be used from
either product. SiteVerify requests are billed as
CreateAssessment calls. You must be authenticated as one
of the current owners of the reCAPTCHA Site Key, and
your user must have the reCAPTCHA Enterprise Admin IAM
role in the destination project.
Args:
request (:class:`google.cloud.recaptchaenterprise_v1.types.MigrateKeyRequest`):
The request object. The migrate key request message.
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:
google.cloud.recaptchaenterprise_v1.types.Key:
A key used to identify and configure
applications (web and/or mobile) that
use reCAPTCHA Enterprise.
"""
# Create or coerce a protobuf request object.
request = recaptchaenterprise.MigrateKeyRequest(request)

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.migrate_key,
default_timeout=None,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
# add these here.
metadata = tuple(metadata) + (
gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
)

# Send the request.
response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,)

# Done; return the response.
return response

async def get_metrics(
self,
request: recaptchaenterprise.GetMetricsRequest = None,
*,
name: str = None,
retry: retries.Retry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> recaptchaenterprise.Metrics:
r"""Get some aggregated metrics for a Key. This data can
be used to build dashboards.
Args:
request (:class:`google.cloud.recaptchaenterprise_v1.types.GetMetricsRequest`):
The request object. The get metrics request message.
name (:class:`str`):
Required. The name of the requested
metrics, in the format
"projects/{project}/keys/{key}/metrics".
This corresponds to the ``name`` field
on the ``request`` instance; if ``request`` is provided, this
should not be set.
retry (google.api_core.retry.Retry): Designation of what errors, if any,
should be retried.
timeout (float): The timeout for this request.
metadata (Sequence[Tuple[str, str]]): Strings which should be
sent along with the request as metadata.
Returns:
google.cloud.recaptchaenterprise_v1.types.Metrics:
Metrics for a single Key.
"""
# 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.
has_flattened_params = any([name])
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."
)

request = recaptchaenterprise.GetMetricsRequest(request)

# If we have keyword arguments corresponding to fields on the
# request, apply these.
if name is not None:
request.name = name

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.get_metrics,
default_timeout=None,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
# add these here.
metadata = tuple(metadata) + (
gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
)

# Send the request.
response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,)

# Done; return the response.
return response


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
Expand Down

0 comments on commit 6c8bf2f

Please sign in to comment.