Skip to content

Commit

Permalink
Update PropertiesLoading.java (#128)
Browse files Browse the repository at this point in the history
* Update PropertiesLoading for kube
  • Loading branch information
JeromeMBourgeois authored May 13, 2024
1 parent 9497d7b commit a5b0e68
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/main/java/fr/insee/rmes/config/PropertiesLoading.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,30 @@ public Properties getProperties() throws IOException {
Properties props = new Properties();
props.load(this.getClass().getClassLoader().getResourceAsStream("api-stable.properties"));
props.load(this.getClass().getClassLoader().getResourceAsStream("rmes-api.properties"));
this.loadIfExists(props, "rmes-api.properties");
this.loadIfExists(props, "rmeswnci.properties");
this.loadIfExists(props, "rmeswncz.properties");
this.loadIfExists(props, "rmeswncd.properties");
this.loadIfExists(props, "production.properties");
this.loadFromCatalinaIfExists(props, "rmes-api.properties");
this.loadFromCatalinaIfExists(props, "rmeswnci.properties");
this.loadFromCatalinaIfExists(props, "rmeswncz.properties");
this.loadFromCatalinaIfExists(props, "rmeswncd.properties");
this.loadFromCatalinaIfExists(props, "production.properties");
this.loadFromFileIfExist(props, "/conf/rmes-api.properties");
return props;
}

/*
* load properties on catalina base
*/
private Properties loadIfExists(Properties props, String filename) throws IOException {
File f;
f = new File(String.format("%s/webapps/%s", System.getProperty("catalina.base"), filename));
if (f.exists() && !f.isDirectory()) {
try (FileReader r = new FileReader(f);){
props.load(r);
return props;
private Properties loadFromCatalinaIfExists (Properties props, String filename) throws IOException {
return loadFromFileIfExist(props, String.format("%s/webapps/%s", System.getProperty("catalina.base"), filename));
}

/*
* Load properties from ConfigMap mounted path and return the modified properties
*/
private Properties loadFromFileIfExist(Properties props, String absolutePathToFile) throws IOException {
File file = new File(absolutePathToFile);
if (file.exists() && !file.isDirectory()) {
try (FileReader reader = new FileReader(file)) {
props.load(reader);
}
}
return props;
Expand Down

0 comments on commit a5b0e68

Please sign in to comment.