Skip to content

Commit

Permalink
Add network proxy option
Browse files Browse the repository at this point in the history
  • Loading branch information
vickishan committed Jun 17, 2016
1 parent c94fbaf commit 8f62ac2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ Sets the `Expires` header on the uploaded files.

*Default:* `Mon Dec 31 2029 21:00:00 GMT-0300 (CLST)`

### proxy

The network proxy used when sending requests to S3.

*Default:* `undefined`

## Prerequisites

The following properties are expected to be present on the deployment `context` object:
Expand Down
10 changes: 10 additions & 0 deletions lib/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ module.exports = CoreObject.extend({
init: function(options) {
this._plugin = options.plugin;
var AWS = require('aws-sdk');
var proxyAgent = require('proxy-agent');
var s3Options = {
region: this._plugin.readConfig('region')
};

const accessKeyId = this._plugin.readConfig('accessKeyId');
const secretAccessKey = this._plugin.readConfig('secretAccessKey');
const sessionToken = this._plugin.readConfig('sessionToken');
const proxy = this._plugin.readConfig('proxy');

if (accessKeyId && secretAccessKey) {
this._plugin.log('Using AWS access key id and secret access key from config', { verbose: true });
Expand All @@ -31,6 +33,14 @@ module.exports = CoreObject.extend({
s3Options.sessionToken = sessionToken;
}

if (proxy) {
AWS.config.update({
httpOptions: {
agent: proxyAgent(proxy)
}
});
}

this._client = this._plugin.readConfig('s3Client') || new AWS.S3(s3Options);
},

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
"ember-cli-deploy-plugin": "^0.2.2",
"lodash": "^3.9.3",
"mime": "^1.3.4",
"minimatch": "^2.0.4"
"minimatch": "^2.0.4",
"proxy-agent": "^2.0.0"
},
"ember-addon": {
"configPath": "tests/dummy/config",
Expand Down
1 change: 1 addition & 0 deletions tests/unit/index-nodetest.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ describe('s3 plugin', function() {
filePattern: '*.{css,js}',
acl: 'authenticated-read',
prefix: '',
proxy: 'http://user:password@internal.proxy.com',
distDir: function(context) {
return context.distDir;
},
Expand Down

0 comments on commit 8f62ac2

Please sign in to comment.