Skip to content

Commit 193f83b

Browse files
authored
Merge pull request #91 from lifeart/feat-endpoint-config-option
feat: endpoint support
2 parents 22f3626 + 2250b88 commit 193f83b

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,16 @@ The client specified MUST implement functions called `getObject` and `putObject`
144144

145145
*Default:* the default S3 library is `aws-sdk`
146146

147+
### endpoint
148+
149+
AWS (or AWS compatible endpoint) to use. E.g. with DigitalOcean Spaces, Microsoft Azure Blob Storage,
150+
or Openstack Swift
151+
152+
If `endpoint` set the `region` option will be ignored.
153+
154+
*Default:* `[region].s3.amazonaws.com`
155+
156+
147157
### serverSideEncryption
148158

149159
The Server-side encryption algorithm used when storing this object in S3 (e.g., AES256, aws:kms). Possible values include:

lib/s3.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ module.exports = CoreObject.extend({
3030
var plugin = options.plugin;
3131
var config = plugin.pluginConfig;
3232
var profile = plugin.readConfig('profile');
33+
var endpoint = plugin.readConfig('endpoint');
3334

3435
this._plugin = plugin;
3536

@@ -38,6 +39,11 @@ module.exports = CoreObject.extend({
3839
AWS.config.credentials = new AWS.SharedIniFileCredentials({ profile: profile });
3940
}
4041

42+
if (endpoint) {
43+
this._plugin.log('Using endpoint from config', { verbose: true });
44+
AWS.config.endpoint = new AWS.Endpoint(endpoint);
45+
}
46+
4147
this._client = plugin.readConfig('s3Client') || new AWS.S3(config);
4248
},
4349

tests/unit/lib/s3-test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,27 @@ describe('s3', function() {
195195
});
196196
});
197197

198+
it('allows `endpoint` option to be passed to customize storage', function() {
199+
var endpoint = 'foo.bar.baz';
200+
subject = new S3({
201+
plugin: Object.assign(plugin, {
202+
readConfig: function(propertyName) {
203+
if (propertyName === 's3Client') {
204+
return s3Client;
205+
} else if (propertyName === 'endpoint') {
206+
return endpoint;
207+
}
208+
}
209+
})
210+
});
211+
var promise = subject.upload(options);
212+
return assert.isFulfilled(promise)
213+
.then(function() {
214+
assert.equal(require('aws-sdk').config.endpoint.host, endpoint, 'Endpoint in SDK is correct');
215+
assert.equal(mockUi.messages[0], '- Using endpoint from config', 'Prefix is included in log output');
216+
});
217+
});
218+
198219
it('allows `cacheControl` option to be passed to customize the used cache-control', function() {
199220
var cacheControl = 'max-age=3600';
200221

0 commit comments

Comments
 (0)