@Test public void testCustomHostnameWithRegion() { final Calendar expiry = Calendar.getInstance(TimeZone.getTimeZone("UTC")); expiry.add(Calendar.MILLISECOND, (int) TimeUnit.DAYS.toMillis(7)); final String url = new S3PresignedUrlProvider().create(new Host(new S3Protocol(), "h"), System.getProperties().getProperty("s3.key"), System.getProperties().getProperty("s3.secret"), "test-us-east-1-cyberduck", null, "f", "GET", expiry.getTimeInMillis()); assertNotNull(url); assertEquals("test-us-east-1-cyberduck.h", URI.create(url).getHost()); }
public String create(final Host host, final String user, final String secret, final String bucket, String region, final String key, final String method, final long expiry) { final S3Protocol.AuthenticationHeaderSignatureVersion signature; if(StringUtils.isBlank(region)) { if(S3Session.isAwsHostname(host.getHostname())) { region = "us-east-1"; signature = S3Protocol.AuthenticationHeaderSignatureVersion.getDefault(host.getProtocol()); } else { signature = S3Protocol.AuthenticationHeaderSignatureVersion.AWS2; } } else { if(S3Session.isAwsHostname(host.getHostname())) { signature = S3Protocol.AuthenticationHeaderSignatureVersion.getDefault(host.getProtocol()); } else { signature = S3Protocol.AuthenticationHeaderSignatureVersion.AWS2; } } return new RestS3Service(new AWSCredentials(StringUtils.strip(user), StringUtils.strip(secret))) { @Override public String getEndpoint() { return host.getHostname(); } }.createSignedUrlUsingSignatureVersion( signature.toString(), region, method, bucket, key, null, null, expiry / 1000, false, true, false); }
S3PresignedUrlProvider { public String create(final Host host, final String user, final String secret, final String bucket, String region, final String key, final String method, final long expiry) { final S3Protocol.AuthenticationHeaderSignatureVersion signature; if(StringUtils.isBlank(region)) { if(S3Session.isAwsHostname(host.getHostname())) { region = "us-east-1"; signature = S3Protocol.AuthenticationHeaderSignatureVersion.getDefault(host.getProtocol()); } else { signature = S3Protocol.AuthenticationHeaderSignatureVersion.AWS2; } } else { if(S3Session.isAwsHostname(host.getHostname())) { signature = S3Protocol.AuthenticationHeaderSignatureVersion.getDefault(host.getProtocol()); } else { signature = S3Protocol.AuthenticationHeaderSignatureVersion.AWS2; } } return new RestS3Service(new AWSCredentials(StringUtils.strip(user), StringUtils.strip(secret))) { @Override public String getEndpoint() { return host.getHostname(); } }.createSignedUrlUsingSignatureVersion( signature.toString(), region, method, bucket, key, null, null, expiry / 1000, false, true, false); } }
S3PresignedUrlProvider { public String create(final Host host, final String user, final String secret, final String bucket, String region, final String key, final String method, final long expiry) { final S3Protocol.AuthenticationHeaderSignatureVersion signature; if(StringUtils.isBlank(region)) { if(S3Session.isAwsHostname(host.getHostname())) { region = "us-east-1"; signature = S3Protocol.AuthenticationHeaderSignatureVersion.getDefault(host.getProtocol()); } else { signature = S3Protocol.AuthenticationHeaderSignatureVersion.AWS2; } } else { if(S3Session.isAwsHostname(host.getHostname())) { signature = S3Protocol.AuthenticationHeaderSignatureVersion.getDefault(host.getProtocol()); } else { signature = S3Protocol.AuthenticationHeaderSignatureVersion.AWS2; } } return new RestS3Service(new AWSCredentials(StringUtils.strip(user), StringUtils.strip(secret))) { @Override public String getEndpoint() { return host.getHostname(); } }.createSignedUrlUsingSignatureVersion( signature.toString(), region, method, bucket, key, null, null, expiry / 1000, false, true, false); }  }
S3PresignedUrlProvider { public String create(final Host host, final String user, final String secret, final String bucket, String region, final String key, final String method, final long expiry) { final S3Protocol.AuthenticationHeaderSignatureVersion signature; if(StringUtils.isBlank(region)) { if(S3Session.isAwsHostname(host.getHostname())) { region = "us-east-1"; signature = S3Protocol.AuthenticationHeaderSignatureVersion.getDefault(host.getProtocol()); } else { signature = S3Protocol.AuthenticationHeaderSignatureVersion.AWS2; } } else { if(S3Session.isAwsHostname(host.getHostname())) { signature = S3Protocol.AuthenticationHeaderSignatureVersion.getDefault(host.getProtocol()); } else { signature = S3Protocol.AuthenticationHeaderSignatureVersion.AWS2; } } return new RestS3Service(new AWSCredentials(StringUtils.strip(user), StringUtils.strip(secret))) { @Override public String getEndpoint() { return host.getHostname(); } }.createSignedUrlUsingSignatureVersion( signature.toString(), region, method, bucket, key, null, null, expiry / 1000, false, true, false); }  String create(final Host host, final String user, final String secret,
                         final String bucket, String region, final String key,
                         final String method, final long expiry); }
S3PresignedUrlProvider { public String create(final Host host, final String user, final String secret, final String bucket, String region, final String key, final String method, final long expiry) { final S3Protocol.AuthenticationHeaderSignatureVersion signature; if(StringUtils.isBlank(region)) { if(S3Session.isAwsHostname(host.getHostname())) { region = "us-east-1"; signature = S3Protocol.AuthenticationHeaderSignatureVersion.getDefault(host.getProtocol()); } else { signature = S3Protocol.AuthenticationHeaderSignatureVersion.AWS2; } } else { if(S3Session.isAwsHostname(host.getHostname())) { signature = S3Protocol.AuthenticationHeaderSignatureVersion.getDefault(host.getProtocol()); } else { signature = S3Protocol.AuthenticationHeaderSignatureVersion.AWS2; } } return new RestS3Service(new AWSCredentials(StringUtils.strip(user), StringUtils.strip(secret))) { @Override public String getEndpoint() { return host.getHostname(); } }.createSignedUrlUsingSignatureVersion( signature.toString(), region, method, bucket, key, null, null, expiry / 1000, false, true, false); }  String create(final Host host, final String user, final String secret,
                         final String bucket, String region, final String key,
                         final String method, final long expiry);  }