Search in sources :

Example 1 with ImageNameResolver

use of com.blackducksoftware.integration.hub.imageinspector.name.ImageNameResolver in project hub-docker-inspector by blackducksoftware.

the class imageNameResolverTest method testNone.

@Test
public void testNone() {
    final ImageNameResolver resolver = new ImageNameResolver("");
    assertFalse(resolver.getNewImageRepo().isPresent());
    assertFalse(resolver.getNewImageTag().isPresent());
}
Also used : ImageNameResolver(com.blackducksoftware.integration.hub.imageinspector.name.ImageNameResolver) Test(org.junit.Test)

Example 2 with ImageNameResolver

use of com.blackducksoftware.integration.hub.imageinspector.name.ImageNameResolver in project hub-docker-inspector by blackducksoftware.

the class imageNameResolverTest method testRepoOnly.

@Test
public void testRepoOnly() {
    final ImageNameResolver resolver = new ImageNameResolver("alpine");
    assertTrue(resolver.getNewImageRepo().isPresent());
    assertTrue(resolver.getNewImageTag().isPresent());
    assertEquals("alpine", resolver.getNewImageRepo().get());
    assertEquals("latest", resolver.getNewImageTag().get());
}
Also used : ImageNameResolver(com.blackducksoftware.integration.hub.imageinspector.name.ImageNameResolver) Test(org.junit.Test)

Example 3 with ImageNameResolver

use of com.blackducksoftware.integration.hub.imageinspector.name.ImageNameResolver in project hub-docker-inspector by blackducksoftware.

the class DockerEnvImageInspector method initImageName.

private void initImageName() throws HubIntegrationException {
    logger.debug(String.format("initImageName(): dockerImage: %s, dockerTar: %s", config.getDockerImage(), config.getDockerTar()));
    final ImageNameResolver resolver = new ImageNameResolver(config.getDockerImage());
    resolver.getNewImageRepo().ifPresent(repoName -> config.setDockerImageRepo(repoName));
    resolver.getNewImageTag().ifPresent(tagName -> config.setDockerImageTag(tagName));
    logger.debug(String.format("initImageName(): final: dockerImage: %s; dockerImageRepo: %s; dockerImageTag: %s", config.getDockerImage(), config.getDockerImageRepo(), config.getDockerImageTag()));
}
Also used : ImageNameResolver(com.blackducksoftware.integration.hub.imageinspector.name.ImageNameResolver)

Example 4 with ImageNameResolver

use of com.blackducksoftware.integration.hub.imageinspector.name.ImageNameResolver 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;
}
Also used : InspectImageCmd(com.github.dockerjava.api.command.InspectImageCmd) DockerClient(com.github.dockerjava.api.DockerClient) ImageNameResolver(com.blackducksoftware.integration.hub.imageinspector.name.ImageNameResolver) InspectImageResponse(com.github.dockerjava.api.command.InspectImageResponse) File(java.io.File) HubIntegrationException(com.blackducksoftware.integration.hub.exception.HubIntegrationException)

Example 5 with ImageNameResolver

use of com.blackducksoftware.integration.hub.imageinspector.name.ImageNameResolver in project hub-docker-inspector by blackducksoftware.

the class imageNameResolverTest method testBoth.

@Test
public void testBoth() {
    final ImageNameResolver resolver = new ImageNameResolver("alpine:1.0");
    assertTrue(resolver.getNewImageRepo().isPresent());
    assertTrue(resolver.getNewImageTag().isPresent());
    assertEquals("alpine", resolver.getNewImageRepo().get());
    assertEquals("1.0", resolver.getNewImageTag().get());
}
Also used : ImageNameResolver(com.blackducksoftware.integration.hub.imageinspector.name.ImageNameResolver) Test(org.junit.Test)

Aggregations

ImageNameResolver (com.blackducksoftware.integration.hub.imageinspector.name.ImageNameResolver)7 Test (org.junit.Test)5 HubIntegrationException (com.blackducksoftware.integration.hub.exception.HubIntegrationException)1 DockerClient (com.github.dockerjava.api.DockerClient)1 InspectImageCmd (com.github.dockerjava.api.command.InspectImageCmd)1 InspectImageResponse (com.github.dockerjava.api.command.InspectImageResponse)1 File (java.io.File)1