Search in sources :

Example 16 with Event

use of com.google.recaptchaenterprise.v1beta1.Event in project incubator-skywalking by apache.

the class EventHookCallbackTest method testEventCallbackHasRightFlow.

@Test
public void testEventCallbackHasRightFlow() throws Exception {
    List<AlarmMessage> msgs = mockAlarmMessagesHasSingleElement();
    EventHookCallback callback = new EventHookCallback(this.moduleManager);
    when(moduleManager.find("event-analyzer")).thenReturn(moduleProviderHolder);
    when(moduleProviderHolder.provider()).thenReturn(moduleServiceHolder);
    when(moduleServiceHolder.getService(EventAnalyzerService.class)).thenReturn(mockEventAnalyzerService);
    // make sure current service be called.
    callback.doAlarm(msgs);
    verify(mockEventAnalyzerService).analyze(any(Event.class));
    when(moduleServiceHolder.getService(EventAnalyzerService.class)).thenReturn(eventAnalyzerService);
    callback.doAlarm(msgs);
    // Ensure that the current Event is properly constructed
    ArgumentCaptor<Event> argument = ArgumentCaptor.forClass(Event.class);
    verify(eventAnalyzerService).analyze(argument.capture());
    Event value = argument.getValue();
    AlarmMessage msg = msgs.get(0);
    assertEquals(msg.getName(), value.getSource().getService());
    assertEquals("Alarm", value.getName());
    assertEquals(msg.getAlarmMessage(), value.getMessage());
    assertEquals(msg.getPeriod(), (value.getEndTime() - value.getStartTime()) / 1000 / 60);
}
Also used : AlarmMessage(org.apache.skywalking.oap.server.core.alarm.AlarmMessage) Event(org.apache.skywalking.apm.network.event.v3.Event) Test(org.junit.Test)

Example 17 with Event

use of com.google.recaptchaenterprise.v1beta1.Event in project incubator-skywalking by apache.

the class EventHookCallbackTest method testRelationEventBeProperlyConstructed.

@Test
public void testRelationEventBeProperlyConstructed() {
    List<AlarmMessage> msgs = mockAlarmMessagesHasSourceAndDest();
    EventHookCallback callback = new EventHookCallback(this.moduleManager);
    when(moduleManager.find("event-analyzer")).thenReturn(moduleProviderHolder);
    when(moduleProviderHolder.provider()).thenReturn(moduleServiceHolder);
    when(moduleServiceHolder.getService(EventAnalyzerService.class)).thenReturn(eventAnalyzerService);
    callback.doAlarm(msgs);
    ArgumentCaptor<Event> argument = ArgumentCaptor.forClass(Event.class);
    verify(eventAnalyzerService, times(2)).analyze(argument.capture());
    List<Event> events = argument.getAllValues();
    assertEquals(events.size(), 2);
    Event sourceEvent = events.get(0);
    Event destEvent = events.get(1);
    AlarmMessage msg = msgs.get(0);
    assertEquals(sourceEvent.getSource().getService(), IDManager.ServiceID.analysisId(msg.getId0()).getName());
    assertEquals((sourceEvent.getEndTime() - sourceEvent.getStartTime()) / 1000 / 60, msg.getPeriod());
    assertEquals(destEvent.getSource().getService(), IDManager.ServiceID.analysisId(msg.getId1()).getName());
    assertEquals((destEvent.getEndTime() - destEvent.getStartTime()) / 1000 / 60, msg.getPeriod());
}
Also used : AlarmMessage(org.apache.skywalking.oap.server.core.alarm.AlarmMessage) Event(org.apache.skywalking.apm.network.event.v3.Event) Test(org.junit.Test)

Example 18 with Event

use of com.google.recaptchaenterprise.v1beta1.Event in project java-docs-samples by GoogleCloudPlatform.

the class GetChannelEvent method getChannelEvent.

public static void getChannelEvent(String projectId, String location, String channelId, String eventId) throws IOException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (LivestreamServiceClient livestreamServiceClient = LivestreamServiceClient.create()) {
        EventName name = EventName.of(projectId, location, channelId, eventId);
        Event response = livestreamServiceClient.getEvent(name);
        System.out.println("Channel event: " + response.getName());
    }
}
Also used : Event(com.google.cloud.video.livestream.v1.Event) EventName(com.google.cloud.video.livestream.v1.EventName) LivestreamServiceClient(com.google.cloud.video.livestream.v1.LivestreamServiceClient)

Example 19 with Event

use of com.google.recaptchaenterprise.v1beta1.Event in project java-docs-samples by GoogleCloudPlatform.

the class ListChannelEvents method listChannelEvents.

public static void listChannelEvents(String projectId, String location, String channelId) throws IOException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (LivestreamServiceClient livestreamServiceClient = LivestreamServiceClient.create()) {
        var listEventsRequest = ListEventsRequest.newBuilder().setParent(ChannelName.of(projectId, location, channelId).toString()).build();
        LivestreamServiceClient.ListEventsPagedResponse response = livestreamServiceClient.listEvents(listEventsRequest);
        System.out.println("Channel events:");
        for (Event event : response.iterateAll()) {
            System.out.println(event.getName());
        }
    }
}
Also used : Event(com.google.cloud.video.livestream.v1.Event) LivestreamServiceClient(com.google.cloud.video.livestream.v1.LivestreamServiceClient)

Example 20 with Event

use of com.google.recaptchaenterprise.v1beta1.Event 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;
}
Also used : Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) CreateAssessmentRequest(com.google.recaptchaenterprise.v1beta1.CreateAssessmentRequest) Service(org.springframework.stereotype.Service) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Assessment(com.google.recaptchaenterprise.v1beta1.Assessment) RecaptchaEnterpriseServiceV1Beta1Client(com.google.cloud.recaptchaenterprise.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client) ProjectName(com.google.recaptchaenterprise.v1beta1.ProjectName) Pattern(java.util.regex.Pattern) Collectors(java.util.stream.Collectors) Event(com.google.recaptchaenterprise.v1beta1.Event) StringUtils(org.springframework.util.StringUtils) ProjectName(com.google.recaptchaenterprise.v1beta1.ProjectName) Assessment(com.google.recaptchaenterprise.v1beta1.Assessment) CreateAssessmentRequest(com.google.recaptchaenterprise.v1beta1.CreateAssessmentRequest) Event(com.google.recaptchaenterprise.v1beta1.Event)

Aggregations

Test (org.junit.Test)18 Event (io.requery.test.model3.Event)9 UUID (java.util.UUID)9 Event (org.apache.skywalking.apm.network.event.v3.Event)9 Test (org.junit.jupiter.api.Test)9 Event (org.eclipse.bpmn2.Event)5 Event (com.google.cloud.video.livestream.v1.Event)4 LivestreamServiceClient (com.google.cloud.video.livestream.v1.LivestreamServiceClient)4 Place (io.requery.test.model3.Place)4 Tag (io.requery.test.model3.Tag)4 AlarmMessage (org.apache.skywalking.oap.server.core.alarm.AlarmMessage)4 ListNamespacedEvent (com.marcnuri.yakc.api.events.v1.EventsV1Api.ListNamespacedEvent)3 Event (com.marcnuri.yakc.model.io.k8s.api.events.v1.Event)3 Event (io.fabric8.kubernetes.api.model.events.v1.Event)3 Event (io.requery.test.model2.Event)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Event (uk.gov.justice.hmpps.prison.api.model.v1.Event)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 JsonArray (com.google.gson.JsonArray)2