Skip to content

Commit

Permalink
feature: allow overriding the email senders (RedHatInsights#2624)
Browse files Browse the repository at this point in the history
We need to provide a way to override the email senders for different
clusters than the commercial one.

RHCLOUD-31979
  • Loading branch information
MikelAlejoBR authored Apr 26, 2024
1 parent 0b33d36 commit c73d2ef
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 16 deletions.
15 changes: 15 additions & 0 deletions .rhcicd/clowdapp-engine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ objects:
value: ${NOTIFICATIONS_EMAIL_HCC_SENDER_NAME_ENABLED}
- name: NOTIFICATIONS_EMAILS_ONLY_MODE_ENABLED
value: ${NOTIFICATIONS_EMAILS_ONLY_MODE_ENABLED}
- name: NOTIFICATIONS_EMAIL_SENDER_HYBRID_CLOUD_CONSOLE
value: ${NOTIFICATIONS_EMAIL_SENDER_HYBRID_CLOUD_CONSOLE}
- name: NOTIFICATIONS_EMAIL_SENDER_OPENSHIFT_STAGE
value: ${NOTIFICATIONS_EMAIL_SENDER_OPENSHIFT_STAGE}
- name: NOTIFICATIONS_EMAIL_SENDER_OPENSHIFT_PROD
value: ${NOTIFICATIONS_EMAIL_SENDER_OPENSHIFT_PROD}
- name: NOTIFICATIONS_KAFKA_CONSUMED_TOTAL_CHECKER_ENABLED
value: ${KAFKA_CONSUMED_TOTAL_CHECKER_ENABLED}
- name: NOTIFICATIONS_KAFKA_CONSUMED_TOTAL_CHECKER_INITIAL_DELAY
Expand Down Expand Up @@ -315,6 +321,15 @@ parameters:
- name: NOTIFICATIONS_EMAILS_ONLY_MODE_ENABLED
description: When this is true, all integration types except emails are disabled
value: "true"
- name: NOTIFICATIONS_EMAIL_SENDER_HYBRID_CLOUD_CONSOLE
description: The email sender address for the Red Hat Hybrid Cloud Console.
value: "\"Red Hat Hybrid Cloud Console\" [email protected]"
- name: NOTIFICATIONS_EMAIL_SENDER_OPENSHIFT_STAGE
description: The email sender address for the OpenShift domain in stage.
value: "\"Red Hat OpenShift (staging)\" [email protected]"
- name: NOTIFICATIONS_EMAIL_SENDER_OPENSHIFT_PROD
description: The email sender address for the OpenShift domain in production.
value: "\"Red Hat OpenShift\" [email protected]"
- name: NOTIFICATIONS_LOG_LEVEL
description: Log level for com.redhat.cloud.notifications
value: INFO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,19 @@
import io.quarkus.logging.Log;
import jakarta.enterprise.context.ApplicationScoped;
import org.eclipse.microprofile.config.inject.ConfigProperty;

import java.time.LocalDate;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

@ApplicationScoped
public class EmailActorsResolver {
@Deprecated
public static final String RH_INSIGHTS_SENDER = "\"Red Hat Insights\" [email protected]";
/**
* Standard "Red Hat Hybrid Cloud Console" sender that the vast majority of the
* ConsoleDot applications will use.
*/
public static final String RH_HCC_SENDER = "\"Red Hat Hybrid Cloud Console\" [email protected]";
@Deprecated
public static final String OPENSHIFT_SENDER_STAGE = "\"Red Hat OpenShift (staging)\" [email protected]";
@Deprecated
public static final String OPENSHIFT_SENDER_PROD = "\"Red Hat OpenShift\" [email protected]";
public static final String OPENSHIFT_SENDER_STAGE_NOREPLY_REDHAT = "\"Red Hat OpenShift (staging)\" [email protected]";
public static final String OPENSHIFT_SENDER_PROD_NOREPLY_REDHAT = "\"Red Hat OpenShift\" [email protected]";
private static final String STAGE_ENVIRONMENT = "stage";
public static String OCM_PENDO_MESSAGE = "The email sender address will soon be changing from [email protected] to <br/><b>[email protected]</b>.<br/><br/>If you have filtering or forwarding logic in place, you will need to update<br/>those rules by <b>%s</b>.";
public static String GENERAL_PENDO_MESSAGE = "The email sender name will soon be changing from Red Hat Insights to<br/><b>Red Hat Hybrid Cloud Console</b>.<br/><br/>If you have filtering or forwarding logic in place, you will need to update<br/>those rules by <b>%s</b>.";
Expand All @@ -30,6 +27,24 @@ public class EmailActorsResolver {
@ConfigProperty(name = "notifications.email.show.pendo.until.date", defaultValue = "2024-05-01")
LocalDate emailChangesActivationDate;

/**
* The email sender address for the Red Hat Hybrid Cloud Console.
*/
@ConfigProperty(name = "notifications.email.sender.hybrid.cloud.console", defaultValue = "\"Red Hat Hybrid Cloud Console\" [email protected]")
protected String rhHccSender;

/**
* The email sender address for OpenShift in stage.
*/
@ConfigProperty(name = "notifications.email.sender.openshift.stage", defaultValue = "\"Red Hat OpenShift (staging)\" [email protected]")
protected String rhOpenshiftSenderStage;

/**
* The email sender address for OpenShift in production.
*/
@ConfigProperty(name = "notifications.email.sender.openshift.prod", defaultValue = "\"Red Hat OpenShift\" [email protected]")
protected String rhOpenshiftSenderProd;

/**
* Determines which sender should be set in the email from the given event.
* When sending emails we will use the sender for both the sender itself
Expand All @@ -55,9 +70,9 @@ public String getEmailSender(final Event event) {
private String getOCMEmailSender(Event event) {
if (isHccEmailSenderNameEnabled()) {
if (STAGE_ENVIRONMENT.equals(event.getSourceEnvironment())) {
return OPENSHIFT_SENDER_STAGE_NOREPLY_REDHAT;
return this.rhOpenshiftSenderStage;
} else {
return OPENSHIFT_SENDER_PROD_NOREPLY_REDHAT;
return this.rhOpenshiftSenderProd;
}
} else {
if (STAGE_ENVIRONMENT.equals(event.getSourceEnvironment())) {
Expand Down Expand Up @@ -95,7 +110,7 @@ private boolean isOCMApp(Event event) {

private String getDefaultEmailSender() {
if (isHccEmailSenderNameEnabled()) {
return RH_HCC_SENDER;
return this.rhHccSender;
} else {
return RH_INSIGHTS_SENDER;
}
Expand All @@ -116,4 +131,16 @@ private boolean isHccEmailSenderNameEnabled() {
public void setEmailChangesActivationDate(LocalDate emailChangesActivationDate) {
this.emailChangesActivationDate = emailChangesActivationDate;
}

public String getRhHccSender() {
return this.rhHccSender;
}

public String getOpenshiftSenderStage() {
return this.rhOpenshiftSenderStage;
}

public String getOpenshiftSenderProd() {
return this.rhOpenshiftSenderProd;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@
import io.quarkus.test.junit.QuarkusTest;
import jakarta.inject.Inject;
import org.junit.jupiter.api.Test;

import java.time.LocalDate;

import static com.redhat.cloud.notifications.processors.email.EmailActorsResolver.GENERAL_PENDO_MESSAGE;
import static com.redhat.cloud.notifications.processors.email.EmailActorsResolver.GENERAL_PENDO_TITLE;
import static com.redhat.cloud.notifications.processors.email.EmailActorsResolver.OCM_PENDO_MESSAGE;
import static com.redhat.cloud.notifications.processors.email.EmailActorsResolver.OCM_PENDO_TITLE;
import static com.redhat.cloud.notifications.processors.email.EmailActorsResolver.OPENSHIFT_SENDER_PROD;
import static com.redhat.cloud.notifications.processors.email.EmailActorsResolver.OPENSHIFT_SENDER_PROD_NOREPLY_REDHAT;
import static com.redhat.cloud.notifications.processors.email.EmailActorsResolver.OPENSHIFT_SENDER_STAGE;
import static com.redhat.cloud.notifications.processors.email.EmailActorsResolver.OPENSHIFT_SENDER_STAGE_NOREPLY_REDHAT;
import static com.redhat.cloud.notifications.processors.email.EmailActorsResolver.RH_HCC_SENDER;
import static com.redhat.cloud.notifications.processors.email.EmailActorsResolver.RH_INSIGHTS_SENDER;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
Expand Down Expand Up @@ -50,7 +48,7 @@ void testDefaultEmailSenderHCC() {
try {
emailActorsResolver.setEmailChangesActivationDate(LocalDate.parse("2024-01-01"));
Event event = buildEvent(null, "rhel", "policies");
assertEquals(RH_HCC_SENDER, emailActorsResolver.getEmailSender(event), "unexpected email sender returned from the function under test");
assertEquals(this.emailActorsResolver.getRhHccSender(), emailActorsResolver.getEmailSender(event), "unexpected email sender returned from the function under test");
} finally {
emailActorsResolver.setEmailChangesActivationDate(LocalDate.parse("2000-01-01"));
}
Expand All @@ -62,7 +60,7 @@ void testDefaultEmailSenderHCC() {
@Test
void testOpenshiftClusterManagerStageEmailSender() {
Event event = buildEvent("stage", "openshift", "cluster-manager");
assertEquals(OPENSHIFT_SENDER_STAGE_NOREPLY_REDHAT, emailActorsResolver.getEmailSender(event), "unexpected email sender returned from the function under test");
assertEquals(this.emailActorsResolver.getOpenshiftSenderStage(), emailActorsResolver.getEmailSender(event), "unexpected email sender returned from the function under test");
try {
emailActorsResolver.setEmailChangesActivationDate(LocalDate.parse("2050-01-01"));

Expand All @@ -79,7 +77,7 @@ void testOpenshiftClusterManagerStageEmailSender() {
@Test
void testOpenshiftClusterManagerDefaultEmailSender() {
Event event = buildEvent("prod", "openshift", "cluster-manager");
assertEquals(OPENSHIFT_SENDER_PROD_NOREPLY_REDHAT, emailActorsResolver.getEmailSender(event), "unexpected email sender returned from the function under test");
assertEquals(this.emailActorsResolver.getOpenshiftSenderProd(), emailActorsResolver.getEmailSender(event), "unexpected email sender returned from the function under test");
try {
emailActorsResolver.setEmailChangesActivationDate(LocalDate.parse("2050-01-01"));

Expand Down

0 comments on commit c73d2ef

Please sign in to comment.