@izara_project/izara-market-library-service-schemas 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +25 -0
- package/package.json +6 -2
- package/src/GenerateCodeLibs/index.js +24 -0
- package/src/GenerateCodeLibs/src/GenerateCodeLibs.js +1373 -0
- package/src/MainLibs/index.js +24 -0
- package/src/MainLibs/src/Consts.js +0 -0
- package/src/MainLibs/src/Utils.js +27 -0
- package/src/SourceManager/index.js +23 -0
- package/src/SourceManager/src/CreateSource.js +181 -0
- package/src/SourceManager/src/Utils.js +64 -0
- package/src/TemplateManager/index.js +23 -0
- package/src/TemplateManager/src/FunctionYaml/HdrApi/data.js +170 -0
- package/src/TemplateManager/src/FunctionYaml/HdrApi/request.json +14 -0
- package/src/TemplateManager/src/FunctionYaml/HdrApi/template.ejs +33 -0
- package/src/TemplateManager/src/FunctionYaml/HdrDsq/data.js +178 -0
- package/src/TemplateManager/src/FunctionYaml/HdrDsq/request.json +19 -0
- package/src/TemplateManager/src/FunctionYaml/HdrDsq/template.ejs +30 -0
- package/src/TemplateManager/src/FunctionYaml/HdrInv/data.js +169 -0
- package/src/TemplateManager/src/FunctionYaml/HdrInv/example req.js +15 -0
- package/src/TemplateManager/src/FunctionYaml/HdrInv/request.json +14 -0
- package/src/TemplateManager/src/FunctionYaml/HdrInv/template.ejs +26 -0
- package/src/TemplateManager/src/FunctionYaml/HdrSqs/data.js +184 -0
- package/src/TemplateManager/src/FunctionYaml/HdrSqs/request.json +19 -0
- package/src/TemplateManager/src/FunctionYaml/HdrSqs/template.ejs +30 -0
- package/src/TemplateManager/src/GenerateCode(Old).js +135 -0
- package/src/TemplateManager/src/GenerateCode.js +207 -0
- package/src/TemplateManager/src/MainResourcesYaml/CreateSourceData.js +76 -0
- package/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Data/MainDynamoDbYamlData.js +155 -0
- package/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Template/DynamoDb.ejs +31 -0
- package/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Template/DynamoDb.exampleData.js +12 -0
- package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrApi/data.js +100 -0
- package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrApi/request.json +7 -0
- package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrApi/template.ejs +76 -0
- package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrDsq/data.js +109 -0
- package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrDsq/request.json +7 -0
- package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrDsq/template.ejs +105 -0
- package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrInv/data.js +102 -0
- package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrInv/request.json +7 -0
- package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrInv/template.ejs +82 -0
- package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrSqs/data.js +102 -0
- package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrSqs/request.json +7 -0
- package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrSqs/template.ejs +124 -0
- package/src/TemplateManager/src/PerActionEndpoint/Handler/testRequest.json +5 -0
- package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Get/data.js +88 -0
- package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Get/request.json +5 -0
- package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Get/template.ejs +219 -0
- package/src/TemplateManager/src/ResourceYaml/CreateSourceData.js +76 -0
- package/src/TemplateManager/src/ResourceYaml/dynamodb/mainResourcePerObjectSchemaData.js +173 -0
- package/src/TemplateManager/src/ResourceYaml/dynamodb/processLogicalAndFindData.js +102 -0
- package/src/TemplateManager/src/ResourceYaml/dynamodb/request.json +7 -0
- package/src/TemplateManager/src/ResourceYaml/dynamodb/template.ejs +31 -0
- package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/defaultSnsInSqsForFindDataAndProcessLogical.js +81 -0
- package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/request.json +4 -0
- package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/snsAndSqsPerActiondata.js +108 -0
- package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/snsTemplate.ejs +59 -0
- package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/sqsTemplate.ejs +42 -0
- package/src/TemplateManager/src/externalService/LambdaRole/data.js +147 -0
- package/src/TemplateManager/src/externalService/LambdaRole/request.json +18 -0
- package/src/TemplateManager/src/externalService/LambdaRole/template.ejs +52 -0
- package/src/TemplateManager/src/externalService/SnsTopicSubscriotions/data.js +31 -0
- package/src/TemplateManager/src/externalService/SnsTopicSubscriotions/request.json +0 -0
- package/src/TemplateManager/src/externalService/SnsTopicSubscriotions/template.ejs +14 -0
- package/src/TemplateManager/src/libs/Consts.js +146 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2020 Sven Mason <http://izara.io>
|
|
3
|
+
|
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
|
5
|
+
it under the terms of the GNU Affero General Public License as
|
|
6
|
+
published by the Free Software Foundation, either version 3 of the
|
|
7
|
+
License, or (at your option) any later version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful,
|
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
GNU Affero General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
'use strict';
|
|
19
|
+
const path = require('path');
|
|
20
|
+
const fs = require('fs');
|
|
21
|
+
|
|
22
|
+
const { ACTIONS, HANDLER, STORAGE_TYPES } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
|
|
23
|
+
const { getGraphServiceNameFromGraphServerTagWithCache } = require('@izara_project/izara-core-library-service-schemas/src/ServiceConfig')
|
|
24
|
+
|
|
25
|
+
const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../MainLibs/src/Utils")
|
|
26
|
+
const { DEFAULT_HANDLER_PER_ACTION, createIamRole, resourceNames, RESOURCE_CLASSES, DEFAULT_LAMBDA_ROLE_PER_ACTION, SOURCE_PATH, externalResourceName, } = require("../../libs/Consts");
|
|
27
|
+
const templatePath = path.join(__dirname, "./template.ejs");
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
async function dataForGenerateLambdaRole(_izContext, allObjSchemas, srcPath) {
|
|
32
|
+
const externalLambdaIamRoleArray = [];
|
|
33
|
+
for (const objectSchema of allObjSchemas) {
|
|
34
|
+
|
|
35
|
+
// per action external lambda role
|
|
36
|
+
for (const action of Object.values(ACTIONS)) {
|
|
37
|
+
if (objectSchema.overWriteHandlers?.[action]) {
|
|
38
|
+
for (const handler of objectSchema.overWriteHandlers[action]) {
|
|
39
|
+
const externalLambdaIamRole = await externalLambdaIamRoleDataPerAction(_izContext, objectSchema, action, handler)
|
|
40
|
+
externalLambdaIamRole && externalLambdaIamRoleArray.push(externalLambdaIamRole);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
} else {
|
|
44
|
+
for (const handler of DEFAULT_HANDLER_PER_ACTION[action]) {
|
|
45
|
+
const externalLambdaIamRole = await externalLambdaIamRoleDataPerAction(_izContext, objectSchema, action, handler)
|
|
46
|
+
externalLambdaIamRole && externalLambdaIamRoleArray.push(externalLambdaIamRole);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// findData external lambda role
|
|
53
|
+
|
|
54
|
+
// processLogical
|
|
55
|
+
|
|
56
|
+
// updateRelationship external lambda role
|
|
57
|
+
// updateRelationshipComplete external lambda role
|
|
58
|
+
|
|
59
|
+
// ... another external lambda role data
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
console.log("createSourceArrayIamRole", (externalLambdaIamRoleArray))
|
|
63
|
+
// return externalLambdaIamRoleArray
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
templatePath: templatePath,
|
|
67
|
+
templateData: { datas: externalLambdaIamRoleArray },
|
|
68
|
+
setting: {
|
|
69
|
+
savePath: path.join(srcPath, SOURCE_PATH.externalService),
|
|
70
|
+
saveFileName: "generatedServiceConfig",
|
|
71
|
+
fileExtension: '.js',
|
|
72
|
+
isAppend: false
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async function externalLambdaIamRoleDataPerAction(_izContext, objectSchema, action, handler) {
|
|
77
|
+
|
|
78
|
+
const objectType = objectSchema.objectType;
|
|
79
|
+
const additionalResourcePermission = [];
|
|
80
|
+
// let functionNameArray = [];
|
|
81
|
+
const graphServiceNames = [];
|
|
82
|
+
for (const storgaeResource of Object.values(objectSchema.storageResources)) {
|
|
83
|
+
if (storgaeResource.storageType === STORAGE_TYPES.graph) {
|
|
84
|
+
// console.log("graphServerTag", storgaeResource.graphServerTag)
|
|
85
|
+
let getGraphServiceName = await getGraphServiceNameFromGraphServerTagWithCache(_izContext, storgaeResource.graphServerTag)
|
|
86
|
+
if (!graphServiceNames.includes(getGraphServiceName)) {
|
|
87
|
+
graphServiceNames.push(getGraphServiceName)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
let functionName = upperCase(objectType) + upperCase(action) + upperCase(handler);
|
|
93
|
+
|
|
94
|
+
if (action === ACTIONS.get) {
|
|
95
|
+
// create functionName
|
|
96
|
+
// functionNameArray.push(functionName)
|
|
97
|
+
// create additionalResourcePermission
|
|
98
|
+
additionalResourcePermission.push(
|
|
99
|
+
createIamRole(
|
|
100
|
+
{ [RESOURCE_CLASSES.lambda]: ["InvokeFunction"] },
|
|
101
|
+
graphServiceNames.map(graphServiceName =>
|
|
102
|
+
externalResourceName(RESOURCE_CLASSES.lambda, "GetNodeHdrInv", graphServiceName)
|
|
103
|
+
)
|
|
104
|
+
)
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
// }else if (action === ACTIONS.create) {
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
// } else if (action === ACTIONS.update) {
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
// } else if (action === ACTIONS.delete) {
|
|
114
|
+
|
|
115
|
+
} else {
|
|
116
|
+
return
|
|
117
|
+
// throw Error("invalid action")
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
console.log("additionalResourcePermission:", (additionalResourcePermission))
|
|
121
|
+
|
|
122
|
+
return {
|
|
123
|
+
functionName: functionName,
|
|
124
|
+
action: action,
|
|
125
|
+
additionalResourcePermission
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
module.exports = dataForGenerateLambdaRole;
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
// for (const action of Object.values(ACTIONS)) {
|
|
135
|
+
// if (objectSchema.overWriteHandlers?.[action]) {
|
|
136
|
+
// // create template data
|
|
137
|
+
// // const createSourceParam = createParamForCreateSource(objectSchema, action, savePath)
|
|
138
|
+
// // createSourceArray.push(createSourceParam)
|
|
139
|
+
// } else {
|
|
140
|
+
// // if not have overWriteHander of action will use default handler
|
|
141
|
+
// const defaultHandler = DEFAULT_HANDLER_PER_ACTION[action]
|
|
142
|
+
|
|
143
|
+
// // const createSourceParam = createParamForCreateSource(objectSchema, action, savePath)
|
|
144
|
+
// // createSourceArray.push(createSourceParam)
|
|
145
|
+
|
|
146
|
+
// }
|
|
147
|
+
// }
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2020 Sven Mason <http://izara.io>
|
|
3
|
+
|
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
|
5
|
+
it under the terms of the GNU Affero General Public License as
|
|
6
|
+
published by the Free Software Foundation, either version 3 of the
|
|
7
|
+
License, or (at your option) any later version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful,
|
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
GNU Affero General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
'use strict';
|
|
19
|
+
|
|
20
|
+
const Logger = require('@izara_project/izara-core-library-logger')
|
|
21
|
+
const izaraShared = require('@izara_project/izara-shared')
|
|
22
|
+
const dynamodbSharedLib = izaraShared.dynamodbSharedLib
|
|
23
|
+
const lambdaSharedLib = izaraShared.lambdaSharedLib
|
|
24
|
+
const snsSharedLib = izaraShared.snsSharedLib
|
|
25
|
+
const initialSetupConfig = require('../../config/Config') // config external serviceName
|
|
26
|
+
const basicNodeSchemaLib = require('@izara_project/izara-attribute-tree').basicNodeSchemaLib
|
|
27
|
+
|
|
28
|
+
module.exports.generatedLambdaRole = [ <%_ datas.forEach((data,dataIndex) => { %>
|
|
29
|
+
{
|
|
30
|
+
functionName: "<%- data.functionName %>",
|
|
31
|
+
statement: [
|
|
32
|
+
{
|
|
33
|
+
"Sid": "<%- data.functionName %>Test<%- dataIndex %>",
|
|
34
|
+
"Effect": <%_ data.additionalResourcePermission.forEach(resourcePermission => { _%>
|
|
35
|
+
"<%- resourcePermission.effect %>",
|
|
36
|
+
"Action": <%_ Object.keys(resourcePermission.action).forEach(resourcePerAction => { _%>
|
|
37
|
+
<%_ resourcePermission.action[resourcePerAction].forEach(permission => { _%>
|
|
38
|
+
[
|
|
39
|
+
"<%- resourcePerAction %>:<%- permission %>",
|
|
40
|
+
],
|
|
41
|
+
"Resource": [
|
|
42
|
+
<%_ resourcePermission.resource.forEach(resource => { _%>
|
|
43
|
+
`<%- resource _%>`,
|
|
44
|
+
<%_ }) _%>
|
|
45
|
+
]
|
|
46
|
+
<%_ }) _%>
|
|
47
|
+
<%_ }) _%>
|
|
48
|
+
<%_ }) _%>
|
|
49
|
+
}
|
|
50
|
+
]
|
|
51
|
+
}, <%_ }) -%>
|
|
52
|
+
]
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2020 Sven Mason <http://izara.io>
|
|
3
|
+
|
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
|
5
|
+
it under the terms of the GNU Affero General Public License as
|
|
6
|
+
published by the Free Software Foundation, either version 3 of the
|
|
7
|
+
License, or (at your option) any later version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful,
|
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
GNU Affero General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
'use strict';
|
|
19
|
+
const path = require('path');
|
|
20
|
+
const fs = require('fs');
|
|
21
|
+
|
|
22
|
+
const { ACTIONS, HANDLER, STORAGE_TYPES } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
|
|
23
|
+
|
|
24
|
+
const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../MainLibs/src/Utils")
|
|
25
|
+
const { DEFAULT_HANDLER_PER_ACTION, createIamRole, resourceNames, RESOURCE_CLASSES, DEFAULT_LAMBDA_ROLE_PER_ACTION, SOURCE_PATH } = require("../../libs/Consts");
|
|
26
|
+
|
|
27
|
+
const templatePath = path.join(__dirname, "./template.ejs");
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
// not done yet wait for comfirmation
|
|
File without changes
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
|
|
2
|
+
//generateSnsSubscriptions
|
|
3
|
+
module.exports.generatedSnsSubscription = [
|
|
4
|
+
{
|
|
5
|
+
serviceName: "editHere.editHere",
|
|
6
|
+
topicName: "editHere",
|
|
7
|
+
sqsEndpoint: "editHere"
|
|
8
|
+
},
|
|
9
|
+
// {
|
|
10
|
+
// serviceName: initialSetupConfig.serviceNameGraphHandler, // external service name
|
|
11
|
+
// topicName: "OutCreateNode", // sns of external service
|
|
12
|
+
// sqsEndpoint: "AucCreateCompleteHdrSqs" // sqs inside this service
|
|
13
|
+
// },
|
|
14
|
+
]
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2020 Sven Mason <http://izara.io>
|
|
3
|
+
|
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
|
5
|
+
it under the terms of the GNU Affero General Public License as
|
|
6
|
+
published by the Free Software Foundation, either version 3 of the
|
|
7
|
+
License, or (at your option) any later version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful,
|
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
GNU Affero General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
'use strict';
|
|
19
|
+
|
|
20
|
+
const {
|
|
21
|
+
HANDLER,
|
|
22
|
+
ACTIONS
|
|
23
|
+
} = require('@izara_project/izara-core-library-service-schemas/src/Consts');
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
const DEFAULT_HANDLER_PER_ACTION = {
|
|
27
|
+
[ACTIONS.create]: [HANDLER.hdrApi, HANDLER.hdrSqs],
|
|
28
|
+
[ACTIONS.update]: [HANDLER.hdrApi, HANDLER.hdrSqs],
|
|
29
|
+
[ACTIONS.get]: [HANDLER.hdrApi, HANDLER.hdrInv],
|
|
30
|
+
[ACTIONS.delete]: [HANDLER.hdrApi, HANDLER.hdrSqs]
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const RESOURCE_CLASSES = {
|
|
34
|
+
sqs: 'sqs',
|
|
35
|
+
s3: 's3',
|
|
36
|
+
dynamoDbTable: 'dynamodb',
|
|
37
|
+
sns: "SNS",
|
|
38
|
+
lambda: "lambda"
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
function resourceNames(resourceClass, resourceName) {
|
|
43
|
+
return {
|
|
44
|
+
[RESOURCE_CLASSES.sqs]: "arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}" + resourceName,
|
|
45
|
+
[RESOURCE_CLASSES.s3]: "arn:aws:s3:::" + resourceName,
|
|
46
|
+
[RESOURCE_CLASSES.dynamoDbTable]: "arn:aws:dynamodb:${self:custom.iz_region}:${self:custom.iz_accountId}:table/${self:custom.iz_resourcePrefix}" + resourceName,
|
|
47
|
+
[RESOURCE_CLASSES.sns]: "arn:aws:sns:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}" + resourceName,
|
|
48
|
+
[RESOURCE_CLASSES.lambda]: "arn:aws:lambda:${self:custom.iz_region}:${self:custom.iz_accountId}:function:" + resourceName
|
|
49
|
+
}[resourceClass];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
function createIamRole(action, resource = [], effect = "Allow") {
|
|
54
|
+
for (const resourceAction in action) {
|
|
55
|
+
if (typeof (action[resourceAction]) === 'string') {
|
|
56
|
+
action[resourceAction] = [action[resourceAction]]
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (!Array.isArray(action[resourceAction])) {
|
|
60
|
+
throw new Error(`resourceAction:${resourceAction} should be string or array`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
effect,
|
|
66
|
+
action,
|
|
67
|
+
resource
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
// relative with ./app/src
|
|
73
|
+
const SOURCE_PATH = {
|
|
74
|
+
appYaml: `../sls_yaml/generatedCode/source/`,
|
|
75
|
+
resourceYaml: `../../resource/sls_yaml/generatedCode/source/`,
|
|
76
|
+
lambdaPerObjectTypePath: `/generatedCode/lambdaPerObjectType/source/`,
|
|
77
|
+
lamdaPerCombindActionPath: `/generatedCode/lamdaPerCombindAction/source/`,
|
|
78
|
+
externalService: '../initial_setup/generatedCode/source/',
|
|
79
|
+
lambdaPerAction: '../src//generatedCode/perAction/source/',
|
|
80
|
+
resourceLocation: 'src/generatedCode/perAction/source/',
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
const DEFAULT_LAMBDA_ROLE_PER_ACTION = {
|
|
85
|
+
[ACTIONS.create]: {
|
|
86
|
+
dynamoDbPermission: 'PutItem',
|
|
87
|
+
httpMethod: 'put',
|
|
88
|
+
},
|
|
89
|
+
[ACTIONS.update]: {
|
|
90
|
+
dynamoDbPermission: 'UpdateItem',
|
|
91
|
+
httpMethod: 'post',
|
|
92
|
+
},
|
|
93
|
+
[ACTIONS.get]: {
|
|
94
|
+
dynamoDbPermission: 'GetItem',
|
|
95
|
+
httpMethod: 'post',
|
|
96
|
+
},
|
|
97
|
+
[ACTIONS.delete]: {
|
|
98
|
+
dynamoDbPermission: 'DeleteItem',
|
|
99
|
+
httpMethod: 'delete',
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const SQS_RESOURCE = {
|
|
104
|
+
sendMessage: "SendMessage",
|
|
105
|
+
recieveMessage: "RecieveMessage",
|
|
106
|
+
deleteMessage: "DeleteMessage",
|
|
107
|
+
getQueueAttributes: "GetQueueAttributes"
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function externalResourceName(resourceClass, functionName, serviceName) {
|
|
111
|
+
return {
|
|
112
|
+
[RESOURCE_CLASSES.dynamoDbTable]: "arn:aws:dynamodb:${process.env.iz_region}:${process.env.iz_accountId}:table/${dynamoSharedLib.tableName(" + `"${functionName}" ,"${serviceName}")}`,
|
|
113
|
+
[RESOURCE_CLASSES.lambda]: "arn:aws:lambda:${process.env.iz_region}:${process.env.iz_accountId}:function:${lambdaSharedLib.lambdaFunctionName(" + `"${functionName}" ,"${serviceName}")}`,
|
|
114
|
+
[RESOURCE_CLASSES.sns]: `snsSharedLib.snsTopicArn("${functionName}" , "${serviceName}")`,
|
|
115
|
+
}[resourceClass]
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const FUNCTION_PER_ACTION = {
|
|
119
|
+
[ACTIONS.create]: "InCreateNode",
|
|
120
|
+
[ACTIONS.update]: "InCreateVersionedData",
|
|
121
|
+
[ACTIONS.get]: "GetNodeHdrInv",
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const DEFAULT_EXTERNAL_IAM_ROLE_PER_ACTION = {
|
|
125
|
+
[ACTIONS.create]: "InCreateNode",
|
|
126
|
+
[ACTIONS.update]: "InCreateVersionedData",
|
|
127
|
+
[ACTIONS.get]: {
|
|
128
|
+
[RESOURCE_CLASSES.lambda]: ["GetNodeHdrInv"],
|
|
129
|
+
},
|
|
130
|
+
[ACTIONS.delete]: "GetNodeHdrInv",
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
module.exports = {
|
|
135
|
+
ACTIONS,
|
|
136
|
+
DEFAULT_HANDLER_PER_ACTION,
|
|
137
|
+
RESOURCE_CLASSES,
|
|
138
|
+
resourceNames,
|
|
139
|
+
createIamRole,
|
|
140
|
+
SOURCE_PATH,
|
|
141
|
+
DEFAULT_LAMBDA_ROLE_PER_ACTION,
|
|
142
|
+
SQS_RESOURCE,
|
|
143
|
+
HANDLER,
|
|
144
|
+
externalResourceName,
|
|
145
|
+
FUNCTION_PER_ACTION
|
|
146
|
+
}
|