Search in sources :

Example 1 with WebhookProperties

use of com.redhat.cloud.notifications.models.WebhookProperties in project notifications-backend by RedHatInsights.

the class WebhookTypeProcessor method process.

private NotificationHistory process(Notification item) {
    processedCount.increment();
    Endpoint endpoint = item.getEndpoint();
    WebhookProperties properties = endpoint.getProperties(WebhookProperties.class);
    final HttpRequest<Buffer> req = getWebClient(properties.getDisableSslVerification()).requestAbs(HttpMethod.valueOf(properties.getMethod().name()), properties.getUrl());
    if (properties.getSecretToken() != null && !properties.getSecretToken().isBlank()) {
        req.putHeader(TOKEN_HEADER, properties.getSecretToken());
    }
    if (properties.getBasicAuthentication() != null) {
        req.basicAuthentication(properties.getBasicAuthentication().getUsername(), properties.getBasicAuthentication().getPassword());
    }
    JsonObject payload = transformer.transform(item.getEvent().getAction());
    return doHttpRequest(item, req, payload);
}
Also used : Buffer(io.vertx.mutiny.core.buffer.Buffer) Endpoint(com.redhat.cloud.notifications.models.Endpoint) WebhookProperties(com.redhat.cloud.notifications.models.WebhookProperties) JsonObject(io.vertx.core.json.JsonObject)

Example 2 with WebhookProperties

use of com.redhat.cloud.notifications.models.WebhookProperties in project notifications-backend by RedHatInsights.

the class ResourceHelpers method createTestEndpoints.

public int[] createTestEndpoints(String tenant, int count) {
    int[] statsValues = new int[3];
    statsValues[0] = count;
    for (int i = 0; i < count; i++) {
        // Add new endpoints
        WebhookProperties properties = new WebhookProperties();
        properties.setMethod(HttpType.POST);
        properties.setUrl("https://localhost");
        Endpoint ep = new Endpoint();
        ep.setType(WEBHOOK);
        ep.setName(String.format("Endpoint %d", count - i));
        ep.setDescription("Automatically generated");
        boolean enabled = (i % (count / 5)) != 0;
        if (!enabled) {
            statsValues[1]++;
        }
        ep.setEnabled(enabled);
        if (i > 0) {
            statsValues[2]++;
            ep.setProperties(properties);
        }
        ep.setAccountId(tenant);
        endpointRepository.createEndpoint(ep);
    }
    return statsValues;
}
Also used : Endpoint(com.redhat.cloud.notifications.models.Endpoint) WebhookProperties(com.redhat.cloud.notifications.models.WebhookProperties) Endpoint(com.redhat.cloud.notifications.models.Endpoint)

Example 3 with WebhookProperties

use of com.redhat.cloud.notifications.models.WebhookProperties in project notifications-backend by RedHatInsights.

the class ResourceHelpers method createWebhookEndpoint.

public UUID createWebhookEndpoint(String accountId) {
    WebhookProperties properties = new WebhookProperties();
    properties.setMethod(HttpType.POST);
    properties.setUrl("https://localhost");
    String name = "Endpoint " + UUID.randomUUID();
    return createEndpoint(accountId, WEBHOOK, null, name, "Automatically generated", properties, TRUE).getId();
}
Also used : WebhookProperties(com.redhat.cloud.notifications.models.WebhookProperties)

Example 4 with WebhookProperties

use of com.redhat.cloud.notifications.models.WebhookProperties in project notifications-backend by RedHatInsights.

the class LifecycleITest method createWebhookEndpoint.

private Endpoint createWebhookEndpoint(String accountId, String secretToken) {
    WebhookProperties properties = new WebhookProperties();
    properties.setMethod(HttpType.POST);
    properties.setDisableSslVerification(true);
    properties.setSecretToken(secretToken);
    properties.setUrl(getMockServerUrl() + WEBHOOK_MOCK_PATH);
    return createEndpoint(accountId, WEBHOOK, "endpoint", "Endpoint", properties);
}
Also used : WebhookProperties(com.redhat.cloud.notifications.models.WebhookProperties)

Example 5 with WebhookProperties

use of com.redhat.cloud.notifications.models.WebhookProperties in project notifications-backend by RedHatInsights.

the class LifecycleITest method createWebhookEndpoint.

private String createWebhookEndpoint(Header identityHeader, String secretToken) {
    WebhookProperties properties = new WebhookProperties();
    properties.setMethod(HttpType.POST);
    properties.setDisableSslVerification(true);
    properties.setSecretToken(secretToken);
    properties.setUrl(getMockServerUrl() + WEBHOOK_MOCK_PATH);
    Endpoint endpoint = new Endpoint();
    endpoint.setType(EndpointType.WEBHOOK);
    endpoint.setName("endpoint");
    endpoint.setDescription("Endpoint");
    endpoint.setEnabled(true);
    endpoint.setProperties(properties);
    String responseBody = given().basePath(API_INTEGRATIONS_V_1_0).header(identityHeader).contentType(JSON).body(Json.encode(endpoint)).when().post("/endpoints").then().statusCode(200).contentType(JSON).extract().body().asString();
    JsonObject jsonEndpoint = new JsonObject(responseBody);
    jsonEndpoint.mapTo(Endpoint.class);
    assertNotNull(jsonEndpoint.getString("id"));
    assertNull(jsonEndpoint.getString("accountId"));
    assertNull(jsonEndpoint.getString("orgId"));
    assertEquals(endpoint.getName(), jsonEndpoint.getString("name"));
    assertEquals(endpoint.getDescription(), jsonEndpoint.getString("description"));
    assertTrue(jsonEndpoint.getBoolean("enabled"));
    assertEquals(EndpointType.WEBHOOK.name().toLowerCase(), jsonEndpoint.getString("type"));
    JsonObject jsonWebhookProperties = jsonEndpoint.getJsonObject("properties");
    jsonWebhookProperties.mapTo(WebhookProperties.class);
    assertEquals(properties.getMethod().name(), jsonWebhookProperties.getString("method"));
    assertEquals(properties.getDisableSslVerification(), jsonWebhookProperties.getBoolean("disable_ssl_verification"));
    if (properties.getSecretToken() != null) {
        assertEquals(properties.getSecretToken(), jsonWebhookProperties.getString("secret_token"));
    }
    assertEquals(properties.getUrl(), jsonWebhookProperties.getString("url"));
    return jsonEndpoint.getString("id");
}
Also used : Endpoint(com.redhat.cloud.notifications.models.Endpoint) WebhookProperties(com.redhat.cloud.notifications.models.WebhookProperties) JsonObject(io.vertx.core.json.JsonObject)

Aggregations

WebhookProperties (com.redhat.cloud.notifications.models.WebhookProperties)15 Endpoint (com.redhat.cloud.notifications.models.Endpoint)13 JsonObject (io.vertx.core.json.JsonObject)9 Header (io.restassured.http.Header)7 Response (io.restassured.response.Response)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 DbIsolatedTest (com.redhat.cloud.notifications.db.DbIsolatedTest)6 QuarkusTest (io.quarkus.test.junit.QuarkusTest)6 Test (org.junit.jupiter.api.Test)6 EndpointPage (com.redhat.cloud.notifications.routers.models.EndpointPage)3 CamelProperties (com.redhat.cloud.notifications.models.CamelProperties)2 BasicAuthentication (com.redhat.cloud.notifications.models.BasicAuthentication)1 EmailSubscriptionProperties (com.redhat.cloud.notifications.models.EmailSubscriptionProperties)1 RequestEmailSubscriptionProperties (com.redhat.cloud.notifications.routers.models.RequestEmailSubscriptionProperties)1 Buffer (io.vertx.mutiny.core.buffer.Buffer)1 HashSet (java.util.HashSet)1 Transactional (javax.transaction.Transactional)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1