Skip to content

Commit 06a8244

Browse files
yoshi-automationSita04
authored andcommitted
chore: regenerate README (#541)
This PR was generated using Autosynth. 🌈 <details><summary>Log from Synthtool</summary> ``` 2021-08-27 16:56:48,130 synthtool [DEBUG] > Executing /root/.cache/synthtool/java-recaptchaenterprise/.github/readme/synth.py. On branch autosynth-readme nothing to commit, working tree clean 2021-08-27 16:56:49,179 synthtool [DEBUG] > Wrote metadata to .github/readme/synth.metadata/synth.metadata. ``` </details> Full log will be available here: https://source.cloud.google.com/results/invocations/d2977c74-0405-4584-b4bf-ce1faa3ada13/targets - [ ] To automatically regenerate this PR, check this box. (May take up to 24 hours.)
1 parent 54cbe85 commit 06a8244

File tree

9 files changed

+81
-71
lines changed

9 files changed

+81
-71
lines changed

recaptcha_enterprise/cloud-client/src/main/java/app/Main.java

-1
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,4 @@ public class Main {
2525
public static void main(String[] args) {
2626
SpringApplication.run(Main.class, args);
2727
}
28-
2928
}

recaptcha_enterprise/cloud-client/src/main/java/app/MainController.java

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.springframework.web.bind.annotation.RequestParam;
2424
import org.springframework.web.servlet.ModelAndView;
2525

26-
2726
@Controller
2827
@RequestMapping
2928
public class MainController {

recaptcha_enterprise/cloud-client/src/main/java/recaptcha/CreateAssessment.java

+21-19
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,17 @@ public static void main(String[] args) throws IOException {
3838
createAssessment(projectID, recaptchaSiteKey, token, recaptchaAction);
3939
}
4040

41-
4241
/**
4342
* Create an assessment to analyze the risk of an UI action.
4443
*
4544
* @param projectID : GCloud Project ID
4645
* @param recaptchaSiteKey : Site key obtained by registering a domain/app to use recaptcha
47-
* services.
46+
* services.
4847
* @param token : The token obtained from the client on passing the recaptchaSiteKey.
4948
* @param recaptchaAction : Action name corresponding to the token.
5049
*/
51-
public static void createAssessment(String projectID, String recaptchaSiteKey, String token,
52-
String recaptchaAction)
50+
public static void createAssessment(
51+
String projectID, String recaptchaSiteKey, String token, String recaptchaAction)
5352
throws IOException {
5453
// Initialize client that will be used to send requests. This client only needs to be created
5554
// once, and can be reused for multiple requests. After completing all of your requests, call
@@ -60,33 +59,36 @@ public static void createAssessment(String projectID, String recaptchaSiteKey, S
6059
// Specify a name for this assessment.
6160
String assessmentName = "assessment-name";
6261
// Set the properties of the event to be tracked.
63-
Event event = Event.newBuilder()
64-
.setSiteKey(recaptchaSiteKey)
65-
.setToken(token)
66-
.build();
62+
Event event = Event.newBuilder().setSiteKey(recaptchaSiteKey).setToken(token).build();
6763

6864
// Build the assessment request.
69-
CreateAssessmentRequest createAssessmentRequest = CreateAssessmentRequest.newBuilder()
70-
.setParent(ProjectName.of(projectID).toString())
71-
.setAssessment(Assessment.newBuilder().setEvent(event).setName(assessmentName).build())
72-
.build();
65+
CreateAssessmentRequest createAssessmentRequest =
66+
CreateAssessmentRequest.newBuilder()
67+
.setParent(ProjectName.of(projectID).toString())
68+
.setAssessment(
69+
Assessment.newBuilder().setEvent(event).setName(assessmentName).build())
70+
.build();
7371

7472
Assessment response = client.createAssessment(createAssessmentRequest);
7573

7674
// Check if the token is valid.
7775
if (!response.getTokenProperties().getValid()) {
78-
System.out.println("The CreateAssessment call failed because the token was: " +
79-
response.getTokenProperties().getInvalidReason().name());
76+
System.out.println(
77+
"The CreateAssessment call failed because the token was: "
78+
+ response.getTokenProperties().getInvalidReason().name());
8079
return;
8180
}
8281

8382
// Check if the expected action was executed.
8483
if (!response.getTokenProperties().getAction().equals(recaptchaAction)) {
8584
System.out.println(
86-
"The action attribute in reCAPTCHA tag is: " + response.getTokenProperties()
87-
.getAction());
88-
System.out.println("The action attribute in the reCAPTCHA tag " +
89-
"does not match the action (" + recaptchaAction + ") you are expecting to score");
85+
"The action attribute in reCAPTCHA tag is: "
86+
+ response.getTokenProperties().getAction());
87+
System.out.println(
88+
"The action attribute in the reCAPTCHA tag "
89+
+ "does not match the action ("
90+
+ recaptchaAction
91+
+ ") you are expecting to score");
9092
return;
9193
}
9294

@@ -102,4 +104,4 @@ public static void createAssessment(String projectID, String recaptchaSiteKey, S
102104
}
103105
}
104106
}
105-
// [END recaptcha_enterprise_create_assessment]
107+
// [END recaptcha_enterprise_create_assessment]

recaptcha_enterprise/cloud-client/src/main/java/recaptcha/CreateSiteKey.java

+15-13
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import com.google.recaptchaenterprise.v1.WebKeySettings.IntegrationType;
2727
import java.io.IOException;
2828

29-
3029
public class CreateSiteKey {
3130

3231
public static void main(String[] args) throws IOException {
@@ -52,18 +51,22 @@ public static String createSiteKey(String projectID, String domainName) throws I
5251

5352
// Set the type of reCAPTCHA to be displayed.
5453
// For different types, see: https://cloud.google.com/recaptcha-enterprise/docs/keys
55-
Key scoreKey = Key.newBuilder()
56-
.setDisplayName("any_descriptive_name_for_the_key")
57-
.setWebSettings(WebKeySettings.newBuilder()
58-
.addAllowedDomains(domainName)
59-
.setAllowAmpTraffic(false)
60-
.setIntegrationType(IntegrationType.SCORE).build())
61-
.build();
54+
Key scoreKey =
55+
Key.newBuilder()
56+
.setDisplayName("any_descriptive_name_for_the_key")
57+
.setWebSettings(
58+
WebKeySettings.newBuilder()
59+
.addAllowedDomains(domainName)
60+
.setAllowAmpTraffic(false)
61+
.setIntegrationType(IntegrationType.SCORE)
62+
.build())
63+
.build();
6264

63-
CreateKeyRequest createKeyRequest = CreateKeyRequest.newBuilder()
64-
.setParent(ProjectName.of(projectID).toString())
65-
.setKey(scoreKey)
66-
.build();
65+
CreateKeyRequest createKeyRequest =
66+
CreateKeyRequest.newBuilder()
67+
.setParent(ProjectName.of(projectID).toString())
68+
.setKey(scoreKey)
69+
.build();
6770

6871
// Get the name of the created reCAPTCHA site key.
6972
Key response = client.createKey(createKeyRequest);
@@ -75,4 +78,3 @@ public static String createSiteKey(String projectID, String domainName) throws I
7578
}
7679
}
7780
// [END recaptcha_enterprise_create_site_key]
78-

recaptcha_enterprise/cloud-client/src/main/java/recaptcha/DeleteSiteKey.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,14 @@ public static void deleteSiteKey(String projectID, String recaptchaSiteKey)
5252
try (RecaptchaEnterpriseServiceClient client = RecaptchaEnterpriseServiceClient.create()) {
5353

5454
// Set the project ID and reCAPTCHA site key.
55-
DeleteKeyRequest deleteKeyRequest = DeleteKeyRequest.newBuilder()
56-
.setName(KeyName.of(projectID, recaptchaSiteKey).toString())
57-
.build();
55+
DeleteKeyRequest deleteKeyRequest =
56+
DeleteKeyRequest.newBuilder()
57+
.setName(KeyName.of(projectID, recaptchaSiteKey).toString())
58+
.build();
5859

5960
client.deleteKeyCallable().futureCall(deleteKeyRequest).get(5, TimeUnit.SECONDS);
6061
System.out.println("reCAPTCHA Site key successfully deleted !");
6162
}
6263
}
6364
}
64-
// [END recaptcha_enterprise_delete_site_key]
65+
// [END recaptcha_enterprise_delete_site_key]

recaptcha_enterprise/cloud-client/src/main/java/recaptcha/GetSiteKey.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ public static void main(String[] args)
3939
getSiteKey(projectID, recaptchaSiteKey);
4040
}
4141

42-
4342
/**
4443
* Get the reCAPTCHA site key present under the project ID.
4544
*
@@ -55,9 +54,10 @@ public static void getSiteKey(String projectID, String recaptchaSiteKey)
5554
try (RecaptchaEnterpriseServiceClient client = RecaptchaEnterpriseServiceClient.create()) {
5655

5756
// Construct the "GetSiteKey" request.
58-
GetKeyRequest getKeyRequest = GetKeyRequest.newBuilder()
59-
.setName(KeyName.of(projectID, recaptchaSiteKey).toString())
60-
.build();
57+
GetKeyRequest getKeyRequest =
58+
GetKeyRequest.newBuilder()
59+
.setName(KeyName.of(projectID, recaptchaSiteKey).toString())
60+
.build();
6161

6262
// Wait for the operation to complete.
6363
ApiFuture<Key> futureCall = client.getKeyCallable().futureCall(getKeyRequest);
@@ -67,4 +67,4 @@ public static void getSiteKey(String projectID, String recaptchaSiteKey)
6767
}
6868
}
6969
}
70-
// [END recaptcha_enterprise_get_site_key]
70+
// [END recaptcha_enterprise_get_site_key]

recaptcha_enterprise/cloud-client/src/main/java/recaptcha/ListSiteKeys.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,8 @@ public static void listSiteKeys(String projectID) throws IOException {
4545
// clean up any remaining background resources.
4646
try (RecaptchaEnterpriseServiceClient client = RecaptchaEnterpriseServiceClient.create()) {
4747
// Set the project ID to list the keys present in it.
48-
ListKeysRequest listKeysRequest = ListKeysRequest.newBuilder()
49-
.setParent(ProjectName.of(projectID).toString())
50-
.build();
48+
ListKeysRequest listKeysRequest =
49+
ListKeysRequest.newBuilder().setParent(ProjectName.of(projectID).toString()).build();
5150

5251
System.out.println("Listing reCAPTCHA site keys: ");
5352
for (Key key : client.listKeys(listKeysRequest).iterateAll()) {
@@ -56,4 +55,4 @@ public static void listSiteKeys(String projectID) throws IOException {
5655
}
5756
}
5857
}
59-
// [END recaptcha_enterprise_list_site_keys]
58+
// [END recaptcha_enterprise_list_site_keys]

recaptcha_enterprise/cloud-client/src/main/java/recaptcha/UpdateSiteKey.java

+19-13
Original file line numberDiff line numberDiff line change
@@ -56,31 +56,37 @@ public static void updateSiteKey(String projectID, String recaptchaSiteKeyID, St
5656
try (RecaptchaEnterpriseServiceClient client = RecaptchaEnterpriseServiceClient.create()) {
5757

5858
// Set the name and the new settings for the key.
59-
UpdateKeyRequest updateKeyRequest = UpdateKeyRequest.newBuilder()
60-
.setKey(Key.newBuilder()
61-
.setName(KeyName.of(projectID, recaptchaSiteKeyID).toString())
62-
.setWebSettings(WebKeySettings.newBuilder()
63-
.setAllowAmpTraffic(true)
64-
.addAllowedDomains(domainName).build())
65-
.build())
66-
.build();
59+
UpdateKeyRequest updateKeyRequest =
60+
UpdateKeyRequest.newBuilder()
61+
.setKey(
62+
Key.newBuilder()
63+
.setName(KeyName.of(projectID, recaptchaSiteKeyID).toString())
64+
.setWebSettings(
65+
WebKeySettings.newBuilder()
66+
.setAllowAmpTraffic(true)
67+
.addAllowedDomains(domainName)
68+
.build())
69+
.build())
70+
.build();
6771

6872
client.updateKeyCallable().futureCall(updateKeyRequest).get();
6973

7074
// Check if the key has been updated.
71-
GetKeyRequest getKeyRequest = GetKeyRequest.newBuilder()
72-
.setName(KeyName.of(projectID, recaptchaSiteKeyID).toString()).build();
75+
GetKeyRequest getKeyRequest =
76+
GetKeyRequest.newBuilder()
77+
.setName(KeyName.of(projectID, recaptchaSiteKeyID).toString())
78+
.build();
7379
Key response = client.getKey(getKeyRequest);
7480

7581
// Get the changed property.
7682
boolean allowedAmpTraffic = response.getWebSettings().getAllowAmpTraffic();
7783
if (!allowedAmpTraffic) {
78-
System.out
79-
.println("Error! reCAPTCHA Site key property hasn't been updated. Please try again !");
84+
System.out.println(
85+
"Error! reCAPTCHA Site key property hasn't been updated. Please try again !");
8086
return;
8187
}
8288
System.out.println("reCAPTCHA Site key successfully updated !");
8389
}
8490
}
8591
}
86-
// [END recaptcha_enterprise_update_site_key]
92+
// [END recaptcha_enterprise_update_site_key]

recaptcha_enterprise/cloud-client/src/test/java/app/SnippetsIT.java

+13-11
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,14 @@ public class SnippetsIT {
5858
private static String RECAPTCHA_SITE_KEY_1 = "recaptcha-site-key1";
5959
private static String RECAPTCHA_SITE_KEY_2 = "recaptcha-site-key2";
6060
private static WebDriver browser;
61-
@LocalServerPort
62-
private int randomServerPort;
61+
@LocalServerPort private int randomServerPort;
6362
private ByteArrayOutputStream stdOut;
6463

65-
6664
// Check if the required environment variables are set.
6765
public static void requireEnvVar(String envVarName) {
6866
assertWithMessage(String.format("Missing environment variable '%s' ", envVarName))
69-
.that(System.getenv(envVarName)).isNotEmpty();
67+
.that(System.getenv(envVarName))
68+
.isNotEmpty();
7069
}
7170

7271
@BeforeClass
@@ -148,16 +147,19 @@ public void testDeleteSiteKey()
148147
public void testCreateAssessment() throws IOException, JSONException, InterruptedException {
149148
// Construct the URL to call for validating the assessment.
150149
String assessURL = "http://localhost:" + randomServerPort + "/";
151-
URI url = UriComponentsBuilder.fromUriString(assessURL)
152-
.queryParam("recaptchaSiteKey", RECAPTCHA_SITE_KEY_1)
153-
.build().encode().toUri();
150+
URI url =
151+
UriComponentsBuilder.fromUriString(assessURL)
152+
.queryParam("recaptchaSiteKey", RECAPTCHA_SITE_KEY_1)
153+
.build()
154+
.encode()
155+
.toUri();
154156

155157
browser.get(url.toURL().toString());
156158

157159
// Wait until the page is loaded.
158160
JavascriptExecutor js = (JavascriptExecutor) browser;
159-
new WebDriverWait(browser, 10).until(
160-
webDriver -> js.executeScript("return document.readyState").equals("complete"));
161+
new WebDriverWait(browser, 10)
162+
.until(webDriver -> js.executeScript("return document.readyState").equals("complete"));
161163

162164
// Pass the values to be entered.
163165
browser.findElement(By.id("username")).sendKeys("username");
@@ -186,8 +188,8 @@ public float assessToken(String token, String action) throws IOException {
186188
recaptcha.CreateAssessment.createAssessment(PROJECT_ID, RECAPTCHA_SITE_KEY_1, token, action);
187189
String response = stdOut.toString();
188190
assertThat(response).contains("The reCAPTCHA score is: ");
189-
float recaptchaScore = Float
190-
.parseFloat(response.substring(response.lastIndexOf(":") + 1).trim());
191+
float recaptchaScore =
192+
Float.parseFloat(response.substring(response.lastIndexOf(":") + 1).trim());
191193
return recaptchaScore;
192194
}
193195
}

0 commit comments

Comments
 (0)