com.appcrossings.config.discovery.HostsFileDiscoveryStrategy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of appconfig-client Show documentation
Show all versions of appconfig-client Show documentation
A property placeholder configurer compatible with Spring and allowing hierarchical configurations to be externalized from the application and loaded by URL
The newest version!
package com.appcrossings.config.discovery;
import java.net.URI;
import java.util.Map;
import java.util.Optional;
import org.slf4j.Logger;
import com.appcrossings.config.Environment;
import com.appcrossings.config.util.StringUtils;
public class HostsFileDiscoveryStrategy implements ConfigDiscoveryStrategy {
private static final Logger logger =
org.slf4j.LoggerFactory.getLogger(HostsFileDiscoveryStrategy.class);
@Override
public Optional lookupConfigPath(Map hostMappings,
Map envProps) {
String envName = (String) envProps.get(Environment.ENV_NAME);
String hostName = (String) envProps.get(Environment.HOST_NAME);
Optional uri = Optional.empty();
String startPath = (String) hostMappings.get(hostName);
// Attempt environment as a backup
if (!StringUtils.hasText(startPath) && StringUtils.hasText(envName)) {
startPath = (String) hostMappings.get(envName);
}
if (!StringUtils.hasText(startPath)) {
logger.warn("Didn't locate any config path for host " + hostName + " or env " + envName
+ ". Falling back to '*' environment.");
startPath = (String) hostMappings.get("*");// catch all
}
if (StringUtils.hasText(startPath)) {
uri = Optional.ofNullable(URI.create(startPath));
} else {
logger.warn("Unable to resolve a config path from hosts lookup");
}
return uri;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy