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

Commit 6c8bf2f

Browse files
feat: add GetMetrics and MigrateKey methods to reCAPTCHA enterprise API (#119)
* feat: add GetMetrics and MigrateKey methods to reCAPTCHA enterprise API PiperOrigin-RevId: 396937887 Source-Link: googleapis/googleapis@020672e Source-Link: https://github.com/googleapis/googleapis-gen/commit/a5847907eb3607837f10f93e95fdfcc0a98e6f21 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>
1 parent fa6d90b commit 6c8bf2f

File tree

12 files changed

+1069
-33
lines changed

12 files changed

+1069
-33
lines changed

google/cloud/recaptchaenterprise/__init__.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
AnnotateAssessmentResponse,
3232
)
3333
from google.cloud.recaptchaenterprise_v1.types.recaptchaenterprise import Assessment
34+
from google.cloud.recaptchaenterprise_v1.types.recaptchaenterprise import (
35+
ChallengeMetrics,
36+
)
3437
from google.cloud.recaptchaenterprise_v1.types.recaptchaenterprise import (
3538
CreateAssessmentRequest,
3639
)
@@ -42,6 +45,9 @@
4245
)
4346
from google.cloud.recaptchaenterprise_v1.types.recaptchaenterprise import Event
4447
from google.cloud.recaptchaenterprise_v1.types.recaptchaenterprise import GetKeyRequest
48+
from google.cloud.recaptchaenterprise_v1.types.recaptchaenterprise import (
49+
GetMetricsRequest,
50+
)
4551
from google.cloud.recaptchaenterprise_v1.types.recaptchaenterprise import IOSKeySettings
4652
from google.cloud.recaptchaenterprise_v1.types.recaptchaenterprise import Key
4753
from google.cloud.recaptchaenterprise_v1.types.recaptchaenterprise import (
@@ -50,7 +56,16 @@
5056
from google.cloud.recaptchaenterprise_v1.types.recaptchaenterprise import (
5157
ListKeysResponse,
5258
)
59+
from google.cloud.recaptchaenterprise_v1.types.recaptchaenterprise import Metrics
60+
from google.cloud.recaptchaenterprise_v1.types.recaptchaenterprise import (
61+
MigrateKeyRequest,
62+
)
5363
from google.cloud.recaptchaenterprise_v1.types.recaptchaenterprise import RiskAnalysis
64+
from google.cloud.recaptchaenterprise_v1.types.recaptchaenterprise import (
65+
ScoreDistribution,
66+
)
67+
from google.cloud.recaptchaenterprise_v1.types.recaptchaenterprise import ScoreMetrics
68+
from google.cloud.recaptchaenterprise_v1.types.recaptchaenterprise import TestingOptions
5469
from google.cloud.recaptchaenterprise_v1.types.recaptchaenterprise import (
5570
TokenProperties,
5671
)
@@ -66,16 +81,23 @@
6681
"AnnotateAssessmentRequest",
6782
"AnnotateAssessmentResponse",
6883
"Assessment",
84+
"ChallengeMetrics",
6985
"CreateAssessmentRequest",
7086
"CreateKeyRequest",
7187
"DeleteKeyRequest",
7288
"Event",
7389
"GetKeyRequest",
90+
"GetMetricsRequest",
7491
"IOSKeySettings",
7592
"Key",
7693
"ListKeysRequest",
7794
"ListKeysResponse",
95+
"Metrics",
96+
"MigrateKeyRequest",
7897
"RiskAnalysis",
98+
"ScoreDistribution",
99+
"ScoreMetrics",
100+
"TestingOptions",
79101
"TokenProperties",
80102
"UpdateKeyRequest",
81103
"WebKeySettings",

google/cloud/recaptchaenterprise_v1/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,23 @@
2121
from .types.recaptchaenterprise import AnnotateAssessmentRequest
2222
from .types.recaptchaenterprise import AnnotateAssessmentResponse
2323
from .types.recaptchaenterprise import Assessment
24+
from .types.recaptchaenterprise import ChallengeMetrics
2425
from .types.recaptchaenterprise import CreateAssessmentRequest
2526
from .types.recaptchaenterprise import CreateKeyRequest
2627
from .types.recaptchaenterprise import DeleteKeyRequest
2728
from .types.recaptchaenterprise import Event
2829
from .types.recaptchaenterprise import GetKeyRequest
30+
from .types.recaptchaenterprise import GetMetricsRequest
2931
from .types.recaptchaenterprise import IOSKeySettings
3032
from .types.recaptchaenterprise import Key
3133
from .types.recaptchaenterprise import ListKeysRequest
3234
from .types.recaptchaenterprise import ListKeysResponse
35+
from .types.recaptchaenterprise import Metrics
36+
from .types.recaptchaenterprise import MigrateKeyRequest
3337
from .types.recaptchaenterprise import RiskAnalysis
38+
from .types.recaptchaenterprise import ScoreDistribution
39+
from .types.recaptchaenterprise import ScoreMetrics
40+
from .types.recaptchaenterprise import TestingOptions
3441
from .types.recaptchaenterprise import TokenProperties
3542
from .types.recaptchaenterprise import UpdateKeyRequest
3643
from .types.recaptchaenterprise import WebKeySettings
@@ -41,17 +48,24 @@
4148
"AnnotateAssessmentRequest",
4249
"AnnotateAssessmentResponse",
4350
"Assessment",
51+
"ChallengeMetrics",
4452
"CreateAssessmentRequest",
4553
"CreateKeyRequest",
4654
"DeleteKeyRequest",
4755
"Event",
4856
"GetKeyRequest",
57+
"GetMetricsRequest",
4958
"IOSKeySettings",
5059
"Key",
5160
"ListKeysRequest",
5261
"ListKeysResponse",
62+
"Metrics",
63+
"MigrateKeyRequest",
5364
"RecaptchaEnterpriseServiceClient",
5465
"RiskAnalysis",
66+
"ScoreDistribution",
67+
"ScoreMetrics",
68+
"TestingOptions",
5569
"TokenProperties",
5670
"UpdateKeyRequest",
5771
"WebKeySettings",

google/cloud/recaptchaenterprise_v1/gapic_metadata.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,21 @@
3535
"get_key"
3636
]
3737
},
38+
"GetMetrics": {
39+
"methods": [
40+
"get_metrics"
41+
]
42+
},
3843
"ListKeys": {
3944
"methods": [
4045
"list_keys"
4146
]
4247
},
48+
"MigrateKey": {
49+
"methods": [
50+
"migrate_key"
51+
]
52+
},
4353
"UpdateKey": {
4454
"methods": [
4555
"update_key"
@@ -75,11 +85,21 @@
7585
"get_key"
7686
]
7787
},
88+
"GetMetrics": {
89+
"methods": [
90+
"get_metrics"
91+
]
92+
},
7893
"ListKeys": {
7994
"methods": [
8095
"list_keys"
8196
]
8297
},
98+
"MigrateKey": {
99+
"methods": [
100+
"migrate_key"
101+
]
102+
},
83103
"UpdateKey": {
84104
"methods": [
85105
"update_key"

google/cloud/recaptchaenterprise_v1/services/recaptcha_enterprise_service/async_client.py

Lines changed: 135 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ class RecaptchaEnterpriseServiceAsyncClient:
5050
)
5151
key_path = staticmethod(RecaptchaEnterpriseServiceClient.key_path)
5252
parse_key_path = staticmethod(RecaptchaEnterpriseServiceClient.parse_key_path)
53+
metrics_path = staticmethod(RecaptchaEnterpriseServiceClient.metrics_path)
54+
parse_metrics_path = staticmethod(
55+
RecaptchaEnterpriseServiceClient.parse_metrics_path
56+
)
5357
common_billing_account_path = staticmethod(
5458
RecaptchaEnterpriseServiceClient.common_billing_account_path
5559
)
@@ -266,7 +270,7 @@ async def annotate_assessment(
266270
) -> recaptchaenterprise.AnnotateAssessmentResponse:
267271
r"""Annotates a previously created Assessment to provide
268272
additional information on whether the event turned out
269-
to be authentic or fradulent.
273+
to be authentic or fraudulent.
270274
271275
Args:
272276
request (:class:`google.cloud.recaptchaenterprise_v1.types.AnnotateAssessmentRequest`):
@@ -281,8 +285,11 @@ async def annotate_assessment(
281285
on the ``request`` instance; if ``request`` is provided, this
282286
should not be set.
283287
annotation (:class:`google.cloud.recaptchaenterprise_v1.types.AnnotateAssessmentRequest.Annotation`):
284-
Required. The annotation that will be
285-
assigned to the Event.
288+
Optional. The annotation that will be
289+
assigned to the Event. This field can be
290+
left empty to provide reasons that apply
291+
to an event without concluding whether
292+
the event is legitimate or fraudulent.
286293
287294
This corresponds to the ``annotation`` field
288295
on the ``request`` instance; if ``request`` is provided, this
@@ -584,6 +591,131 @@ async def delete_key(
584591
request, retry=retry, timeout=timeout, metadata=metadata,
585592
)
586593

594+
async def migrate_key(
595+
self,
596+
request: recaptchaenterprise.MigrateKeyRequest = None,
597+
*,
598+
retry: retries.Retry = gapic_v1.method.DEFAULT,
599+
timeout: float = None,
600+
metadata: Sequence[Tuple[str, str]] = (),
601+
) -> recaptchaenterprise.Key:
602+
r"""Migrates an existing key from reCAPTCHA to reCAPTCHA
603+
Enterprise. Once a key is migrated, it can be used from
604+
either product. SiteVerify requests are billed as
605+
CreateAssessment calls. You must be authenticated as one
606+
of the current owners of the reCAPTCHA Site Key, and
607+
your user must have the reCAPTCHA Enterprise Admin IAM
608+
role in the destination project.
609+
610+
Args:
611+
request (:class:`google.cloud.recaptchaenterprise_v1.types.MigrateKeyRequest`):
612+
The request object. The migrate key request message.
613+
retry (google.api_core.retry.Retry): Designation of what errors, if any,
614+
should be retried.
615+
timeout (float): The timeout for this request.
616+
metadata (Sequence[Tuple[str, str]]): Strings which should be
617+
sent along with the request as metadata.
618+
619+
Returns:
620+
google.cloud.recaptchaenterprise_v1.types.Key:
621+
A key used to identify and configure
622+
applications (web and/or mobile) that
623+
use reCAPTCHA Enterprise.
624+
625+
"""
626+
# Create or coerce a protobuf request object.
627+
request = recaptchaenterprise.MigrateKeyRequest(request)
628+
629+
# Wrap the RPC method; this adds retry and timeout information,
630+
# and friendly error handling.
631+
rpc = gapic_v1.method_async.wrap_method(
632+
self._client._transport.migrate_key,
633+
default_timeout=None,
634+
client_info=DEFAULT_CLIENT_INFO,
635+
)
636+
637+
# Certain fields should be provided within the metadata header;
638+
# add these here.
639+
metadata = tuple(metadata) + (
640+
gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
641+
)
642+
643+
# Send the request.
644+
response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,)
645+
646+
# Done; return the response.
647+
return response
648+
649+
async def get_metrics(
650+
self,
651+
request: recaptchaenterprise.GetMetricsRequest = None,
652+
*,
653+
name: str = None,
654+
retry: retries.Retry = gapic_v1.method.DEFAULT,
655+
timeout: float = None,
656+
metadata: Sequence[Tuple[str, str]] = (),
657+
) -> recaptchaenterprise.Metrics:
658+
r"""Get some aggregated metrics for a Key. This data can
659+
be used to build dashboards.
660+
661+
Args:
662+
request (:class:`google.cloud.recaptchaenterprise_v1.types.GetMetricsRequest`):
663+
The request object. The get metrics request message.
664+
name (:class:`str`):
665+
Required. The name of the requested
666+
metrics, in the format
667+
"projects/{project}/keys/{key}/metrics".
668+
669+
This corresponds to the ``name`` field
670+
on the ``request`` instance; if ``request`` is provided, this
671+
should not be set.
672+
retry (google.api_core.retry.Retry): Designation of what errors, if any,
673+
should be retried.
674+
timeout (float): The timeout for this request.
675+
metadata (Sequence[Tuple[str, str]]): Strings which should be
676+
sent along with the request as metadata.
677+
678+
Returns:
679+
google.cloud.recaptchaenterprise_v1.types.Metrics:
680+
Metrics for a single Key.
681+
"""
682+
# Create or coerce a protobuf request object.
683+
# Sanity check: If we got a request object, we should *not* have
684+
# gotten any keyword arguments that map to the request.
685+
has_flattened_params = any([name])
686+
if request is not None and has_flattened_params:
687+
raise ValueError(
688+
"If the `request` argument is set, then none of "
689+
"the individual field arguments should be set."
690+
)
691+
692+
request = recaptchaenterprise.GetMetricsRequest(request)
693+
694+
# If we have keyword arguments corresponding to fields on the
695+
# request, apply these.
696+
if name is not None:
697+
request.name = name
698+
699+
# Wrap the RPC method; this adds retry and timeout information,
700+
# and friendly error handling.
701+
rpc = gapic_v1.method_async.wrap_method(
702+
self._client._transport.get_metrics,
703+
default_timeout=None,
704+
client_info=DEFAULT_CLIENT_INFO,
705+
)
706+
707+
# Certain fields should be provided within the metadata header;
708+
# add these here.
709+
metadata = tuple(metadata) + (
710+
gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
711+
)
712+
713+
# Send the request.
714+
response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,)
715+
716+
# Done; return the response.
717+
return response
718+
587719

588720
try:
589721
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

0 commit comments

Comments
 (0)