Skip to content

Commit

Permalink
RHCLOUD-28235 Unify how org ID is passed to connectors (phase 2)
Browse files Browse the repository at this point in the history
  • Loading branch information
gwenneg committed Sep 25, 2023
1 parent 28aad98 commit c5d643b
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.apache.commons.validator.routines.UrlValidator;
import org.apache.http.ProtocolException;

import static com.redhat.cloud.notifications.connector.ExchangeProperty.ORG_ID;
import static com.redhat.cloud.notifications.connector.ExchangeProperty.TARGET_URL;
import static com.redhat.cloud.notifications.connector.servicenow.ExchangeProperty.ACCOUNT_ID;
import static com.redhat.cloud.notifications.connector.servicenow.ExchangeProperty.AUTHENTICATION_TOKEN;
Expand All @@ -26,8 +25,6 @@ public class ServiceNowCloudEventDataExtractor extends CloudEventDataExtractor {
@Override
public void extract(Exchange exchange, JsonObject cloudEventData) throws Exception {

// TODO Rely on the org ID parsing from IncomingCloudEventProcessor?
exchange.setProperty(ORG_ID, cloudEventData.getString("org_id"));
exchange.setProperty(ACCOUNT_ID, cloudEventData.getString("account_id"));

JsonObject metadata = cloudEventData.getJsonObject(NOTIF_METADATA);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private void testExtract(String url, boolean trustAll) throws Exception {
JsonObject cloudEventDataCopy = cloudEventData.copy();
serviceNowCloudEventDataExtractor.extract(exchange, cloudEventData);

assertEquals(cloudEventDataCopy.getString("org_id"), exchange.getProperty(ORG_ID, String.class));
assertEquals(cloudEventDataCopy.getString("orgId"), exchange.getProperty(ORG_ID, String.class));
assertEquals(cloudEventDataCopy.getString("account_id"), exchange.getProperty(ACCOUNT_ID, String.class));
assertEquals(cloudEventDataCopy.getJsonObject(NOTIF_METADATA).getString("url"), exchange.getProperty(TARGET_URL, String.class));
assertTrue(cloudEventDataCopy.getJsonObject(NOTIF_METADATA).getString("url").endsWith(exchange.getProperty(TARGET_URL_NO_SCHEME, String.class)));
Expand All @@ -133,7 +133,7 @@ private JsonObject createCloudEventData(String url, boolean trustAll) {
metadata.put("X-Insights-Token", "super-secret-token");

JsonObject cloudEventData = new JsonObject();
cloudEventData.put("org_id", DEFAULT_ORG_ID);
cloudEventData.put("orgId", DEFAULT_ORG_ID);
cloudEventData.put("account_id", DEFAULT_ACCOUNT_ID);
cloudEventData.put(NOTIF_METADATA, metadata);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.apache.commons.validator.routines.UrlValidator;
import org.apache.http.ProtocolException;

import static com.redhat.cloud.notifications.connector.ExchangeProperty.ORG_ID;
import static com.redhat.cloud.notifications.connector.ExchangeProperty.TARGET_URL;
import static com.redhat.cloud.notifications.connector.splunk.ExchangeProperty.ACCOUNT_ID;
import static com.redhat.cloud.notifications.connector.splunk.ExchangeProperty.AUTHENTICATION_TOKEN;
Expand All @@ -31,8 +30,6 @@ public class SplunkCloudEventDataExtractor extends CloudEventDataExtractor {
@Override
public void extract(Exchange exchange, JsonObject cloudEventData) throws Exception {

// TODO Rely on the org ID parsing from IncomingCloudEventProcessor?
exchange.setProperty(ORG_ID, cloudEventData.getString("org_id"));
exchange.setProperty(ACCOUNT_ID, cloudEventData.getString("account_id"));

JsonObject metadata = cloudEventData.getJsonObject(NOTIF_METADATA);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private void testExtract(String url, boolean trustAll) throws Exception {
JsonObject cloudEventDataCopy = cloudEventData.copy();
splunkCloudEventDataExtractor.extract(exchange, cloudEventData);

assertEquals(cloudEventDataCopy.getString("org_id"), exchange.getProperty(ORG_ID, String.class));
assertEquals(cloudEventDataCopy.getString("orgId"), exchange.getProperty(ORG_ID, String.class));
assertEquals(cloudEventDataCopy.getString("account_id"), exchange.getProperty(ACCOUNT_ID, String.class));
assertTrue(exchange.getProperty(TARGET_URL, String.class).endsWith(SERVICES_COLLECTOR_EVENT));
// Trailing slashes should be removed before we modify the target URL path.
Expand All @@ -157,7 +157,7 @@ private JsonObject createCloudEventData(String url, boolean trustAll) {
metadata.put("X-Insights-Token", "super-secret-token");

JsonObject cloudEventData = new JsonObject();
cloudEventData.put("org_id", DEFAULT_ORG_ID);
cloudEventData.put("orgId", DEFAULT_ORG_ID);
cloudEventData.put("account_id", DEFAULT_ACCOUNT_ID);
cloudEventData.put(NOTIF_METADATA, metadata);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.net.URL;
import java.util.MissingResourceException;

import static com.redhat.cloud.notifications.connector.ExchangeProperty.ORG_ID;
import static com.redhat.cloud.notifications.connector.ExchangeProperty.TARGET_URL;
import static com.redhat.cloud.notifications.connector.webhook.ExchangeProperty.BASIC_AUTH_PASSWORD;
import static com.redhat.cloud.notifications.connector.webhook.ExchangeProperty.BASIC_AUTH_USERNAME;
Expand Down Expand Up @@ -45,12 +44,6 @@ public void extract(Exchange exchange, JsonObject cloudEventData) throws Malform
exchange.setProperty(BASIC_AUTH_PASSWORD, basicAuth.getString("password"));
}

if (cloudEventData.getJsonObject(PAYLOAD).containsKey("org_id")) {
exchange.setProperty(ORG_ID, cloudEventData.getJsonObject(PAYLOAD).getString("org_id"));
} else if (cloudEventData.getJsonObject(PAYLOAD).containsKey("redhatorgid")) {
exchange.setProperty(ORG_ID, cloudEventData.getJsonObject(PAYLOAD).getString("redhatorgid"));
}

exchange.getIn().setBody(cloudEventData.getJsonObject(PAYLOAD).encode());
exchange.getIn().setHeader(Exchange.HTTP_METHOD, HttpMethods.valueOf(endpointProperties.getString("method")));

Expand Down

0 comments on commit c5d643b

Please sign in to comment.