Skip to content

Commit

Permalink
Merge branch 'main' into k-diger/kafbat#675
Browse files Browse the repository at this point in the history
  • Loading branch information
K-Diger authored Dec 9, 2024
2 parents 43179a8 + 3c0cd73 commit 1c02bfd
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 12 deletions.
18 changes: 17 additions & 1 deletion api/src/main/java/io/kafbat/ui/emitter/MessageFilters.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,23 @@ public static Predicate<TopicMessageDTO> noop() {

public static Predicate<TopicMessageDTO> containsStringFilter(String string) {
return msg -> StringUtils.contains(msg.getKey(), string)
|| StringUtils.contains(msg.getContent(), string);
|| StringUtils.contains(msg.getContent(), string) || headersContains(msg, string);
}

private static boolean headersContains(TopicMessageDTO msg, String searchString) {
final var headers = msg.getHeaders();

if (headers == null) {
return false;
}

for (final var entry : headers.entrySet()) {
if (StringUtils.contains(entry.getKey(), searchString) || StringUtils.contains(entry.getValue(), searchString)) {
return true;
}
}

return false;
}

public static Predicate<TopicMessageDTO> celScriptFilter(String script) {
Expand Down
2 changes: 2 additions & 0 deletions api/src/main/java/io/kafbat/ui/model/rbac/Role.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.kafbat.ui.model.rbac;

import com.google.common.base.Preconditions;
import java.util.List;
import lombok.Data;

Expand All @@ -12,6 +13,7 @@ public class Role {
List<Permission> permissions;

public void validate() {
Preconditions.checkArgument(!clusters.isEmpty(), "Role clusters cannot be empty");
permissions.forEach(Permission::transform);
permissions.forEach(Permission::validate);
}
Expand Down
15 changes: 14 additions & 1 deletion api/src/test/java/io/kafbat/ui/emitter/MessageFiltersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class StringContainsFilter {
Predicate<TopicMessageDTO> filter = containsStringFilter("abC");

@Test
void returnsTrueWhenStringContainedInKeyOrContentOrInBoth() {
void returnsTrueWhenStringContainedInKeyOrContentOrHeadersOrInAllThree() {
assertTrue(
filter.test(msg().key("contains abCd").content("some str"))
);
Expand All @@ -40,6 +40,14 @@ void returnsTrueWhenStringContainedInKeyOrContentOrInBoth() {
assertTrue(
filter.test(msg().key("contains abCd").content("contains abCd"))
);

assertTrue(
filter.test(msg().key("dfg").content("does-not-contain").headers(Map.of("abC", "value")))
);

assertTrue(
filter.test(msg().key("dfg").content("does-not-contain").headers(Map.of("x1", "some abC")))
);
}

@Test
Expand All @@ -55,6 +63,11 @@ void returnsFalseOtherwise() {
assertFalse(
filter.test(msg().key("aBc").content("AbC"))
);

assertFalse(
filter.test(msg().key("aBc").content("AbC").headers(Map.of("abc", "value")))
);

}

}
Expand Down
3 changes: 2 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@
"follow-redirects@<1.15.4": ">=1.15.4",
"json5@>=2.0.0 <2.2.2": ">=2.2.2",
"semver@>=7.0.0 <7.5.2": ">=7.5.2",
"axios@>=0.8.1 <0.28.0": ">=0.28.0"
"axios@>=0.8.1 <0.28.0": ">=0.28.0",
"braces": "3.0.3"
}
}
}
19 changes: 10 additions & 9 deletions frontend/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1c02bfd

Please sign in to comment.