use of com.blackducksoftware.integration.hub.exception.HubIntegrationException in project hub-docker-inspector by blackducksoftware.
the class DockerClientManager method pullImage.
public String pullImage(final String imageName, final String tagName) throws HubIntegrationException {
logger.info(String.format("Pulling image %s:%s", imageName, tagName));
final DockerClient dockerClient = hubDockerClient.getDockerClient();
final Image alreadyPulledImage = getLocalImage(dockerClient, imageName, tagName);
if (alreadyPulledImage == null) {
// Only pull if we dont already have it
final PullImageCmd pull = dockerClient.pullImageCmd(imageName).withTag(tagName);
try {
pull.exec(new PullImageResultCallback()).awaitSuccess();
} catch (final NotFoundException e) {
final String msg = String.format("Pull failed: Image %s:%s not found. Please check the image name/tag", imageName, tagName);
logger.error(msg);
throw new HubIntegrationException(msg, e);
}
final Image justPulledImage = getLocalImage(dockerClient, imageName, tagName);
if (justPulledImage == null) {
final String msg = String.format("Pulled image %s:%s not found in image list.", imageName, tagName);
logger.error(msg);
throw new HubIntegrationException(msg);
}
return justPulledImage.getId();
} else {
logger.info("Image already pulled");
return alreadyPulledImage.getId();
}
}
use of com.blackducksoftware.integration.hub.exception.HubIntegrationException in project hub-alert by blackducksoftware.
the class VulnerabilityCache method getEvents.
@Override
public Collection<NotificationEvent> getEvents() throws HubIntegrationException {
final Collection<NotificationEvent> vulnerabilities = super.getEvents();
// need to group the vulnerabilities by severity which can be gathered by the vulnerability API.
final Collection<NotificationEvent> result = new LinkedList<>();
for (final NotificationEvent event : vulnerabilities) {
List<NotificationEvent> vulnerabilityEvents;
try {
vulnerabilityEvents = createVulnerabilityEvents(event);
} catch (final IntegrationException e) {
throw new HubIntegrationException(e);
}
for (final NotificationEvent vulnerability : vulnerabilityEvents) {
result.add(vulnerability);
}
}
return this.addUserInformation(result);
}
use of com.blackducksoftware.integration.hub.exception.HubIntegrationException in project hub-docker-inspector by blackducksoftware.
the class DockerClientManager method getDockerEngineVersion.
public String getDockerEngineVersion() {
logger.info("Requesting version string from Docker engine");
try {
final DockerClient dockerClient = hubDockerClient.getDockerClient();
final Info dockerInfo = dockerClient.infoCmd().exec();
final String engineVersion = dockerInfo.getServerVersion();
logger.debug(String.format("Docker Engine (Server) Version: %s", engineVersion));
if (engineVersion == null) {
return "Unknown";
} else {
return engineVersion;
}
} catch (final HubIntegrationException e) {
return "Unknown";
}
}
use of com.blackducksoftware.integration.hub.exception.HubIntegrationException in project hub-docker-inspector by blackducksoftware.
the class DockerClientManager method getTarFileFromDockerImageById.
public File getTarFileFromDockerImageById(final String imageId) throws HubIntegrationException, IOException {
final File imageTarDirectory = new File(new File(programPaths.getHubDockerWorkingDirPath()), "tarDirectory");
final DockerClient dockerClient = hubDockerClient.getDockerClient();
final InspectImageCmd inspectImageCmd = dockerClient.inspectImageCmd(imageId);
final InspectImageResponse imageDetails = inspectImageCmd.exec();
final List<String> repoTags = imageDetails.getRepoTags();
if (repoTags.size() == 0) {
throw new HubIntegrationException(String.format("Unable to get image name:tag for image ID %s", imageId));
}
final ImageNameResolver resolver = new ImageNameResolver(repoTags.get(0));
final String imageName = resolver.getNewImageRepo().get();
final String tagName = resolver.getNewImageTag().get();
logger.info(String.format("Converted image ID %s to image name:tag %s:%s", imageId, imageName, tagName));
final File imageTarFile = saveImageToDir(imageTarDirectory, Names.getImageTarFilename(imageName, tagName), imageName, tagName);
return imageTarFile;
}
use of com.blackducksoftware.integration.hub.exception.HubIntegrationException in project hub-docker-inspector by blackducksoftware.
the class HubClient method testHubConnection.
public void testHubConnection() throws HubIntegrationException {
// ArgsWithSpacesTest tests this in output
logger.trace(String.format("Hub username: %s", getHubUsername()));
if (!config.isUploadBdio()) {
logger.debug("Upload of BDIO not enabled; skipping verification of Hub connection");
return;
}
RestConnection restConnection;
try {
restConnection = createRestConnection();
restConnection.connect();
} catch (final IntegrationException e) {
final String msg = String.format("Error connecting to Hub: %s", e.getMessage());
throw new HubIntegrationException(msg);
}
logger.info("Successful connection to the Hub.");
}
Aggregations