in amazon-inspector-image-scanner/amazon-inspector-image-scanner-agent/src/main/java/com/amazon/inspector/teamcity/sbomgen/SbomgenRunner.java [50:92]
private String runSbomgen(String sbomgenPath, String archivePath) throws Exception {
if (!isValidPath(sbomgenPath)) {
throw new IllegalArgumentException("Invalid sbomgen path: " + sbomgenPath);
}
publicProgressLogger.message("Making downloaded SBOMGen executable...");
new ProcessBuilder(new String[]{"chmod", "+x", sbomgenPath}).start();
publicProgressLogger.message("Running command...");
String[] command = new String[] {
sbomgenPath, "container", "--image", archivePath
};
publicProgressLogger.message(Arrays.toString(command));
ProcessBuilder builder = new ProcessBuilder(command);
Map<String, String> environment = builder.environment();
if (dockerPassword != null && !dockerPassword.isEmpty()) {
environment.put("INSPECTOR_SBOMGEN_USERNAME", dockerUsername);
environment.put("INSPECTOR_SBOMGEN_PASSWORD", dockerPassword);
}
builder.redirectErrorStream(true);
Process p = null;
try {
p = builder.start();
} catch (IOException e) {
throw new SbomgenNotFoundException(String.format("There was an issue running inspector-sbomgen, " +
"is %s the correct path?", sbomgenPath));
}
BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
StringBuilder sb = new StringBuilder();
while (true) {
line = r.readLine();
sb.append(line + "\n");
if (line == null) { break; }
}
return processSbomgenOutput(sb.toString());
}