${NAME:default}
are resolved at the Environment
level
@ulisesbocchio
hey, sorry for kinda late reply. I tried to use EncryptableEnvironment, and it seemed like the original case worked, but now there's another problem:
user: user
password: ${PASSWORD:ENC(asdf)}
endpoint: https://${user}:${password}@localhost:30000
Trying to resolve turns into:
user: user
password: ENC(asdf)
endpoint: https://user:ENC(asdf)@localhost:30000
This makes sense since resolve happens before decrypt. But seems like this is a bug because the EncryptableEnvironment, when it follows the ${...} resolution, it should also be trying to decrypt if it can. Thoughts?
propVal = placeholderResolver.resolvePlaceholder(propVal);
for now you should probably stick to:
user: user
defaultPassword: ENC(asdf)
password: ${PASSWORD:${defaultPassword}}
endpoint: https://${user}:${password}@localhost:30000
which adds one more level of indirection but the works because defaultPassword
is a top level property
-Djasypt.encryptor.password=password
should be enough in any JVM. Keep in mind though that spring boot has to run.
@Bean
public PropertySource allPropertiesSource() throws Exception {
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Resource[] resources = resolver.getResources("classpath*:*.properties");
PropertySourceLoader loader = new PropertiesPropertySourceLoader();
Function<Resource, PropertySource> toSource = resource -> {
try {
return loader.load(resource.getFilename(), resource).get(0);
} catch (Exception e) {
throw new RuntimeException(e);
}
};
Function<List<PropertySource>, PropertySource> collector = sources -> {
CompositePropertySource ps = new CompositePropertySource("all properties");
sources.forEach(ps::addPropertySource);
return ps;
};
return Arrays.stream(resources).map(toSource).collect(Collectors.collectingAndThen(Collectors.toList(), collector));
}