@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,178 @@
|
|
|
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
|
+
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
|
+
console.log("defaultIamRole Api", defaultIamRole)
|
|
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
|
+
let createSourceArray = [];
|
|
68
|
+
|
|
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.hdrDsq)) {
|
|
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.hdrDsq)) {
|
|
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
|
+
function createParamForCreateSource(objectSchema, action, srcPath) {
|
|
92
|
+
let objectType = objectSchema.objectType;
|
|
93
|
+
let actionHandler = action;
|
|
94
|
+
let functionName = objectType + upperCase(actionHandler);
|
|
95
|
+
|
|
96
|
+
let additionalResourcePermission = defaultIamRolePerAction();
|
|
97
|
+
let tableForGetItem = [];
|
|
98
|
+
|
|
99
|
+
let hasGraphStorage = false;
|
|
100
|
+
for (let storageResource of Object.values(objectSchema.storageResources)) {
|
|
101
|
+
if (storageResource.storageType === STORAGE_TYPES.dynamoDB) {
|
|
102
|
+
// add IamRole for dynamodb depend on tableName in storageResources of objectSchema
|
|
103
|
+
tableForGetItem.push(resourceNames(RESOURCE_CLASSES.dynamoDbTable, storageResource.tableName));
|
|
104
|
+
|
|
105
|
+
} else if (storageResource.storageType === STORAGE_TYPES.graph) {
|
|
106
|
+
// find graph serviceName from graphServerTag or *GetNodeHdrInv ?
|
|
107
|
+
|
|
108
|
+
if (hasGraphStorage) {
|
|
109
|
+
continue;
|
|
110
|
+
} else {
|
|
111
|
+
hasGraphStorage = true;
|
|
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.recieveMessage,
|
|
133
|
+
SQS_RESOURCE.sendMessage
|
|
134
|
+
]
|
|
135
|
+
}, [
|
|
136
|
+
resourceNames(RESOURCE_CLASSES.sqs, functionName + upperCase(HANDLER.hdrDsq)),
|
|
137
|
+
resourceNames(RESOURCE_CLASSES.sqs, functionName + upperCase(HANDLER.hdrDsq) + "DLQ")
|
|
138
|
+
]
|
|
139
|
+
)
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
return {
|
|
145
|
+
templatePath: templatePath,
|
|
146
|
+
templateData: {
|
|
147
|
+
functionName: functionName,
|
|
148
|
+
resourceLocation: SOURCE_PATH.resourceLocation,
|
|
149
|
+
handlerType: "HdrDsq",
|
|
150
|
+
additionalResourcePermission
|
|
151
|
+
},
|
|
152
|
+
setting: {
|
|
153
|
+
savePath: path.join(srcPath, SOURCE_PATH.appYaml),
|
|
154
|
+
saveFileName: `function`,
|
|
155
|
+
fileExtension: '.yml',
|
|
156
|
+
isAppend: true
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
// [
|
|
165
|
+
// {
|
|
166
|
+
// 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',
|
|
167
|
+
// templateData: { tableName: 'ObjectTypeSingle', attributes: [Array] },
|
|
168
|
+
// setting: {
|
|
169
|
+
// savePath: '/generatedCode/source/',
|
|
170
|
+
// saveFileName: 'ObjectTypeGet',
|
|
171
|
+
// fileExtension: '.js',
|
|
172
|
+
// isAppend: false
|
|
173
|
+
// }
|
|
174
|
+
// }
|
|
175
|
+
// ]
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
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,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.resourceLocation,
|
|
140
|
+
handlerType: "HdrInv",
|
|
141
|
+
additionalResourcePermission
|
|
142
|
+
},
|
|
143
|
+
setting: {
|
|
144
|
+
savePath: path.join(srcPath, SOURCE_PATH.appYaml),
|
|
145
|
+
saveFileName: `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;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// example template data
|
|
2
|
+
const templateData = {
|
|
3
|
+
functionName: "xx",
|
|
4
|
+
handlerType: "xx",
|
|
5
|
+
resourceLocation: "xx",
|
|
6
|
+
additionalResourcePermission: [
|
|
7
|
+
{
|
|
8
|
+
effect: "Allow",
|
|
9
|
+
action: {
|
|
10
|
+
dynamodb: ["GetItem"],
|
|
11
|
+
},
|
|
12
|
+
resource: ["aws:sqs", "..."]
|
|
13
|
+
}
|
|
14
|
+
]
|
|
15
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
iamRoleStatements:
|
|
6
|
+
<%_ additionalResourcePermission.forEach(resourcePermission => { _%>
|
|
7
|
+
- Effect: <%- resourcePermission.effect %>
|
|
8
|
+
Action:
|
|
9
|
+
<%_ Object.keys(resourcePermission.action).forEach(resourcePerAction => { _%>
|
|
10
|
+
<%_ resourcePermission.action[resourcePerAction].forEach(permission => { _%>
|
|
11
|
+
- <%- resourcePerAction %>:<%- permission %>
|
|
12
|
+
<%_}) _%>
|
|
13
|
+
<%_ }) _%>
|
|
14
|
+
Resource:
|
|
15
|
+
<%_ resourcePermission.resource.forEach(resource => { _%>
|
|
16
|
+
- <%- resource %>
|
|
17
|
+
<%_ }) _%>
|
|
18
|
+
<%_}) _%>
|
|
19
|
+
#<#<%- functionName %><%- handlerType %>IamRole#>
|
|
20
|
+
#<#/<%- functionName %><%- handlerType %>IamRole#>
|
|
21
|
+
<%_ function firstLetterUpperCase(text){
|
|
22
|
+
return text.charAt(0).toUpperCase() + text.slice(1)
|
|
23
|
+
} _%>
|
|
24
|
+
<%_ function firstLetterLowerCase(str) {
|
|
25
|
+
return str.charAt(0).toLowerCase() + str.slice(1)
|
|
26
|
+
} _%>
|
|
@@ -0,0 +1,184 @@
|
|
|
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.recieveMessage,
|
|
133
|
+
SQS_RESOURCE.sendMessage
|
|
134
|
+
]
|
|
135
|
+
}, [
|
|
136
|
+
resourceNames(RESOURCE_CLASSES.sqs, functionName + upperCase(HANDLER.hdrSqs)),
|
|
137
|
+
resourceNames(RESOURCE_CLASSES.sqs, functionName + upperCase(HANDLER.hdrSqs) + "DLQ")
|
|
138
|
+
]
|
|
139
|
+
)
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
additionalResourcePermission.push(
|
|
143
|
+
createIamRole({
|
|
144
|
+
[RESOURCE_CLASSES.sns]: ["Publish", "Subscribe"]
|
|
145
|
+
}, [resourceNames(RESOURCE_CLASSES.sns, functionName + upperCase(HANDLER.hdrSqs))])
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
console.log("additionalResourcePermissionBeforeReturn", additionalResourcePermission)
|
|
149
|
+
return {
|
|
150
|
+
templatePath: templatePath,
|
|
151
|
+
templateData: {
|
|
152
|
+
functionName: functionName,
|
|
153
|
+
actionHandler: actionHandler,
|
|
154
|
+
resourceLocation: SOURCE_PATH.resourceLocation,
|
|
155
|
+
handlerType: "HdrSqs",
|
|
156
|
+
additionalResourcePermission
|
|
157
|
+
},
|
|
158
|
+
setting: {
|
|
159
|
+
savePath: path.join(srcPath, SOURCE_PATH.appYaml),
|
|
160
|
+
saveFileName: `function`,
|
|
161
|
+
fileExtension: '.yml',
|
|
162
|
+
isAppend: true
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
// [
|
|
171
|
+
// {
|
|
172
|
+
// 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',
|
|
173
|
+
// templateData: { tableName: 'ObjectTypeSingle', attributes: [Array] },
|
|
174
|
+
// setting: {
|
|
175
|
+
// savePath: '/generatedCode/source/',
|
|
176
|
+
// saveFileName: 'ObjectTypeGet',
|
|
177
|
+
// fileExtension: '.js',
|
|
178
|
+
// isAppend: false
|
|
179
|
+
// }
|
|
180
|
+
// }
|
|
181
|
+
// ]
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
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
|
+
} _%>
|