Search in sources :

Example 21 with EnumerablePropertySource

use of org.springframework.core.env.EnumerablePropertySource in project grails-core by grails.

the class PropertySourcesConfig method initializeFromPropertySources.

protected void initializeFromPropertySources(PropertySources propertySources) {
    EnvironmentAwarePropertySource environmentAwarePropertySource = new EnvironmentAwarePropertySource(propertySources);
    if (propertySources instanceof MutablePropertySources) {
        final String applicationConfig = "applicationConfigurationProperties";
        if (propertySources.contains(applicationConfig)) {
            ((MutablePropertySources) propertySources).addBefore(applicationConfig, environmentAwarePropertySource);
        } else {
            ((MutablePropertySources) propertySources).addLast(environmentAwarePropertySource);
        }
    }
    List<PropertySource<?>> propertySourceList = DefaultGroovyMethods.toList(propertySources);
    Collections.reverse(propertySourceList);
    for (PropertySource propertySource : propertySourceList) {
        if (propertySource instanceof EnumerablePropertySource) {
            EnumerablePropertySource enumerablePropertySource = (EnumerablePropertySource) propertySource;
            mergeEnumerablePropertySource(enumerablePropertySource);
        }
    }
}
Also used : EnumerablePropertySource(org.springframework.core.env.EnumerablePropertySource) MutablePropertySources(org.springframework.core.env.MutablePropertySources) PropertySource(org.springframework.core.env.PropertySource) EnumerablePropertySource(org.springframework.core.env.EnumerablePropertySource) MapPropertySource(org.springframework.core.env.MapPropertySource)

Example 22 with EnumerablePropertySource

use of org.springframework.core.env.EnumerablePropertySource in project kork by spinnaker.

the class SecretAwarePropertySourceTest method setup.

@Before
public void setup() {
    EnumerablePropertySource source = new EnumerablePropertySource("testSource") {

        @Override
        public String[] getPropertyNames() {
            return new String[0];
        }

        @Override
        public Object getProperty(String name) {
            return testValues.get(name);
        }
    };
    testValues.put("testSecretFile", "encrypted:noop!k:testValue");
    testValues.put("testSecretPath", "encrypted:noop!k:testValue");
    testValues.put("testSecretCert", "encryptedFile:noop!k:testValue");
    testValues.put("testSecretString", "encrypted:noop!k:testValue");
    testValues.put("testNotSoSecret", "unencrypted");
    secretManager = mock(SecretManager.class);
    secretAwarePropertySource = new SecretAwarePropertySource(source, secretManager);
    when(secretManager.decryptAsFile(any())).thenReturn(Paths.get("decryptedFile"));
    when(secretManager.decrypt(any())).thenReturn("decryptedString");
}
Also used : EnumerablePropertySource(org.springframework.core.env.EnumerablePropertySource) Before(org.junit.Before)

Aggregations

EnumerablePropertySource (org.springframework.core.env.EnumerablePropertySource)22 CompositePropertySource (org.springframework.core.env.CompositePropertySource)8 MutablePropertySources (org.springframework.core.env.MutablePropertySources)7 PropertySource (org.springframework.core.env.PropertySource)7 HashMap (java.util.HashMap)5 LinkedHashMap (java.util.LinkedHashMap)4 Environment (org.springframework.core.env.Environment)4 Map (java.util.Map)3 Properties (java.util.Properties)3 Test (org.junit.jupiter.api.Test)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 HashSet (java.util.HashSet)2 Collectors (java.util.stream.Collectors)2 StringUtils (org.apache.commons.lang3.StringUtils)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)2 MapPropertySource (org.springframework.core.env.MapPropertySource)2