Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions plugins/tasks/ansible/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@
<artifactId>slf4j-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.ini4j</groupId>
<artifactId>ini4j</artifactId>
</dependency>

<!-- Immutables -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,10 @@
*/

import com.walmartlabs.concord.common.ConfigurationUtils;
import org.ini4j.Ini;
import org.ini4j.Profile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
Expand All @@ -37,6 +34,7 @@

import static com.walmartlabs.concord.sdk.MapUtils.getMap;
import static com.walmartlabs.concord.sdk.MapUtils.getString;
import static java.nio.charset.StandardCharsets.UTF_8;

public class AnsibleConfig {

Expand Down Expand Up @@ -87,7 +85,7 @@ public Path write() {

Path cfgPath = getConfigPath();
try {
Files.write(cfgPath, b.toString().getBytes(StandardCharsets.UTF_8), StandardOpenOption.CREATE);
Files.write(cfgPath, b.toString().getBytes(UTF_8), StandardOpenOption.CREATE);
} catch (IOException e) {
log.error("Configuration write {} error", CFG_FILE_NAME, e);
throw new RuntimeException("Configuration write error: " + e.getMessage());
Expand Down Expand Up @@ -186,21 +184,43 @@ private static StringBuilder addCfgSection(StringBuilder b, String name, Map<Str

private Map<String, Map<String, Object>> loadFromFile(Path file) {
try {
Ini ini = new Ini();
ini.load(file.toFile());

Map<String, Map<String, Object>> result = new HashMap<>();
for (Map.Entry<String, Profile.Section> e : ini.entrySet()) {
Map<String, Object> section = new HashMap<>();
for (Map.Entry<String, String> s : e.getValue().entrySet()) {
section.put(s.getKey(), s.getValue());
}
result.put(e.getKey(), section);
}
return result;
return parseIniFile(file);
} catch (IOException e) {
log.error("Configuration parse error: {}", e.getMessage());
throw new RuntimeException("Configuration parse error " + file + ": " + e.getMessage());
}
}

private static Map<String, Map<String, Object>> parseIniFile(Path file) throws IOException {
Map<String, Map<String, Object>> result = new HashMap<>();
Map<String, Object> currentSection = null;
for (String line : Files.readAllLines(file, UTF_8)) {
line = line.trim();

if (line.isEmpty() || line.startsWith("#") || line.startsWith(";")) {
continue;
}

if (line.startsWith("[") && line.endsWith("]")) {
String sectionName = line.substring(1, line.length() - 1).trim();
currentSection = new HashMap<>();
result.put(sectionName, currentSection);
continue;
}

if (currentSection != null && line.contains("=")) {
int equalIndex = line.indexOf("=");
String key = line.substring(0, equalIndex).trim();
String value = line.substring(equalIndex + 1).trim();

if ((value.startsWith("\"") && value.endsWith("\"")) ||
(value.startsWith("'") && value.endsWith("'"))) {
value = value.substring(1, value.length() - 1);
}

currentSection.put(key, value);
}
}
return result;
}
}
6 changes: 0 additions & 6 deletions targetplatform/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
<httpcore.version>4.4.13</httpcore.version>
<httpmime.version>4.5.11</httpmime.version>
<immutables.version>2.9.3</immutables.version>
<ini4j.version>0.5.4</ini4j.version>
<jackson.databind.version>2.18.3</jackson.databind.version>
<jackson.jsonschema.version>1.0.39</jackson.jsonschema.version>
<jackson.version>2.18.3</jackson.version>
Expand Down Expand Up @@ -989,11 +988,6 @@
<artifactId>config</artifactId>
<version>${config.version}</version>
</dependency>
<dependency>
<groupId>org.ini4j</groupId>
<artifactId>ini4j</artifactId>
<version>${ini4j.version}</version>
</dependency>
<dependency>
<groupId>org.javers</groupId>
<artifactId>javers-core</artifactId>
Expand Down