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);
}
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;
}
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();
}
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);
}
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");
}
Aggregations