Search in sources :

Example 1 with FileOperations

use of com.synopsys.integration.blackduck.imageinspector.linux.FileOperations in project blackduck-docker-inspector by blackducksoftware.

the class DockerClientManagerTest method setUp.

@BeforeAll
public static void setUp() {
    Logger rootLogger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    rootLogger.setLevel(Level.INFO);
    Logger integrationLogger = (Logger) LoggerFactory.getLogger("com.synopsys.integration");
    integrationLogger.setLevel(Level.DEBUG);
    config = Mockito.mock(Config.class);
    programPaths = Mockito.mock(ProgramPaths.class);
    FileOperations fileOperations = new FileOperations();
    dockerClientManager = new DockerClientManager(fileOperations, new ImageNameResolver(), config, new ImageTarFilename(), programPaths);
}
Also used : ImageTarFilename(com.synopsys.integration.blackduck.dockerinspector.output.ImageTarFilename) Config(com.synopsys.integration.blackduck.dockerinspector.config.Config) ImageNameResolver(com.synopsys.integration.blackduck.imageinspector.api.name.ImageNameResolver) FileOperations(com.synopsys.integration.blackduck.imageinspector.linux.FileOperations) ProgramPaths(com.synopsys.integration.blackduck.dockerinspector.config.ProgramPaths) Logger(ch.qos.logback.classic.Logger) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 2 with FileOperations

use of com.synopsys.integration.blackduck.imageinspector.linux.FileOperations in project blackduck-docker-inspector by blackducksoftware.

the class OutputTest method testSquashedImageCreation.

@Test
public void testSquashedImageCreation() throws IOException, IntegrationException {
    Mockito.when(config.getOutputPath()).thenReturn(outputDir.getAbsolutePath());
    Mockito.when(config.isOutputIncludeSquashedImage()).thenReturn(true);
    Mockito.when(programPaths.getUserOutputDirPath()).thenReturn(outputDir.getAbsolutePath());
    Mockito.when(programPaths.getDockerInspectorWorkingOutputPath()).thenReturn(workingDir.getAbsolutePath());
    Mockito.when(programPaths.getDockerInspectorSquashedImageTarFilePath()).thenReturn(squashedImageTarfile.getAbsolutePath());
    Mockito.when(programPaths.getDockerInspectorSquashedImageDirPath()).thenReturn(squashingTempDir.getAbsolutePath());
    SimpleBdioDocument bdioDoc = Mockito.mock(SimpleBdioDocument.class);
    BdioBillOfMaterials bom = new BdioBillOfMaterials();
    bom.spdxName = "registry.luciddg.com_luciddg_ldg-server-qa_2020.16.03_DPKG";
    Mockito.when(bdioDoc.getBillOfMaterials()).thenReturn(bom);
    BdioProject project = new BdioProject();
    Mockito.when(bdioDoc.getProject()).thenReturn(project);
    Mockito.when(containerFilesystemFilename.deriveContainerFilesystemFilename(null, null)).thenReturn("target_containerfilesystem.tar.gz");
    ImageTarFilename imageTarFilename = new ImageTarFilename();
    FileOperations fileOperations = new FileOperations();
    DockerClientManager dockerClientManager = new DockerClientManager(fileOperations, new ImageNameResolver(), config, imageTarFilename, programPaths);
    SquashedImage squashedImage = new SquashedImage();
    squashedImage.setFileOperations(fileOperations);
    squashedImage.setDockerClientManager(dockerClientManager);
    output.setSquashedImage(squashedImage);
    // Test
    OutputFiles outputFiles = output.addOutputToFinalOutputDir(bdioDoc, null, null);
    // Verify
    File generatedSquashedImageCompressedFile = outputFiles.getSquashedImageFile();
    File generatedSquashedImageTarfile = new File(workingDir, "generatedImageTarfile");
    CompressedFile.gunZipFile(generatedSquashedImageCompressedFile, generatedSquashedImageTarfile);
    File generatedSquashedImageContents = new File(workingDir, "generatedSquashedImageContents");
    CompressedFile.unTarFile(generatedSquashedImageTarfile, generatedSquashedImageContents);
    System.out.println(String.format("Look in: %s", generatedSquashedImageContents.getAbsolutePath()));
    Collection<File> layerFiles = FileUtils.listFiles(generatedSquashedImageContents, new NameFileFilter("layer.tar"), TrueFileFilter.TRUE);
    assertEquals(1, layerFiles.size());
    File generatedLayer = new File(workingDir, "generatedLayer");
    CompressedFile.unTarFile(layerFiles.iterator().next(), generatedLayer);
    File expectedFile = new File(generatedLayer, "opt/luciddg-server/modules/django/bin/100_assets.csv");
    assertTrue(expectedFile.exists());
}
Also used : NameFileFilter(org.apache.commons.io.filefilter.NameFileFilter) BdioBillOfMaterials(com.synopsys.integration.bdio.model.BdioBillOfMaterials) BdioProject(com.synopsys.integration.bdio.model.BdioProject) DockerClientManager(com.synopsys.integration.blackduck.dockerinspector.dockerclient.DockerClientManager) ImageNameResolver(com.synopsys.integration.blackduck.imageinspector.api.name.ImageNameResolver) FileOperations(com.synopsys.integration.blackduck.imageinspector.linux.FileOperations) File(java.io.File) SimpleBdioDocument(com.synopsys.integration.bdio.model.SimpleBdioDocument) Test(org.junit.jupiter.api.Test)

Example 3 with FileOperations

use of com.synopsys.integration.blackduck.imageinspector.linux.FileOperations in project blackduck-docker-inspector by blackducksoftware.

the class SquashedImageTest method setUp.

@BeforeAll
static void setUp() throws IOException {
    Logger rootLogger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    rootLogger.setLevel(Level.INFO);
    Logger integrationLogger = (Logger) LoggerFactory.getLogger("com.synopsys.integration");
    integrationLogger.setLevel(Level.DEBUG);
    testWorkingDir = new File("test/output/squashingTest");
    ImageTarFilename imageTarFilename = new ImageTarFilename();
    FileOperations fileOperations = new FileOperations();
    Config config = Mockito.mock(Config.class);
    Mockito.when(config.getWorkingDirPath()).thenReturn(testWorkingDir.getCanonicalPath());
    ProgramPaths programPaths = new ProgramPaths(config, new ProcessId());
    dockerClientManager = new DockerClientManager(fileOperations, new ImageNameResolver(), config, imageTarFilename, programPaths);
    squashedImage = new SquashedImage();
    squashedImage.setDockerClientManager(dockerClientManager);
    squashedImage.setFileOperations(new FileOperations());
}
Also used : Config(com.synopsys.integration.blackduck.dockerinspector.config.Config) DockerClientManager(com.synopsys.integration.blackduck.dockerinspector.dockerclient.DockerClientManager) ImageNameResolver(com.synopsys.integration.blackduck.imageinspector.api.name.ImageNameResolver) FileOperations(com.synopsys.integration.blackduck.imageinspector.linux.FileOperations) ProgramPaths(com.synopsys.integration.blackduck.dockerinspector.config.ProgramPaths) ProcessId(com.synopsys.integration.blackduck.dockerinspector.ProcessId) Logger(ch.qos.logback.classic.Logger) File(java.io.File) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 4 with FileOperations

use of com.synopsys.integration.blackduck.imageinspector.linux.FileOperations in project blackduck-docker-inspector by blackducksoftware.

the class CompressedFile method unTarFile.

public static void unTarFile(final File tarFile, final File destinationDir) throws IOException {
    // TODO this should call a simpler method, not an image-archive-specific method
    final ImageLayerArchiveExtractor tarExtractor = new ImageLayerArchiveExtractor();
    tarExtractor.extractLayerTarToDir(new FileOperations(), tarFile, destinationDir);
}
Also used : ImageLayerArchiveExtractor(com.synopsys.integration.blackduck.imageinspector.image.common.archive.ImageLayerArchiveExtractor) FileOperations(com.synopsys.integration.blackduck.imageinspector.linux.FileOperations)

Aggregations

FileOperations (com.synopsys.integration.blackduck.imageinspector.linux.FileOperations)4 ImageNameResolver (com.synopsys.integration.blackduck.imageinspector.api.name.ImageNameResolver)3 Logger (ch.qos.logback.classic.Logger)2 Config (com.synopsys.integration.blackduck.dockerinspector.config.Config)2 ProgramPaths (com.synopsys.integration.blackduck.dockerinspector.config.ProgramPaths)2 DockerClientManager (com.synopsys.integration.blackduck.dockerinspector.dockerclient.DockerClientManager)2 File (java.io.File)2 BeforeAll (org.junit.jupiter.api.BeforeAll)2 BdioBillOfMaterials (com.synopsys.integration.bdio.model.BdioBillOfMaterials)1 BdioProject (com.synopsys.integration.bdio.model.BdioProject)1 SimpleBdioDocument (com.synopsys.integration.bdio.model.SimpleBdioDocument)1 ProcessId (com.synopsys.integration.blackduck.dockerinspector.ProcessId)1 ImageTarFilename (com.synopsys.integration.blackduck.dockerinspector.output.ImageTarFilename)1 ImageLayerArchiveExtractor (com.synopsys.integration.blackduck.imageinspector.image.common.archive.ImageLayerArchiveExtractor)1 NameFileFilter (org.apache.commons.io.filefilter.NameFileFilter)1 Test (org.junit.jupiter.api.Test)1