Skip to content

Commit

Permalink
Merge server env (#830)
Browse files Browse the repository at this point in the history
* Preserve keystore_password when merging env properties

* Fix previous changes for preserving keystore_password

* Fix existing test case and remove unnecessary new test case
  • Loading branch information
cherylking committed Jun 2, 2023
1 parent 9d0f17c commit 540ba55
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 194 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,7 @@ abstract class AbstractServerTask extends AbstractLibertyTask {
if (serverEnvPath == null && server.serverEnvFile == null) {
// Do a special case merge but ONLY if there is no server.env file present in configDirectory or specified with serverEnvFile
envPropsToWrite = mergeSpecialPropsFromInstallServerEnvIfAbsent(envFile, configuredProps)
logger.warn("The default " + envFile.getCanonicalPath() + " file is overwritten by inlined configuration.")
} else if (serverEnvPath != null) {
logger.warn("The " + serverEnvPath + " file is overwritten by inlined configuration.")
}
Expand All @@ -911,19 +912,16 @@ abstract class AbstractServerTask extends AbstractLibertyTask {
*/
private Properties mergeSpecialPropsFromInstallServerEnvIfAbsent(File envFile, Properties envProps) throws IOException {

String[] specialProps = { "keystore_password" }

// Make a copy to avoid side effects
Properties mergedProps = new Properties()
mergedProps.putAll(envProps)

// From install (target) dir
Properties serverEnvProps = convertServerEnvToProperties(envFile)

for (String propertyName : specialProps) {
if (serverEnvProps.containsKey(propertyName)) {
mergedProps.putIfAbsent(propertyName,serverEnvProps.get(propertyName))
}
String propertyName = "keystore_password"
if (serverEnvProps.containsKey(propertyName)) {
mergedProps.putIfAbsent(propertyName,serverEnvProps.get(propertyName))
}

return mergedProps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,15 @@ public class TestCreateWithInlineProperties extends AbstractIntegrationTest{

prop = new Properties();
prop.load( input2 );
assert prop.size() == 2 : "expected 2 properties in server.env file but found "+prop.size()
assert prop.size() == 3 : "expected 3 properties in server.env file but found "+prop.size()
String value2 = prop.getProperty("some.env.var");
assert value2 != null && value2.equals("someValue") : "property not found in server.env file"
assert value2 != null && value2.equals("someValue") : "some.env.var property not found in server.env file"
value2 = prop.getProperty("another.env.var");
assert value2 != null && value2.equals("anotherValue") : "property not found in server.env file"
assert value2 != null && value2.equals("anotherValue") : "another.env.var property not found in server.env file"
// if no server.env file is specified in configuration and mergeServerEnv is not set to true,
// the keystore_password is still preserved when present in the default server.env file and not specified in a property
value2 = prop.getProperty("keystore_password");
assert value2 != null : "keystore_password property not found in server.env file"

assert libertyConfigVarOverridesFile.text.contains("name=\"someVar\"") : "configDropins/overrides/liberty-plugin-variable-config.xml does not contain expected variable: "+libertyConfigVarOverridesFile.text
assert libertyConfigVarOverridesFile.text.contains("value=\"someValue\"") : "configDropins/overrides/liberty-plugin-variable-config.xml does not contain expected variable: "+libertyConfigVarOverridesFile.text
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit 540ba55

Please sign in to comment.