Compare commits
2 Commits
e0692f7913
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| a42a8dd3a5 | |||
| ab0e2ffa68 |
@@ -10,4 +10,4 @@ COPY --from=build /app/bootstrap/target/*.jar app.jar
|
||||
EXPOSE 8080
|
||||
EXPOSE 5005
|
||||
|
||||
ENTRYPOINT ["java", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005", "-jar", "app.jar"]
|
||||
ENTRYPOINT ["java", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005", "-Xmx512m", "-Xms256m", "-jar", "app.jar"]
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.pablotj.restemailbridge.bootstrap;
|
||||
|
||||
import org.springframework.context.ApplicationContextInitializer;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
|
||||
public class EnvironmentValidatorInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
|
||||
|
||||
@Override
|
||||
public void initialize(ConfigurableApplicationContext ctx) {
|
||||
String[] requiredProperties = {
|
||||
"APP_ENCRYPTION_SECRET",
|
||||
"APP_ALLOWED_ORIGINS",
|
||||
"DB_NAME",
|
||||
"DB_USER",
|
||||
"DB_PASSWORD",
|
||||
"DB_HOST",
|
||||
"DB_PORT",
|
||||
"GMAIL_OAUTH_CLIENT_ID",
|
||||
"GMAIL_OAUTH_CLIENT_SECRET"
|
||||
};
|
||||
|
||||
for (String prop : requiredProperties) {
|
||||
String value = ctx.getEnvironment().getProperty(prop);
|
||||
if (value == null || value.isEmpty()) {
|
||||
throw new IllegalStateException("ERROR: Property '" + prop + "' is not defined or empty");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,8 @@ import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||
public class RestEmailBridgeApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(RestEmailBridgeApplication.class, args);
|
||||
SpringApplication app = new SpringApplication(RestEmailBridgeApplication.class);
|
||||
app.addInitializers(new EnvironmentValidatorInitializer());
|
||||
app.run(args);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,8 +27,11 @@ spring:
|
||||
password: ${DB_PASSWORD:postgres}
|
||||
driver-class-name: org.postgresql.Driver
|
||||
hikari:
|
||||
maximum-pool-size: 20
|
||||
minimum-idle: 5
|
||||
maximum-pool-size: 3
|
||||
minimum-idle: 1
|
||||
idle-timeout: 30000
|
||||
connection-timeout: 10000
|
||||
leak-detection-threshold: 10000
|
||||
|
||||
jpa:
|
||||
hibernate:
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
package com.pablotj.restemailbridge.infrastructure.config;
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class AppPropertiesValidator {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(AppPropertiesValidator.class);
|
||||
|
||||
@Value("${app.encryption.secret:}")
|
||||
private String encryptionSecret;
|
||||
|
||||
@Value("${app.cors.allowed-origins:}")
|
||||
private String allowedOrigins;
|
||||
|
||||
@Value("${spring.datasource.url:}")
|
||||
private String datasourceUrl;
|
||||
|
||||
@Value("${spring.datasource.username:}")
|
||||
private String datasourceUser;
|
||||
|
||||
@Value("${spring.datasource.password:}")
|
||||
private String datasourcePassword;
|
||||
|
||||
@Value("${gmail.oauth2.clientId:}")
|
||||
private String gmailClientId;
|
||||
|
||||
@Value("${gmail.oauth2.clientSecret:}")
|
||||
private String gmailClientSecret;
|
||||
|
||||
@PostConstruct
|
||||
public void validate() {
|
||||
check("APP_ENCRYPTION_SECRET", encryptionSecret, false);
|
||||
check("APP_ALLOWED_ORIGINS", allowedOrigins, true);
|
||||
check("DB_URL", datasourceUrl, true);
|
||||
check("DB_USER", datasourceUser, true);
|
||||
check("DB_PASSWORD", datasourcePassword, false);
|
||||
check("GMAIL_OAUTH_CLIENT_ID", gmailClientId, true);
|
||||
check("GMAIL_OAUTH_CLIENT_SECRET", gmailClientSecret, false);
|
||||
}
|
||||
|
||||
private void check(String name, String value, boolean logValue) {
|
||||
if (value == null || value.isEmpty()) {
|
||||
throw new IllegalStateException("ERROR: Property '" + name + "' is not defined or empty");
|
||||
} else if (logValue) {
|
||||
log.info("Property '{}' is defined with value: {}", name, value);
|
||||
} else {
|
||||
log.info("Property '{}' is defined", name);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user