Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
@Provides
@Singleton
ApiSettings getApiSettings() {
// TODO: currently, any setting in both a base and env config will be overridden by the last
// definition. e.g. a setting in api.yaml and env/api.yaml will take the definition in
// env/api.yaml. Determine whether this is intended behavior.
try {
ImmutableList<String> settingsFiles = ImmutableList.<String>builder()
.add(API_SETTINGS_PATH)
.add(ENV_API_SETTINGS_PATH)
.add(COMMON_SETTINGS_PATH)
.add(ENV_COMMON_SETTINGS_PATH)
.build();
// ApiSettings apiSettings = getApiSettings(settingsFiles);
String tempSettings = "baseUrl: http://localhost:3000\nbaseApiUrl: http://localhost:8080\n";
InputStream in = new ByteArrayInputStream(tempSettings.getBytes(StandardCharsets.UTF_8));
ApiSettings apiSettings = getApiSettings(in);
logger.debug("Parsed flags: {}", apiSettings);
return apiSettings;
} catch (IOException e) {
throw new IllegalArgumentException("Problem parsing api settings", e);
}
}
static ApiSettings getApiSettings(ImmutableList<String> settingsFiles) throws IOException {
InputStream combinedInputStream = ConfigUtils.getSettingsCombinedInputStream(settingsFiles);
return getApiSettings(combinedInputStream);
}
static ApiSettings getApiSettings(InputStream inputStream) {
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
return mapper.readValue(combinedInputStream, ApiSettings.class);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.