-
Notifications
You must be signed in to change notification settings - Fork 6.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(samples): added sample and tests for annotate assessment API (#155)
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/python-recaptcha-enterprise/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [ ] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) Fixes #154 🦕
- Loading branch information
Showing
3 changed files
with
78 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Copyright 2021 Google Inc. All Rights Reserved. | ||
# | ||
# 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. | ||
|
||
# [START recaptcha_enterprise_annotate_assessment] | ||
from google.cloud import recaptchaenterprise_v1 | ||
|
||
|
||
def annotate_assessment(project_id: str, assessment_id: str) -> None: | ||
""" Pre-requisite: Create an assessment before annotating. | ||
Annotate an assessment to provide feedback on the correctness of recaptcha prediction. | ||
Args: | ||
project_id: Google Cloud Project ID | ||
assessment_id: Value of the 'name' field returned from the create_assessment() call. | ||
""" | ||
|
||
client = recaptchaenterprise_v1.RecaptchaEnterpriseServiceClient() | ||
|
||
assessment_name = f"projects/{project_id}/assessments/{assessment_id}" | ||
# Build the annotation request. | ||
# For more info on when/how to annotate, see: | ||
# https://cloud.google.com/recaptcha-enterprise/docs/annotate-assessment#when_to_annotate | ||
request = recaptchaenterprise_v1.AnnotateAssessmentRequest() | ||
request.name = assessment_name | ||
request.annotation = request.Annotation.FRAUDULENT | ||
request.reasons = [request.Reason.FAILED_TWO_FACTOR] | ||
|
||
# Empty response is sent back. | ||
client.annotate_assessment(request) | ||
print("Annotated response sent successfully ! ") | ||
|
||
|
||
# [END recaptcha_enterprise_annotate_assessment] |
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