io.quarkus.vault.runtime.config.VaultMapConfigParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of quarkus-vault Show documentation
Show all versions of quarkus-vault Show documentation
Store your credentials securely in HashiCorp Vault
package io.quarkus.vault.runtime.config;
import static java.util.stream.Collectors.toMap;
import java.util.AbstractMap;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;
import org.eclipse.microprofile.config.spi.ConfigSource;
public class VaultMapConfigParser {
private Pattern pattern;
private Stream configSourceStream;
private Function buildConfigObject;
public VaultMapConfigParser(Pattern pattern, Function buildConfigObject,
Stream configSourceStream) {
this.pattern = pattern;
this.configSourceStream = configSourceStream;
this.buildConfigObject = buildConfigObject;
}
public Map getConfig() {
return configSourceStream
.flatMap(configSource -> configSource.getPropertyNames().stream())
.map(this::getKey)
.filter(Objects::nonNull)
.distinct()
.map(this::createKeyValuePair)
.collect(toMap(AbstractMap.SimpleEntry::getKey, AbstractMap.SimpleEntry::getValue));
}
private AbstractMap.SimpleEntry createKeyValuePair(String name) {
return new AbstractMap.SimpleEntry<>(name, buildConfigObject.apply(name));
}
private String getKey(String propertyName) {
Matcher matcher = pattern.matcher(propertyName);
return matcher.find() ? matcher.group(1) : null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy