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);
}
}
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);
}
}
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"));
}
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"));
}
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);
}
Aggregations