protected Set<Path> getContainers(final List<Path> files) { final Set<Path> containers = new HashSet<>(); for(Path file : files) { containers.add(containerService.getContainer(file)); } return containers; }
private Map<Path, Boolean> getRoomEncryptionStatus(final Map<TransferItem, TransferStatus> files) throws BackgroundException { final Map<Path, Boolean> rooms = new HashMap<>(); for(Map.Entry<TransferItem, TransferStatus> entry : files.entrySet()) { // Get top level room final Path container = new PathContainerService().getContainer(entry.getKey().remote); if(rooms.containsKey(container)) { continue; } rooms.put(container, nodeid.isEncrypted(entry.getKey().remote)); } return rooms; }
@Override public DescriptiveUrlBag toUrl(final Path file) { if(distributions.containsKey(containerService.getContainer(file))) { return new DistributionUrlProvider(distributions.get(containerService.getContainer(file))).toUrl(file); } return DescriptiveUrlBag.empty(); }
@Override public DescriptiveUrlBag toUrl(final Path file) { final Path container = containerService.getContainer(file); if(distributions.containsKey(container)) { return new DistributionUrlProvider(distributions.get(container)).toUrl(file); } return DescriptiveUrlBag.empty(); }
@Override public boolean isSupported(final Path source, final Path target) { if(Boolean.valueOf(containerService.getContainer(source).attributes().getCustom().get(SDSAttributesFinderFeature.KEY_ENCRYPTED)) ^ Boolean.valueOf(containerService.getContainer(target).attributes().getCustom().get(SDSAttributesFinderFeature.KEY_ENCRYPTED))) { return session.getFeature(Copy.class).isSupported(source, target); } return proxy.isSupported(source, target); }
@Override public boolean isRecursive(final Path source, final Path target) { if(Boolean.valueOf(containerService.getContainer(source).attributes().getCustom().get(SDSAttributesFinderFeature.KEY_ENCRYPTED)) ^ Boolean.valueOf(containerService.getContainer(target).attributes().getCustom().get(SDSAttributesFinderFeature.KEY_ENCRYPTED))) { return session.getFeature(Copy.class).isRecursive(source, target); } return proxy.isRecursive(source, target); }
@Override public ChecksumCompute checksum(final Path file) { if(Boolean.valueOf(containerService.getContainer(file).attributes().getCustom().get(SDSAttributesFinderFeature.KEY_ENCRYPTED))) { return new CryptoWriteFeature(session, proxy).checksum(file); } return proxy.checksum(file); } }
@Override public Algorithm getDefault(final Path file) { final String setting = preferences.getProperty("s3.encryption.algorithm"); if(StringUtils.equals(KMSEncryptionFeature.SSE_KMS_DEFAULT.algorithm, setting)) { final String key = String.format("s3.encryption.key.%s", containerService.getContainer(file).getName()); if(StringUtils.isNotBlank(preferences.getProperty(key))) { return Algorithm.fromString(preferences.getProperty(key)); } return KMSEncryptionFeature.SSE_KMS_DEFAULT; } return super.getDefault(file); }
@Override public Acl getPermission(final Path file) { if(containerService.isContainer(file)) { return containerService.getContainer(file).attributes().getAcl(); } return Acl.EMPTY; }
@Override public DescriptiveUrlBag toUrl(final Path file) { final Distribution distribution = new Distribution(URI.create(String.format("%s://%s.%s", Distribution.DOWNLOAD.getScheme(), containerService.getContainer(file).getName(), this.getHostname())), Distribution.DOWNLOAD, false); distribution.setUrl(URI.create(String.format("%s://%s.%s", Distribution.DOWNLOAD.getScheme(), containerService.getContainer(file).getName(), this.getHostname()))); return new DistributionUrlProvider(distribution).toUrl(file); }
@Override public Algorithm getEncryption(final Path file) throws BackgroundException { if(containerService.isContainer(file)) { final String key = String.format("s3.encryption.key.%s", containerService.getContainer(file).getName()); if(StringUtils.isNotBlank(preferences.getProperty(key))) { return Algorithm.fromString(preferences.getProperty(key)); } } return super.getEncryption(file); }
@Override public StorageObject call(final AbstractHttpEntity entity) throws BackgroundException { try { final RequestEntityRestStorageService client = session.getClient(); client.putObjectWithRequestEntityImpl( containerService.getContainer(file).getName(), object, entity, status.getParameters()); if(log.isDebugEnabled()) { log.debug(String.format("Saved object %s with checksum %s", file, object.getETag())); } } catch(ServiceException e) { throw new S3ExceptionMappingService().map("Upload {0} failed", e, file); } return object; }
protected String copy(final Path source, final S3Object destination, final TransferStatus status) throws BackgroundException { try { // Copying object applying the metadata of the original final Map<String, Object> stringObjectMap = session.getClient().copyVersionedObject(source.attributes().getVersionId(), containerService.getContainer(source).getName(), containerService.getKey(source), destination.getBucketName(), destination, false); final Map complete = (Map) stringObjectMap.get(Constants.KEY_FOR_COMPLETE_METADATA); return (String) complete.get(Constants.AMZ_VERSION_ID); } catch(ServiceException e) { throw new S3ExceptionMappingService().map("Cannot copy {0}", e, source); } }
/** * @return Path relative to the container name */ public String getKey(final Path file) { if(file.isRoot()) { return null; } if(this.isContainer(file)) { return null; } return PathRelativizer.relativize(this.getContainer(file).getAbsolute(), file.getAbsolute()); } }
@Override public boolean getStatus(final Path file) throws BackgroundException { final Path bucket = containerService.getContainer(file); try { return session.getClient().getAccelerateConfig(bucket.getName()).isEnabled(); } catch(S3ServiceException failure) { throw new S3ExceptionMappingService().map("Failure to read attributes of {0}", failure, bucket); } }
private String getHostnameForContainer(final Path bucket) { if(!ServiceUtils.isBucketNameValidDNSName(containerService.getContainer(bucket).getName())) { return session.getHost().getHostname(); } if(session.getHost().getHostname().equals(session.getHost().getProtocol().getDefaultHostname())) { return String.format("%s.%s", bucket.getName(), session.getHost().getHostname()); } return session.getHost().getHostname(); } }
@Override public boolean isSupported(final Path file) { if(containerService.isContainer(file)) { if(PreferencesFactory.get().getBoolean("sds.delete.dataroom.enable")) { // Need the query permission on the parent data room if file itself is subroom new SDSPermissionsFeature(session, nodeid).containsRole(containerService.getContainer(file.getParent()), SDSPermissionsFeature.MANAGE_ROLE); } return false; } return new SDSPermissionsFeature(session, nodeid).containsRole(file, SDSPermissionsFeature.DELETE_ROLE); }
@Override public void setStatus(final Path file, final boolean enabled) throws BackgroundException { final Path bucket = containerService.getContainer(file); try { if(!ServiceUtils.isBucketNameValidDNSName(bucket.getName())) { throw new InteroperabilityException("The name of the bucket used for Transfer Acceleration must be DNS-compliant and must not contain periods."); } session.getClient().setAccelerateConfig(bucket.getName(), new AccelerateConfig(enabled)); } catch(S3ServiceException failure) { throw new S3ExceptionMappingService().map("Failure to write attributes of {0}", failure, bucket); } }
@Override public void revert(final Path file) throws BackgroundException { final Ds3Client client = new SpectraClientBuilder().wrap(session.getClient(), session.getHost()); final Path container = containerService.getContainer(file); try { client.undeleteObjectSpectraS3(new UndeleteObjectSpectraS3Request(container.getName(), containerService.getKey(file))); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Cannot revert file", e, file); } }
public Region lookup(final Path file) throws BackgroundException { final Path container = containerService.getContainer(file); if(Location.unknown.equals(new SwiftLocationFeature.SwiftRegion(container.attributes().getRegion()))) { return this.lookup(location.getLocation(container)); } return this.lookup(new SwiftLocationFeature.SwiftRegion(container.attributes().getRegion())); }