Skip to content

Commit 35393c2

Browse files
committed
Mark all broker configs as read-only in read-only clusters (kafbat#556)
1 parent 3f3ca4c commit 35393c2

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

api/src/main/java/io/kafbat/ui/controller/BrokersController.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package io.kafbat.ui.controller;
22

33
import io.kafbat.ui.api.BrokersApi;
4+
import io.kafbat.ui.config.Config;
5+
import io.kafbat.ui.exception.ClusterNotFoundException;
46
import io.kafbat.ui.mapper.ClusterMapper;
57
import io.kafbat.ui.model.BrokerConfigDTO;
68
import io.kafbat.ui.model.BrokerConfigItemDTO;
@@ -30,6 +32,7 @@ public class BrokersController extends AbstractController implements BrokersApi
3032

3133
private final BrokerService brokerService;
3234
private final ClusterMapper clusterMapper;
35+
private final Config config;
3336

3437
@Override
3538
public Mono<ResponseEntity<Flux<BrokerDTO>>> getBrokers(String clusterName,
@@ -94,10 +97,24 @@ public Mono<ResponseEntity<Flux<BrokerConfigDTO>>> getBrokerConfig(String cluste
9497
.operationParams(Map.of(BROKER_ID, id))
9598
.build();
9699

100+
Flux<BrokerConfigDTO> brokerConfigs = brokerService.getBrokerConfig(getCluster(clusterName), id)
101+
.map(clusterMapper::toBrokerConfig);
102+
103+
var kafkaCluster = clustersStorage.getClusterByName(clusterName)
104+
.orElseThrow(
105+
() -> new ClusterNotFoundException(
106+
String.format("No cluster for name '%s'", clusterName)));
107+
108+
if (kafkaCluster.isReadOnly()) {
109+
brokerConfigs = brokerConfigs.map(config -> {
110+
config.setIsReadOnly(true);
111+
return config;
112+
});
113+
}
114+
97115
return validateAccess(context).thenReturn(
98116
ResponseEntity.ok(
99-
brokerService.getBrokerConfig(getCluster(clusterName), id)
100-
.map(clusterMapper::toBrokerConfig))
117+
brokerConfigs)
101118
).doOnEach(sig -> audit(context, sig));
102119
}
103120

0 commit comments

Comments
 (0)