Skip to content

Commit e537292

Browse files
authored
Add optional environment variable for specifying a ccloud executable path (#58)
* fix: added verbose output for failed ccloud command execution * feat: add optional environment variable for ccloud executable path * docs: add optional ccloud path environment var
1 parent 309658d commit e537292

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

docs/confluent-cloud.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ Additionally, you'll need to login to the `ccloud` tool. You can automate this b
5353

5454
Then, you can run `ccloud login` and it will run without a prompt. This is great for CI builds.
5555

56+
You can optionally specify a path to a `ccloud` executable:
57+
58+
* `CCLOUD_EXECUTABLE_PATH`: `/full/path/to/ccloud`
59+
60+
Otherwise, `ccloud` must be on your path.
61+
5662
## Validate
5763

5864
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
109115

110116
Welcome to GitOps!
111117

112-
[installation]: /installation.md
118+
[installation]: /installation.md

src/main/java/com/devshawn/kafka/gitops/service/ConfluentCloudService.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class ConfluentCloudService {
1414
private static org.slf4j.Logger log = LoggerFactory.getLogger(ConfluentCloudService.class);
1515

1616
private final ObjectMapper objectMapper;
17+
private static final String ccloudExecutable;
1718

1819
public ConfluentCloudService(ObjectMapper objectMapper) {
1920
this.objectMapper = objectMapper;
@@ -22,10 +23,11 @@ public ConfluentCloudService(ObjectMapper objectMapper) {
2223
public List<ServiceAccount> getServiceAccounts() {
2324
log.info("Fetching service account list from Confluent Cloud via ccloud tool.");
2425
try {
25-
String result = execCmd(new String[]{"ccloud", "service-account", "list", "-o", "json"});
26+
String result = execCmd(new String[]{ccloudExecutable, "service-account", "list", "-o", "json"});
2627
return objectMapper.readValue(result, new TypeReference<List<ServiceAccount>>() {
2728
});
2829
} catch (IOException ex) {
30+
log.info(ex.getMessage());
2931
throw new ConfluentCloudException("There was an error listing Confluent Cloud service accounts. Are you logged in?");
3032
}
3133
}
@@ -35,7 +37,7 @@ public ServiceAccount createServiceAccount(String name, boolean isUser) {
3537
try {
3638
String serviceName = isUser ? String.format("user-%s", name) : name;
3739
String description = isUser ? String.format("User: %s", name) : String.format("Service account: %s", name);
38-
String result = execCmd(new String[]{"ccloud", "service-account", "create", serviceName, "--description", description, "-o", "json"});
40+
String result = execCmd(new String[]{ccloudExecutable, "service-account", "create", serviceName, "--description", description, "-o", "json"});
3941
return objectMapper.readValue(result, ServiceAccount.class);
4042
} catch (IOException ex) {
4143
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 {
4648
java.util.Scanner s = new java.util.Scanner(Runtime.getRuntime().exec(cmd).getInputStream()).useDelimiter("\\A");
4749
return s.hasNext() ? s.next() : "";
4850
}
51+
52+
static {
53+
ccloudExecutable = System.getenv("CCLOUD_EXECUTABLE_PATH") != null ? System.getenv("CCLOUD_EXECUTABLE_PATH") : "ccloud";
54+
log.info("Using ccloud executable at: {}", ccloudExecutable);
55+
}
4956
}

0 commit comments

Comments
 (0)