Search in sources :

Example 1 with MapPropertySource

use of io.micronaut.context.env.MapPropertySource in project kestra by kestra-io.

the class DeleteConfigurationApplicationListenersTest method run.

@Test
void run() throws IOException {
    File tempFile = File.createTempFile("test", ".yml");
    Files.write(tempFile.toPath(), "kestra.configurations.delete-files-on-start: true".getBytes());
    MapPropertySource mapPropertySource = new MapPropertySource(tempFile.getAbsolutePath(), Map.of("kestra.configurations.delete-files-on-start", true));
    try (ApplicationContext ctx = ApplicationContext.run(mapPropertySource, Environment.CLI, Environment.TEST)) {
        assertThat(tempFile.exists(), is(false));
    }
}
Also used : ApplicationContext(io.micronaut.context.ApplicationContext) MapPropertySource(io.micronaut.context.env.MapPropertySource) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 2 with MapPropertySource

use of io.micronaut.context.env.MapPropertySource in project kestra by kestra-io.

the class BasicAuthEndpointsFilterTest method test.

void test(boolean password, BiConsumer<RxHttpClient, MutableHttpRequest<String>> consumer) {
    MapPropertySource mapPropertySource = new MapPropertySource("unittest", password ? Map.of("endpoints.all.enabled", true, "endpoints.all.sensitive", false, "endpoints.all.basic-auth.username", "foo", "endpoints.all.basic-auth.password", "bar") : Map.of("endpoints.all.enabled", true, "endpoints.all.sensitive", false));
    try (ApplicationContext ctx = ApplicationContext.run(mapPropertySource, Environment.CLI, Environment.TEST)) {
        EmbeddedServer embeddedServer = ctx.getBean(EmbeddedServer.class);
        embeddedServer.start();
        RxHttpClient client = ctx.getBean(RxHttpClient.class);
        consumer.accept(client, HttpRequest.GET("http://localhost:" + embeddedServer.getPort() + "/health"));
    }
}
Also used : ApplicationContext(io.micronaut.context.ApplicationContext) MapPropertySource(io.micronaut.context.env.MapPropertySource) RxHttpClient(io.micronaut.rxjava2.http.client.RxHttpClient) EmbeddedServer(io.micronaut.runtime.server.EmbeddedServer)

Example 3 with MapPropertySource

use of io.micronaut.context.env.MapPropertySource in project micronaut-aot by micronaut-projects.

the class YamlPropertySourceGenerator method createMapProperty.

private void createMapProperty(YamlPropertySourceLoader loader, AOTContext context, String resource) {
    Optional<PropertySource> optionalSource = loader.load(resource, new DefaultClassPathResourceLoader(this.getClass().getClassLoader()));
    if (optionalSource.isPresent()) {
        LOGGER.info("Converting {} into Java based configuration", resource + ".yml");
        context.registerExcludedResource(resource + ".yml");
        context.registerExcludedResource(resource + ".yaml");
        PropertySource ps = optionalSource.get();
        if (ps instanceof MapPropertySource) {
            MapPropertySource mps = (MapPropertySource) ps;
            Map<String, Object> values = mps.asMap();
            MapPropertySourceGenerator generator = new MapPropertySourceGenerator(resource, values);
            generator.generate(context);
        } else {
            throw new UnsupportedOperationException("Unknown property source type:" + ps.getClass());
        }
    }
}
Also used : MapPropertySource(io.micronaut.context.env.MapPropertySource) DefaultClassPathResourceLoader(io.micronaut.core.io.scan.DefaultClassPathResourceLoader) PropertySource(io.micronaut.context.env.PropertySource) MapPropertySource(io.micronaut.context.env.MapPropertySource)

Example 4 with MapPropertySource

use of io.micronaut.context.env.MapPropertySource in project micronaut-aws by micronaut-projects.

the class AwsDistributedConfigurationClient method getPropertySources.

@Override
public Publisher<PropertySource> getPropertySources(Environment environment) {
    List<String> configurationResolutionPrefixes = generateConfigurationResolutionPrefixes(environment);
    Map<String, Map> configurationResolutionPrefixesValues = new HashMap<>();
    for (String prefix : configurationResolutionPrefixes) {
        Optional<Map> keyValuesOptional = keyValueFetcher.keyValuesByPrefix(prefix);
        if (keyValuesOptional.isPresent()) {
            Map keyValues = keyValuesOptional.get();
            configurationResolutionPrefixesValues.put(prefix, keyValues);
        }
    }
    Set<String> allKeys = new HashSet<>();
    for (Map m : configurationResolutionPrefixesValues.values()) {
        allKeys.addAll(m.keySet());
    }
    Map<String, Object> result = new HashMap<>();
    if (LOG.isTraceEnabled()) {
        LOG.trace("evaluating {} keys", allKeys.size());
    }
    for (String k : allKeys) {
        if (!result.containsKey(k)) {
            for (String prefix : configurationResolutionPrefixes) {
                if (configurationResolutionPrefixesValues.containsKey(prefix)) {
                    Map<String, ?> values = configurationResolutionPrefixesValues.get(prefix);
                    if (values.containsKey(k)) {
                        if (LOG.isTraceEnabled()) {
                            LOG.trace("adding property {} from prefix {}", k, prefix);
                        }
                        result.put(k, values.get(k));
                        break;
                    }
                }
            }
        }
    }
    String propertySourceName = getPropertySourceName();
    if (LOG.isDebugEnabled()) {
        LOG.debug("Property source {} with #{} items", propertySourceName, result.size());
    }
    if (LOG.isTraceEnabled()) {
        for (String k : result.keySet()) {
            LOG.trace("property {} resolved", k);
        }
    }
    return Publishers.just(new MapPropertySource(propertySourceName, result));
}
Also used : HashMap(java.util.HashMap) MapPropertySource(io.micronaut.context.env.MapPropertySource) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

MapPropertySource (io.micronaut.context.env.MapPropertySource)4 ApplicationContext (io.micronaut.context.ApplicationContext)2 PropertySource (io.micronaut.context.env.PropertySource)1 DefaultClassPathResourceLoader (io.micronaut.core.io.scan.DefaultClassPathResourceLoader)1 EmbeddedServer (io.micronaut.runtime.server.EmbeddedServer)1 RxHttpClient (io.micronaut.rxjava2.http.client.RxHttpClient)1 File (java.io.File)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Test (org.junit.jupiter.api.Test)1