2424
2525package org .sourcelab .kafka .webview .ui .manager .kafka .config ;
2626
27+ import com .fasterxml .jackson .databind .ObjectMapper ;
2728import org .sourcelab .kafka .webview .ui .manager .encryption .SecretManager ;
2829import org .sourcelab .kafka .webview .ui .manager .sasl .SaslProperties ;
2930import org .sourcelab .kafka .webview .ui .manager .sasl .SaslUtility ;
3031import org .sourcelab .kafka .webview .ui .model .Cluster ;
3132
33+ import java .io .IOException ;
3234import java .util .Arrays ;
35+ import java .util .Collections ;
36+ import java .util .HashMap ;
3337import java .util .HashSet ;
38+ import java .util .Map ;
3439import java .util .Set ;
3540import java .util .stream .Collectors ;
3641
@@ -58,6 +63,11 @@ public class ClusterConfig {
5863 private final String saslMechanism ;
5964 private final String saslJaas ;
6065
66+ /**
67+ * Client Properties defined on the Cluster configuration.
68+ */
69+ private final Map <String , String > clusterClientProperties ;
70+
6171 /**
6272 * Private constructor for connecting to SSL brokers.
6373 */
@@ -72,7 +82,9 @@ private ClusterConfig(
7282 final String saslPlaintextUsername ,
7383 final String saslPlaintextPassword ,
7484 final String saslMechanism ,
75- final String saslJaas ) {
85+ final String saslJaas ,
86+ final Map <String , String > clusterClientProperties
87+ ) {
7688
7789 this .brokerHosts = brokerHosts ;
7890
@@ -89,6 +101,11 @@ private ClusterConfig(
89101 this .saslPlaintextPassword = saslPlaintextPassword ;
90102 this .saslMechanism = saslMechanism ;
91103 this .saslJaas = saslJaas ;
104+
105+ // Shallow copy the cluster client properties.
106+ this .clusterClientProperties = Collections .unmodifiableMap (
107+ new HashMap <>(clusterClientProperties )
108+ );
92109 }
93110
94111 public Set <String > getBrokerHosts () {
@@ -139,6 +156,10 @@ public String getSaslJaas() {
139156 return saslJaas ;
140157 }
141158
159+ public Map <String , String > getClusterClientProperties () {
160+ return clusterClientProperties ;
161+ }
162+
142163 @ Override
143164 public String toString () {
144165 return "ClusterConfig{"
@@ -196,6 +217,19 @@ public static Builder newBuilder(final Cluster cluster, final SecretManager secr
196217 builder .withUseSasl (false );
197218 }
198219
220+ // If we have defined cluster client options, decode and set them.
221+ if (cluster .getOptionParameters () != null ) {
222+ final ObjectMapper objectMapper = new ObjectMapper ();
223+ Map <String , String > customOptions ;
224+ try {
225+ customOptions = objectMapper .readValue (cluster .getOptionParameters (), Map .class );
226+ } catch (final IOException e ) {
227+ // Fail safe?
228+ customOptions = new HashMap <>();
229+ }
230+ builder .withClusterClientConfig (customOptions );
231+ }
232+
199233 return builder ;
200234 }
201235
@@ -223,6 +257,12 @@ public static final class Builder {
223257 private String saslMechanism ;
224258 private String saslJaas ;
225259
260+ /**
261+ * Override properties defined from the cluster.option_parameters field.
262+ * These should be applied LAST ontop of all the other config options.
263+ */
264+ private Map <String , String > clusterOverrideProperties = new HashMap <>();
265+
226266 private Builder () {
227267 }
228268
@@ -323,6 +363,22 @@ public Builder withSaslJaas(final String saslJaas) {
323363 return this ;
324364 }
325365
366+ /**
367+ * Declare Override Properties defined on the cluster.
368+ */
369+ public Builder withClusterClientConfig (final Map <String , String > clusterClientConfig ) {
370+ this .clusterOverrideProperties .putAll (clusterClientConfig );
371+ return this ;
372+ }
373+
374+ /**
375+ * Declare Override Properties defined on the cluster.
376+ */
377+ public Builder withClusterClientConfig (final String key , final String value ) {
378+ this .clusterOverrideProperties .put (key , value );
379+ return this ;
380+ }
381+
326382 /**
327383 * Create ClusterConfig instance from builder values.
328384 */
@@ -340,7 +396,9 @@ public ClusterConfig build() {
340396 saslPlaintextUsername ,
341397 saslPlaintextPassword ,
342398 saslMechanism ,
343- saslJaas
399+ saslJaas ,
400+ // Cluster client properties
401+ clusterOverrideProperties
344402 );
345403 }
346404 }
0 commit comments