Skip to content

Commit

Permalink
migrated ccloud commands to confluent cli v2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
tball-dev authored and tball-trimble committed Apr 29, 2022
1 parent 61c1dcd commit e777280
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/devshawn/kafka/gitops/StateManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,8 @@ private void validateTopics(DesiredStateFile desiredStateFile) {
}

private boolean isConfluentCloudEnabled(DesiredStateFile desiredStateFile) {
if (desiredStateFile.getSettings().isPresent() && desiredStateFile.getSettings().get().getCcloud().isPresent()) {
return desiredStateFile.getSettings().get().getCcloud().get().isEnabled();
if (desiredStateFile.getSettings().isPresent() && desiredStateFile.getSettings().get().getConfluent().isPresent()) {
return desiredStateFile.getSettings().get().getConfluent().get().isEnabled();
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@JsonDeserialize(builder = Settings.Builder.class)
public interface Settings {

Optional<SettingsCCloud> getCcloud();
Optional<SettingsConfluent> getConfluent();

Optional<SettingsTopics> getTopics();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import org.inferred.freebuilder.FreeBuilder;

@FreeBuilder
@JsonDeserialize(builder = SettingsCCloud.Builder.class)
public interface SettingsCCloud {
@JsonDeserialize(builder = SettingsConfluent.Builder.class)
public interface SettingsConfluent {

boolean isEnabled();

class Builder extends SettingsCCloud_Builder {
class Builder extends SettingsConfluent_Builder {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ public class ConfluentCloudService {
private static org.slf4j.Logger log = LoggerFactory.getLogger(ConfluentCloudService.class);

private final ObjectMapper objectMapper;
private static final String ccloudExecutable;
private static final String confluentExecutable;

public ConfluentCloudService(ObjectMapper objectMapper) {
this.objectMapper = objectMapper;
}

public List<ServiceAccount> getServiceAccounts() {
log.info("Fetching service account list from Confluent Cloud via ccloud tool.");
log.info("Fetching service account list from Confluent Cloud via confluent tool.");
try {
String result = execCmd(new String[]{ccloudExecutable, "service-account", "list", "-o", "json"});
String result = execCmd(new String[]{confluentExecutable, "iam", "service-account", "list", "-o", "json"});
return objectMapper.readValue(result, new TypeReference<List<ServiceAccount>>() {
});
} catch (IOException ex) {
Expand All @@ -33,11 +33,11 @@ public List<ServiceAccount> getServiceAccounts() {
}

public ServiceAccount createServiceAccount(String name, boolean isUser) {
log.info("Creating service account {} in Confluent Cloud via ccloud tool.", name);
log.info("Creating service account {} in Confluent Cloud via confluent tool.", name);
try {
String serviceName = isUser ? String.format("user-%s", name) : name;
String description = isUser ? String.format("User: %s", name) : String.format("Service account: %s", name);
String result = execCmd(new String[]{ccloudExecutable, "service-account", "create", serviceName, "--description", description, "-o", "json"});
String result = execCmd(new String[]{confluentExecutable, "iam", "service-account", "create", serviceName, "--description", description, "-o", "json"});
return objectMapper.readValue(result, ServiceAccount.class);
} catch (IOException ex) {
throw new ConfluentCloudException(String.format("There was an error creating Confluent Cloud service account: %s.", name));
Expand All @@ -50,7 +50,7 @@ public static String execCmd(String[] cmd) throws java.io.IOException {
}

static {
ccloudExecutable = System.getenv("CCLOUD_EXECUTABLE_PATH") != null ? System.getenv("CCLOUD_EXECUTABLE_PATH") : "ccloud";
log.info("Using ccloud executable at: {}", ccloudExecutable);
confluentExecutable = System.getenv("CONFLUENT_EXECUTABLE_PATH") != null ? System.getenv("CONFLUENT_EXECUTABLE_PATH") : "confluent";
log.info("Using confluent executable at: {}", confluentExecutable);
}
}

0 comments on commit e777280

Please sign in to comment.