com.github.mowedgrass.jasyptgradleboot.password.property.PropertyResolver Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jasypt-gradle-boot-encryptor Show documentation
Show all versions of jasypt-gradle-boot-encryptor Show documentation
Shared jasypt encryptor for jasypt-gradle-boot-plugin
The newest version!
package com.github.mowedgrass.jasyptgradleboot.password.property;
import org.springframework.core.env.StandardEnvironment;
import java.util.Optional;
import java.util.function.Function;
import static java.util.Optional.ofNullable;
public class PropertyResolver {
private StandardEnvironment environment;
public PropertyResolver(StandardEnvironment environment) {
this.environment = environment;
}
public Optional getEnvironmentProperty(String key) {
return getProperty(environment::getProperty, key);
}
public Optional getSystemProperty(String key) {
return getProperty(
property -> ((String) environment.getSystemEnvironment().get(property)),
key
);
}
private Optional getProperty(Function source, String key) {
return ofNullable(source.apply(key))
.filter(s -> !s.isEmpty());
}
}