use of org.springframework.cloud.config.environment.PropertySource in project spring-cloud-config by spring-cloud.
the class EnvironmentControllerTests method whenPlaceholdersSystemPropsWithDefault.
private void whenPlaceholdersSystemPropsWithDefault() {
System.setProperty("foo", "bar");
this.environment.addFirst(new PropertySource("two", Collections.singletonMap("a.b.c", "${foo:spam}")));
Mockito.when(this.repository.findOne("foo", "bar", null)).thenReturn(this.environment);
}
use of org.springframework.cloud.config.environment.PropertySource in project spring-cloud-config by spring-cloud.
the class EnvironmentEncryptorEnvironmentRepositoryTests method allowOverrideFalse.
@Test
public void allowOverrideFalse() throws Exception {
this.controller.setOverrides(Collections.singletonMap("foo", "bar"));
Map<String, Object> map = new HashMap<String, Object>();
map.put("a.b.c", "d");
this.environment.add(new PropertySource("one", map));
Mockito.when(this.repository.findOne("foo", "bar", "master")).thenReturn(this.environment);
assertEquals("{foo=bar}", this.controller.findOne("foo", "bar", "master").getPropertySources().get(0).getSource().toString());
}
use of org.springframework.cloud.config.environment.PropertySource in project spring-cloud-config by spring-cloud.
the class EnvironmentEncryptorEnvironmentRepositoryTests method overrideWithEscapedPlaceholders.
@Test
public void overrideWithEscapedPlaceholders() throws Exception {
this.controller.setOverrides(Collections.singletonMap("foo", "$\\{bar}"));
Map<String, Object> map = new HashMap<String, Object>();
map.put("bar", "foo");
this.environment.add(new PropertySource("one", map));
Mockito.when(this.repository.findOne("foo", "bar", "master")).thenReturn(this.environment);
assertEquals("{foo=${bar}}", this.controller.findOne("foo", "bar", "master").getPropertySources().get(0).getSource().toString());
}
use of org.springframework.cloud.config.environment.PropertySource in project spring-cloud-config by spring-cloud.
the class PropertiesResultSetExtractor method findOne.
@Override
public Environment findOne(String application, String profile, String label) {
String config = application;
if (StringUtils.isEmpty(label)) {
label = "master";
}
if (StringUtils.isEmpty(profile)) {
profile = "default";
}
if (!profile.startsWith("default")) {
profile = "default," + profile;
}
String[] profiles = StringUtils.commaDelimitedListToStringArray(profile);
Environment environment = new Environment(application, profiles, label, null, null);
if (!config.startsWith("application")) {
config = "application," + config;
}
List<String> applications = new ArrayList<String>(new LinkedHashSet<>(Arrays.asList(StringUtils.commaDelimitedListToStringArray(config))));
List<String> envs = new ArrayList<String>(new LinkedHashSet<>(Arrays.asList(profiles)));
Collections.reverse(applications);
Collections.reverse(envs);
for (String app : applications) {
for (String env : envs) {
Map<String, String> next = (Map<String, String>) jdbc.query(this.sql, new Object[] { app, env, label }, this.extractor);
if (!next.isEmpty()) {
environment.add(new PropertySource(app + "-" + env, next));
}
}
}
return environment;
}
use of org.springframework.cloud.config.environment.PropertySource in project spring-cloud-config by spring-cloud.
the class VaultEnvironmentRepository method findOne.
@Override
public Environment findOne(String application, String profile, String label) {
String state = request.getHeader(STATE_HEADER);
String newState = this.watch.watch(state);
String[] profiles = StringUtils.commaDelimitedListToStringArray(profile);
List<String> scrubbedProfiles = scrubProfiles(profiles);
List<String> keys = findKeys(application, scrubbedProfiles);
Environment environment = new Environment(application, profiles, label, null, newState);
for (String key : keys) {
// read raw 'data' key from vault
String data = read(key);
if (data != null) {
// data is in json format of which, yaml is a superset, so parse
final YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();
yaml.setResources(new ByteArrayResource(data.getBytes()));
Properties properties = yaml.getObject();
if (!properties.isEmpty()) {
environment.add(new PropertySource("vault:" + key, properties));
}
}
}
return environment;
}
Aggregations