Search in sources :

Example 6 with ManifestContents

use of org.eclipse.virgo.util.parser.manifest.ManifestContents in project winery by eclipse.

the class CsarExporterTest method csarFilesHaveImmutableStorageAddresses.

@Test
// todo check how to enable
@Disabled
public void csarFilesHaveImmutableStorageAddresses() throws Exception {
    Map<String, Object> exportConfiguration = new HashMap<>();
    exportConfiguration.put(STORE_IMMUTABLY.name(), null);
    try (InputStream inputStream = this.createOutputAndInputStream("origin/plain", new ServiceTemplateId("http://plain.winery.opentosca.org/servicetemplates", "ServiceTemplateWithAllReqCapVariants", false), exportConfiguration);
        ZipInputStream zis = new ZipInputStream(inputStream)) {
        ManifestContents manifestContents = parseManifest(zis);
        assertNotNull(manifestContents);
        for (String section : manifestContents.getSectionNames()) {
            assertNotNull(manifestContents.getAttributesForSection(section).get(TOSCAMetaFileAttributes.IMMUTABLE_ADDRESS));
        }
    }
}
Also used : ManifestContents(org.eclipse.virgo.util.parser.manifest.ManifestContents) ZipInputStream(java.util.zip.ZipInputStream) HashMap(java.util.HashMap) ZipInputStream(java.util.zip.ZipInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 7 with ManifestContents

use of org.eclipse.virgo.util.parser.manifest.ManifestContents in project winery by eclipse.

the class AccountabilityManagerImpl method getHistoryOfSingleFile.

protected List<FileProvenanceElement> getHistoryOfSingleFile(List<ModelProvenanceElement> historyElements, String fileId, AuthorizationInfo authorizationInfo) {
    List<FileProvenanceElement> history = new ArrayList<>();
    if (Objects.nonNull(historyElements) && historyElements.size() > 0) {
        for (ModelProvenanceElement modelProvenanceElement : historyElements) {
            if (Objects.nonNull(modelProvenanceElement.getFingerprint())) {
                ManifestContents manifestContents = new RecoveringManifestParser().parse(modelProvenanceElement.getFingerprint());
                for (String name : manifestContents.getSectionNames()) {
                    if (name.equals(fileId)) {
                        modelProvenanceElement.setAuthorizedFlag(authorizationInfo);
                        modelProvenanceElement.setAuthorName(authorizationInfo.getRealWorldIdentity(modelProvenanceElement.getAuthorAddress()).orElseGet(String::new));
                        FileProvenanceElement currentFile = new FileProvenanceElement(modelProvenanceElement);
                        currentFile.setAddressInImmutableStorage(manifestContents.getAttributesForSection(name).get(TOSCAMetaFileAttributes.IMMUTABLE_ADDRESS));
                        currentFile.setFileHash(TOSCAMetaFileAttributes.HASH + "-" + manifestContents.getAttributesForSection(name).get(TOSCAMetaFileAttributes.HASH));
                        currentFile.setFileName(fileId);
                        history.add(currentFile);
                        break;
                    }
                }
            }
        }
    }
    if (history.size() > 0)
        return history;
    return null;
}
Also used : ManifestContents(org.eclipse.virgo.util.parser.manifest.ManifestContents) RecoveringManifestParser(org.eclipse.virgo.util.parser.manifest.RecoveringManifestParser) ModelProvenanceElement(org.eclipse.winery.accountability.model.ModelProvenanceElement) ArrayList(java.util.ArrayList) FileProvenanceElement(org.eclipse.winery.accountability.model.FileProvenanceElement)

Example 8 with ManifestContents

use of org.eclipse.virgo.util.parser.manifest.ManifestContents in project winery by eclipse.

the class CsarExporterTest method testHashesForEachFile.

@Test
public void testHashesForEachFile() throws Exception {
    Map<String, Object> exportConfiguration = new HashMap<>();
    exportConfiguration.put(INCLUDE_HASHES.name(), null);
    try (InputStream inputStream = this.createOutputAndInputStream(// quick fix - should work if eclipse/winery#305 is merged
    "7c8d8c7057403a07fde90dec1f44f0190ae65ae2", new ServiceTemplateId("http://plain.winery.opentosca.org/servicetemplates", "ServiceTemplateWithAllReqCapVariants", false), exportConfiguration);
        ZipInputStream zis = new ZipInputStream(inputStream)) {
        ZipEntry entry;
        List<CsarContentProperties> elementsList = new ArrayList<>();
        ManifestContents manifestContents = null;
        while ((entry = zis.getNextEntry()) != null) {
            CsarContentProperties fileProperties = new CsarContentProperties(entry.getName());
            elementsList.add(fileProperties);
            byte[] array = IOUtils.toByteArray(zis);
            ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(array);
            fileProperties.setFileHash(HashingUtil.getChecksum(byteArrayInputStream, TOSCAMetaFileAttributes.HASH));
            if ("TOSCA-Metadata/TOSCA.meta".equals(fileProperties.getPathInsideCsar())) {
                String s = new String(array, StandardCharsets.UTF_8);
                manifestContents = new RecoveringManifestParser().parse(s);
            }
        }
        assertNotNull(manifestContents);
        for (CsarContentProperties fileProperties : elementsList) {
            Map<String, String> attributes = manifestContents.getAttributesForSection(fileProperties.getPathInsideCsar());
            if (!"TOSCA-Metadata/TOSCA.meta".equals(fileProperties.getPathInsideCsar())) {
                // ensure each file has a hash
                assertTrue(attributes.containsKey(TOSCAMetaFileAttributes.HASH));
                // ensure that the hashes match
                assertEquals(fileProperties.getFileHash(), attributes.get(TOSCAMetaFileAttributes.HASH));
            }
        }
        // ensures that every file in the archive has a hash in the manifest
        assertEquals(elementsList.size() - 1, manifestContents.getSectionNames().size());
    }
}
Also used : RecoveringManifestParser(org.eclipse.virgo.util.parser.manifest.RecoveringManifestParser) HashMap(java.util.HashMap) ZipInputStream(java.util.zip.ZipInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) ManifestContents(org.eclipse.virgo.util.parser.manifest.ManifestContents) ZipInputStream(java.util.zip.ZipInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.jupiter.api.Test)

Example 9 with ManifestContents

use of org.eclipse.virgo.util.parser.manifest.ManifestContents in project winery by eclipse.

the class CsarExporterTest method metafileDoesNotContainUnnecessaryFileAttributes.

@Test
public void metafileDoesNotContainUnnecessaryFileAttributes() throws Exception {
    // create an empty configuration object
    Map<String, Object> exportConfiguration = new HashMap<>();
    try (InputStream inputStream = this.createOutputAndInputStream("origin/plain", new ArtifactTemplateId("http://plain.winery.opentosca.org/artifacttemplates", "ArtifactTemplateWithFilesAndSources-ArtifactTypeWithoutProperties", false), exportConfiguration);
        ZipInputStream zis = new ZipInputStream(inputStream)) {
        ManifestContents manifestContents = parseManifest(zis);
        assertNotNull(manifestContents);
        for (String section : manifestContents.getSectionNames()) {
            assertNull(manifestContents.getAttributesForSection(section).get(TOSCAMetaFileAttributes.HASH));
            assertNull(manifestContents.getAttributesForSection(section).get(TOSCAMetaFileAttributes.IMMUTABLE_ADDRESS));
        }
    }
}
Also used : ManifestContents(org.eclipse.virgo.util.parser.manifest.ManifestContents) ZipInputStream(java.util.zip.ZipInputStream) HashMap(java.util.HashMap) ZipInputStream(java.util.zip.ZipInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) Test(org.junit.jupiter.api.Test)

Aggregations

ManifestContents (org.eclipse.virgo.util.parser.manifest.ManifestContents)9 RecoveringManifestParser (org.eclipse.virgo.util.parser.manifest.RecoveringManifestParser)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 InputStream (java.io.InputStream)5 ZipInputStream (java.util.zip.ZipInputStream)5 Test (org.junit.jupiter.api.Test)5 HashMap (java.util.HashMap)4 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)4 ArrayList (java.util.ArrayList)3 ZipEntry (java.util.zip.ZipEntry)3 FileProvenanceElement (org.eclipse.winery.accountability.model.FileProvenanceElement)2 Disabled (org.junit.jupiter.api.Disabled)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 ManifestParser (org.eclipse.virgo.util.parser.manifest.ManifestParser)1 ManifestProblem (org.eclipse.virgo.util.parser.manifest.ManifestProblem)1 ModelProvenanceElement (org.eclipse.winery.accountability.model.ModelProvenanceElement)1 TOSCAMetaFile (org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFile)1