@Test public void testListRestrictRegion() throws Exception { final AttributedList<Path> list = new S3BucketListService(session, new S3LocationFeature.S3Region("eu-central-1")).list( new Path(String.valueOf(Path.DELIMITER), EnumSet.of(Path.Type.volume, Path.Type.directory)), new DisabledListProgressListener()); assertFalse(list.isEmpty()); for(Path bucket : list) { assertEquals("eu-central-1", bucket.attributes().getRegion()); } }
@Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { if(log.isDebugEnabled()) { log.debug(String.format("List containers for %s", session)); } try { if(session.getHost().getCredentials().isAnonymousLogin()) { if(StringUtils.isEmpty(this.getContainer(session.getHost()))) { if(StringUtils.isNotBlank(session.getHost().getDefaultPath())) { if(containerService.isContainer(new Path(PathNormalizer.normalize(session.getHost().getDefaultPath()), EnumSet.of(Path.Type.directory)))) { final Path bucket = containerService.getContainer( new Path(PathNormalizer.normalize(session.getHost().getDefaultPath()), EnumSet.of(Path.Type.directory)) ); log.info(String.format("Using default %s path to determine bucket name %s", session.getHost().getDefaultPath(), bucket)); final AttributedList<Path> buckets = new AttributedList<>(Collections.singletonList(bucket)); listener.chunk(directory, buckets); return buckets; } } log.warn(String.format("No bucket name given in hostname %s", session.getHost().getHostname())); final Path bucket = new Path(PathNormalizer.normalize(session.getHost().getHostname()), EnumSet.of(Path.Type.volume, Path.Type.directory)); final AttributedList<Path> buckets = new AttributedList<>(Collections.singletonList(bucket)); listener.chunk(directory, buckets); return buckets; } else { final Path bucket = new Path(PathNormalizer.normalize(this.getContainer(session.getHost())), EnumSet.of(Path.Type.volume, Path.Type.directory)); final AttributedList<Path> buckets = new AttributedList<>(Collections.singletonList(bucket)); listener.chunk(directory, buckets); return buckets; } } else { final String bucketname = this.getContainer(session.getHost()); if(StringUtils.isNotEmpty(bucketname)) { final Path bucket = new Path(PathNormalizer.normalize(bucketname), EnumSet.of(Path.Type.volume, Path.Type.directory)); final AttributedList<Path> buckets = new AttributedList<>(Collections.singletonList(bucket)); listener.chunk(directory, buckets); return buckets; } else { final AttributedList<Path> buckets = new AttributedList<Path>(); for(StorageBucket b : session.getClient().listAllBuckets()) { final Path bucket = new Path(PathNormalizer.normalize(b.getName()), EnumSet.of(Path.Type.volume, Path.Type.directory)); if(b.getOwner() != null) { bucket.attributes().setOwner(b.getOwner().getId()); } bucket.attributes().setCreationDate(b.getCreationDate().getTime()); if(b.isLocationKnown()) { bucket.attributes().setRegion(b.getLocation()); } if(region.getIdentifier() != null) { final String location; if(!b.isLocationKnown()) { location = session.getFeature(Location.class).getLocation(bucket).getIdentifier(); } else { location = b.getLocation(); } if(!StringUtils.equals(location, region.getIdentifier())) { log.warn(String.format("Skip bucket %s in region %s", bucket, location)); continue; } bucket.attributes().setRegion(location); } buckets.add(bucket); listener.chunk(directory, buckets); } return buckets; } } } catch(ServiceException e) { throw new S3ExceptionMappingService().map("Listing directory {0} failed", e, directory); } }
S3BucketListService implements RootListService { @Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { if(log.isDebugEnabled()) { log.debug(String.format("List containers for %s", session)); } try { if(session.getHost().getCredentials().isAnonymousLogin()) { if(StringUtils.isEmpty(this.getContainer(session.getHost()))) { if(StringUtils.isNotBlank(session.getHost().getDefaultPath())) { if(containerService.isContainer(new Path(PathNormalizer.normalize(session.getHost().getDefaultPath()), EnumSet.of(Path.Type.directory)))) { final Path bucket = containerService.getContainer( new Path(PathNormalizer.normalize(session.getHost().getDefaultPath()), EnumSet.of(Path.Type.directory)) ); log.info(String.format("Using default %s path to determine bucket name %s", session.getHost().getDefaultPath(), bucket)); final AttributedList<Path> buckets = new AttributedList<>(Collections.singletonList(bucket)); listener.chunk(directory, buckets); return buckets; } } log.warn(String.format("No bucket name given in hostname %s", session.getHost().getHostname())); final Path bucket = new Path(PathNormalizer.normalize(session.getHost().getHostname()), EnumSet.of(Path.Type.volume, Path.Type.directory)); final AttributedList<Path> buckets = new AttributedList<>(Collections.singletonList(bucket)); listener.chunk(directory, buckets); return buckets; } else { final Path bucket = new Path(PathNormalizer.normalize(this.getContainer(session.getHost())), EnumSet.of(Path.Type.volume, Path.Type.directory)); final AttributedList<Path> buckets = new AttributedList<>(Collections.singletonList(bucket)); listener.chunk(directory, buckets); return buckets; } } else { final String bucketname = this.getContainer(session.getHost()); if(StringUtils.isNotEmpty(bucketname)) { final Path bucket = new Path(PathNormalizer.normalize(bucketname), EnumSet.of(Path.Type.volume, Path.Type.directory)); final AttributedList<Path> buckets = new AttributedList<>(Collections.singletonList(bucket)); listener.chunk(directory, buckets); return buckets; } else { final AttributedList<Path> buckets = new AttributedList<Path>(); for(StorageBucket b : session.getClient().listAllBuckets()) { final Path bucket = new Path(PathNormalizer.normalize(b.getName()), EnumSet.of(Path.Type.volume, Path.Type.directory)); if(b.getOwner() != null) { bucket.attributes().setOwner(b.getOwner().getId()); } bucket.attributes().setCreationDate(b.getCreationDate().getTime()); if(b.isLocationKnown()) { bucket.attributes().setRegion(b.getLocation()); } if(region.getIdentifier() != null) { final String location; if(!b.isLocationKnown()) { location = session.getFeature(Location.class).getLocation(bucket).getIdentifier(); } else { location = b.getLocation(); } if(!StringUtils.equals(location, region.getIdentifier())) { log.warn(String.format("Skip bucket %s in region %s", bucket, location)); continue; } bucket.attributes().setRegion(location); } buckets.add(bucket); listener.chunk(directory, buckets); } return buckets; } } } catch(ServiceException e) { throw new S3ExceptionMappingService().map("Listing directory {0} failed", e, directory); } } }
S3BucketListService implements RootListService { @Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { if(log.isDebugEnabled()) { log.debug(String.format("List containers for %s", session)); } try { if(session.getHost().getCredentials().isAnonymousLogin()) { if(StringUtils.isEmpty(this.getContainer(session.getHost()))) { if(StringUtils.isNotBlank(session.getHost().getDefaultPath())) { if(containerService.isContainer(new Path(PathNormalizer.normalize(session.getHost().getDefaultPath()), EnumSet.of(Path.Type.directory)))) { final Path bucket = containerService.getContainer( new Path(PathNormalizer.normalize(session.getHost().getDefaultPath()), EnumSet.of(Path.Type.directory)) ); log.info(String.format("Using default %s path to determine bucket name %s", session.getHost().getDefaultPath(), bucket)); final AttributedList<Path> buckets = new AttributedList<>(Collections.singletonList(bucket)); listener.chunk(directory, buckets); return buckets; } } log.warn(String.format("No bucket name given in hostname %s", session.getHost().getHostname())); final Path bucket = new Path(PathNormalizer.normalize(session.getHost().getHostname()), EnumSet.of(Path.Type.volume, Path.Type.directory)); final AttributedList<Path> buckets = new AttributedList<>(Collections.singletonList(bucket)); listener.chunk(directory, buckets); return buckets; } else { final Path bucket = new Path(PathNormalizer.normalize(this.getContainer(session.getHost())), EnumSet.of(Path.Type.volume, Path.Type.directory)); final AttributedList<Path> buckets = new AttributedList<>(Collections.singletonList(bucket)); listener.chunk(directory, buckets); return buckets; } } else { final String bucketname = this.getContainer(session.getHost()); if(StringUtils.isNotEmpty(bucketname)) { final Path bucket = new Path(PathNormalizer.normalize(bucketname), EnumSet.of(Path.Type.volume, Path.Type.directory)); final AttributedList<Path> buckets = new AttributedList<>(Collections.singletonList(bucket)); listener.chunk(directory, buckets); return buckets; } else { final AttributedList<Path> buckets = new AttributedList<Path>(); for(StorageBucket b : session.getClient().listAllBuckets()) { final Path bucket = new Path(PathNormalizer.normalize(b.getName()), EnumSet.of(Path.Type.volume, Path.Type.directory)); if(b.getOwner() != null) { bucket.attributes().setOwner(b.getOwner().getId()); } bucket.attributes().setCreationDate(b.getCreationDate().getTime()); if(b.isLocationKnown()) { bucket.attributes().setRegion(b.getLocation()); } if(region.getIdentifier() != null) { final String location; if(!b.isLocationKnown()) { location = session.getFeature(Location.class).getLocation(bucket).getIdentifier(); } else { location = b.getLocation(); } if(!StringUtils.equals(location, region.getIdentifier())) { log.warn(String.format("Skip bucket %s in region %s", bucket, location)); continue; } bucket.attributes().setRegion(location); } buckets.add(bucket); listener.chunk(directory, buckets); } return buckets; } } } catch(ServiceException e) { throw new S3ExceptionMappingService().map("Listing directory {0} failed", e, directory); } } S3BucketListService(final S3Session session);  S3BucketListService(final S3Session session, final S3LocationFeature.S3Region region); }
S3BucketListService implements RootListService { @Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { if(log.isDebugEnabled()) { log.debug(String.format("List containers for %s", session)); } try { if(session.getHost().getCredentials().isAnonymousLogin()) { if(StringUtils.isEmpty(this.getContainer(session.getHost()))) { if(StringUtils.isNotBlank(session.getHost().getDefaultPath())) { if(containerService.isContainer(new Path(PathNormalizer.normalize(session.getHost().getDefaultPath()), EnumSet.of(Path.Type.directory)))) { final Path bucket = containerService.getContainer( new Path(PathNormalizer.normalize(session.getHost().getDefaultPath()), EnumSet.of(Path.Type.directory)) ); log.info(String.format("Using default %s path to determine bucket name %s", session.getHost().getDefaultPath(), bucket)); final AttributedList<Path> buckets = new AttributedList<>(Collections.singletonList(bucket)); listener.chunk(directory, buckets); return buckets; } } log.warn(String.format("No bucket name given in hostname %s", session.getHost().getHostname())); final Path bucket = new Path(PathNormalizer.normalize(session.getHost().getHostname()), EnumSet.of(Path.Type.volume, Path.Type.directory)); final AttributedList<Path> buckets = new AttributedList<>(Collections.singletonList(bucket)); listener.chunk(directory, buckets); return buckets; } else { final Path bucket = new Path(PathNormalizer.normalize(this.getContainer(session.getHost())), EnumSet.of(Path.Type.volume, Path.Type.directory)); final AttributedList<Path> buckets = new AttributedList<>(Collections.singletonList(bucket)); listener.chunk(directory, buckets); return buckets; } } else { final String bucketname = this.getContainer(session.getHost()); if(StringUtils.isNotEmpty(bucketname)) { final Path bucket = new Path(PathNormalizer.normalize(bucketname), EnumSet.of(Path.Type.volume, Path.Type.directory)); final AttributedList<Path> buckets = new AttributedList<>(Collections.singletonList(bucket)); listener.chunk(directory, buckets); return buckets; } else { final AttributedList<Path> buckets = new AttributedList<Path>(); for(StorageBucket b : session.getClient().listAllBuckets()) { final Path bucket = new Path(PathNormalizer.normalize(b.getName()), EnumSet.of(Path.Type.volume, Path.Type.directory)); if(b.getOwner() != null) { bucket.attributes().setOwner(b.getOwner().getId()); } bucket.attributes().setCreationDate(b.getCreationDate().getTime()); if(b.isLocationKnown()) { bucket.attributes().setRegion(b.getLocation()); } if(region.getIdentifier() != null) { final String location; if(!b.isLocationKnown()) { location = session.getFeature(Location.class).getLocation(bucket).getIdentifier(); } else { location = b.getLocation(); } if(!StringUtils.equals(location, region.getIdentifier())) { log.warn(String.format("Skip bucket %s in region %s", bucket, location)); continue; } bucket.attributes().setRegion(location); } buckets.add(bucket); listener.chunk(directory, buckets); } return buckets; } } } catch(ServiceException e) { throw new S3ExceptionMappingService().map("Listing directory {0} failed", e, directory); } } S3BucketListService(final S3Session session);  S3BucketListService(final S3Session session, final S3LocationFeature.S3Region region); @Override AttributedList<Path> list(final Path directory, final ListProgressListener listener); }
S3BucketListService implements RootListService { @Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { if(log.isDebugEnabled()) { log.debug(String.format("List containers for %s", session)); } try { if(session.getHost().getCredentials().isAnonymousLogin()) { if(StringUtils.isEmpty(this.getContainer(session.getHost()))) { if(StringUtils.isNotBlank(session.getHost().getDefaultPath())) { if(containerService.isContainer(new Path(PathNormalizer.normalize(session.getHost().getDefaultPath()), EnumSet.of(Path.Type.directory)))) { final Path bucket = containerService.getContainer( new Path(PathNormalizer.normalize(session.getHost().getDefaultPath()), EnumSet.of(Path.Type.directory)) ); log.info(String.format("Using default %s path to determine bucket name %s", session.getHost().getDefaultPath(), bucket)); final AttributedList<Path> buckets = new AttributedList<>(Collections.singletonList(bucket)); listener.chunk(directory, buckets); return buckets; } } log.warn(String.format("No bucket name given in hostname %s", session.getHost().getHostname())); final Path bucket = new Path(PathNormalizer.normalize(session.getHost().getHostname()), EnumSet.of(Path.Type.volume, Path.Type.directory)); final AttributedList<Path> buckets = new AttributedList<>(Collections.singletonList(bucket)); listener.chunk(directory, buckets); return buckets; } else { final Path bucket = new Path(PathNormalizer.normalize(this.getContainer(session.getHost())), EnumSet.of(Path.Type.volume, Path.Type.directory)); final AttributedList<Path> buckets = new AttributedList<>(Collections.singletonList(bucket)); listener.chunk(directory, buckets); return buckets; } } else { final String bucketname = this.getContainer(session.getHost()); if(StringUtils.isNotEmpty(bucketname)) { final Path bucket = new Path(PathNormalizer.normalize(bucketname), EnumSet.of(Path.Type.volume, Path.Type.directory)); final AttributedList<Path> buckets = new AttributedList<>(Collections.singletonList(bucket)); listener.chunk(directory, buckets); return buckets; } else { final AttributedList<Path> buckets = new AttributedList<Path>(); for(StorageBucket b : session.getClient().listAllBuckets()) { final Path bucket = new Path(PathNormalizer.normalize(b.getName()), EnumSet.of(Path.Type.volume, Path.Type.directory)); if(b.getOwner() != null) { bucket.attributes().setOwner(b.getOwner().getId()); } bucket.attributes().setCreationDate(b.getCreationDate().getTime()); if(b.isLocationKnown()) { bucket.attributes().setRegion(b.getLocation()); } if(region.getIdentifier() != null) { final String location; if(!b.isLocationKnown()) { location = session.getFeature(Location.class).getLocation(bucket).getIdentifier(); } else { location = b.getLocation(); } if(!StringUtils.equals(location, region.getIdentifier())) { log.warn(String.format("Skip bucket %s in region %s", bucket, location)); continue; } bucket.attributes().setRegion(location); } buckets.add(bucket); listener.chunk(directory, buckets); } return buckets; } } } catch(ServiceException e) { throw new S3ExceptionMappingService().map("Listing directory {0} failed", e, directory); } } S3BucketListService(final S3Session session);  S3BucketListService(final S3Session session, final S3LocationFeature.S3Region region); @Override AttributedList<Path> list(final Path directory, final ListProgressListener listener);  }