Skip to content

Commit

Permalink
initial draft, still need to move most of the services over
Browse files Browse the repository at this point in the history
  • Loading branch information
roaringdev committed May 24, 2018
1 parent 41ef646 commit d5b563c
Show file tree
Hide file tree
Showing 5 changed files with 190 additions and 5 deletions.
20 changes: 20 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
let cache = {};

const secrets = require("./lib/secretsmanager");
const dynamodb = require("./lib/dynamodb");

function build(configuration) {
return {
secrets: secrets(configuration),
dynamodb: dynamodb(configuration)
};
}

module.exports = function(configuration, forceNew = false) {
let c = JSON.stringify(configuration);

if (!(c in cache) || forceNew) {
cache[c] = build(configuration);
}
return cache[c];
};
38 changes: 38 additions & 0 deletions lib/dynamodb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"use strict";
var AWS = require('aws-sdk');
var https = require("https");
let extend = require("extend");
const async = require("async");

// AWS.config.logger = console;

module.exports = function(configuration) {
configuration = Object.assign({
maxRetries: 2,
convertEmptyValues: true,
httpOptions: {
connectTimeout: 2000,
timeout: 5000,
agent: new https.Agent({
ciphers: 'ALL',
secureProtocol: 'TLSv1_method',
// keepAlive: true
})
}
},
configuration || {});
var docClient = new AWS.DynamoDB.DocumentClient(configuration);
return {
_service: docClient,
get: function(table, id, opts = {}) {
return docClient.get({
TableName: table,
Key: {
[opts.id || 'id']: id
},
ConsistentRead: true,
"ReturnConsumedCapacity": 'TOTAL'
}).promise().then(data => data.Item);
}
};
};
7 changes: 3 additions & 4 deletions lib/secretsmanager.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
"use strict";
const aws = require('aws-sdk');

let cache = {};
module.exports = function(configuration) {
let secret = new AWS.SecretsManager({
region: configuration.aws.region
});
let secret = new aws.SecretsManager(configuration);
return {
_service: secret,
getSecret: function(secretName, opts) {
Expand Down Expand Up @@ -32,7 +31,7 @@ module.exports = function(configuration) {
} catch (e) {
reject("Invalid JSON");
}
}).cactch(reject);
}).catch(reject);
});
}
};
Expand Down
123 changes: 123 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,10 @@
"streaming",
"backoff",
"retry"
]
],
"dependencies": {
"async": "^2.6.1",
"aws-sdk": "^2.245.1",
"extend": "^3.0.1"
}
}

0 comments on commit d5b563c

Please sign in to comment.