-
Notifications
You must be signed in to change notification settings - Fork 5
/
factory.js
43 lines (36 loc) · 1017 Bytes
/
factory.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
'use strict';
const config = require('leo-config');
const AWS = require('aws-sdk');
const merge = require('lodash.merge');
const leoaws = {
cloudformation: require('./lib/cloudformation'),
dynamodb: require('./lib/dynamodb'),
kms: require('./lib/kms'),
secrets: require('./lib/secretsmanager'),
sqs: require('./lib/sqs'),
};
function factory (service, options) {
const configuration = config.leoaws;
if (configuration && configuration.profile && !configuration.credentials) {
configuration.credentials = new AWS.SharedIniFileCredentials({
profile: configuration.profile,
role: configuration.role,
});
}
if (options) {
merge(configuration, options);
}
const lowerService = service.toLowerCase();
if (leoaws[lowerService]) {
return leoaws[lowerService](configuration);
} else {
// return a configured AWS service
return {
_service: new AWS[service](configuration),
};
}
}
factory.injector = (dependencies = {}) => {
merge(leoaws, dependencies);
};
module.exports = factory;