use of com.google.cloud.dialogflow.v2beta1.ProjectName in project pomocua-ogloszenia by coi-gov-pl.
the class CaptchaValidator method validate.
public boolean validate(String recaptchaResponse) {
if (!properties.isEnabled()) {
log.debug("Skip captcha validation. To enable change 'app.captcha.enabled' property");
return true;
}
if (!responseSanityCheck(recaptchaResponse)) {
log.warn("Response contains invalid characters");
return false;
}
ProjectName projectName = ProjectName.of(properties.getGoogleCloudProjectId());
Event event = Event.newBuilder().setSiteKey(properties.getSiteKey()).setToken(recaptchaResponse).build();
CreateAssessmentRequest createAssessmentRequest = CreateAssessmentRequest.newBuilder().setParent(projectName.toString()).setAssessment(Assessment.newBuilder().setEvent(event).build()).build();
Assessment response = recaptchaClient.createAssessment(createAssessmentRequest);
if (response == null) {
log.warn("Empty response from reCaptcha");
return false;
}
// Check if the token is valid.
if (!response.getTokenProperties().getValid()) {
String invalidTokenReason = response.getTokenProperties().getInvalidReason().name();
log.debug("The CreateAssessment call failed because the token was: " + invalidTokenReason);
return false;
}
float score = response.getScore();
if (score < properties.getAcceptLevel()) {
List<String> reasons = response.getReasonsList().stream().map(classificationReason -> classificationReason.getDescriptorForType().getFullName()).collect(Collectors.toList());
log.debug("Validation failed. Score: " + score + ". Reasons: " + String.join(", ", reasons));
return false;
}
log.debug("Validation OK - score: " + score);
return true;
}
use of com.google.cloud.dialogflow.v2beta1.ProjectName in project java-dialogflow by googleapis.
the class KnowledgeBasesClientTest method listKnowledgeBasesTest2.
@Test
public void listKnowledgeBasesTest2() throws Exception {
KnowledgeBase responsesElement = KnowledgeBase.newBuilder().build();
ListKnowledgeBasesResponse expectedResponse = ListKnowledgeBasesResponse.newBuilder().setNextPageToken("").addAllKnowledgeBases(Arrays.asList(responsesElement)).build();
mockKnowledgeBases.addResponse(expectedResponse);
ProjectName parent = ProjectName.of("[PROJECT]");
ListKnowledgeBasesPagedResponse pagedListResponse = client.listKnowledgeBases(parent);
List<KnowledgeBase> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getKnowledgeBasesList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockKnowledgeBases.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListKnowledgeBasesRequest actualRequest = ((ListKnowledgeBasesRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.dialogflow.v2beta1.ProjectName in project java-secretmanager by googleapis.
the class NativeImageSecretManagerSample method hasSecret.
static boolean hasSecret(SecretManagerServiceClient client, String projectId, String secretId) {
ProjectName projectName = ProjectName.of(projectId);
ListSecretsPagedResponse pagedResponse = client.listSecrets(projectName);
for (Secret secret : pagedResponse.iterateAll()) {
String otherSecretId = extractSecretId(secret);
if (secretId.equals(otherSecretId)) {
return true;
}
}
return false;
}
use of com.google.cloud.dialogflow.v2beta1.ProjectName in project java-secretmanager by googleapis.
the class NativeImageSecretManagerSample method createSecret.
static void createSecret(SecretManagerServiceClient client, String projectId, String secretId) {
Secret secret = Secret.newBuilder().setReplication(Replication.newBuilder().setAutomatic(Replication.Automatic.newBuilder().build()).build()).build();
ProjectName projectName = ProjectName.of(projectId);
Secret createdSecret = client.createSecret(projectName, secretId, secret);
System.out.println("Created secret: " + createdSecret.getName());
}
use of com.google.cloud.dialogflow.v2beta1.ProjectName in project java-secretmanager by googleapis.
the class CreateSecret method createSecret.
// Add a new version to the existing secret.
public void createSecret(String projectId, String secretId) throws IOException {
// the "close" method on the client to safely clean up any remaining background resources.
try (SecretManagerServiceClient client = SecretManagerServiceClient.create()) {
// Build the parent name from the project.
ProjectName projectName = ProjectName.of(projectId);
// Build the secret to create.
Secret secret = Secret.newBuilder().setReplication(Replication.newBuilder().setAutomatic(Replication.Automatic.newBuilder().build()).build()).build();
// Create the secret.
Secret createdSecret = client.createSecret(projectName, secretId, secret);
System.out.printf("Created secret %s\n", createdSecret.getName());
}
}
Aggregations