Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/aws.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const AWS = require('aws-sdk');

if (typeof process.env.AWS_CONTAINER_CREDENTIALS_RELATIVE_URI !== 'undefined') {
AWS.config.credentials = new AWS.ECSCredentials({
httpOptions: { timeout: 5000 },
maxRetries: 10,
retryDelayOptions: { base: 200 }
});
}

if (typeof process.env.AWS_DEFAULT_REGION !== 'undefined') {
AWS.config.update({region: process.env.AWS_DEFAULT_REGION});
}

module.exports = AWS;
6 changes: 1 addition & 5 deletions lib/keys.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
const AWS = require('aws-sdk');
const AWS = require('./aws');
const async = require('async');
const encoder = require('./encoder');

if (typeof process.env.AWS_DEFAULT_REGION !== 'undefined') {
AWS.config.update({region: process.env.AWS_DEFAULT_REGION});
}

function decrypt(key, done) {
var params = {
CiphertextBlob: encoder.decode(key)
Expand Down
6 changes: 1 addition & 5 deletions lib/secrets.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
const AWS = require('aws-sdk');
const async = require('async');

if (typeof process.env.AWS_DEFAULT_REGION !== 'undefined') {
AWS.config.update({region: process.env.AWS_DEFAULT_REGION});
}
const AWS = require('./aws');

// Blatantly borrowed from https://www.electrictoolbox.com/pad-number-zeroes-javascript/
function pad(number, length) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"dependencies": {
"aes-js": "0.2.2",
"async": "1.5.2",
"aws-sdk": "2.2.35",
"aws-sdk": "2.28.0",
"xtend": "4.0.1"
}
}
16 changes: 16 additions & 0 deletions test/aws.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const should = require('chai').should();

describe('AWS', () => {
const env = Object.assign({}, process.env);
process.env.AWS_CONTAINER_CREDENTIALS_RELATIVE_URI = 'https://fake-uri';

afterEach(() => {
process.env = env;
});

it('can work with ecs credentials', (done) => {
const AWS = require('../lib/aws.js');
AWS.config.credentials.should.be.an.instanceOf(AWS.ECSCredentials);
done();
});
});