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

org.zodic.kubernetes.confcenter.KubernetesPropertySource Maven / Gradle / Ivy

package org.zodic.kubernetes.confcenter;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.MapPropertySource;

public class KubernetesPropertySource extends MapPropertySource {

    private static final Logger LOG = LoggerFactory.getLogger(KubernetesPropertySource.class);

    protected KubernetesPropertySource(String name, Map source) {
        super(name, source);
    }

    protected static void putPathConfig(Map result, List paths) {
        paths.stream().map(Paths::get).filter(Files::exists).forEach(p -> putAll(p, result));
    }

    private static void putAll(Path path, Map result) {
        try {
            Files.walk(path).filter(Files::isRegularFile).forEach(p -> readFile(p, result));
        } catch (IOException e) {
            LOG.warn("Error walking configReloadInfo files", e);
        }
    }

    private static void readFile(Path path, Map result) {
        try {
            result.put(path.getFileName().toString(), new String(Files.readAllBytes(path)).trim());
        } catch (IOException e) {
            LOG.warn("Error reading configReloadInfo file", e);
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy