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