From 99130d0181ba3ae1ec2b3130a8f41c889274c68f Mon Sep 17 00:00:00 2001 From: Athou Date: Tue, 25 Apr 2023 10:39:57 +0200 Subject: [PATCH] combine EnvironmentSubstitutor and SubstitutingSourceProvider (#1050) --- .../java/com/commafeed/CommaFeedApplication.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/commafeed-server/src/main/java/com/commafeed/CommaFeedApplication.java b/commafeed-server/src/main/java/com/commafeed/CommaFeedApplication.java index 11583788c..5226089d2 100644 --- a/commafeed-server/src/main/java/com/commafeed/CommaFeedApplication.java +++ b/commafeed-server/src/main/java/com/commafeed/CommaFeedApplication.java @@ -61,6 +61,8 @@ import io.dropwizard.Application; import io.dropwizard.assets.AssetsBundle; import io.dropwizard.configuration.DefaultConfigurationFactoryFactory; +import io.dropwizard.configuration.EnvironmentVariableSubstitutor; +import io.dropwizard.configuration.SubstitutingSourceProvider; import io.dropwizard.db.DataSourceFactory; import io.dropwizard.forms.MultiPartBundle; import io.dropwizard.hibernate.HibernateBundle; @@ -96,7 +98,15 @@ protected ObjectMapper configureObjectMapper(ObjectMapper objectMapper) { return objectMapper.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES); } }); - bootstrap.setConfigurationSourceProvider(new EnvironmentSubstitutor("CF", bootstrap.getConfigurationSourceProvider())); + + // enable config.yml string substitution + // e.g. having a custom config.yml file with app.session.path=${SOME_ENV_VAR} will substitute SOME_ENV_VAR + SubstitutingSourceProvider substitutingSourceProvider = new SubstitutingSourceProvider(bootstrap.getConfigurationSourceProvider(), + new EnvironmentVariableSubstitutor(false)); + // enable config.yml properties override with env variables prefixed with CF_ + // e.g. setting CF_APP_ALLOWREGISTRATIONS=true will set app.allowRegistrations to true + EnvironmentSubstitutor environmentSubstitutor = new EnvironmentSubstitutor("CF", substitutingSourceProvider); + bootstrap.setConfigurationSourceProvider(environmentSubstitutor); bootstrap.getObjectMapper().registerModule(new MetricsModule(TimeUnit.SECONDS, TimeUnit.SECONDS, false));