Search in sources :

Example 31 with Key

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;
    }
}
Also used : CreateKeyRequest(com.google.recaptchaenterprise.v1.CreateKeyRequest) Key(com.google.recaptchaenterprise.v1.Key) RecaptchaEnterpriseServiceClient(com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient)

Example 32 with Key

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());
    }
}
Also used : GetKeyRequest(com.google.recaptchaenterprise.v1.GetKeyRequest) Key(com.google.recaptchaenterprise.v1.Key) RecaptchaEnterpriseServiceClient(com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient)

Example 33 with Key

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;
    }
}
Also used : ListKeysPagedResponse(com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient.ListKeysPagedResponse) ListKeysRequest(com.google.recaptchaenterprise.v1.ListKeysRequest) Key(com.google.recaptchaenterprise.v1.Key) RecaptchaEnterpriseServiceClient(com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient)

Example 34 with Key

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());
}
Also used : CommitRequest(com.google.datastore.v1.CommitRequest) Entity(com.google.datastore.v1.Entity) CommitResponse(com.google.datastore.v1.CommitResponse) Mutation(com.google.datastore.v1.Mutation) Key(com.google.datastore.v1.Key)

Aggregations

Test (org.junit.Test)23 Key (com.google.datastore.v1.Key)17 DatastoreHelper.makeKey (com.google.datastore.v1.client.DatastoreHelper.makeKey)11 AbstractMessage (com.google.protobuf.AbstractMessage)10 Key (com.google.recaptchaenterprise.v1.Key)10 Entity (com.google.datastore.v1.Entity)7 DeleteKey (org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.DeleteKey)7 DatastoreV1.isValidKey (org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.isValidKey)7 RecaptchaEnterpriseServiceClient (com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient)5 Mutation (com.google.datastore.v1.Mutation)5 Key (com.google.recaptchaenterprise.v1beta1.Key)4 HashMap (java.util.HashMap)4 DeleteEntity (org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.DeleteEntity)4 Query (com.google.datastore.v1.Query)3 GetKeyRequest (com.google.recaptchaenterprise.v1.GetKeyRequest)3 ArrayList (java.util.ArrayList)3 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)2 ListKeysPagedResponse (com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient.ListKeysPagedResponse)2 PathElement (com.google.datastore.v1.Key.PathElement)2 PartitionId (com.google.datastore.v1.PartitionId)2