Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate config values before start #876

Merged
merged 4 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator</artifactId>
Expand Down
21 changes: 16 additions & 5 deletions api/src/main/java/io/kafbat/ui/config/ClustersProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import io.kafbat.ui.model.MetricsConfig;
import jakarta.annotation.PostConstruct;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
Expand All @@ -17,13 +20,15 @@
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;

@Configuration
@ConfigurationProperties("kafka")
@Data
@Validated
public class ClustersProperties {

List<Cluster> clusters = new ArrayList<>();
List<@Valid Cluster> clusters = new ArrayList<>();

String internalTopicPrefix;

Expand All @@ -33,7 +38,9 @@ public class ClustersProperties {

@Data
public static class Cluster {
@NotBlank(message = "field name for for cluster could not be blank")
String name;
@NotBlank(message = "field bootstrapServers for for cluster could not be blank")
String bootstrapServers;

TruststoreConfig ssl;
Expand All @@ -46,9 +53,9 @@ public static class Cluster {
KsqldbServerAuth ksqldbServerAuth;
KeystoreConfig ksqldbServerSsl;

List<ConnectCluster> kafkaConnect;
List<@Valid ConnectCluster> kafkaConnect;

List<SerdeConfig> serde;
List<@Valid SerdeConfig> serde;
String defaultKeySerde;
String defaultValueSerde;

Expand All @@ -58,7 +65,7 @@ public static class Cluster {

Long pollingThrottleRate;

List<Masking> masking;
List<@Valid Masking> masking;

AuditProperties audit;
}
Expand Down Expand Up @@ -88,7 +95,9 @@ public static class MetricsConfigData {
@Builder(toBuilder = true)
@ToString(exclude = {"password", "keystorePassword"})
public static class ConnectCluster {
@NotBlank
String name;
@NotBlank
String address;
String username;
String password;
Expand Down Expand Up @@ -122,6 +131,7 @@ public static class KeystoreConfig {

@Data
public static class SerdeConfig {
@NotBlank
String name;
String className;
String filePath;
Expand All @@ -139,6 +149,7 @@ public static class KsqldbServerAuth {

@Data
public static class Masking {
@NotNull
Type type;
List<String> fields;
String fieldsNamePattern;
Expand All @@ -160,7 +171,7 @@ public static class AuditProperties {
Integer auditTopicsPartitions;
Boolean topicAuditEnabled;
Boolean consoleAuditEnabled;
LogLevel level;
LogLevel level = LogLevel.ALTER_ONLY;
Map<String, String> auditTopicProperties;

public enum LogLevel {
Expand Down
Loading