Skip to content

Commit

Permalink
Parse environment variables in es.featureproxy.targeturi property (#242)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanpommier authored May 4, 2023
1 parent 48b2b93 commit 4fde177
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.io.InputStream;
import java.nio.file.Paths;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* This class allows to resolve variables from the georchestra.datadir/geonetwork/geonetwork.properties
Expand All @@ -31,6 +33,16 @@ public static String resolveProperty(String name) {
} catch (Exception ex) {
throw new RuntimeException("unable to read geonetwork.properties from the geOrchestra datadir");
}
return gnProps.getProperty(name);
String prop = gnProps.getProperty(name);
// Resolve environment variables in the property string
Pattern p = Pattern.compile("\\$\\{([A-Z_]+)\\}") ;
Matcher m = p.matcher(prop) ;
while (m.find()) {
String envvar = m.group();
// Get the string stripped of its $ and braces
String envvar_str = envvar.replaceAll("[\\$\\{\\}]", "");
prop = prop.replaceAll(Pattern.quote(envvar), System.getenv(envvar_str));
}
return prop;
}
}

0 comments on commit 4fde177

Please sign in to comment.