use of com.blackducksoftware.integration.hub.request.Request in project hub-detect by blackducksoftware.
the class DockerInspectorManager method getShellScript.
private File getShellScript() throws DetectUserFriendlyException {
if (null == this.dockerInspectorShellScript) {
try {
final File shellScriptFile;
final File airGapHubDockerInspectorShellScript = new File(this.detectConfiguration.getDockerInspectorAirGapPath(), "hub-docker-inspector.sh");
this.logger.debug(String.format("Verifying air gap shell script present at %s", airGapHubDockerInspectorShellScript.getCanonicalPath()));
if (StringUtils.isNotBlank(this.detectConfiguration.getDockerInspectorPath())) {
shellScriptFile = new File(this.detectConfiguration.getDockerInspectorPath());
} else if (airGapHubDockerInspectorShellScript.exists()) {
shellScriptFile = airGapHubDockerInspectorShellScript;
} else {
String hubDockerInspectorShellScriptUrl = LATEST_URL;
if (!"latest".equals(this.detectConfiguration.getDockerInspectorVersion())) {
hubDockerInspectorShellScriptUrl = String.format("https://blackducksoftware.github.io/hub-docker-inspector/hub-docker-inspector-%s.sh", this.detectConfiguration.getDockerInspectorVersion());
}
this.logger.info(String.format("Getting the Docker inspector shell script from %s", hubDockerInspectorShellScriptUrl));
final UnauthenticatedRestConnection restConnection = this.detectConfiguration.createUnauthenticatedRestConnection(hubDockerInspectorShellScriptUrl);
final Request request = new Request.Builder().uri(hubDockerInspectorShellScriptUrl).build();
String shellScriptContents = null;
Response response = null;
try {
response = restConnection.executeRequest(request);
shellScriptContents = response.getContentString();
} finally {
if (response != null) {
response.close();
}
}
shellScriptFile = this.detectFileManager.createFile(BomToolType.DOCKER, String.format("hub-docker-inspector-%s.sh", this.detectConfiguration.getDockerInspectorVersion()));
this.detectFileManager.writeToFile(shellScriptFile, shellScriptContents);
shellScriptFile.setExecutable(true);
}
this.dockerInspectorShellScript = shellScriptFile;
} catch (final Exception e) {
throw new DetectUserFriendlyException(String.format("There was a problem retrieving the docker inspector shell script: %s", e.getMessage()), e, ExitCodeType.FAILURE_GENERAL_ERROR);
}
}
return this.dockerInspectorShellScript;
}
Aggregations