All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.quarkus.vault.runtime.config.VaultMapConfigParser Maven / Gradle / Ivy

There is a newer version: 3.0.0.Beta1
Show newest version
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