use of com.google.recaptchaenterprise.v1.Key in project java-recaptchaenterprise by googleapis.
the class DeleteSiteKey method deleteSiteKey.
/**
* Delete the given reCAPTCHA site key present under the project ID.
*
* @param projectID: GCloud Project ID.
* @param recaptchaSiteKey: Specify the site key to be deleted.
*/
public static void deleteSiteKey(String projectID, String recaptchaSiteKey) throws IOException, ExecutionException, InterruptedException, TimeoutException {
// clean up any remaining background resources.
try (RecaptchaEnterpriseServiceClient client = RecaptchaEnterpriseServiceClient.create()) {
// Set the project ID and reCAPTCHA site key.
DeleteKeyRequest deleteKeyRequest = DeleteKeyRequest.newBuilder().setName(KeyName.of(projectID, recaptchaSiteKey).toString()).build();
client.deleteKeyCallable().futureCall(deleteKeyRequest).get(5, TimeUnit.SECONDS);
System.out.println("reCAPTCHA Site key successfully deleted !");
}
}
use of com.google.recaptchaenterprise.v1.Key in project java-recaptchaenterprise by googleapis.
the class GetSiteKey method getSiteKey.
/**
* Get the reCAPTCHA site key present under the project ID.
*
* @param projectID: GCloud Project ID.
* @param recaptchaSiteKey: Specify the site key to get the details.
*/
public static void getSiteKey(String projectID, String recaptchaSiteKey) throws IOException, InterruptedException, ExecutionException, TimeoutException {
// clean up any remaining background resources.
try (RecaptchaEnterpriseServiceClient client = RecaptchaEnterpriseServiceClient.create()) {
// Construct the "GetSiteKey" request.
GetKeyRequest getKeyRequest = GetKeyRequest.newBuilder().setName(KeyName.of(projectID, recaptchaSiteKey).toString()).build();
// Wait for the operation to complete.
ApiFuture<Key> futureCall = client.getKeyCallable().futureCall(getKeyRequest);
Key key = futureCall.get(5, TimeUnit.SECONDS);
System.out.println("Successfully obtained the key !" + key.getName());
}
}
use of com.google.recaptchaenterprise.v1.Key in project java-recaptchaenterprise by googleapis.
the class ListSiteKeys method listSiteKeys.
/**
* List all keys present under the given project ID.
*
* @param projectID : GCloud Project ID.
*/
public static ListKeysPagedResponse listSiteKeys(String projectID) throws IOException {
// clean up any remaining background resources.
try (RecaptchaEnterpriseServiceClient client = RecaptchaEnterpriseServiceClient.create()) {
// Set the project ID to list the keys present in it.
ListKeysRequest listKeysRequest = ListKeysRequest.newBuilder().setParent(ProjectName.of(projectID).toString()).build();
ListKeysPagedResponse response = client.listKeys(listKeysRequest);
System.out.println("Listing reCAPTCHA site keys: ");
for (Key key : response.iterateAll()) {
System.out.println(key.getName());
}
return response;
}
}
use of com.google.recaptchaenterprise.v1.Key in project java-recaptchaenterprise by googleapis.
the class RecaptchaEnterpriseServiceClientTest method deleteKeyTest.
@Test
public void deleteKeyTest() throws Exception {
Empty expectedResponse = Empty.newBuilder().build();
mockRecaptchaEnterpriseService.addResponse(expectedResponse);
DeleteKeyRequest request = DeleteKeyRequest.newBuilder().setName(KeyName.of("[PROJECT]", "[KEY]").toString()).build();
client.deleteKey(request);
List<AbstractMessage> actualRequests = mockRecaptchaEnterpriseService.getRequests();
Assert.assertEquals(1, actualRequests.size());
DeleteKeyRequest actualRequest = ((DeleteKeyRequest) actualRequests.get(0));
Assert.assertEquals(request.getName(), actualRequest.getName());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.recaptchaenterprise.v1.Key in project java-recaptchaenterprise by googleapis.
the class RecaptchaEnterpriseServiceClientTest method deleteKeyExceptionTest.
@Test
public void deleteKeyExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockRecaptchaEnterpriseService.addException(exception);
try {
DeleteKeyRequest request = DeleteKeyRequest.newBuilder().setName(KeyName.of("[PROJECT]", "[KEY]").toString()).build();
client.deleteKey(request);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
Aggregations