Search in sources :

Example 6 with ModelProvenanceElement

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

the class AccountabilityResource method getModelHistory.

@GET
@Path("modelHistory")
@Produces(MediaType.APPLICATION_JSON)
public List<ModelProvenanceElement> getModelHistory() {
    ServiceTemplateId serviceTemplateId = new ServiceTemplateId(new QName(provenanceId));
    String qNameWithComponentVersionOnly = VersionSupport.getQNameWithComponentVersionOnly(serviceTemplateId);
    try {
        return getAccountabilityManager().getHistory(qNameWithComponentVersionOnly).exceptionally(error -> null).get();
    } catch (InterruptedException | ExecutionException | AccountabilityException e) {
        LOGGER.error("Cannot get history of model. Reason: {}", 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)

Example 7 with ModelProvenanceElement

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

the class ProvenanceSmartContractWrapper method generateProvenanceElement.

private ModelProvenanceElement generateProvenanceElement(final Provenance.ResourceVersionEventResponse event) throws EthereumException {
    try {
        final Log log = event.log;
        final ModelProvenanceElement result = new ModelProvenanceElement();
        result.setTransactionHash(log.getTransactionHash());
        result.setAuthorAddress(event._creator);
        // decompress the state
        final byte[] compressedState = event._compressedResource;
        result.setFingerprint(new String(CompressionUtils.decompress(compressedState), StandardCharsets.UTF_8));
        // get the timestamp of the block that includes the tx that includes the state change
        result.setUnixTimestamp(web3j.ethGetBlockByHash(log.getBlockHash(), false).send().getBlock().getTimestamp().longValue());
        return result;
    } catch (IOException e) {
        final String msg = "Error while fetching block timestamp. Reason: " + e.getMessage();
        LOGGER.error(msg);
        throw new EthereumException(msg, e);
    }
}
Also used : Log(org.web3j.protocol.core.methods.response.Log) ModelProvenanceElement(org.eclipse.winery.accountability.model.ModelProvenanceElement) EthereumException(org.eclipse.winery.accountability.exceptions.EthereumException) Utf8String(org.web3j.abi.datatypes.Utf8String) IOException(java.io.IOException)

Example 8 with ModelProvenanceElement

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

the class AccountabilityManagerImplTest method validateBlockchainInputArguments.

private static Stream<Arguments> validateBlockchainInputArguments() throws Exception {
    String manifestFile = "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: myTestFile.tosca\n" + "Content-Type: application/vnd.oasis.tosca.definitions\n" + "SHA-256: 97193968948686d6947d4d760d3fe724b9981980056b8902be92e91fbe9e3eed\n" + "\n" + "Name: myTestFile2.tosca\n" + "Content-Type: application/vnd.oasis.tosca.definitions\n" + "SHA-256: a99c9a8e954355e34f11282a6dec25cc5e0b3aec2fd25d33daf2ca06267b477e\n";
    ModelProvenanceElement element = new ModelProvenanceElement();
    element.setFingerprint(manifestFile);
    element.setAuthorAddress("0x11111");
    Map<String, File> validFilesHashMap = new HashMap<>();
    validFilesHashMap.put("myTestFile.tosca", new File(ClassLoader.getSystemClassLoader().getResource("emptyDefinition.tosca").toURI()));
    validFilesHashMap.put("myTestFile2.tosca", new File(ClassLoader.getSystemClassLoader().getResource("secondDefinition.tosca").toURI()));
    validFilesHashMap.put("Tosca.meta", new File(ClassLoader.getSystemClassLoader().getResource("Tosca.meta").toURI()));
    AuthorizationElement authorizationElement = new AuthorizationElement();
    authorizationElement.setAuthorizerBlockchainAddress("0x11111");
    authorizationElement.setAuthorizedBlockchainAddress("0x11111");
    authorizationElement.setAuthorizedIdentity("Gharreb");
    authorizationElement.setTransactionHash("0x3215F23");
    List<AuthorizationElement> authList = Arrays.asList(authorizationElement);
    AuthorizationInfo authorizationInfo = new AuthorizationTree(authList);
    return Stream.of(Arguments.of(VERIFIED, Collections.singletonList(element), validFilesHashMap, authorizationInfo, "Simple valid file in manifest"));
}
Also used : HashMap(java.util.HashMap) ModelProvenanceElement(org.eclipse.winery.accountability.model.ModelProvenanceElement) AuthorizationTree(org.eclipse.winery.accountability.model.authorization.AuthorizationTree) AuthorizationElement(org.eclipse.winery.accountability.model.authorization.AuthorizationElement) File(java.io.File) AuthorizationInfo(org.eclipse.winery.accountability.model.authorization.AuthorizationInfo)

Example 9 with ModelProvenanceElement

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

the class AccountabilityManagerImplTest method verifyFileInProvenanceElementArguments.

private static Stream<Arguments> verifyFileInProvenanceElementArguments() throws URISyntaxException {
    String file0 = "myTestFile.tosca";
    String file1 = "myTestFile2.tosca";
    String missingFileManifest = "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: " + file0 + "\n" + "Content-Type: application/vnd.oasis.tosca.definitions\n" + "SHA-256: 97193968948686d6947d4d760d3fe724b9981980056b8902be92e91fbe9e3eed\n";
    String missingHashManifest = missingFileManifest + "\n" + "Name: " + file1 + "\n" + "Content-Type: application/vnd.oasis.tosca.definitions\n";
    String completeManifestFile = missingHashManifest + "SHA-256: a99c9a8e954355e34f11282a6dec25cc5e0b3aec2fd25d33daf2ca06267b477e";
    ModelProvenanceElement element = new ModelProvenanceElement();
    element.setFingerprint(completeManifestFile);
    ModelProvenanceElement invalidElement = new ModelProvenanceElement();
    invalidElement.setFingerprint(completeManifestFile.substring(0, completeManifestFile.length() - 5) + "1111");
    ModelProvenanceElement elementWithNoHash = new ModelProvenanceElement();
    elementWithNoHash.setFingerprint(missingHashManifest);
    ModelProvenanceElement elementWithMissingFile = new ModelProvenanceElement();
    elementWithMissingFile.setFingerprint(missingFileManifest);
    Map<String, ProvenanceVerification> validVerificationMap = new HashMap<>();
    validVerificationMap.put(file0, VERIFIED);
    validVerificationMap.put(file1, VERIFIED);
    Map<String, ProvenanceVerification> invalidVerificationMap = new HashMap<>();
    invalidVerificationMap.put(file0, VERIFIED);
    invalidVerificationMap.put(file1, INVALID);
    Map<String, ProvenanceVerification> noHashVerificationMap = new HashMap<>();
    noHashVerificationMap.put(file0, VERIFIED);
    noHashVerificationMap.put(file1, NO_HASH_AVAILABLE);
    Map<String, ProvenanceVerification> missingFileVerificationMap = new HashMap<>();
    missingFileVerificationMap.put(file0, VERIFIED);
    missingFileVerificationMap.put(file1, ID_NOT_FOUND);
    Map<String, File> validFilesHashMap = new HashMap<>();
    validFilesHashMap.put(file0, new File(ClassLoader.getSystemClassLoader().getResource("emptyDefinition.tosca").toURI()));
    validFilesHashMap.put(file1, new File(ClassLoader.getSystemClassLoader().getResource("secondDefinition.tosca").toURI()));
    return Stream.of(Arguments.of(validVerificationMap, element, validFilesHashMap, "Expects that all files are validated"), Arguments.of(invalidVerificationMap, invalidElement, validFilesHashMap, "Expects that one file is invalid"), Arguments.of(noHashVerificationMap, elementWithNoHash, validFilesHashMap, "Expects one file with no hash available"), Arguments.of(missingFileVerificationMap, elementWithMissingFile, validFilesHashMap, "Expects a missing file in the manifest"));
}
Also used : ProvenanceVerification(org.eclipse.winery.accountability.model.ProvenanceVerification) HashMap(java.util.HashMap) ModelProvenanceElement(org.eclipse.winery.accountability.model.ModelProvenanceElement) File(java.io.File)

Example 10 with ModelProvenanceElement

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

the class AccountabilityManagerImplTest method verifyManifest.

@ParameterizedTest(name = "{index} => ''{3}''")
@MethodSource("verifyManifestArguments")
public void verifyManifest(ModelProvenanceElement historyElement, ProvenanceVerification expectedVerification, AuthorizationInfo authorizationInfo, String description) throws Exception {
    String manifestId = "Tosca.meta";
    List<ModelProvenanceElement> historyElementList = Objects.nonNull(historyElement) ? Arrays.asList(historyElement) : null;
    Map<String, File> filesMap = new HashMap<>();
    filesMap.put(manifestId, new File(ClassLoader.getSystemResource(manifestId).toURI()));
    Map<String, ProvenanceVerification> verificationMap = new HashMap<>();
    provenance.verifyManifest(historyElementList, manifestId, filesMap, verificationMap, authorizationInfo);
    ProvenanceVerification verification = verificationMap.get(manifestId);
    assertEquals(expectedVerification, verification);
}
Also used : ProvenanceVerification(org.eclipse.winery.accountability.model.ProvenanceVerification) HashMap(java.util.HashMap) ModelProvenanceElement(org.eclipse.winery.accountability.model.ModelProvenanceElement) File(java.io.File) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

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