Skip to content

Commit

Permalink
RHCLOUD-28235 Unify how org ID is passed to connectors (snake case) (R…
Browse files Browse the repository at this point in the history
  • Loading branch information
gwenneg authored Sep 26, 2023
1 parent e875adc commit 7a6f441
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ public void process(Exchange exchange) throws Exception {
exchange.setProperty(RETURN_SOURCE, connectorConfig.getConnectorName());

JsonObject data = cloudEvent.getJsonObject(CLOUD_EVENT_DATA);
exchange.setProperty(ORG_ID, data.getString("orgId"));
exchange.setProperty(ORG_ID, data.getString("org_id"));
if (exchange.getProperty(ORG_ID, String.class) == null) { // TODO For migration purposes, remove ASAP.
exchange.setProperty(ORG_ID, data.getString("orgId"));
}

cloudEventDataExtractor.extract(exchange, data);
}
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.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 @@ -12,7 +12,6 @@

import static com.redhat.cloud.notifications.TestConstants.DEFAULT_ACCOUNT_ID;
import static com.redhat.cloud.notifications.TestConstants.DEFAULT_ORG_ID;
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 Down Expand Up @@ -118,7 +117,6 @@ 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("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 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 @@ -12,7 +12,6 @@

import static com.redhat.cloud.notifications.TestConstants.DEFAULT_ACCOUNT_ID;
import static com.redhat.cloud.notifications.TestConstants.DEFAULT_ORG_ID;
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 Down Expand Up @@ -140,7 +139,6 @@ 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("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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public class ConnectorSender {
NotificationHistoryRepository notificationHistoryRepository;

public void send(Event event, Endpoint endpoint, JsonObject payload) {
payload.put("orgId", event.getOrgId());
payload.put("org_id", event.getOrgId());
payload.put("orgId", event.getOrgId()); // TODO For migration purposes, remove ASAP.

String connector = getConnector(endpoint);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ protected void verifyKafkaMessage() {

JsonObject notification = message.getPayload();

assertEquals(DEFAULT_ORG_ID, notification.getString("orgId"));
assertEquals(DEFAULT_ORG_ID, notification.getString("org_id"));
assertEquals(WEBHOOK_URL, notification.getString("webhookUrl"));
assertEquals(getExpectedMessage(), notification.getString("message"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected void verifyKafkaMessage() {

JsonObject notification = message.getPayload();

assertEquals(DEFAULT_ORG_ID, notification.getString("orgId"));
assertEquals(DEFAULT_ORG_ID, notification.getString("org_id"));
assertEquals(WEBHOOK_URL, notification.getString("webhookUrl"));
assertEquals(CHANNEL, notification.getString("channel"));
assertEquals(SLACK_EXPECTED_MSG, notification.getString("message"));
Expand Down

0 comments on commit 7a6f441

Please sign in to comment.