Search in sources :

Example 11 with Request

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;
}
Also used : Response(com.blackducksoftware.integration.hub.request.Response) DetectUserFriendlyException(com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException) Request(com.blackducksoftware.integration.hub.request.Request) File(java.io.File) UnauthenticatedRestConnection(com.blackducksoftware.integration.hub.rest.UnauthenticatedRestConnection) IOException(java.io.IOException) DetectUserFriendlyException(com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException) ExecutableRunnerException(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunnerException)

Aggregations

Request (com.blackducksoftware.integration.hub.request.Request)11 RestConnection (com.blackducksoftware.integration.hub.rest.RestConnection)6 Test (org.junit.Test)6 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)4 ChannelTest (com.blackducksoftware.integration.hub.alert.channel.ChannelTest)3 ChannelRequestHelper (com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRequestHelper)3 MockSlackEntity (com.blackducksoftware.integration.hub.alert.channel.slack.mock.MockSlackEntity)3 Response (com.blackducksoftware.integration.hub.request.Response)3 ExternalConnectionTest (com.blackducksoftware.integration.test.annotation.ExternalConnectionTest)3 HashMap (java.util.HashMap)3 ProjectData (com.blackducksoftware.integration.hub.alert.digest.model.ProjectData)2 IOException (java.io.IOException)2 Map (java.util.Map)2 DetectUserFriendlyException (com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException)1 ExecutableRunnerException (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunnerException)1 BodyContent (com.blackducksoftware.integration.hub.request.BodyContent)1 UnauthenticatedRestConnection (com.blackducksoftware.integration.hub.rest.UnauthenticatedRestConnection)1 UnauthenticatedRestConnectionBuilder (com.blackducksoftware.integration.hub.rest.UnauthenticatedRestConnectionBuilder)1 File (java.io.File)1