Search in sources :

Example 26 with PropertySource

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);
}
Also used : PropertySource(org.springframework.cloud.config.environment.PropertySource)

Example 27 with PropertySource

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());
}
Also used : HashMap(java.util.HashMap) PropertySource(org.springframework.cloud.config.environment.PropertySource) Test(org.junit.Test)

Example 28 with PropertySource

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());
}
Also used : HashMap(java.util.HashMap) PropertySource(org.springframework.cloud.config.environment.PropertySource) Test(org.junit.Test)

Example 29 with PropertySource

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;
}
Also used : ArrayList(java.util.ArrayList) Environment(org.springframework.cloud.config.environment.Environment) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) PropertySource(org.springframework.cloud.config.environment.PropertySource)

Example 30 with PropertySource

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;
}
Also used : Environment(org.springframework.cloud.config.environment.Environment) YamlPropertiesFactoryBean(org.springframework.beans.factory.config.YamlPropertiesFactoryBean) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Properties(java.util.Properties) JsonIgnoreProperties(com.fasterxml.jackson.annotation.JsonIgnoreProperties) PropertySource(org.springframework.cloud.config.environment.PropertySource)

Aggregations

PropertySource (org.springframework.cloud.config.environment.PropertySource)33 Test (org.junit.Test)20 LinkedHashMap (java.util.LinkedHashMap)19 Environment (org.springframework.cloud.config.environment.Environment)12 Map (java.util.Map)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 MapPropertySource (org.springframework.core.env.MapPropertySource)4 CompositePropertySource (org.springframework.core.env.CompositePropertySource)3 JsonIgnoreProperties (com.fasterxml.jackson.annotation.JsonIgnoreProperties)1 File (java.io.File)1 IOException (java.io.IOException)1 LinkedHashSet (java.util.LinkedHashSet)1 Properties (java.util.Properties)1 TreeMap (java.util.TreeMap)1 YamlPropertiesFactoryBean (org.springframework.beans.factory.config.YamlPropertiesFactoryBean)1 EnvironmentRepository (org.springframework.cloud.config.server.environment.EnvironmentRepository)1 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)1 StandardEnvironment (org.springframework.core.env.StandardEnvironment)1 ByteArrayResource (org.springframework.core.io.ByteArrayResource)1