Search in sources :

Example 1 with FileProvenanceElement

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

the class AccountabilityManagerImplTest method getHistoryOfSingleFileArguments.

private static Stream<Arguments> getHistoryOfSingleFileArguments() {
    String fileId = "folder/myFile.tosca";
    ModelProvenanceElement elementWithFileOccurrence_0 = new ModelProvenanceElement("0x1000000000000000000000000000000000000000", 0, "0x11111", // region string
    "TOSCA-Meta-Version: 1.0\n" + "CSAR-Version: 1.0\n" + "Created-By: Winery 3.0.0-SNAPSHOT\n" + "Entry-Definitions: Definitions/servicetemplates1__MyTinyToDo_Bare_Docker.tosca\n" + "\n" + "Name: Definitions/myTestFile.tosca\n" + "Content-Type: application/vnd.oasis.tosca.definitions\n" + "SHA-256: 9e69d43768c487b7a68b95faed372544\n" + "\n" + "Name: " + fileId + "\n" + "Content-Type: application/vnd.oasis.tosca.definitions\n" + "SHA-256: 9e69d43768c487b7a68b95faed372544");
    ModelProvenanceElement elementWithFileOccurrence_1 = new ModelProvenanceElement("0x2000000000000000000000000000000000000000", 0, "0x3333", // region string
    "TOSCA-Meta-Version: 1.0\n" + "CSAR-Version: 1.0\n" + "Created-By: Winery 3.0.0-SNAPSHOT\n" + "Entry-Definitions: Definitions/servicetemplates1__MyTinyToDo_Bare_Docker.tosca\n" + "\n" + "Name: Definitions/myTestFile.tosca\n" + "Content-Type: application/vnd.oasis.tosca.definitions\n" + "SHA-256: 9e69d43768c487b7a68b95faed372544\n" + "\n" + "Name: " + fileId + "\n" + "Content-Type: application/vnd.oasis.tosca.definitions\n" + "SHA-256: 9e69d43768c487b9e69d43768c487b7a68b95faed3725444" + "\n" + "Name: Definitions/myTestFile2.tosca\n" + "Content-Type: application/vnd.oasis.tosca.definitions\n" + "SHA-256: 9e69d43768c487b7a68b95faed372544");
    ModelProvenanceElement elementWithoutFileOccurrence_0 = new ModelProvenanceElement("0x3000000000000000000000000000000000000000", 0, "0x11111", // region string
    "TOSCA-Meta-Version: 1.0\n" + "CSAR-Version: 1.0\n" + "Created-By: Winery 3.0.0-SNAPSHOT\n" + "Entry-Definitions: Definitions/servicetemplates1__MyTinyToDo_Bare_Docker.tosca\n" + "\n" + "Name: Definitions/myTestFile.tosca\n" + "Content-Type: application/vnd.oasis.tosca.definitions\n" + "SHA-256: 9e69d43768c487b7a68b95faed372544\n" + "\n" + "Name: Definitions/myTestFile1.tosca\n" + "Content-Type: application/vnd.oasis.tosca.definitions\n" + "SHA-256: 9e69d43768c487b9e69d43768c487b7a68b95faed3725444" + "\n" + "Name: Definitions/myTestFile2.tosca\n" + "Content-Type: application/vnd.oasis.tosca.definitions\n" + "SHA-256: 9e69d43768c487b7a68b95faed372544");
    AuthorizationElement authorizationElement = new AuthorizationElement();
    authorizationElement.setAuthorizerBlockchainAddress("0x11111");
    authorizationElement.setAuthorizedBlockchainAddress("0x11111");
    authorizationElement.setAuthorizedIdentity("Gharreb");
    authorizationElement.setTransactionHash("0x3215F230003215F230003215F230003215F23000");
    List<AuthorizationElement> authList = Arrays.asList(authorizationElement);
    AuthorizationInfo authorizationInfo = new AuthorizationTree(authList);
    return Stream.of(Arguments.of(null, "someId", null, authorizationInfo, null, "Empty provenance elements list"), Arguments.of(Arrays.asList(elementWithFileOccurrence_0, elementWithoutFileOccurrence_0, elementWithFileOccurrence_1), fileId, Arrays.asList(new FileProvenanceElement(elementWithFileOccurrence_0), new FileProvenanceElement(elementWithFileOccurrence_1)), authorizationInfo, new boolean[] { true, false }, "Find two file occurrences"));
}
Also used : ModelProvenanceElement(org.eclipse.winery.accountability.model.ModelProvenanceElement) AuthorizationTree(org.eclipse.winery.accountability.model.authorization.AuthorizationTree) AuthorizationElement(org.eclipse.winery.accountability.model.authorization.AuthorizationElement) AuthorizationInfo(org.eclipse.winery.accountability.model.authorization.AuthorizationInfo) FileProvenanceElement(org.eclipse.winery.accountability.model.FileProvenanceElement)

Example 2 with FileProvenanceElement

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

the class AccountabilityManagerImpl method getHistory.

@Override
public CompletableFuture<List<FileProvenanceElement>> getHistory(String processIdentifier, String fileId) {
    CompletableFuture<AuthorizationInfo> authorizationTree = this.blockchain.getAuthorizationTree(processIdentifier);
    return this.blockchain.getProvenance(processIdentifier).thenCombine(authorizationTree, (provenanceElements, authorizationInfo) -> {
        List<FileProvenanceElement> result;
        if (authorizationInfo != null) {
            result = getHistoryOfSingleFile(provenanceElements, fileId, authorizationInfo);
        } else {
            LOGGER.info(NO_AUTHORIZATION_DATA);
            FileProvenanceElement historyElement = new FileProvenanceElement("", 0, NO_AUTHORIZATION_DATA);
            historyElement.setAuthorized(false);
            historyElement.setFileName(fileId);
            result = Collections.singletonList(historyElement);
        }
        return result;
    });
}
Also used : AuthorizationInfo(org.eclipse.winery.accountability.model.authorization.AuthorizationInfo) FileProvenanceElement(org.eclipse.winery.accountability.model.FileProvenanceElement)

Example 3 with FileProvenanceElement

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

the class AccountabilityManagerImpl method fillFilesOfModel.

private void fillFilesOfModel(ModelProvenanceElement model) {
    // 1. parse element.state as ManifestContent
    RecoveringManifestParser genericParser = new RecoveringManifestParser();
    ManifestContents manifestContents = genericParser.parse(model.getFingerprint());
    // 2. parse the ManifestContent as a TOSCAMetaFile
    TOSCAMetaFileParser parser = new TOSCAMetaFileParser();
    TOSCAMetaFile toscaMetaFile = parser.parse(manifestContents, genericParser.getProblems().size());
    // 3. retrieve files from meta file
    Objects.requireNonNull(toscaMetaFile);
    List<FileProvenanceElement> result = toscaMetaFile.getFileBlocks().stream().map(fileSection -> {
        FileProvenanceElement fileElement = new FileProvenanceElement(model);
        fileElement.setFileHash(fileSection.get(TOSCAMetaFileAttributes.HASH));
        fileElement.setAddressInImmutableStorage(fileSection.get(TOSCAMetaFileAttributes.IMMUTABLE_ADDRESS));
        fileElement.setFileName(fileSection.get(TOSCAMetaFileAttributes.NAME));
        return fileElement;
    }).sorted(Comparator.comparing(FileProvenanceElement::getFileName)).collect(Collectors.toList());
    model.setFiles(result);
}
Also used : ManifestContents(org.eclipse.virgo.util.parser.manifest.ManifestContents) RecoveringManifestParser(org.eclipse.virgo.util.parser.manifest.RecoveringManifestParser) TOSCAMetaFileParser(org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFileParser) TOSCAMetaFile(org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFile) FileProvenanceElement(org.eclipse.winery.accountability.model.FileProvenanceElement)

Example 4 with FileProvenanceElement

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

the class AccountabilityManagerImplIntegrationTest method getHistoryWithoutAuthenticationData.

@Test
void getHistoryWithoutAuthenticationData() throws Exception {
    String processId = "SomeProcessIdForIvalidTestingPurposeOnly";
    String fileId = "not needed in this test";
    CompletableFuture<List<FileProvenanceElement>> history = this.accountabilityManager.getHistory(processId, fileId);
    List<FileProvenanceElement> historyElements = history.get();
    FileProvenanceElement element = historyElements.get(0);
    assertFalse(element.isAuthorized());
    assertEquals("no authorization data stored in the blockchain", element.getAuthorAddress());
}
Also used : List(java.util.List) FileProvenanceElement(org.eclipse.winery.accountability.model.FileProvenanceElement) Test(org.junit.jupiter.api.Test)

Example 5 with FileProvenanceElement

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

the class AccountabilityResource method getFileHistory.

@GET
@Path("fileHistory")
@Produces(MediaType.APPLICATION_JSON)
public List<FileProvenanceElement> getFileHistory(@QueryParam("fileId") String fileId) {
    ServiceTemplateId serviceTemplateId = new ServiceTemplateId(new QName(provenanceId));
    String qNameWithComponentVersionOnly = VersionSupport.getQNameWithComponentVersionOnly(serviceTemplateId);
    Objects.requireNonNull(fileId);
    String fileIdDecoded = EncodingUtil.URLdecode(fileId);
    try {
        return getAccountabilityManager().getHistory(qNameWithComponentVersionOnly, fileIdDecoded).exceptionally(error -> null).get();
    } catch (InterruptedException | ExecutionException | AccountabilityException e) {
        LOGGER.error("Cannot history of file {}. Reason: {}", fileId, e.getMessage());
        throw createException(e);
    }
}
Also used : ModelProvenanceElement(org.eclipse.winery.accountability.model.ModelProvenanceElement) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) AccountabilityManager(org.eclipse.winery.accountability.AccountabilityManager) Path(javax.ws.rs.Path) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) LoggerFactory(org.slf4j.LoggerFactory) FileProvenanceElement(org.eclipse.winery.accountability.model.FileProvenanceElement) ArrayList(java.util.ArrayList) EncodingUtil(org.eclipse.winery.model.ids.EncodingUtil) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) Charset(java.nio.charset.Charset) Consumes(javax.ws.rs.Consumes) VersionSupport(org.eclipse.winery.model.version.VersionSupport) AccountabilityManagerFactory(org.eclipse.winery.accountability.AccountabilityManagerFactory) POST(javax.ws.rs.POST) Logger(org.slf4j.Logger) AuthorizationNode(org.eclipse.winery.accountability.model.authorization.AuthorizationNode) IOException(java.io.IOException) StreamingOutput(javax.ws.rs.core.StreamingOutput) AccountabilityException(org.eclipse.winery.accountability.exceptions.AccountabilityException) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Response(javax.ws.rs.core.Response) AuthorizationInfo(org.eclipse.winery.accountability.model.authorization.AuthorizationInfo) WebApplicationException(javax.ws.rs.WebApplicationException) QName(javax.xml.namespace.QName) InputStream(java.io.InputStream) AccountabilityException(org.eclipse.winery.accountability.exceptions.AccountabilityException) QName(javax.xml.namespace.QName) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) ExecutionException(java.util.concurrent.ExecutionException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

FileProvenanceElement (org.eclipse.winery.accountability.model.FileProvenanceElement)7 ModelProvenanceElement (org.eclipse.winery.accountability.model.ModelProvenanceElement)3 AuthorizationInfo (org.eclipse.winery.accountability.model.authorization.AuthorizationInfo)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ManifestContents (org.eclipse.virgo.util.parser.manifest.ManifestContents)2 RecoveringManifestParser (org.eclipse.virgo.util.parser.manifest.RecoveringManifestParser)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Charset (java.nio.charset.Charset)1 Objects (java.util.Objects)1 ExecutionException (java.util.concurrent.ExecutionException)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 QueryParam (javax.ws.rs.QueryParam)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 MediaType (javax.ws.rs.core.MediaType)1