Skip to content

Add optional environment variable for specifying a ccloud executable path #58

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

Merged
merged 3 commits into from
Feb 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 7 additions & 1 deletion docs/confluent-cloud.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -109,4 +115,4 @@ Congrats! You're now using `kafka-gitops` to manage your Confluent Cloud cluster

Welcome to GitOps!

[installation]: /installation.md
[installation]: /installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,10 +23,11 @@ public ConfluentCloudService(ObjectMapper objectMapper) {
public List<ServiceAccount> 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<List<ServiceAccount>>() {
});
} catch (IOException ex) {
log.info(ex.getMessage());
throw new ConfluentCloudException("There was an error listing Confluent Cloud service accounts. Are you logged in?");
}
}
Expand All @@ -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));
Expand All @@ -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);
}
}