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

fix: Make config file optional and don't override settings #95

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@ private ManagerConfig generateStateManagerConfig() {
.setDeleteDisabled(parent.isDeleteDisabled())
.setIncludeUnchangedEnabled(false)
.setSkipAclsDisabled(parent.areAclsDisabled())
.setConfigFile(parent.getConfigFile())
.setNullableConfigFile(parent.getConfigFile())
.setStateFile(parent.getStateFile())
.build();
}
Original file line number Diff line number Diff line change
@@ -55,7 +55,7 @@ private ManagerConfig generateStateManagerConfig() {
.setDeleteDisabled(parent.isDeleteDisabled())
.setIncludeUnchangedEnabled(false)
.setSkipAclsDisabled(parent.areAclsDisabled())
.setConfigFile(parent.getConfigFile())
.setNullableConfigFile(parent.getConfigFile())
.setStateFile(parent.getStateFile())
.setNullablePlanFile(planFile)
.build();
Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@ private ManagerConfig generateStateManagerConfig() {
.setVerboseRequested(parent.isVerboseRequested())
.setDeleteDisabled(parent.isDeleteDisabled())
.setIncludeUnchangedEnabled(includeUnchanged)
.setConfigFile(parent.getConfigFile())
.setNullableConfigFile(parent.getConfigFile())
.setStateFile(parent.getStateFile())
.setSkipAclsDisabled(parent.areAclsDisabled())
.setNullablePlanFile(outputFile)
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ private ManagerConfig generateStateManagerConfig() {
.setDeleteDisabled(parent.isDeleteDisabled())
.setIncludeUnchangedEnabled(false)
.setSkipAclsDisabled(parent.areAclsDisabled())
.setConfigFile(parent.getConfigFile())
.setNullableConfigFile(parent.getConfigFile())
.setStateFile(parent.getStateFile())
.build();
}
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ private static void setConfigFromFile(File configFile, KafkaGitopsConfig.Builder
if (configFile == null) {
return;
}
try(InputStream inputStream = new FileInputStream(configFile)) {
try (InputStream inputStream = new FileInputStream(configFile)) {
Properties properties = new Properties();
properties.load(inputStream);
properties.forEach( (k, v) -> builder.putConfig(k.toString(), v));
@@ -60,21 +60,21 @@ private static void setConfigFromEnvironment(KafkaGitopsConfig.Builder builder)
}
});

handleDefaultConfig(config);
handleAuthentication(username, password, config);

log.info("Kafka Config: {}", config);

builder.putAllConfig(config);
handleDefaultConfig(builder);
}

private static void handleDefaultConfig(Map<String, Object> config) {
if (!config.containsKey(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG)) {
config.put(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
private static void handleDefaultConfig(KafkaGitopsConfig.Builder builder) {
if (!builder.getConfig().containsKey(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG)) {
builder.putConfig(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
}

if (!config.containsKey(CommonClientConfigs.CLIENT_ID_CONFIG)) {
config.put(CommonClientConfigs.CLIENT_ID_CONFIG, "kafka-gitops");
if (!builder.getConfig().containsKey(CommonClientConfigs.CLIENT_ID_CONFIG)) {
builder.putConfig(CommonClientConfigs.CLIENT_ID_CONFIG, "kafka-gitops");
}
}

Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ public interface ManagerConfig {

boolean isSkipAclsDisabled();

File getConfigFile();
Optional<File> getConfigFile();

File getStateFile();

Original file line number Diff line number Diff line change
@@ -48,13 +48,14 @@ class KafkaGitopsConfigLoaderSpec extends Specification {
void 'test command config file'() {
setup:
File configFile = new File(getClass().getResource("/command.properties").toURI())
environmentVariables.clear("KAFKA_BOOTSTRAP_SERVERS")

when:
KafkaGitopsConfig config = KafkaGitopsConfigLoader.load(configFile)

then:
config.config.get(CommonClientConfigs.CLIENT_ID_CONFIG) == "kafka-gitops"
config.config.get(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG) == "localhost:9092"
config.config.get(CommonClientConfigs.CLIENT_ID_CONFIG) == "kafka-client-id"
config.config.get(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG) == "example.com:9092"
config.config.get(SaslConfigs.SASL_MECHANISM) == "PLAIN"
}

4 changes: 2 additions & 2 deletions src/test/resources/command.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
bootstrap.servers=commande.9092
client.id=kafka-gitops
bootstrap.servers=example.com:9092
client.id=kafka-client-id