Skip to content

Commit

Permalink
fix(provider/kafka): fix resource KafkaPrincipalAuthorizationList res…
Browse files Browse the repository at this point in the history
…ource (#496)

fix: #496
  • Loading branch information
fhussonnois committed Nov 16, 2024
1 parent e04e076 commit ddf6088
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<String, Object> 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);
Expand All @@ -73,5 +72,12 @@ public ValuesLoader(final @NotNull ObjectMapper objectMapper) {
}
}

private record ValuesFile(String file, NamedValueSet values) { }
@VisibleForTesting
@NotNull Stream<ValuesFile> load(String location, InputStream stream) throws IOException {
@SuppressWarnings("unchecked")
Map<String, Object> values = objectMapper.readValue(stream, Map.class);
return Stream.of(new ValuesFile(location, NamedValueSet.setOf(values)));
}

record ValuesFile(String file, NamedValueSet values) { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -127,6 +128,7 @@ public void registerResources(@NotNull ResourceRegistry registry) {
V1KafkaTopicList.class,
V1KafkaTopic.class,
V1KafkaPrincipalAuthorization.class,
V1KafkaPrincipalAuthorizationList.class,
V1KafkaPrincipalRole.class,
V1KafkaTableRecord.class,
V1KafkaConsumerGroup.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.jetbrains.annotations.Nullable;

@ApiVersion("kafka.jikkou.io/v1beta2")
@Kind("KafkaTopicAuthorizationList")
@Kind("KafkaPrincipalAuthorizationList")
public class V1KafkaPrincipalAuthorizationList extends DefaultResourceListObject<V1KafkaPrincipalAuthorization> {


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public class JinjaResourceTemplateRenderer implements ResourceTemplateRenderer {
private static final String CONFIG_NS = "jinja";

public static final ConfigProperty<Boolean> 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 {
Expand All @@ -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) {
Expand All @@ -91,7 +95,7 @@ public String render(@NotNull final String template,

List<TemplateError> 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",
Expand All @@ -111,10 +115,7 @@ public String render(@NotNull final String template,
static Map<String, Object> buildBindingsMapFrom(final TemplateBindings bindings) {
HashMap<String, Object> bindingsMap = new HashMap<>();

Map<String, Object> 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<String, Object> labels = new HashMap<>();
CollectionUtils.toNestedMap(bindings.getLabels(), labels, null);
Expand Down

0 comments on commit ddf6088

Please sign in to comment.