diff --git a/core/src/main/java/io/streamthoughts/jikkou/core/io/ValuesLoader.java b/core/src/main/java/io/streamthoughts/jikkou/core/io/ValuesLoader.java index 03b94c82e..8b9817f4d 100644 --- a/core/src/main/java/io/streamthoughts/jikkou/core/io/ValuesLoader.java +++ b/core/src/main/java/io/streamthoughts/jikkou/core/io/ValuesLoader.java @@ -20,6 +20,7 @@ import java.util.Objects; import java.util.stream.Stream; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.VisibleForTesting; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -52,9 +53,7 @@ public ValuesLoader(final @NotNull ObjectMapper objectMapper) { Path path = Path.of(location); if (Files.size(path) > 0) { try (InputStream stream = Files.newInputStream(path)) { - @SuppressWarnings("unchecked") - Map values = objectMapper.readValue(stream, Map.class); - return Stream.of(new ValuesFile(location, NamedValueSet.setOf(values))); + return load(location, stream); } } else { LOG.debug("Ignore values from '{}'. File is empty.", location); @@ -73,5 +72,12 @@ public ValuesLoader(final @NotNull ObjectMapper objectMapper) { } } - private record ValuesFile(String file, NamedValueSet values) { } + @VisibleForTesting + @NotNull Stream load(String location, InputStream stream) throws IOException { + @SuppressWarnings("unchecked") + Map values = objectMapper.readValue(stream, Map.class); + return Stream.of(new ValuesFile(location, NamedValueSet.setOf(values))); + } + + record ValuesFile(String file, NamedValueSet values) { } } diff --git a/providers/jikkou-provider-kafka/src/main/java/io/streamthoughts/jikkou/kafka/KafkaExtensionProvider.java b/providers/jikkou-provider-kafka/src/main/java/io/streamthoughts/jikkou/kafka/KafkaExtensionProvider.java index c635ce6fc..c5dd68844 100644 --- a/providers/jikkou-provider-kafka/src/main/java/io/streamthoughts/jikkou/kafka/KafkaExtensionProvider.java +++ b/providers/jikkou-provider-kafka/src/main/java/io/streamthoughts/jikkou/kafka/KafkaExtensionProvider.java @@ -12,6 +12,7 @@ import io.streamthoughts.jikkou.kafka.action.KafkaConsumerGroupsResetOffsets; import io.streamthoughts.jikkou.kafka.collections.V1KafkaBrokerList; import io.streamthoughts.jikkou.kafka.collections.V1KafkaClientQuotaList; +import io.streamthoughts.jikkou.kafka.collections.V1KafkaPrincipalAuthorizationList; import io.streamthoughts.jikkou.kafka.collections.V1KafkaTopicList; import io.streamthoughts.jikkou.kafka.health.KafkaBrokerHealthIndicator; import io.streamthoughts.jikkou.kafka.model.user.V1KafkaUser; @@ -127,6 +128,7 @@ public void registerResources(@NotNull ResourceRegistry registry) { V1KafkaTopicList.class, V1KafkaTopic.class, V1KafkaPrincipalAuthorization.class, + V1KafkaPrincipalAuthorizationList.class, V1KafkaPrincipalRole.class, V1KafkaTableRecord.class, V1KafkaConsumerGroup.class, diff --git a/providers/jikkou-provider-kafka/src/main/java/io/streamthoughts/jikkou/kafka/collections/V1KafkaPrincipalAuthorizationList.java b/providers/jikkou-provider-kafka/src/main/java/io/streamthoughts/jikkou/kafka/collections/V1KafkaPrincipalAuthorizationList.java index e821c1c60..d79fb7547 100644 --- a/providers/jikkou-provider-kafka/src/main/java/io/streamthoughts/jikkou/kafka/collections/V1KafkaPrincipalAuthorizationList.java +++ b/providers/jikkou-provider-kafka/src/main/java/io/streamthoughts/jikkou/kafka/collections/V1KafkaPrincipalAuthorizationList.java @@ -17,7 +17,7 @@ import org.jetbrains.annotations.Nullable; @ApiVersion("kafka.jikkou.io/v1beta2") -@Kind("KafkaTopicAuthorizationList") +@Kind("KafkaPrincipalAuthorizationList") public class V1KafkaPrincipalAuthorizationList extends DefaultResourceListObject { diff --git a/template-jinja/src/main/java/io/streamthoughts/jikkou/api/template/JinjaResourceTemplateRenderer.java b/template-jinja/src/main/java/io/streamthoughts/jikkou/api/template/JinjaResourceTemplateRenderer.java index a0b4a01df..f406c84bb 100644 --- a/template-jinja/src/main/java/io/streamthoughts/jikkou/api/template/JinjaResourceTemplateRenderer.java +++ b/template-jinja/src/main/java/io/streamthoughts/jikkou/api/template/JinjaResourceTemplateRenderer.java @@ -38,9 +38,9 @@ public class JinjaResourceTemplateRenderer implements ResourceTemplateRenderer { private static final String CONFIG_NS = "jinja"; public static final ConfigProperty ENABLE_RECURSIVE_MACRO_CALLS = ConfigProperty - .ofBoolean(CONFIG_NS + ".enableRecursiveMacroCalls") - .orElse(true) - .description("Enable recursive macro calls."); + .ofBoolean(CONFIG_NS + ".enableRecursiveMacroCalls") + .orElse(true) + .description("Enable recursive macro calls."); // list of scopes for bindings public enum Scopes { @@ -67,13 +67,17 @@ public JinjaResourceTemplateRenderer withPreserveRawTags(final boolean preserveR private Configuration configuration = Configuration.empty(); - /** {@inheritDoc} **/ + /** + * {@inheritDoc} + **/ @Override public void configure(final @NotNull Configuration config) throws ConfigException { - this.configuration = config; + this.configuration = config; } - /** {@inheritDoc} **/ + /** + * {@inheritDoc} + **/ @Override public String render(@NotNull final String template, @NotNull final TemplateBindings bindings) { @@ -91,7 +95,7 @@ public String render(@NotNull final String template, List errors = result.getErrors(); if (!errors.isEmpty()) { - TemplateError error = errors.get(0); + TemplateError error = errors.getFirst(); throw new JikkouRuntimeException( String.format( "Cannot render resource template. '%s': line %d, start_pos: %d, %s", @@ -111,10 +115,7 @@ public String render(@NotNull final String template, static Map buildBindingsMapFrom(final TemplateBindings bindings) { HashMap bindingsMap = new HashMap<>(); - Map values = new HashMap<>(); - CollectionUtils.toNestedMap(bindings.getValues(), values, null); - CollectionUtils.toFlattenMap(bindings.getValues(), values, null); - bindingsMap.put(Scopes.VALUES.key(), values); + bindingsMap.put(Scopes.VALUES.key(), bindings.getValues()); Map labels = new HashMap<>(); CollectionUtils.toNestedMap(bindings.getLabels(), labels, null);