Skip to content

Commit

Permalink
Adds support for using dualstack with accelerate with S3.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisradek committed Oct 13, 2016
1 parent 471dd1a commit ec99a24
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changes/next-release/feature-S3-2319154a.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "feature",
"category": "S3",
"description": "Adds support for using dualstack with accelerate endpoints."
}
10 changes: 5 additions & 5 deletions lib/services/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ AWS.util.update(AWS.S3.prototype, {
messages.push('An endpoint must be provided when configuring ' +
'`s3BucketEndpoint` to true.');
}
if (this.config.useAccelerateEndpoint && this.config.useDualstack) {
messages.push('`useAccelerateEndpoint` and `useDualstack` ' +
'cannot both be configured to true.');
}
if (messages.length === 1) {
msg = messages[0];
} else if (messages.length > 1) {
Expand Down Expand Up @@ -173,7 +169,11 @@ AWS.util.update(AWS.S3.prototype, {
if (b) {
if (!service.pathStyleBucketName(b)) {
if (service.config.useAccelerateEndpoint && service.isValidAccelerateOperation(req.operation)) {
endpoint.hostname = b + '.s3-accelerate.amazonaws.com';
if (service.config.useDualstack) {
endpoint.hostname = b + '.s3-accelerate.dualstack.amazonaws.com';
} else {
endpoint.hostname = b + '.s3-accelerate.amazonaws.com';
}
} else if (!service.config.s3BucketEndpoint) {
endpoint.hostname =
b + '.' + endpoint.hostname;
Expand Down
39 changes: 30 additions & 9 deletions test/services/s3.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ describe 'AWS.S3', ->
expect(-> new AWS.S3(s3BucketEndpoint: true)).to.throw(
/An endpoint must be provided/)

it 'does not allow useDualstack and useAccelerateEndpoint to both be true', ->
expect(-> new AWS.S3(useDualstack: true, useAccelerateEndpoint: true)).to.throw(
/cannot both be configured to true/)

describe 'endpoint', ->

it 'sets hostname to s3.amazonaws.com when region is un-specified', ->
Expand Down Expand Up @@ -235,19 +231,44 @@ describe 'AWS.S3', ->
req = build('getObject', {Bucket: 'foo', Key: 'baz'})
expect(req.endpoint.hostname).to.equal('foo.s3-accelerate.amazonaws.com')

describe 'does not use s3-accelerate', ->
describe 'does not use s3-accelerate.dualstack or s3-accelerate', ->
it 'on dns-incompatible buckets', ->
req = build('getObject', {Bucket: 'foo.baz', Key: 'bar'})
expect(req.endpoint.hostname).to.not.contain('s3-accelerate.amazonaws.com')
expect(req.endpoint.hostname).to.not.contain('s3-accelerate')

it 'on excluded operations', ->
req = build('listBuckets')
expect(req.endpoint.hostname).to.not.contain('s3-accelerate.amazonaws.com')
expect(req.endpoint.hostname).to.not.contain('s3-accelerate')
req = build('createBucket', {Bucket: 'foo'})
expect(req.endpoint.hostname).to.not.contain('s3-accelerate.amazonaws.com')
expect(req.endpoint.hostname).to.not.contain('s3-accelerate')
req = build('deleteBucket', {Bucket: 'foo'})
expect(req.endpoint.hostname).to.not.contain('s3-accelerate.amazonaws.com')
expect(req.endpoint.hostname).to.not.contain('s3-accelerate')

describe 'with useAccelerateEndpoint and dualstack set to true', ->
beforeEach ->
s3 = new AWS.S3(useAccelerateEndpoint: true, useDualstack: true)

it 'changes the hostname to use s3-accelerate for dns-comaptible buckets', ->
req = build('getObject', {Bucket: 'foo', Key: 'bar'})
expect(req.endpoint.hostname).to.equal('foo.s3-accelerate.dualstack.amazonaws.com')

it 'overrides s3BucketEndpoint configuration when s3BucketEndpoint is set', ->
s3 = new AWS.S3(useAccelerateEndpoint: true, useDualstack: true, s3BucketEndpoint: true, endpoint: 'foo.region.amazonaws.com')
req = build('getObject', {Bucket: 'foo', Key: 'baz'})
expect(req.endpoint.hostname).to.equal('foo.s3-accelerate.dualstack.amazonaws.com')

describe 'does not use s3-accelerate.dualstack or s3-accelerate', ->
it 'on dns-incompatible buckets', ->
req = build('getObject', {Bucket: 'foo.baz', Key: 'bar'})
expect(req.endpoint.hostname).to.not.contain('s3-accelerate')

it 'on excluded operations', ->
req = build('listBuckets')
expect(req.endpoint.hostname).to.not.contain('s3-accelerate')
req = build('createBucket', {Bucket: 'foo'})
expect(req.endpoint.hostname).to.not.contain('s3-accelerate')
req = build('deleteBucket', {Bucket: 'foo'})
expect(req.endpoint.hostname).to.not.contain('s3-accelerate')

describe 'uri escaped params', ->
it 'uri-escapes path and querystring params', ->
Expand Down

0 comments on commit ec99a24

Please sign in to comment.