Search in sources :

Example 11 with ModelProvenanceElement

use of org.eclipse.winery.accountability.model.ModelProvenanceElement 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 12 with ModelProvenanceElement

use of org.eclipse.winery.accountability.model.ModelProvenanceElement in project winery by eclipse.

the class AccountabilityManagerImpl method validateBlockchainInput.

protected Map<String, ProvenanceVerification> validateBlockchainInput(List<ModelProvenanceElement> historyElements, String manifestId, Map<String, File> files, AuthorizationInfo authorizationInfo) throws IOException, NoSuchAlgorithmException {
    LOGGER.info("Start validating...");
    Map<String, ProvenanceVerification> verificationMap = new HashMap<>();
    ModelProvenanceElement validHistoryElement = verifyManifest(historyElements, manifestId, files, verificationMap, authorizationInfo);
    if (Objects.nonNull(validHistoryElement) && verificationMap.get(manifestId) == VERIFIED) {
        verifyFiles(validHistoryElement, files, verificationMap);
    }
    LOGGER.info("Completed validation.");
    return verificationMap;
}
Also used : ProvenanceVerification(org.eclipse.winery.accountability.model.ProvenanceVerification) HashMap(java.util.HashMap) ModelProvenanceElement(org.eclipse.winery.accountability.model.ModelProvenanceElement)

Aggregations

ModelProvenanceElement (org.eclipse.winery.accountability.model.ModelProvenanceElement)12 File (java.io.File)4 HashMap (java.util.HashMap)4 ProvenanceVerification (org.eclipse.winery.accountability.model.ProvenanceVerification)4 AuthorizationInfo (org.eclipse.winery.accountability.model.authorization.AuthorizationInfo)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 FileProvenanceElement (org.eclipse.winery.accountability.model.FileProvenanceElement)3 AuthorizationElement (org.eclipse.winery.accountability.model.authorization.AuthorizationElement)3 AuthorizationTree (org.eclipse.winery.accountability.model.authorization.AuthorizationTree)3 List (java.util.List)2 EthereumException (org.eclipse.winery.accountability.exceptions.EthereumException)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 Disposable (io.reactivex.disposables.Disposable)1 InputStream (java.io.InputStream)1 Charset (java.nio.charset.Charset)1 Objects (java.util.Objects)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutionException (java.util.concurrent.ExecutionException)1