@izara_project/izara-market-library-service-schemas 1.0.2 → 1.0.4
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/package.json +5 -5
- package/src/GenerateCodeLibs/src/Consts.js +40 -0
- package/src/SourceManager/src/CreateSource.js +0 -1
- package/src/SourceManager/src/Utils.js +15 -1
- 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 +180 -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/{PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Template/HdrInv.exampleData.js → FunctionYaml/HdrInv/example req.js } +3 -3
- package/src/TemplateManager/src/FunctionYaml/HdrInv/request.json +14 -0
- package/src/TemplateManager/src/{PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Template/HdrInv.ejs → FunctionYaml/HdrInv/template.ejs} +5 -5
- package/src/TemplateManager/src/FunctionYaml/HdrSqs/data.js +182 -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 +175 -15
- 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/dynamodb/awaitingMultipleStepData.js +98 -0
- package/src/TemplateManager/src/{MainResourcesYaml/TemplateAndData/DynamoDbMain/Data/MainDynamoDbYamlData.js → ResourceYaml/dynamodb/mainResourcePerObjectSchemaData.js} +66 -46
- package/src/TemplateManager/src/ResourceYaml/dynamodb/processLogicalAndFindData.js +103 -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 +43 -0
- package/src/TemplateManager/src/ResourceYaml/sns-out/data.js +89 -0
- package/src/TemplateManager/src/ResourceYaml/sns-out/request.json +3 -0
- package/src/TemplateManager/src/ResourceYaml/sns-out/template.ejs +10 -0
- package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/functionYaml/data.js +151 -0
- package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/functionYaml/request.json +3 -0
- package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/functionYaml/template.ejs +33 -0
- package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/handler/HdrSqs/data.js +76 -0
- package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/handler/HdrSqs/template.ejs +127 -0
- package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/mainFunction/data.js +55 -0
- package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/mainFunction/request.json +1 -0
- package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/mainFunction/template.ejs +140 -0
- package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/sns-in-sqs/data.js +75 -0
- package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/sns-in-sqs/request.json +3 -0
- package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/sns-in-sqs/template.ejs +45 -0
- package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/sns-out/data.js +70 -0
- package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/sns-out/request.json +3 -0
- package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrApi/data.js +127 -0
- package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrApi/template.ejs +33 -0
- package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrDsq/data.js +148 -0
- package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrInv/data.js +125 -0
- package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrSqs/data.js +148 -0
- package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/mainFunction/data.js +80 -0
- package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/mainFunction/request.json +1 -0
- package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/mainFunction/template.ejs +324 -0
- package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrApi/data.js +72 -0
- package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrApi/request.json +7 -0
- package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrApi/template.ejs +120 -0
- package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrDsq/data.js +73 -0
- package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrDsq/request.json +7 -0
- package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrDsq/template.ejs +167 -0
- package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrInv/data.js +73 -0
- package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrInv/request.json +5 -0
- package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrInv/template.ejs +126 -0
- package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrSqs/data.js +73 -0
- package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrSqs/request.json +7 -0
- package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrSqs/template.ejs +146 -0
- package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/request.json +31 -0
- package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/sns-in-sqs/data.js +91 -0
- package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/sns-in-sqs/request.json +3 -0
- package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/sns-out/data.js +70 -0
- package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/sns-out/request.json +3 -0
- package/src/TemplateManager/src/externalService/LambdaRole/data.js +193 -0
- package/src/TemplateManager/src/externalService/LambdaRole/request.json +18 -0
- package/src/TemplateManager/src/externalService/LambdaRole/template.ejs +56 -0
- package/src/TemplateManager/src/externalService/SnsTopicSubscriotions/data.js +96 -0
- package/src/TemplateManager/src/externalService/SnsTopicSubscriotions/request.json +12 -0
- package/src/TemplateManager/src/externalService/SnsTopicSubscriotions/template.ejs +10 -0
- package/src/TemplateManager/src/libs/Consts.js +32 -3
- package/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Template/DynamoDb.ejs +0 -31
- package/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Template/DynamoDb.exampleData.js +0 -12
- package/src/TemplateManager/src/PerActionEndpoint/CreateSourceData.js +0 -131
- package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/MainFunction/MainFunctionTemplate/Create.js +0 -18
- package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/MainFunction/MainFunctionTemplate/Delete.js +0 -18
- package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/MainFunction/MainFunctionTemplate/Get.js +0 -18
- package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/MainFunction/MainFunctionTemplate/Update.js +0 -18
- package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Data/LambdaYamlData.js +0 -166
- package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Template/HdrSqs.ejs +0 -0
- /package/src/TemplateManager/src/{MainResourcesYaml → ResourceYaml}/CreateSourceData.js +0 -0
- /package/src/TemplateManager/src/{PerActionEndpoint/DataPerActionEndpoint.js → UpdateRelationshipSchema/updateRalationshipComplete/handler/HdrSqs/request.json} +0 -0
- /package/src/TemplateManager/src/{PerActionEndpoint/TemplateAndData/Handler/Handler.js → UpdateRelationshipSchema/updateRelationship/functionYaml/HdrApi/request.json} +0 -0
- /package/src/TemplateManager/src/{PerActionEndpoint/TemplateAndData/MainFunction/MainFunctionTemplateData.js → UpdateRelationshipSchema/updateRelationship/functionYaml/HdrDsq/request.json} +0 -0
- /package/src/TemplateManager/src/{PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Template/HdrApi.ejs → UpdateRelationshipSchema/updateRelationship/functionYaml/HdrInv/request.json} +0 -0
- /package/src/TemplateManager/src/{PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Template/HdrDsq.ejs → UpdateRelationshipSchema/updateRelationship/functionYaml/HdrSqs/request.json} +0 -0
|
@@ -0,0 +1,169 @@
|
|
|
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
|
+
function defaultIamRolePerAction() {
|
|
30
|
+
|
|
31
|
+
let defaultIamRole = [];
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
defaultIamRole.push(
|
|
35
|
+
createIamRole(
|
|
36
|
+
{
|
|
37
|
+
[RESOURCE_CLASSES.s3]: ["GetObject", "GetObjectVersion"],
|
|
38
|
+
},
|
|
39
|
+
[
|
|
40
|
+
resourceNames(RESOURCE_CLASSES.s3, "object-schema/perServiceSchemas/*"),
|
|
41
|
+
resourceNames(RESOURCE_CLASSES.s3, "object-schema/serviceConfig/ServiceNameConfig.json"),
|
|
42
|
+
resourceNames(RESOURCE_CLASSES.s3, "object-schema/serviceConfig/GraphServerTags.json"),
|
|
43
|
+
]
|
|
44
|
+
)
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
defaultIamRole.push(
|
|
48
|
+
createIamRole(
|
|
49
|
+
{ [RESOURCE_CLASSES.s3]: ["ListBucket"] },
|
|
50
|
+
[
|
|
51
|
+
resourceNames(RESOURCE_CLASSES.s3, "object-schema"),
|
|
52
|
+
]
|
|
53
|
+
)
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
return defaultIamRole
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* receive objectSchema
|
|
61
|
+
* create data for hdrInv template
|
|
62
|
+
*
|
|
63
|
+
* @param {Object} objectSchema
|
|
64
|
+
* @return {{ templatePath, templateData, setting } }
|
|
65
|
+
*/
|
|
66
|
+
function data(_izContext, objectSchema, srcPath) {
|
|
67
|
+
|
|
68
|
+
// const shortNamePath = path.join(srcPath, "./schemas/ShortNameObjectType.js");
|
|
69
|
+
|
|
70
|
+
// const shortName = fs.existsSync(shortNamePath) ? require(shortNamePath) : {};
|
|
71
|
+
|
|
72
|
+
// console.log("objectSchema in mainFunction: ", objectSchema)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
let createSourceArray = [];
|
|
76
|
+
|
|
77
|
+
for (const action of Object.values(ACTIONS)) {
|
|
78
|
+
if (objectSchema.overWriteHandlers?.[action]) {
|
|
79
|
+
// if have overWriteHander of action check hdrInv inside
|
|
80
|
+
if (objectSchema.overWriteHandlers[action].includes(HANDLER.hdrInv)) {
|
|
81
|
+
// create template data
|
|
82
|
+
const createSourceParam = createParamForCreateSource(objectSchema, action, srcPath)
|
|
83
|
+
createSourceArray.push(createSourceParam)
|
|
84
|
+
}
|
|
85
|
+
} else {
|
|
86
|
+
// if not have overWriteHander of action will use default handler
|
|
87
|
+
const defaultHandler = DEFAULT_HANDLER_PER_ACTION[action]
|
|
88
|
+
if (defaultHandler.includes(HANDLER.hdrInv)) {
|
|
89
|
+
// create template data and object for create source
|
|
90
|
+
const createSourceParam = createParamForCreateSource(objectSchema, action, srcPath)
|
|
91
|
+
createSourceArray.push(createSourceParam)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return createSourceArray;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
function createParamForCreateSource(objectSchema, action, srcPath) {
|
|
101
|
+
let objectType = objectSchema.objectType;
|
|
102
|
+
let actionHandler = action;
|
|
103
|
+
let functionName = objectType + upperCase(actionHandler);
|
|
104
|
+
let additionalResourcePermission = defaultIamRolePerAction();
|
|
105
|
+
let tableForGetItem = [];
|
|
106
|
+
|
|
107
|
+
let hasGraphStorage = false;
|
|
108
|
+
for (let storageResource of Object.values(objectSchema.storageResources)) {
|
|
109
|
+
if (storageResource.storageType === STORAGE_TYPES.dynamoDB) {
|
|
110
|
+
// add IamRole for dynamodb depend on tableName in storageResources of objectSchema
|
|
111
|
+
tableForGetItem.push(resourceNames(RESOURCE_CLASSES.dynamoDbTable, storageResource.tableName));
|
|
112
|
+
|
|
113
|
+
} else if (storageResource.storageType === STORAGE_TYPES.graph) {
|
|
114
|
+
// find graph serviceName from graphServerTag or *GetNodeHdrInv ?
|
|
115
|
+
|
|
116
|
+
if (hasGraphStorage) {
|
|
117
|
+
continue;
|
|
118
|
+
} else {
|
|
119
|
+
hasGraphStorage = true;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (tableForGetItem.length) {
|
|
125
|
+
additionalResourcePermission.push(
|
|
126
|
+
createIamRole(
|
|
127
|
+
{ [RESOURCE_CLASSES.dynamoDbTable]: [DEFAULT_LAMBDA_ROLE_PER_ACTION[action].dynamoDbPermission] },
|
|
128
|
+
tableForGetItem
|
|
129
|
+
)
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
return {
|
|
136
|
+
templatePath: templatePath,
|
|
137
|
+
templateData: {
|
|
138
|
+
functionName: functionName,
|
|
139
|
+
resourceLocation: SOURCE_PATH.resourceLocationPerAction,
|
|
140
|
+
handlerType: "HdrInv",
|
|
141
|
+
additionalResourcePermission
|
|
142
|
+
},
|
|
143
|
+
setting: {
|
|
144
|
+
savePath: path.join(srcPath, SOURCE_PATH.appYaml),
|
|
145
|
+
saveFileName: `per-action-function`,
|
|
146
|
+
fileExtension: '.yml',
|
|
147
|
+
isAppend: true
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
// [
|
|
156
|
+
// {
|
|
157
|
+
// templatePath: '/home/toughnut/BasProgram/empty-service-template/app/node_modules/@izara_project/izara-market-library-service-schemas/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Template/DynamoDb.ejs',
|
|
158
|
+
// templateData: { tableName: 'ObjectTypeSingle', attributes: [Array] },
|
|
159
|
+
// setting: {
|
|
160
|
+
// savePath: '/generatedCode/source/',
|
|
161
|
+
// saveFileName: 'ObjectTypeGet',
|
|
162
|
+
// fileExtension: '.js',
|
|
163
|
+
// isAppend: false
|
|
164
|
+
// }
|
|
165
|
+
// }
|
|
166
|
+
// ]
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
module.exports = data;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// example template data
|
|
2
2
|
const templateData = {
|
|
3
|
-
|
|
3
|
+
functionName: "xx",
|
|
4
4
|
handlerType: "xx",
|
|
5
5
|
resourceLocation: "xx",
|
|
6
6
|
additionalResourcePermission: [
|
|
7
7
|
{
|
|
8
|
-
effect: "
|
|
8
|
+
effect: "Allow",
|
|
9
9
|
action: {
|
|
10
|
-
|
|
10
|
+
dynamodb: ["GetItem"],
|
|
11
11
|
},
|
|
12
12
|
resource: ["aws:sqs", "..."]
|
|
13
13
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<%_ const join = require('path').join; _%>
|
|
2
|
-
<%- firstLetterUpperCase(
|
|
3
|
-
handler: <%- join(resourceLocation, `${firstLetterUpperCase(
|
|
4
|
-
name: ${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(
|
|
2
|
+
<%- firstLetterUpperCase(functionName) %><%- firstLetterUpperCase(handlerType) %>:
|
|
3
|
+
handler: <%- join(resourceLocation, `${firstLetterUpperCase(functionName)}_${firstLetterUpperCase(handlerType)}.main`)%>
|
|
4
|
+
name: ${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionName) %><%- firstLetterUpperCase(handlerType) %>
|
|
5
5
|
iamRoleStatements:
|
|
6
6
|
<%_ additionalResourcePermission.forEach(resourcePermission => { _%>
|
|
7
7
|
- Effect: <%- resourcePermission.effect %>
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
- <%- resource %>
|
|
17
17
|
<%_ }) _%>
|
|
18
18
|
<%_}) _%>
|
|
19
|
-
#<#<%-
|
|
20
|
-
#<#/<%-
|
|
19
|
+
#<#<%- functionName %><%- handlerType %>IamRole#>
|
|
20
|
+
#<#/<%- functionName %><%- handlerType %>IamRole#>
|
|
21
21
|
<%_ function firstLetterUpperCase(text){
|
|
22
22
|
return text.charAt(0).toUpperCase() + text.slice(1)
|
|
23
23
|
} _%>
|
|
@@ -0,0 +1,182 @@
|
|
|
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, SQS_RESOURCE, SOURCE_PATH } = require("../../libs/Consts");
|
|
26
|
+
|
|
27
|
+
const templatePath = path.join(__dirname, "./template.ejs")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
function defaultIamRolePerAction() {
|
|
31
|
+
|
|
32
|
+
let defaultIamRole = [];
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
defaultIamRole.push(
|
|
36
|
+
createIamRole(
|
|
37
|
+
{
|
|
38
|
+
[RESOURCE_CLASSES.s3]: ["GetObject", "GetObjectVersion"],
|
|
39
|
+
},
|
|
40
|
+
[
|
|
41
|
+
resourceNames(RESOURCE_CLASSES.s3, "object-schema/perServiceSchemas/*"),
|
|
42
|
+
resourceNames(RESOURCE_CLASSES.s3, "object-schema/serviceConfig/ServiceNameConfig.json"),
|
|
43
|
+
resourceNames(RESOURCE_CLASSES.s3, "object-schema/serviceConfig/GraphServerTags.json"),
|
|
44
|
+
]
|
|
45
|
+
)
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
defaultIamRole.push(
|
|
49
|
+
createIamRole(
|
|
50
|
+
{ [RESOURCE_CLASSES.s3]: ["ListBucket"] },
|
|
51
|
+
[
|
|
52
|
+
resourceNames(RESOURCE_CLASSES.s3, "object-schema"),
|
|
53
|
+
]
|
|
54
|
+
)
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
return defaultIamRole
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* receive objectSchema
|
|
62
|
+
* create data for hdrInv template
|
|
63
|
+
*
|
|
64
|
+
* @param {Object} objectSchema
|
|
65
|
+
* @return {{ templatePath, templateData, setting } }
|
|
66
|
+
*/
|
|
67
|
+
function data(_izContext, objectSchema, srcPath) {
|
|
68
|
+
let createSourceArray = [];
|
|
69
|
+
for (const action of Object.values(ACTIONS)) {
|
|
70
|
+
if (objectSchema.overWriteHandlers?.[action]) {
|
|
71
|
+
// if have overWriteHander of action check hdrApi inside
|
|
72
|
+
if (objectSchema.overWriteHandlers[action].includes(HANDLER.hdrSqs)) {
|
|
73
|
+
// create template data
|
|
74
|
+
const createSourceParam = createParamForCreateSource(objectSchema, action, srcPath)
|
|
75
|
+
createSourceArray.push(createSourceParam)
|
|
76
|
+
}
|
|
77
|
+
} else {
|
|
78
|
+
// if not have overWriteHander of action will use default handler
|
|
79
|
+
const defaultHandler = DEFAULT_HANDLER_PER_ACTION[action]
|
|
80
|
+
if (defaultHandler.includes(HANDLER.hdrSqs)) {
|
|
81
|
+
// create template data and object for create source
|
|
82
|
+
const createSourceParam = createParamForCreateSource(objectSchema, action, srcPath)
|
|
83
|
+
createSourceArray.push(createSourceParam)
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return createSourceArray;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
function createParamForCreateSource(objectSchema, action, srcPath) {
|
|
93
|
+
let objectType = objectSchema.objectType;
|
|
94
|
+
let actionHandler = action;
|
|
95
|
+
let functionName = objectType + upperCase(actionHandler);
|
|
96
|
+
let additionalResourcePermission = defaultIamRolePerAction();
|
|
97
|
+
let tableForGetItem = [];
|
|
98
|
+
let hasGraphStorage = false;
|
|
99
|
+
for (let storageResource of Object.values(objectSchema.storageResources)) {
|
|
100
|
+
if (storageResource.storageType === STORAGE_TYPES.dynamoDB) {
|
|
101
|
+
// add IamRole for dynamodb depend on tableName in storageResources of objectSchema
|
|
102
|
+
tableForGetItem.push(resourceNames(RESOURCE_CLASSES.dynamoDbTable, storageResource.tableName));
|
|
103
|
+
|
|
104
|
+
} else if (storageResource.storageType === STORAGE_TYPES.graph) {
|
|
105
|
+
// find graph serviceName from graphServerTag or *GetNodeHdrInv ?
|
|
106
|
+
|
|
107
|
+
if (hasGraphStorage) {
|
|
108
|
+
continue;
|
|
109
|
+
} else {
|
|
110
|
+
hasGraphStorage = true;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
if (tableForGetItem.length) {
|
|
118
|
+
additionalResourcePermission.push(
|
|
119
|
+
createIamRole(
|
|
120
|
+
{ [RESOURCE_CLASSES.dynamoDbTable]: [DEFAULT_LAMBDA_ROLE_PER_ACTION[action].dynamoDbPermission] },
|
|
121
|
+
tableForGetItem
|
|
122
|
+
)
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
additionalResourcePermission.push(
|
|
127
|
+
createIamRole({
|
|
128
|
+
[RESOURCE_CLASSES.sqs]:
|
|
129
|
+
[
|
|
130
|
+
SQS_RESOURCE.deleteMessage,
|
|
131
|
+
SQS_RESOURCE.getQueueAttributes,
|
|
132
|
+
SQS_RESOURCE.receiveMessage,
|
|
133
|
+
SQS_RESOURCE.sendMessage,
|
|
134
|
+
SQS_RESOURCE.deleteMessageBatch,
|
|
135
|
+
SQS_RESOURCE.getQueueUrl
|
|
136
|
+
], [RESOURCE_CLASSES.sns]: ["Publish", "Subscribe"]
|
|
137
|
+
}, [
|
|
138
|
+
resourceNames(RESOURCE_CLASSES.sqs, functionName + upperCase(HANDLER.hdrSqs)),
|
|
139
|
+
resourceNames(RESOURCE_CLASSES.sqs, functionName + upperCase(HANDLER.hdrSqs) + "DLQ"),
|
|
140
|
+
resourceNames(RESOURCE_CLASSES.sns, "In" + functionName),
|
|
141
|
+
resourceNames(RESOURCE_CLASSES.sns, "Out" + functionName)
|
|
142
|
+
]
|
|
143
|
+
)
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
// console.log("additionalResourcePermissionBeforeReturn", additionalResourcePermission)
|
|
147
|
+
return {
|
|
148
|
+
templatePath: templatePath,
|
|
149
|
+
templateData: {
|
|
150
|
+
functionName: functionName,
|
|
151
|
+
actionHandler: actionHandler,
|
|
152
|
+
resourceLocation: SOURCE_PATH.resourceLocationPerAction,
|
|
153
|
+
handlerType: "HdrSqs",
|
|
154
|
+
additionalResourcePermission
|
|
155
|
+
},
|
|
156
|
+
setting: {
|
|
157
|
+
savePath: path.join(srcPath, SOURCE_PATH.appYaml),
|
|
158
|
+
saveFileName: `per-action-function`,
|
|
159
|
+
fileExtension: '.yml',
|
|
160
|
+
isAppend: true
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
// [
|
|
169
|
+
// {
|
|
170
|
+
// templatePath: '/home/toughnut/BasProgram/empty-service-template/app/node_modules/@izara_project/izara-market-library-service-schemas/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Template/DynamoDb.ejs',
|
|
171
|
+
// templateData: { tableName: 'ObjectTypeSingle', attributes: [Array] },
|
|
172
|
+
// setting: {
|
|
173
|
+
// savePath: '/generatedCode/source/',
|
|
174
|
+
// saveFileName: 'ObjectTypeGet',
|
|
175
|
+
// fileExtension: '.js',
|
|
176
|
+
// isAppend: false
|
|
177
|
+
// }
|
|
178
|
+
// }
|
|
179
|
+
// ]
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
module.exports = data;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
<%_ const join = require('path').join; _%>
|
|
2
|
+
<%- firstLetterUpperCase(functionName) %><%- firstLetterUpperCase(handlerType) %>:
|
|
3
|
+
handler: <%- join(resourceLocation, `${firstLetterUpperCase(functionName)}_${firstLetterUpperCase(handlerType)}.main`)%>
|
|
4
|
+
name: ${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionName) %><%- firstLetterUpperCase(handlerType) %>
|
|
5
|
+
events:
|
|
6
|
+
- sqs:
|
|
7
|
+
arn: arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionName) %><%- firstLetterUpperCase(handlerType) %>
|
|
8
|
+
batchSize: 10
|
|
9
|
+
iamRoleStatements:
|
|
10
|
+
<%_ additionalResourcePermission.forEach(resourcePermission => { _%>
|
|
11
|
+
- Effect: <%- resourcePermission.effect %>
|
|
12
|
+
Action:
|
|
13
|
+
<%_ Object.keys(resourcePermission.action).forEach(resourcePerAction => { _%>
|
|
14
|
+
<%_ resourcePermission.action[resourcePerAction].forEach(permission => { _%>
|
|
15
|
+
- <%- resourcePerAction %>:<%- permission %>
|
|
16
|
+
<%_}) _%>
|
|
17
|
+
<%_ }) _%>
|
|
18
|
+
Resource:
|
|
19
|
+
<%_ resourcePermission.resource.forEach(resource => { _%>
|
|
20
|
+
- "<%- resource %>"
|
|
21
|
+
<%_ }) _%>
|
|
22
|
+
<%_}) _%>
|
|
23
|
+
#<#<%- functionName %><%- handlerType %>IamRole#>
|
|
24
|
+
#<#/<%- functionName %><%- handlerType %>IamRole#>
|
|
25
|
+
<%_ function firstLetterUpperCase(text){
|
|
26
|
+
return text.charAt(0).toUpperCase() + text.slice(1)
|
|
27
|
+
} _%>
|
|
28
|
+
<%_ function firstLetterLowerCase(str) {
|
|
29
|
+
return str.charAt(0).toLowerCase() + str.slice(1)
|
|
30
|
+
} _%>
|
|
@@ -0,0 +1,135 @@
|
|
|
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 join = require('path').join;
|
|
21
|
+
const { readFileSync } = require('fs');
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
const {
|
|
25
|
+
getAllLocalObjectSchemasWithHierarchy,
|
|
26
|
+
getAllLocalRelationshipSchemas
|
|
27
|
+
} = require('@izara_project/izara-core-library-service-schemas/src/GetObjectSchema');
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
const { createSource } = require("../../SourceManager/src/CreateSource");
|
|
32
|
+
const { deleteFileInDir } = require("../../SourceManager/src/Utils");
|
|
33
|
+
|
|
34
|
+
const perAction = require("./PerActionEndpoint/CreateSourceData");
|
|
35
|
+
|
|
36
|
+
const mainResources = require("./MainResourcesYaml/CreateSourceData");
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
*
|
|
41
|
+
* get template and send to
|
|
42
|
+
*
|
|
43
|
+
* @param {object} objSchemaPath
|
|
44
|
+
* @returns
|
|
45
|
+
*
|
|
46
|
+
* add another param
|
|
47
|
+
* {string[]} objectTypes
|
|
48
|
+
* {string[]} templates
|
|
49
|
+
* {string} saveFilePath
|
|
50
|
+
*/
|
|
51
|
+
async function generateCodeWithTemplate(_izContext, objSchemaPath) {
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
|
|
55
|
+
// point to app/src
|
|
56
|
+
let saveFilePath = join(objSchemaPath, `../`);
|
|
57
|
+
|
|
58
|
+
// define path for store yml file
|
|
59
|
+
const GENERATECODE_SOURCE_PATH = {
|
|
60
|
+
appYaml: join(saveFilePath, `../sls_yaml/generatedCode/source/`),
|
|
61
|
+
resourceYaml: join(saveFilePath, `../../resource/sls_yaml/generatedCode/source/`),
|
|
62
|
+
lambdaPerObjectTypePath: join(saveFilePath, `/generatedCode/lambdaPerObjectType/source/`), // test
|
|
63
|
+
lamdaPerCombindActionPath: join(saveFilePath, `/generatedCode/lamdaPerCombindAction/source/`), // test
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
// from app/src/shcemas
|
|
68
|
+
let allObjSchemas = await getAllLocalObjectSchemasWithHierarchy(_izContext, objSchemaPath);
|
|
69
|
+
|
|
70
|
+
const allObjectRelationships = await getAllLocalRelationshipSchemas(_izContext, objSchemaPath);
|
|
71
|
+
|
|
72
|
+
/*
|
|
73
|
+
Should we generateCode with objectSchema that not in hierarchy or not?
|
|
74
|
+
Should use objectSchema with hierarchy because we use storageResource of parent to create lambda iam role in .yml file
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
let createSourceParams = [];
|
|
78
|
+
|
|
79
|
+
for (const relTag in allObjectRelationships) {
|
|
80
|
+
const relTagData = allObjectRelationships[relTag];
|
|
81
|
+
|
|
82
|
+
// create main resource per relationshipSchema
|
|
83
|
+
const createSourceMainResourcesRelSchema = mainResources.createSourceDataRelSchema(_izContext, { [relTag]: relTagData }, saveFilePath);
|
|
84
|
+
console.log("createSourceMainResourcesRelSchema: ", createSourceMainResourcesRelSchema);
|
|
85
|
+
|
|
86
|
+
createSourceParams = createSourceParams.concat(createSourceMainResourcesRelSchema);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
//
|
|
91
|
+
for (let objectSchema of allObjSchemas.records) {
|
|
92
|
+
|
|
93
|
+
// create main resource per objectSchema
|
|
94
|
+
let createSourceMainResourcesObjectSchema = mainResources.createSourceDataObjectSchema(_izContext, objectSchema, saveFilePath);
|
|
95
|
+
// console.log("createSourceMainResourcesObjectSchema: ", createSourceMainResourcesObjectSchema);
|
|
96
|
+
|
|
97
|
+
// mainFunction, handlerFunction, resourceYaml per action
|
|
98
|
+
let createSourcePerAction = perAction.createSourceDataObjectSchema(_izContext, objectSchema, saveFilePath);
|
|
99
|
+
// console.log("createSourcePerAction: ", createSourcePerAction)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
// console.log("createSourceParams begore concat: ", createSourceParams);
|
|
104
|
+
|
|
105
|
+
createSourceParams = createSourceParams.concat([...createSourcePerAction, ...createSourceMainResourcesObjectSchema]);
|
|
106
|
+
|
|
107
|
+
// console.log("createSourceParams after concat: ", createSourceParams);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
// delete file .yml before start to prevent confilct of data
|
|
112
|
+
for (let folderPathToEmpty of Object.keys(GENERATECODE_SOURCE_PATH)) {
|
|
113
|
+
await deleteFileInDir(GENERATECODE_SOURCE_PATH[folderPathToEmpty]);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
// start create source
|
|
118
|
+
for (let { templatePath, templateData, setting } of createSourceParams) {
|
|
119
|
+
await createSource(
|
|
120
|
+
readFileSync(templatePath, 'utf8'),
|
|
121
|
+
templateData,
|
|
122
|
+
setting,
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
return "return values";
|
|
128
|
+
|
|
129
|
+
} catch (err) {
|
|
130
|
+
console.log('error templateManager: ', err);
|
|
131
|
+
throw (err);
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
module.exports = { generateCodeWithTemplate };
|