Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add separate email templates dir #49

Merged
merged 11 commits into from
Dec 5, 2024
Merged
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ COPY --from=webappbuild /www/ /usr/local/tomee/webapps/ROOT/

# Copy the war file to the webapps directory
COPY --from=javabuild /app/build/libs/irma_email_issuer.war /usr/local/tomee/webapps/
COPY ./src/main/resources/email-en.html /config/email-en.html
COPY ./src/main/resources/email-nl.html /config/email-nl.html
COPY ./src/main/resources/email-en.html /email-templates/email-en.html
COPY ./src/main/resources/email-nl.html /email-templates/email-nl.html

ENV IRMA_CONF="/config/"
ENV EMAIL_TEMPLATE_DIR="/email-templates/"
EXPOSE 8080

# Copy the config file to the webapp. This is done at runtime so that the config file can be mounted as a volume.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static void load() {

public String getVerifyEmailBody(String language) {
try {
return new String(EmailConfiguration.getResource("email-" + language + ".html"));
return new String(EmailConfiguration.getEmailTemplate("email-" + language + ".html"));
} catch (IOException e) {
logger.error("Failed to read email file");
throw new RuntimeException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
public static String filename = "config.json";
public static String environmentVarPrefix = "IRMA_CONF_";
public static String confDirEnvironmentVarName = "IRMA_CONF";
public static String emailTemplateDirVarName = "EMAIL_TEMPLATE_DIR";
public static String emailTemplateDir;
public static String confDirName;
public static boolean printOnLoad = false;
public static boolean testing = false;
Expand Down Expand Up @@ -68,6 +70,17 @@
return convertStreamToByteArray(getResourceStream(filename), 2048);
}

public static byte[] getEmailTemplate(String filename) throws IOException {
try {
return convertStreamToByteArray(new FileInputStream(new File(getEnvironmentVariableTemplateDir().resolve(filename))), 2048);
Fixed Show fixed Hide fixed
} catch (URISyntaxException e) {
logger.error("Invalid URI for email template (" + filename + "): " + e.getMessage());
logger.error("Terminating now");
System.exit(-1);
}
return new byte[]{};
}

public static byte[] convertStreamToByteArray(InputStream stream, int size) throws IOException {
byte[] buffer = new byte[size];
ByteArrayOutputStream os = new ByteArrayOutputStream();
Expand Down Expand Up @@ -211,6 +224,13 @@
return pathToURI(envDir, true);
}

public static URI getEnvironmentVariableTemplateDir() throws URISyntaxException {
String envDir = System.getenv(emailTemplateDirVarName);
if (envDir == null || envDir.length() == 0)
return null;
return pathToURI(envDir, true);
}

/**
* Returns true if the specified path is a valid configuration directory. A directory
* is considered a valid configuration directory if it contains a file called $filename.
Expand Down
Loading