Skip to content

Commit

Permalink
fix: move isReadOnly check from dropdown to list items
Browse files Browse the repository at this point in the history
  • Loading branch information
spartanns committed Oct 21, 2024
2 parents e254bcf + 6f35c47 commit 1835be4
Show file tree
Hide file tree
Showing 14 changed files with 217 additions and 186 deletions.
15 changes: 1 addition & 14 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
<dependency>
<groupId>software.amazon.msk</groupId>
<artifactId>aws-msk-iam-auth</artifactId>
<version>2.1.0</version>
<version>2.2.0</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -266,18 +266,6 @@
<artifactId>cel</artifactId>
</dependency>
<!-- CVE fixes -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.4.12</version>
</dependency>
<!-- CVE fixes -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.4.12</version>
</dependency>
<!-- CVE fixes -->
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>logging-interceptor</artifactId>
Expand All @@ -289,7 +277,6 @@
<artifactId>commons-compress</artifactId>
<version>1.26.0</version>
</dependency>

</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class ReadOnlyModeFilter implements WebFilter {
Pattern.compile("/api/clusters/(?<clusterName>[^/]++)");

private static final Set<Pattern> SAFE_ENDPOINTS = Set.of(
Pattern.compile("/api/clusters/[^/]+/topics/[^/]+/(smartfilters)$")
Pattern.compile("/api/clusters/[^/]+/topics/[^/]+/(smartfilters|analysis)$")
);

private final ClustersStorage clustersStorage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ public class InternalBrokerConfig {
private final boolean isReadOnly;
private final List<ConfigEntry.ConfigSynonym> synonyms;

public static InternalBrokerConfig from(ConfigEntry configEntry) {
public static InternalBrokerConfig from(ConfigEntry configEntry, boolean readOnlyCluster) {
InternalBrokerConfig.InternalBrokerConfigBuilder builder = InternalBrokerConfig.builder()
.name(configEntry.name())
.value(configEntry.value())
.source(configEntry.source())
.isReadOnly(configEntry.isReadOnly())
.isReadOnly(readOnlyCluster || configEntry.isReadOnly())
.isSensitive(configEntry.isSensitive())
.synonyms(configEntry.synonyms());
return builder.build();
Expand Down
2 changes: 1 addition & 1 deletion api/src/main/java/io/kafbat/ui/service/BrokerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private Flux<InternalBrokerConfig> getBrokersConfig(KafkaCluster cluster, Intege
}
return loadBrokersConfig(cluster, brokerId)
.map(list -> list.stream()
.map(InternalBrokerConfig::from)
.map(configEntry -> InternalBrokerConfig.from(configEntry, cluster.isReadOnly()))
.collect(Collectors.toList()))
.flatMapMany(Flux::fromIterable);
}
Expand Down
4 changes: 2 additions & 2 deletions api/src/main/java/io/kafbat/ui/service/acl/AclsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public Mono<Void> createConsumerAcl(KafkaCluster cluster, CreateConsumerAclDTO r
.then();
}

//Read, Describe on topics, Read on consumerGroups
//Read, Describe on topics and consumerGroups
private List<AclBinding> createConsumerBindings(CreateConsumerAclDTO request) {
List<AclBinding> bindings = new ArrayList<>();
bindings.addAll(
Expand All @@ -172,7 +172,7 @@ private List<AclBinding> createConsumerBindings(CreateConsumerAclDTO request) {
bindings.addAll(
createAllowBindings(
GROUP,
List.of(READ),
List.of(READ, DESCRIBE),
request.getPrincipal(),
request.getHost(),
request.getConsumerGroupsPrefix(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

import java.util.List;
import java.util.Map;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.springframework.boot.context.properties.bind.BindException;
Expand All @@ -21,11 +19,7 @@ class PropertyResolverImplTest {

private final MockEnvironment env = new MockEnvironment();

@Data
@AllArgsConstructor
public static class CustomPropertiesClass {
private String f1;
private Integer f2;
public record CustomPropertiesClass(String f1, Integer f2) {
}

@Test
Expand Down
21 changes: 15 additions & 6 deletions api/src/test/java/io/kafbat/ui/service/acl/AclsServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ void createsConsumerDependantAcls() {
.topics(List.of("t1", "t2"))
).block();

//Read, Describe on topics, Read on consumerGroups
//Read, Describe on topics and consumerGroups
Collection<AclBinding> createdBindings = createdCaptor.getValue();
assertThat(createdBindings)
.hasSize(6)
.hasSize(8)
.contains(new AclBinding(
new ResourcePattern(ResourceType.TOPIC, "t1", PatternType.LITERAL),
new AccessControlEntry(principal, host, AclOperation.READ, AclPermissionType.ALLOW)))
Expand All @@ -122,9 +122,15 @@ void createsConsumerDependantAcls() {
.contains(new AclBinding(
new ResourcePattern(ResourceType.GROUP, "cg1", PatternType.LITERAL),
new AccessControlEntry(principal, host, AclOperation.READ, AclPermissionType.ALLOW)))
.contains(new AclBinding(
new ResourcePattern(ResourceType.GROUP, "cg1", PatternType.LITERAL),
new AccessControlEntry(principal, host, AclOperation.DESCRIBE, AclPermissionType.ALLOW)))
.contains(new AclBinding(
new ResourcePattern(ResourceType.GROUP, "cg2", PatternType.LITERAL),
new AccessControlEntry(principal, host, AclOperation.READ, AclPermissionType.ALLOW)))
.contains(new AclBinding(
new ResourcePattern(ResourceType.GROUP, "cg2", PatternType.LITERAL),
new AccessControlEntry(principal, host, AclOperation.READ, AclPermissionType.ALLOW)));
new AccessControlEntry(principal, host, AclOperation.DESCRIBE, AclPermissionType.ALLOW)));
}

@Test
Expand All @@ -145,10 +151,10 @@ void createsConsumerDependantAclsWhenTopicsAndGroupsSpecifiedByPrefix() {
.topicsPrefix("topicPref")
).block();

//Read, Describe on topics, Read on consumerGroups
//Read, Describe on topics and consumerGroups
Collection<AclBinding> createdBindings = createdCaptor.getValue();
assertThat(createdBindings)
.hasSize(3)
.hasSize(4)
.contains(new AclBinding(
new ResourcePattern(ResourceType.TOPIC, "topicPref", PatternType.PREFIXED),
new AccessControlEntry(principal, host, AclOperation.READ, AclPermissionType.ALLOW)))
Expand All @@ -157,7 +163,10 @@ void createsConsumerDependantAclsWhenTopicsAndGroupsSpecifiedByPrefix() {
new AccessControlEntry(principal, host, AclOperation.DESCRIBE, AclPermissionType.ALLOW)))
.contains(new AclBinding(
new ResourcePattern(ResourceType.GROUP, "cgPref", PatternType.PREFIXED),
new AccessControlEntry(principal, host, AclOperation.READ, AclPermissionType.ALLOW)));
new AccessControlEntry(principal, host, AclOperation.READ, AclPermissionType.ALLOW)))
.contains(new AclBinding(
new ResourcePattern(ResourceType.GROUP, "cgPref", PatternType.PREFIXED),
new AccessControlEntry(principal, host, AclOperation.DESCRIBE, AclPermissionType.ALLOW)));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
import static org.assertj.core.api.Assertions.assertThat;

import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.DecimalNode;
import com.fasterxml.jackson.databind.node.DoubleNode;
import com.fasterxml.jackson.databind.node.IntNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.TextNode;
import io.kafbat.ui.AbstractIntegrationTest;
import java.math.BigDecimal;
import java.time.Duration;
import java.util.Map;
import org.junit.jupiter.api.AfterAll;
Expand Down Expand Up @@ -80,23 +79,23 @@ private void assertLastKsqTutorialQueryResult(KsqlApiClient client) {
assertThat(header.getValues()).isNull();
})
.assertNext(row -> {
var distance = (DecimalNode) row.getValues().get(0).get(0);
var distance = (DoubleNode) row.getValues().get(0).get(0);
var riders = (ArrayNode) row.getValues().get(0).get(1);
var count = (IntNode) row.getValues().get(0).get(2);

assertThat(distance).isEqualTo(new DecimalNode(new BigDecimal(0)));
assertThat(distance).isEqualTo(new DoubleNode(0D));
assertThat(riders).isEqualTo(new ArrayNode(JsonNodeFactory.instance)
.add(new TextNode("4ab5cbad"))
.add(new TextNode("8b6eae59"))
.add(new TextNode("4a7c7b41")));
assertThat(count).isEqualTo(new IntNode(3));
})
.assertNext(row -> {
var distance = (DecimalNode) row.getValues().get(0).get(0);
var distance = (DoubleNode) row.getValues().get(0).get(0);
var riders = (ArrayNode) row.getValues().get(0).get(1);
var count = (IntNode) row.getValues().get(0).get(2);

assertThat(distance).isEqualTo(new DecimalNode(new BigDecimal(10)));
assertThat(distance).isEqualTo(new DoubleNode(10D));
assertThat(riders).isEqualTo(new ArrayNode(JsonNodeFactory.instance)
.add(new TextNode("18f4ea86")));
assertThat(count).isEqualTo(new IntNode(1));
Expand Down
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"pretty-ms": "7.0.1",
"react": "18.2.0",
"react-ace": "11.0.1",
"react-datepicker": "6.9.0",
"react-datepicker": "7.4.0",
"react-dom": "18.2.0",
"react-error-boundary": "4.0.13",
"react-hook-form": "7.51.3",
Expand Down
Loading

0 comments on commit 1835be4

Please sign in to comment.