Skip to content

Instantly share code, notes, and snippets.

@rtannenbaum
Created March 13, 2018 21:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rtannenbaum/e8d31500567ac2d1cfaf3b5c36e0425a to your computer and use it in GitHub Desktop.
Save rtannenbaum/e8d31500567ac2d1cfaf3b5c36e0425a to your computer and use it in GitHub Desktop.
@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