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));
}
}
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"));
}
}
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());
}
}
}
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));
}
Aggregations