use of com.redhat.cloud.notifications.models.CamelProperties in project notifications-backend by RedHatInsights.
the class CamelTypeProcessor method callCamel.
public NotificationHistory callCamel(Notification item, UUID historyId, JsonObject payload, String originalEventId) {
final long startTime = System.currentTimeMillis();
Endpoint endpoint = item.getEndpoint();
String accountId = endpoint.getAccountId();
// the next could give a CCE, but we only come here when it is a camel endpoint anyway
String subType = endpoint.getSubType();
CamelProperties camelProperties = endpoint.getProperties(CamelProperties.class);
String integrationName = endpoint.getName();
if (subType.equals("slack")) {
// OpenBridge
long endTime;
NotificationHistory history = getHistoryStub(endpoint, item.getEvent(), 0L, historyId);
try {
callOpenBridge(payload, historyId, accountId, camelProperties, integrationName, originalEventId);
history.setInvocationResult(true);
} catch (Exception e) {
history.setInvocationResult(false);
Map<String, Object> details = new HashMap<>();
details.put("failure", e.getMessage());
history.setDetails(details);
LOGGER.infof("SE: Sending event with historyId=%s and originalId=%s failed: %s ", historyId, originalEventId, e.getMessage());
} finally {
endTime = System.currentTimeMillis();
}
history.setInvocationTime(endTime - startTime);
return history;
} else {
reallyCallCamel(payload, historyId, accountId, subType, integrationName, originalEventId);
final long endTime = System.currentTimeMillis();
// We only create a basic stub. The FromCamel filler will update it later
NotificationHistory history = getHistoryStub(endpoint, item.getEvent(), endTime - startTime, historyId);
return history;
}
}
use of com.redhat.cloud.notifications.models.CamelProperties in project notifications-backend by RedHatInsights.
the class CamelTypeProcessorTest method buildCamelEndpoint.
private static Endpoint buildCamelEndpoint(String accountId) {
BasicAuthentication basicAuth = new BasicAuthentication("john", "doe");
CamelProperties properties = new CamelProperties();
properties.setUrl("https://redhat.com");
properties.setDisableSslVerification(TRUE);
properties.setSecretToken("top-secret");
properties.setBasicAuthentication(basicAuth);
properties.setExtras(Map.of("foo", "bar"));
// Todo: NOTIF-429 backward compatibility change - Remove soon.
properties.setSubType(SUB_TYPE);
Endpoint endpoint = new Endpoint();
endpoint.setAccountId(accountId);
endpoint.setType(CAMEL);
endpoint.setSubType(SUB_TYPE);
endpoint.setProperties(properties);
return endpoint;
}
use of com.redhat.cloud.notifications.models.CamelProperties in project notifications-backend by RedHatInsights.
the class EndpointResourceTest method addCamelEndpoint.
@Test
void addCamelEndpoint() {
String tenant = "empty";
String orgId = "empty";
String userName = "user";
String identityHeaderValue = TestHelpers.encodeRHIdentityInfo(tenant, orgId, userName);
Header identityHeader = TestHelpers.createRHIdentityHeader(identityHeaderValue);
MockServerConfig.addMockRbacAccess(identityHeaderValue, MockServerConfig.RbacAccess.FULL_ACCESS);
CamelProperties cAttr = new CamelProperties();
cAttr.setDisableSslVerification(false);
cAttr.setUrl(getMockServerUrl());
cAttr.setBasicAuthentication(new BasicAuthentication("testuser", "secret"));
Map<String, String> extras = new HashMap<>();
extras.put("template", "11");
cAttr.setExtras(extras);
Endpoint ep = new Endpoint();
ep.setType(EndpointType.CAMEL);
ep.setSubType("ansible");
ep.setName("Push the camel through the needle's ear");
ep.setDescription("How many humps has a camel?");
ep.setEnabled(true);
ep.setProperties(cAttr);
String responseBody = given().header(identityHeader).when().contentType(JSON).body(Json.encode(ep)).post("/endpoints").then().statusCode(200).contentType(JSON).extract().asString();
JsonObject responsePoint = new JsonObject(responseBody);
responsePoint.mapTo(Endpoint.class);
String id = responsePoint.getString("id");
assertNotNull(id);
try {
JsonObject endpoint = fetchSingle(id, identityHeader);
JsonObject properties = responsePoint.getJsonObject("properties");
assertNotNull(properties);
assertTrue(endpoint.getBoolean("enabled"));
assertEquals("ansible", endpoint.getString("sub_type"));
// Todo: NOTIF-429 backward compatibility change - Remove soon.
assertEquals("ansible", properties.getString("sub_type"));
JsonObject extrasObject = properties.getJsonObject("extras");
assertNotNull(extrasObject);
String template = extrasObject.getString("template");
assertEquals("11", template);
JsonObject basicAuth = properties.getJsonObject("basic_authentication");
assertNotNull(basicAuth);
String user = basicAuth.getString("username");
String pass = basicAuth.getString("password");
assertEquals("testuser", user);
assertEquals("secret", pass);
} finally {
given().header(identityHeader).when().delete("/endpoints/" + id).then().statusCode(204).extract().body().asString();
}
}
use of com.redhat.cloud.notifications.models.CamelProperties in project notifications-backend by RedHatInsights.
the class EndpointResourceTest method addBogusCamelEndpoint.
@Test
void addBogusCamelEndpoint() {
String tenant = "empty";
String orgId = "empty";
String userName = "user";
String identityHeaderValue = TestHelpers.encodeRHIdentityInfo(tenant, orgId, userName);
Header identityHeader = TestHelpers.createRHIdentityHeader(identityHeaderValue);
MockServerConfig.addMockRbacAccess(identityHeaderValue, MockServerConfig.RbacAccess.FULL_ACCESS);
CamelProperties cAttr = new CamelProperties();
cAttr.setDisableSslVerification(false);
cAttr.setUrl(getMockServerUrl());
cAttr.setBasicAuthentication(new BasicAuthentication("testuser", "secret"));
Map<String, String> extras = new HashMap<>();
extras.put("template", "11");
cAttr.setExtras(extras);
// This is bogus because it has no sub_type
Endpoint ep = new Endpoint();
ep.setType(EndpointType.CAMEL);
ep.setName("Push the camel through the needle's ear");
ep.setDescription("How many humps has a camel?");
ep.setEnabled(true);
ep.setProperties(cAttr);
given().header(identityHeader).when().contentType(JSON).body(Json.encode(ep)).post("/endpoints").then().statusCode(400);
endpointResource.obEnabled = true;
given().header(identityHeader).when().contentType(JSON).body(Json.encode(ep)).post("/endpoints").then().statusCode(400);
endpointResource.obEnabled = false;
}
use of com.redhat.cloud.notifications.models.CamelProperties in project notifications-backend by RedHatInsights.
the class EndpointResourceTest method addOpenBridgeEndpoint.
@Test
void addOpenBridgeEndpoint() {
String tenant = "empty";
String orgId = "empty";
String userName = "user";
String identityHeaderValue = TestHelpers.encodeRHIdentityInfo(tenant, orgId, userName);
Header identityHeader = TestHelpers.createRHIdentityHeader(identityHeaderValue);
MockServerConfig.addMockRbacAccess(identityHeaderValue, MockServerConfig.RbacAccess.FULL_ACCESS);
CamelProperties cAttr = new CamelProperties();
cAttr.setDisableSslVerification(false);
cAttr.setUrl(getMockServerUrl());
Map<String, String> extras = new HashMap<>();
extras.put("channel", "#notifications");
cAttr.setExtras(extras);
Endpoint ep = new Endpoint();
ep.setType(EndpointType.CAMEL);
ep.setSubType("slack");
ep.setName("Push the camel through the needle's ear");
ep.setDescription("I guess the camel is slacking");
ep.setEnabled(true);
ep.setProperties(cAttr);
endpointResource.obEnabled = true;
bridgeHelper.setObEnabled(true);
// First we try with bogus values for the OB endpoint itself (no valid bridge)
given().header(identityHeader).when().contentType(JSON).body(Json.encode(ep)).post("/endpoints").then().statusCode(500);
// Now set up some mock OB endpoints (simulate valid bridge)
Bridge bridge = new Bridge("321", "http://some.events/", "my bridge");
Map<String, String> auth = new HashMap<>();
auth.put("access_token", "li-la-lu-token");
Map<String, String> processor = new HashMap<>();
processor.put("id", "p-my-id");
MockServerConfig.addOpenBridgeEndpoints(auth, bridge, processor);
bridgeHelper.setOurBridge("321");
String responseBody = given().header(identityHeader).when().contentType(JSON).body(Json.encode(ep)).post("/endpoints").then().statusCode(200).contentType(JSON).extract().asString();
JsonObject responsePoint = new JsonObject(responseBody);
responsePoint.mapTo(Endpoint.class);
String id = responsePoint.getString("id");
assertNotNull(id);
try {
JsonObject endpoint = fetchSingle(id, identityHeader);
JsonObject properties = responsePoint.getJsonObject("properties");
assertNotNull(properties);
assertTrue(endpoint.getBoolean("enabled"));
assertEquals("slack", endpoint.getString("sub_type"));
JsonObject extrasObject = properties.getJsonObject("extras");
assertNotNull(extrasObject);
String channel = extrasObject.getString("channel");
assertEquals("#notifications", channel);
} finally {
given().header(identityHeader).when().delete("/endpoints/" + id).then().statusCode(204);
}
MockServerConfig.clearOpenBridgeEndpoints(bridge);
bridgeHelper.setObEnabled(false);
endpointResource.obEnabled = false;
}
Aggregations