Search in sources :

Example 41 with Event

use of com.google.recaptchaenterprise.v1beta1.Event in project kubernetes-client by fabric8io.

the class V1EventsTest method testGet.

@Test
void testGet() {
    // Given
    server.expect().get().withPath("/apis/events.k8s.io/v1/namespaces/default/events/event1").andReturn(HttpURLConnection.HTTP_OK, new EventBuilder().withNewMetadata().withName("event1").endMetadata().build()).once();
    // When
    Event e1 = client.events().v1().events().inNamespace("default").withName("event1").get();
    // Then
    assertThat(e1).isNotNull().hasFieldOrPropertyWithValue("metadata.name", "event1");
}
Also used : EventBuilder(io.fabric8.kubernetes.api.model.events.v1.EventBuilder) Event(io.fabric8.kubernetes.api.model.events.v1.Event) Test(org.junit.jupiter.api.Test)

Example 42 with Event

use of com.google.recaptchaenterprise.v1beta1.Event in project yakc by manusa.

the class EventsV1ApiIT method readNamespacedEvent.

@Test
@DisplayName("readNamespacedEvent, should read existing Event with provided name")
void readNamespacedEvent() throws IOException {
    // When
    final Event result = KC.create(EventsV1Api.class).readNamespacedEvent(eventName, NAMESPACE).get();
    // Then
    assertThat(result).isNotNull().extracting("metadata").hasFieldOrPropertyWithValue("name", eventName).hasFieldOrPropertyWithValue("creationTimestamp", event.getMetadata().getCreationTimestamp());
}
Also used : Event(com.marcnuri.yakc.model.io.k8s.api.events.v1.Event) ListNamespacedEvent(com.marcnuri.yakc.api.events.v1.EventsV1Api.ListNamespacedEvent) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 43 with Event

use of com.google.recaptchaenterprise.v1beta1.Event in project java-recaptchaenterprise by googleapis.

the class CreateAssessment method createAssessment.

/**
 * Create an assessment to analyze the risk of an UI action. Assessment approach is the same for
 * both 'score' and 'checkbox' type recaptcha site keys.
 *
 * @param projectID : GCloud Project ID
 * @param recaptchaSiteKey : Site key obtained by registering a domain/app to use recaptcha
 *     services. (score/ checkbox type)
 * @param token : The token obtained from the client on passing the recaptchaSiteKey.
 * @param recaptchaAction : Action name corresponding to the token.
 */
public static void createAssessment(String projectID, String recaptchaSiteKey, String token, String recaptchaAction) throws IOException {
    // clean up any remaining background resources.
    try (RecaptchaEnterpriseServiceClient client = RecaptchaEnterpriseServiceClient.create()) {
        // Set the properties of the event to be tracked.
        Event event = Event.newBuilder().setSiteKey(recaptchaSiteKey).setToken(token).build();
        // Build the assessment request.
        CreateAssessmentRequest createAssessmentRequest = CreateAssessmentRequest.newBuilder().setParent(ProjectName.of(projectID).toString()).setAssessment(Assessment.newBuilder().setEvent(event).build()).build();
        Assessment response = client.createAssessment(createAssessmentRequest);
        // Check if the token is valid.
        if (!response.getTokenProperties().getValid()) {
            System.out.println("The CreateAssessment call failed because the token was: " + response.getTokenProperties().getInvalidReason().name());
            return;
        }
        // (If the key is checkbox type and 'action' attribute wasn't set, skip this check.)
        if (!response.getTokenProperties().getAction().equals(recaptchaAction)) {
            System.out.println("The action attribute in reCAPTCHA tag is: " + response.getTokenProperties().getAction());
            System.out.println("The action attribute in the reCAPTCHA tag " + "does not match the action (" + recaptchaAction + ") you are expecting to score");
            return;
        }
        // see: https://cloud.google.com/recaptcha-enterprise/docs/interpret-assessment
        for (ClassificationReason reason : response.getRiskAnalysis().getReasonsList()) {
            System.out.println(reason);
        }
        float recaptchaScore = response.getRiskAnalysis().getScore();
        System.out.println("The reCAPTCHA score is: " + recaptchaScore);
        // Get the assessment name (id). Use this to annotate the assessment.
        String assessmentName = response.getName();
        System.out.println("Assessment name: " + assessmentName.substring(assessmentName.lastIndexOf("/") + 1));
    }
}
Also used : Assessment(com.google.recaptchaenterprise.v1.Assessment) CreateAssessmentRequest(com.google.recaptchaenterprise.v1.CreateAssessmentRequest) Event(com.google.recaptchaenterprise.v1.Event) ClassificationReason(com.google.recaptchaenterprise.v1.RiskAnalysis.ClassificationReason) RecaptchaEnterpriseServiceClient(com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient)

Example 44 with Event

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

the class EventReportServiceClient method shutdown.

@Override
public void shutdown() throws Throwable {
    if (!CONNECTED.equals(status)) {
        return;
    }
    final CountDownLatch latch = new CountDownLatch(1);
    final Event.Builder shutdownEvent = Event.newBuilder().setUuid(UUID.randomUUID().toString()).setName("Shutdown").setStartTime(System.currentTimeMillis()).setEndTime(System.currentTimeMillis()).setMessage("Shutting down Java Application").setType(Type.Normal).setSource(Source.newBuilder().setService(Config.Agent.SERVICE_NAME).setServiceInstance(Config.Agent.INSTANCE_NAME).build());
    final StreamObserver<Event> collector = eventServiceStub.collect(new StreamObserver<Commands>() {

        @Override
        public void onNext(final Commands commands) {
            ServiceManager.INSTANCE.findService(CommandService.class).receiveCommand(commands);
        }

        @Override
        public void onError(final Throwable t) {
            LOGGER.error("Failed to report shutdown event.", t);
            // Ignore status change at shutting down stage.
            latch.countDown();
        }

        @Override
        public void onCompleted() {
            latch.countDown();
        }
    });
    collector.onNext(shutdownEvent.build());
    collector.onCompleted();
    latch.await();
}
Also used : Commands(org.apache.skywalking.apm.network.common.v3.Commands) Event(org.apache.skywalking.apm.network.event.v3.Event) CountDownLatch(java.util.concurrent.CountDownLatch)

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