-
Notifications
You must be signed in to change notification settings - Fork 9
/
helperMethods.js
61 lines (50 loc) · 2.03 KB
/
helperMethods.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const _ = require('lodash');
const Params = {
CognitoUserPoolIdOutputKey: 'CognitoUserPoolIdOutputKey',
CustomAttributes: 'CustomAttributes',
CognitoUserPoolClientIdOutputKey: 'CognitoUserPoolClientIdOutputKey',
};
const describeStack = async (AWS) => {
const response = await AWS.request('CloudFormation', 'describeStacks', { StackName: AWS.naming.getStackName() });
return _.first(response.Stacks);
};
const loadCustom = (log, custom) => {
let result = [];
if (custom && custom.CognitoAddCustomAttributes) {
if(Array.isArray(custom.CognitoAddCustomAttributes)) {
custom.CognitoAddCustomAttributes.forEach(cognitoCustomAttributeMappingItem => {
result.push(parseCustomItem(log, cognitoCustomAttributeMappingItem));
});
} else {
result.push(parseCustomItem(log, custom.CognitoAddCustomAttributes));
}
}
return result;
};
const parseCustomItem = (log, item) => {
const result = {};
let skippingItem = false;
const CognitoUserPoolIdOutputKey = _.get(item, Params.CognitoUserPoolIdOutputKey);
const CustomAttributes = _.get(item, Params.CustomAttributes);
const CognitoUserPoolClientIdOutputKey = _.get(item, Params.CognitoUserPoolClientIdOutputKey);
if (!CognitoUserPoolIdOutputKey || !(typeof(CognitoUserPoolIdOutputKey) === 'string')) {
log('CognitoUserPoolIdOutputKey is required.');
skippingItem = true;
} else if (!CustomAttributes || !Array.isArray(CustomAttributes)) {
log('CustomAttributes array is required.');
skippingItem = true;
} else {
result.CognitoUserPoolIdOutputKey = CognitoUserPoolIdOutputKey;
result.CustomAttributes = CustomAttributes;
result.CognitoUserPoolClientIdOutputKey = CognitoUserPoolClientIdOutputKey;
}
if(skippingItem) {
log(`Custom Attribute is being skipped due to missing information. [CognitoUserPoolIdOutputKey: ${CognitoUserPoolIdOutputKey}] [CognitoUserPoolClientIdOutputKey: ${CognitoUserPoolClientIdOutputKey}]`);
}
return result;
};
module.exports = {
Params,
loadCustom,
describeStack
};