Skip to content

Commit

Permalink
Update the impl to get the config value from the configured file path
Browse files Browse the repository at this point in the history
Update the filename

Update the filename
  • Loading branch information
kalaiyarasiganeshalingam committed Feb 14, 2025
1 parent 35b5893 commit d715ad1
Showing 1 changed file with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class ConfigDeployer implements AppDeploymentHandler {

private static final String LOCAL_CONFIG_FILE_NAME = "config.properties";
private static final String FILE_PROPERTIES_NAME = "file.properties";

private static final String FILE_PROPERTY_PATH = "properties.file.path";
public static final char URL_SEPARATOR_CHAR = '/';

public ConfigDeployer() {
Expand Down Expand Up @@ -100,21 +100,26 @@ private void writePropertyToMap(Artifact artifact) {
List<CappFile> files = artifact.getFiles();
if (files.size() == 1) {
Path confFolder = Paths.get(getHome(), "conf");
Path globalPropertiesFilePath = confFolder.resolve(FILE_PROPERTIES_NAME) ;
Path serverPropertiesFilePath = confFolder.resolve(FILE_PROPERTIES_NAME) ;
String configFilePath = artifact.getExtractedPath() + File.separator + LOCAL_CONFIG_FILE_NAME;
processConfFile(artifact.getName(), configFilePath, globalPropertiesFilePath.toString());
processConfFile(artifact.getName(), configFilePath, serverPropertiesFilePath.toString());
} else {
log.error("config/property type must have a single file which declares " +
"config. But " + files.size() + " files found.");
}
}

private void processConfFile(String integrationName, String configFilePath, String globalPropertiesFilePath) {
private void processConfFile(String integrationName, String configFilePath, String serverPropertiesFilePath) {
File configFile = new File(configFilePath);
// Load capp conf property file
Properties configProperties = loadPropertiesFromFile(configFile);
// Load file property file
Properties fileProperties = loadPropertiesFromFile(new File(globalPropertiesFilePath));
Properties serverFileProperties = loadPropertiesFromFile(new File(serverPropertiesFilePath));
Properties fileProperties = null;
String filePropertyPath = System.getProperty(FILE_PROPERTY_PATH);
if (filePropertyPath != null && !filePropertyPath.trim().isEmpty()) {
fileProperties = loadPropertiesFromFile(new File(filePropertyPath));
}
if (configProperties.isEmpty() ) {
if (log.isDebugEnabled()) {
log.debug(String.format("No configuration is used in the integration[%s]", integrationName));
Expand All @@ -123,13 +128,14 @@ private void processConfFile(String integrationName, String configFilePath, Stri
for (Map.Entry<Object, Object> entry : configProperties.entrySet()) {
String key = entry.getKey().toString();
String type = entry.getValue().toString();
processConfigProperties(key, type, fileProperties);
processConfigProperties(key, type, serverFileProperties, fileProperties);
}
}
}

private void processConfigProperties(String key, String type, Properties fileProperties) {
String value = getValueOfKey(key, fileProperties);
private void processConfigProperties(String key, String type, Properties serverFileProperties,
Properties fileProperties) {
String value = getValueOfKey(key, serverFileProperties, fileProperties);
if (value != null) {
if (Objects.equals(type, "cert")) {
deployCert(key, value);
Expand Down Expand Up @@ -198,12 +204,15 @@ private Properties loadPropertiesFromFile(File file) {
return properties;
}

private String getValueOfKey(String key, Properties fileProperties) {
private String getValueOfKey(String key, Properties serverFileProperties, Properties fileProperties) {
String value = System.getenv(key);
if (value == null) {
value = System.getProperty(key);
if (value == null) {
value = fileProperties.getProperty(key);
if (value == null) {
value = serverFileProperties.getProperty(key);
}
}
}
return value;
Expand Down

0 comments on commit d715ad1

Please sign in to comment.