private static AccountabilityManager getAccountabilityManager() throws AccountabilityException { Properties props = RepositoryFactory.getRepository().getAccountabilityConfigurationManager().properties; return AccountabilityManagerFactory.getAccountabilityManager(props); }
private boolean isValid(ImportMetaInformation metaInformation, Map<String, File> fileMap) throws ExecutionException, InterruptedException, AccountabilityException { ServiceTemplateId entryServiceTemplate = metaInformation.entryServiceTemplate; metaInformation.verificationMap = new HashMap<>(); if (Objects.nonNull(entryServiceTemplate)) { Properties props = RepositoryFactory.getRepository().getAccountabilityConfigurationManager().properties; AccountabilityManager accountabilityManager = AccountabilityManagerFactory.getAccountabilityManager(props); String provenanceIdentifier = VersionUtils.getQNameWithComponentVersionOnly(entryServiceTemplate); metaInformation.verificationMap = accountabilityManager .verify(provenanceIdentifier, "TOSCA-Metadata/TOSCA.meta", fileMap) .exceptionally(e -> { LOGGER.debug("accountabilityManager.verify completed exceptionally", e); return null; }) .get(); return metaInformation.verificationMap.values().stream().allMatch(v -> v == ProvenanceVerification.VERIFIED); } return false; }
public CompletableFuture<String> writeCsarAndSaveManifestInProvenanceLayer(IRepository repository, DefinitionsChildId entryId, OutputStream out) throws IOException, RepositoryCorruptException, AccountabilityException, InterruptedException, ExecutionException { LocalDateTime start = LocalDateTime.now(); Properties props = repository.getAccountabilityConfigurationManager().properties; AccountabilityManager accountabilityManager = AccountabilityManagerFactory.getAccountabilityManager(props); Map<String, Object> exportConfiguration = new HashMap<>(); exportConfiguration.put(CsarExportConfiguration.INCLUDE_HASHES.name(), null); exportConfiguration.put(CsarExportConfiguration.STORE_IMMUTABLY.name(), null); String manifestString = this.writeCsar(repository, entryId, out, exportConfiguration); String qNameWithComponentVersionOnly = VersionUtils.getQNameWithComponentVersionOnly(entryId); LOGGER.debug("Preparing CSAR export (provenance) lasted {}", Duration.between(LocalDateTime.now(), start).toString()); return accountabilityManager.storeFingerprint(qNameWithComponentVersionOnly, manifestString); }
/** * Stores all files listed in the map in the immutable file storage, and updates the CsarContentProperties of each * file to contain its address in the aforementioned storage. * * @param filesToStore a map of the CsarContentProperties of all files to be stored in the CSAR and their contents. */ private void immutablyStoreRefFiles(Map<CsarContentProperties, CsarEntry> filesToStore, IRepository repository) throws AccountabilityException, ExecutionException, InterruptedException, IOException { Properties props = repository.getAccountabilityConfigurationManager().properties; AccountabilityManager manager = AccountabilityManagerFactory.getAccountabilityManager(props); Map<String, InputStream> filesMap = new HashMap<>(); for (Map.Entry<CsarContentProperties, CsarEntry> entry : filesToStore.entrySet()) { filesMap.put(entry.getKey().getPathInsideCsar(), entry.getValue().getInputStream()); } // store all files in immutable storage (already stored files will get their same old address) Map<String, String> addressMap = manager .storeState(filesMap) .get(); filesToStore.keySet().forEach((CsarContentProperties properties) -> { properties.setImmutableAddress(addressMap.get(properties.getPathInsideCsar())); }); }