forked from sid88in/serverless-appsync-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
get-config.js
72 lines (66 loc) · 2.33 KB
/
get-config.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
62
63
64
65
66
67
68
69
70
71
72
const fs = require('fs');
const path = require('path');
const {
mapObjIndexed,
pipe,
values,
merge,
} = require('ramda');
const objectToArrayWithNameProp = pipe(
mapObjIndexed((item, key) => merge({ name: key }, item)),
values,
);
module.exports = (config, provider, servicePath) => {
if (!(
config.authenticationType === 'API_KEY' ||
config.authenticationType === 'AWS_IAM' ||
config.authenticationType === 'AMAZON_COGNITO_USER_POOLS' ||
config.authenticationType === 'OPENID_CONNECT'
)) {
throw new Error('appSync property `authenticationType` is missing or invalid.');
}
if (!config.serviceRole) {
throw new Error('appSync property `serviceRole` is required.');
}
if (
config.authenticationType === 'AMAZON_COGNITO_USER_POOLS' &&
!config.userPoolConfig
) {
throw new Error('appSync property `userPoolConfig` is required when authenticationType `AMAZON_COGNITO_USER_POOLS` is chosen.');
}
if (
config.authenticationType === 'OPENID_CONNECT' &&
!config.openIdConnectConfig
) {
throw new Error('appSync property `openIdConnectConfig` is required when authenticationType `OPENID_CONNECT` is chosenXXX.');
}
if (config.logConfig && !config.logConfig.loggingRoleArn) {
throw new Error('logConfig property `loggingRoleArn` is required when logConfig exists.');
}
if (config.logConfig && !config.logConfig.level) {
throw new Error('logConfig property `level` must be NONE, ERROR, or ALL when logConfig exists.');
}
const mappingTemplatesLocation = config.mappingTemplatesLocation || 'mapping-templates';
const mappingTemplates = config.mappingTemplates || [];
const schemaPath = path.join(servicePath, config.schema || 'schema.graphql');
const schemaContent = fs.readFileSync(schemaPath, {
encoding: 'utf8',
});
const dataSources = objectToArrayWithNameProp(config.dataSources);
return {
name: config.name || 'api',
apiId: config.apiId,
apiKey: config.apiKey,
region: provider.region,
authenticationType: config.authenticationType,
schema: schemaContent,
userPoolConfig: config.userPoolConfig,
openIdConnectConfig: config.openIdConnectConfig,
serviceRoleArn: config.serviceRole,
// TODO verify dataSources structure
dataSources,
mappingTemplatesLocation,
mappingTemplates,
logConfig: config.logConfig,
};
};