Skip to content

Commit

Permalink
removed deprecated basic auth config from dialog - added migration sc…
Browse files Browse the repository at this point in the history
…ript - formatted error in case of update check failed
  • Loading branch information
Haring, Bernhard (Extern) authored and Haring, Bernhard (Extern) committed Oct 25, 2023
1 parent 9dda215 commit c34a01e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
7 changes: 0 additions & 7 deletions src/main/java/at/esque/kafka/dialogs/ClusterConfigDialog.java
Expand Up @@ -21,7 +21,6 @@ public class ClusterConfigDialog {
public static final String LABEL_IDENTIFIER = "Identifier";
public static final String LABEL_BOOTSTRAP_SERVERS = "Bootstrap-Servers";
public static final String LABEL_SCHEMA_REGISTRY_URL = "Schema Registry URL";
public static final String LABEL_SCHEMA_REGISTRY_BASIC_AUTH_USER_INFO = "<<Deprecated>>Schema Registry Basic Auth User Info";
public static final String LABEL_SCHEMA_REGISTRY_AUTH_USER_INFO = "Schema Registry Auth Info";
public static final String LABEL_SCHEMA_REGISTRY_AUTH_MODE = "Schema Registry Auth Mode";
public static final String LABEL_ENABLE_SSL = "Enable SSL";
Expand Down Expand Up @@ -76,12 +75,6 @@ public static Optional<ClusterConfig> show(ClusterConfig existingConfig) {
.placeholder(LABEL_SCHEMA_REGISTRY_URL)
.format(new NullFormatStringConverter())
.bind(copy.schemaRegistryProperty()),
Field.ofStringType(copy.getSchemaRegistryBasicAuthUserInfo() == null ? "" : copy.getSchemaRegistryBasicAuthUserInfo())
.label(LABEL_SCHEMA_REGISTRY_BASIC_AUTH_USER_INFO)
.tooltip(LABEL_SCHEMA_REGISTRY_BASIC_AUTH_USER_INFO)
.placeholder(LABEL_SCHEMA_REGISTRY_BASIC_AUTH_USER_INFO)
.format(new NullFormatStringConverter())
.bind(copy.schemaRegistryBasicAuthUserInfoProperty()),
Field.ofSingleSelectionType(copy.schemaRegistryAuthModesProperty())
.label(LABEL_SCHEMA_REGISTRY_AUTH_MODE)
.tooltip(LABEL_SCHEMA_REGISTRY_AUTH_MODE)
Expand Down
34 changes: 28 additions & 6 deletions src/main/java/at/esque/kafka/handlers/ConfigHandler.java
Expand Up @@ -24,6 +24,7 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Function;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -214,6 +215,7 @@ public ClusterConfigs loadOrCreateConfigs() {
} else if (clusterConfig.exists()) {
try {
clusterConfigs = objectMapper.readValue(clusterConfig, ClusterConfigs.class);
maybeMigrateDeprecatedConfig(clusterConfigs);
return clusterConfigs;
} catch (IOException e) {
ErrorAlert.show(e);
Expand All @@ -232,11 +234,34 @@ public ClusterConfigs loadOrCreateConfigs() {
return clusterConfigs;
}

public void saveConfigs() {
public void maybeMigrateDeprecatedConfig(ClusterConfigs clusterConfigs) {
AtomicBoolean updated = new AtomicBoolean(false);
clusterConfigs.getClusterConfigs().forEach(config -> {
var schemaRegistryBasicAuthUserInfo = config.getSchemaRegistryBasicAuthUserInfo();
if (StringUtils.isNotBlank(schemaRegistryBasicAuthUserInfo)) {
config.setSchemaRegistryAuthMode(ClusterConfig.SchemaRegistryAuthMode.BASIC);
config.setSchemaRegistryAuthConfig(schemaRegistryBasicAuthUserInfo);
config.setSchemaRegistryBasicAuthUserInfo(null);
updated.set(true);
}
});
if (updated.get()) {
if (saveConfigs()) {
LOGGER.info("deprecated property migration sucessful!");
} else {
LOGGER.warn("deprecated property migration failed!");
}
}
}


public boolean saveConfigs() {
try {
objectMapper.writeValue(clusterConfig, clusterConfigs);
return true;
} catch (IOException e) {
ErrorAlert.show(e);
return false;
}
}

Expand Down Expand Up @@ -318,13 +343,10 @@ public Map<String, String> getSaslProperties(ClusterConfig config) {
public Map<String, ?> getSchemaRegistryAuthProperties(ClusterConfig config) {
Map<String, String> props = new HashMap<>();

if (StringUtils.isNoneEmpty(config.getSchemaRegistryBasicAuthUserInfo())) {
props.put(SchemaRegistryClientConfig.BASIC_AUTH_CREDENTIALS_SOURCE, "USER_INFO");
props.put(SchemaRegistryClientConfig.CLIENT_NAMESPACE + SchemaRegistryClientConfig.USER_INFO_CONFIG, config.getSchemaRegistryBasicAuthUserInfo());
} else if (ClusterConfig.SchemaRegistryAuthMode.BASIC.equals(config.getSchemaRegistryAuthMode())){
if (ClusterConfig.SchemaRegistryAuthMode.BASIC.equals(config.getSchemaRegistryAuthMode())) {
props.put(SchemaRegistryClientConfig.BASIC_AUTH_CREDENTIALS_SOURCE, "USER_INFO");
props.put(SchemaRegistryClientConfig.CLIENT_NAMESPACE + SchemaRegistryClientConfig.USER_INFO_CONFIG, config.getSchemaRegistryAuthConfig());
}else if (ClusterConfig.SchemaRegistryAuthMode.TOKEN.equals(config.getSchemaRegistryAuthMode())){
} else if (ClusterConfig.SchemaRegistryAuthMode.TOKEN.equals(config.getSchemaRegistryAuthMode())) {
props.put(SchemaRegistryClientConfig.BEARER_AUTH_CREDENTIALS_SOURCE, "STATIC_TOKEN");
props.put(SchemaRegistryClientConfig.BEARER_AUTH_TOKEN_CONFIG, config.getSchemaRegistryAuthConfig());
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/at/esque/kafka/handlers/VersionInfoHandler.java
Expand Up @@ -117,7 +117,7 @@ private Map<String, Object> checkLatestVersion() {


} catch (Exception e) {
Platform.runLater(() -> ErrorAlert.show(e));
Platform.runLater(() -> ErrorAlert.show("Update Check failed", "Failed to check for availabe Updates", e.getMessage(), e, null, false));
}
} else {
return (Map<String, Object>) versionCheckContent.get("release");
Expand All @@ -133,7 +133,7 @@ public void showDialogIfUpdateIsAvailable(HostServices hostServices) {
if (openInBrowser) {
try {
hostServices.showDocument(updateInfo.getReleasePage());
}catch (Exception e){
} catch (Exception e) {
ErrorAlert.show(e);
}
}
Expand Down

0 comments on commit c34a01e

Please sign in to comment.