@@ -14,6 +14,7 @@ public class ConfluentCloudService {
14
14
private static org .slf4j .Logger log = LoggerFactory .getLogger (ConfluentCloudService .class );
15
15
16
16
private final ObjectMapper objectMapper ;
17
+ private static final String ccloudExecutable ;
17
18
18
19
public ConfluentCloudService (ObjectMapper objectMapper ) {
19
20
this .objectMapper = objectMapper ;
@@ -22,10 +23,11 @@ public ConfluentCloudService(ObjectMapper objectMapper) {
22
23
public List <ServiceAccount > getServiceAccounts () {
23
24
log .info ("Fetching service account list from Confluent Cloud via ccloud tool." );
24
25
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" });
26
27
return objectMapper .readValue (result , new TypeReference <List <ServiceAccount >>() {
27
28
});
28
29
} catch (IOException ex ) {
30
+ log .info (ex .getMessage ());
29
31
throw new ConfluentCloudException ("There was an error listing Confluent Cloud service accounts. Are you logged in?" );
30
32
}
31
33
}
@@ -35,7 +37,7 @@ public ServiceAccount createServiceAccount(String name, boolean isUser) {
35
37
try {
36
38
String serviceName = isUser ? String .format ("user-%s" , name ) : name ;
37
39
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" });
39
41
return objectMapper .readValue (result , ServiceAccount .class );
40
42
} catch (IOException ex ) {
41
43
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 {
46
48
java .util .Scanner s = new java .util .Scanner (Runtime .getRuntime ().exec (cmd ).getInputStream ()).useDelimiter ("\\ A" );
47
49
return s .hasNext () ? s .next () : "" ;
48
50
}
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
+ }
49
56
}
0 commit comments