com.akeyless.config.ConfigUtils Maven / Gradle / Ivy
package com.akeyless.config;
import com.akeyless.exceptions.AkeylessRuntimeException;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.nio.file.Path;
public class ConfigUtils {
public static AkeylessUserConfiguration loadSdkConfigurationFromFile(Path filePath)
throws FileNotFoundException, AkeylessRuntimeException {
return loadConfigFromFile(filePath, AkeylessUserConfiguration.class);
}
private static T loadConfigFromFile(Path configurationFile, Class c) throws FileNotFoundException,
AkeylessRuntimeException {
Reader configReader = new FileReader(configurationFile.toFile());
ObjectMapper mapper = new ObjectMapper();
T config;
try {
config = mapper.readValue(configReader, c);
} catch (IOException e) {
throw new AkeylessRuntimeException(e);
}
return config;
}
}