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

Confluent CLI migration #91

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
migrated ccloud commands to confluent cli v2.x
  • Loading branch information
tball-dev committed May 4, 2022
commit a9f725ff4c0286d6b6612d4017991e89d9ff9451
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,14 +14,15 @@ public class ConfluentCloudService {
private static org.slf4j.Logger log = LoggerFactory.getLogger(ConfluentCloudService.class);

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

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"});
return objectMapper.readValue(result, new TypeReference<List<ServiceAccount>>() {
Expand All @@ -33,11 +34,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 +51,9 @@ public static String execCmd(String[] cmd) throws java.io.IOException {
}

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