@Test public void testCreateBucket() throws Exception { final AtomicBoolean header = new AtomicBoolean(); final AtomicBoolean signature = new AtomicBoolean(); session.withListener(new TranscriptListener() { @Override public void log(final Type request, final String message) { if(StringUtils.contains(message, "Expect: 100-continue")) { header.set(true); } if(StringUtils.contains(message, "SignedHeaders=content-type;date;expect;host;x-amz-acl;x-amz-content-sha256;x-amz-date")) { signature.set(true); } } }); final S3BucketCreateService create = new S3BucketCreateService(session); final Path bucket = new Path(new AsciiRandomStringService().random(), EnumSet.of(Path.Type.directory, Path.Type.volume)); create.create(bucket, "eu-central-1"); assertTrue(header.get()); bucket.attributes().setRegion("eu-central-1"); assertTrue(new S3FindFeature(session).find(bucket)); new S3DefaultDeleteFeature(session).delete(Collections.<Path>singletonList(bucket), new DisabledLoginCallback(), new Delete.DisabledCallback()); }
public void create(final Path bucket, final String region) throws BackgroundException { if(!session.getClient().getConfiguration().getBoolProperty("s3service.disable-dns-buckets", false)) { if(!ServiceUtils.isBucketNameValidDNSName(bucket.getName())) { throw new InteroperabilityException(LocaleFactory.localizedString("Bucket name is not DNS compatible", "S3")); } } AccessControlList acl; if(PreferencesFactory.get().getProperty("s3.bucket.acl.default").equals("public-read")) { acl = AccessControlList.REST_CANNED_PUBLIC_READ; } else { acl = AccessControlList.REST_CANNED_PRIVATE; } try { this.create(bucket, acl, region); } catch(ResolveFailedException e) { log.warn(String.format("Failure %s resolving bucket name. Disable use of DNS bucket names", e)); session.getClient().getConfiguration().setProperty("s3service.disable-dns-buckets", String.valueOf(true)); this.create(bucket, acl, region); } }
S3BucketCreateService { public void create(final Path bucket, final String region) throws BackgroundException { if(!session.getClient().getConfiguration().getBoolProperty("s3service.disable-dns-buckets", false)) { if(!ServiceUtils.isBucketNameValidDNSName(bucket.getName())) { throw new InteroperabilityException(LocaleFactory.localizedString("Bucket name is not DNS compatible", "S3")); } } AccessControlList acl; if(PreferencesFactory.get().getProperty("s3.bucket.acl.default").equals("public-read")) { acl = AccessControlList.REST_CANNED_PUBLIC_READ; } else { acl = AccessControlList.REST_CANNED_PRIVATE; } try { this.create(bucket, acl, region); } catch(ResolveFailedException e) { log.warn(String.format("Failure %s resolving bucket name. Disable use of DNS bucket names", e)); session.getClient().getConfiguration().setProperty("s3service.disable-dns-buckets", String.valueOf(true)); this.create(bucket, acl, region); } } }
S3BucketCreateService { public void create(final Path bucket, final String region) throws BackgroundException { if(!session.getClient().getConfiguration().getBoolProperty("s3service.disable-dns-buckets", false)) { if(!ServiceUtils.isBucketNameValidDNSName(bucket.getName())) { throw new InteroperabilityException(LocaleFactory.localizedString("Bucket name is not DNS compatible", "S3")); } } AccessControlList acl; if(PreferencesFactory.get().getProperty("s3.bucket.acl.default").equals("public-read")) { acl = AccessControlList.REST_CANNED_PUBLIC_READ; } else { acl = AccessControlList.REST_CANNED_PRIVATE; } try { this.create(bucket, acl, region); } catch(ResolveFailedException e) { log.warn(String.format("Failure %s resolving bucket name. Disable use of DNS bucket names", e)); session.getClient().getConfiguration().setProperty("s3service.disable-dns-buckets", String.valueOf(true)); this.create(bucket, acl, region); } } S3BucketCreateService(final S3Session session); }
S3BucketCreateService { public void create(final Path bucket, final String region) throws BackgroundException { if(!session.getClient().getConfiguration().getBoolProperty("s3service.disable-dns-buckets", false)) { if(!ServiceUtils.isBucketNameValidDNSName(bucket.getName())) { throw new InteroperabilityException(LocaleFactory.localizedString("Bucket name is not DNS compatible", "S3")); } } AccessControlList acl; if(PreferencesFactory.get().getProperty("s3.bucket.acl.default").equals("public-read")) { acl = AccessControlList.REST_CANNED_PUBLIC_READ; } else { acl = AccessControlList.REST_CANNED_PRIVATE; } try { this.create(bucket, acl, region); } catch(ResolveFailedException e) { log.warn(String.format("Failure %s resolving bucket name. Disable use of DNS bucket names", e)); session.getClient().getConfiguration().setProperty("s3service.disable-dns-buckets", String.valueOf(true)); this.create(bucket, acl, region); } } S3BucketCreateService(final S3Session session); void create(final Path bucket, final String region); }
S3BucketCreateService { public void create(final Path bucket, final String region) throws BackgroundException { if(!session.getClient().getConfiguration().getBoolProperty("s3service.disable-dns-buckets", false)) { if(!ServiceUtils.isBucketNameValidDNSName(bucket.getName())) { throw new InteroperabilityException(LocaleFactory.localizedString("Bucket name is not DNS compatible", "S3")); } } AccessControlList acl; if(PreferencesFactory.get().getProperty("s3.bucket.acl.default").equals("public-read")) { acl = AccessControlList.REST_CANNED_PUBLIC_READ; } else { acl = AccessControlList.REST_CANNED_PRIVATE; } try { this.create(bucket, acl, region); } catch(ResolveFailedException e) { log.warn(String.format("Failure %s resolving bucket name. Disable use of DNS bucket names", e)); session.getClient().getConfiguration().setProperty("s3service.disable-dns-buckets", String.valueOf(true)); this.create(bucket, acl, region); } } S3BucketCreateService(final S3Session session); void create(final Path bucket, final String region);  }