diff --git a/docs/confluent-cloud.md b/docs/confluent-cloud.md index f1b12127..dc6a397e 100644 --- a/docs/confluent-cloud.md +++ b/docs/confluent-cloud.md @@ -53,6 +53,12 @@ Additionally, you'll need to login to the `ccloud` tool. You can automate this b Then, you can run `ccloud login` and it will run without a prompt. This is great for CI builds. +You can optionally specify a path to a `ccloud` executable: + +* `CCLOUD_EXECUTABLE_PATH`: `/full/path/to/ccloud` + +Otherwise, `ccloud` must be on your path. + ## Validate First, validate your state file is correct by running: @@ -109,4 +115,4 @@ Congrats! You're now using `kafka-gitops` to manage your Confluent Cloud cluster Welcome to GitOps! -[installation]: /installation.md \ No newline at end of file +[installation]: /installation.md diff --git a/src/main/java/com/devshawn/kafka/gitops/service/ConfluentCloudService.java b/src/main/java/com/devshawn/kafka/gitops/service/ConfluentCloudService.java index 9603f9ff..113c4302 100644 --- a/src/main/java/com/devshawn/kafka/gitops/service/ConfluentCloudService.java +++ b/src/main/java/com/devshawn/kafka/gitops/service/ConfluentCloudService.java @@ -14,6 +14,7 @@ public class ConfluentCloudService { private static org.slf4j.Logger log = LoggerFactory.getLogger(ConfluentCloudService.class); private final ObjectMapper objectMapper; + private static final String ccloudExecutable; public ConfluentCloudService(ObjectMapper objectMapper) { this.objectMapper = objectMapper; @@ -22,10 +23,11 @@ public ConfluentCloudService(ObjectMapper objectMapper) { public List getServiceAccounts() { log.info("Fetching service account list from Confluent Cloud via ccloud tool."); try { - String result = execCmd(new String[]{"ccloud", "service-account", "list", "-o", "json"}); + String result = execCmd(new String[]{ccloudExecutable, "service-account", "list", "-o", "json"}); return objectMapper.readValue(result, new TypeReference>() { }); } catch (IOException ex) { + log.info(ex.getMessage()); throw new ConfluentCloudException("There was an error listing Confluent Cloud service accounts. Are you logged in?"); } } @@ -35,7 +37,7 @@ public ServiceAccount createServiceAccount(String name, boolean isUser) { 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[]{"ccloud", "service-account", "create", serviceName, "--description", description, "-o", "json"}); + String result = execCmd(new String[]{ccloudExecutable, "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)); @@ -46,4 +48,9 @@ public static String execCmd(String[] cmd) throws java.io.IOException { java.util.Scanner s = new java.util.Scanner(Runtime.getRuntime().exec(cmd).getInputStream()).useDelimiter("\\A"); return s.hasNext() ? s.next() : ""; } + + static { + ccloudExecutable = System.getenv("CCLOUD_EXECUTABLE_PATH") != null ? System.getenv("CCLOUD_EXECUTABLE_PATH") : "ccloud"; + log.info("Using ccloud executable at: {}", ccloudExecutable); + } }