use of com.google.recaptchaenterprise.v1beta1.Key in project java-recaptchaenterprise by googleapis.
the class CreateSiteKey method createSiteKey.
/**
* Create reCAPTCHA Site key which binds a domain name to a unique key.
*
* @param projectID : GCloud Project ID.
* @param domainName : Specify the domain name in which the reCAPTCHA should be activated.
*/
public static String createSiteKey(String projectID, String domainName) throws IOException {
// clean up any remaining background resources.
try (RecaptchaEnterpriseServiceClient client = RecaptchaEnterpriseServiceClient.create()) {
// Set the type of reCAPTCHA to be displayed.
// For different types, see: https://cloud.google.com/recaptcha-enterprise/docs/keys
Key scoreKey = Key.newBuilder().setDisplayName("any_descriptive_name_for_the_key").setWebSettings(WebKeySettings.newBuilder().addAllowedDomains(domainName).setAllowAmpTraffic(false).setIntegrationType(IntegrationType.SCORE).build()).build();
CreateKeyRequest createKeyRequest = CreateKeyRequest.newBuilder().setParent(ProjectName.of(projectID).toString()).setKey(scoreKey).build();
// Get the name of the created reCAPTCHA site key.
Key response = client.createKey(createKeyRequest);
String keyName = response.getName();
String recaptchaSiteKey = keyName.substring(keyName.lastIndexOf("/") + 1);
System.out.println("reCAPTCHA Site key created successfully. Site Key: " + recaptchaSiteKey);
return recaptchaSiteKey;
}
}
use of com.google.recaptchaenterprise.v1beta1.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.v1beta1.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.v1beta1.Key in project grpc-gcp-java by GoogleCloudPlatform.
the class DataStoreChecksumClient method commitTransaction.
private static void commitTransaction(DatastoreBlockingStub stub, String projectId) {
int transactionBytes = 2000;
String payload = new String(new char[transactionBytes]).replace('\0', 'x');
Key key = Key.newBuilder().addPath(PathElement.newBuilder().setKind("Data").setName("data1").build()).build();
Entity entity = Entity.newBuilder().setKey(key).putProperties("2kb", Value.newBuilder().setExcludeFromIndexes(true).setStringValue(payload).build()).build();
Mutation mutation = Mutation.newBuilder().setUpdate(entity).build();
CommitRequest commitRequest = CommitRequest.newBuilder().setProjectId(projectId).setMode(Mode.NON_TRANSACTIONAL).addMutations(mutation).build();
CommitResponse commitResponse = stub.commit(commitRequest);
System.out.println("index updates: " + commitResponse.getIndexUpdates());
}
Aggregations