@izara_project/izara-market-library-service-schemas 1.0.5 → 1.0.7
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 +2 -2
- package/src/GenerateCodeLibs/index.js +2 -1
- package/src/GenerateCodeLibs/src/Consts.js +12 -3
- package/src/GenerateCodeLibs/src/GenerateCodeLibs.js +232 -7
- package/src/GenerateCodeLibs/src/TranslateIdsLibs.js +89 -0
- package/src/MainLibs/src/Utils.js +10 -0
- package/src/TemplateManager/src/CreateRelationship/createRelationship/functionYaml/HdrApi/data.js +10 -2
- package/src/TemplateManager/src/CreateRelationship/createRelationship/functionYaml/HdrDsq/data.js +5 -4
- package/src/TemplateManager/src/CreateRelationship/createRelationship/functionYaml/HdrInv/data.js +11 -1
- package/src/TemplateManager/src/CreateRelationship/createRelationship/functionYaml/HdrSqs/data.js +4 -3
- package/src/TemplateManager/src/CreateRelationship/createRelationship/mainFunction/template.ejs +24 -22
- package/src/TemplateManager/src/CreateRelationship/createRelationship/perAction/HdrDsq/data.js +0 -1
- package/src/TemplateManager/src/CreateRelationship/createRelationship/perAction/HdrSqs/data.js +1 -1
- package/src/TemplateManager/src/CreateRelationship/createRelationship/sns-in-sqs/data.js +0 -2
- package/src/TemplateManager/src/CreateRelationship/createRelationshipComplete/functionYaml/data.js +2 -2
- package/src/TemplateManager/src/CreateRelationship/createRelationshipComplete/handler/HdrSqs/data.js +0 -1
- package/src/TemplateManager/src/CreateRelationship/createRelationshipComplete/sns-out/data.js +1 -1
- package/src/TemplateManager/src/FindData/FindDataYaml/data.js +188 -0
- package/src/TemplateManager/src/FindData/FindDataYaml/template.ejs +27 -0
- package/src/TemplateManager/src/FindData/GetByStorage/getByDynamo.ejs +53 -0
- package/src/TemplateManager/src/FindData/GetByStorage/getByGraph.ejs +99 -0
- package/src/TemplateManager/src/FindData/Handler/data.js +48 -0
- package/src/TemplateManager/src/FindData/Handler/template.ejs +140 -0
- package/src/TemplateManager/src/FindData/mainFunction/data.js +279 -0
- package/src/TemplateManager/src/FindData/mainFunction/template.ejs +158 -0
- package/src/TemplateManager/src/GenerateCode(Old).js +1 -1
- package/src/TemplateManager/src/GenerateCode.js +163 -42
- package/src/TemplateManager/src/OutPerActionComplete/OutCreateComplete/functionYaml/data.js +98 -0
- package/src/TemplateManager/src/OutPerActionComplete/OutCreateComplete/functionYaml/template.ejs +33 -0
- package/src/TemplateManager/src/OutPerActionComplete/OutCreateComplete/handler/data.js +59 -0
- package/src/TemplateManager/src/OutPerActionComplete/OutCreateComplete/handler/template.ejs +129 -0
- package/src/TemplateManager/src/OutPerActionComplete/OutCreateComplete/mainFunction/createObjectComplete_main.js +172 -0
- package/src/TemplateManager/src/OutPerActionComplete/OutCreateComplete/mainFunction/data.js +53 -0
- package/src/TemplateManager/src/OutPerActionComplete/OutCreateComplete/mainFunction/template.ejs +172 -0
- package/src/TemplateManager/src/OutPerActionComplete/OutCreateComplete/sns-in-sqs/data.js +58 -0
- package/src/TemplateManager/src/OutPerActionComplete/OutCreateComplete/sns-in-sqs/template.ejs +47 -0
- package/src/TemplateManager/src/OutPerActionComplete/OutCreateComplete/sns-out/data.js +62 -0
- package/src/TemplateManager/src/OutPerActionComplete/OutCreateComplete/sns-out/template.ejs +10 -0
- package/src/TemplateManager/src/OutPerActionComplete/OutUpdateComplete/functionYaml/data.js +98 -0
- package/src/TemplateManager/src/OutPerActionComplete/OutUpdateComplete/functionYaml/template.ejs +33 -0
- package/src/TemplateManager/src/OutPerActionComplete/OutUpdateComplete/handler/data.js +59 -0
- package/src/TemplateManager/src/OutPerActionComplete/OutUpdateComplete/handler/template.ejs +129 -0
- package/src/TemplateManager/src/OutPerActionComplete/OutUpdateComplete/mainFunction/data.js +53 -0
- package/src/TemplateManager/src/OutPerActionComplete/OutUpdateComplete/mainFunction/template.ejs +126 -0
- package/src/TemplateManager/src/OutPerActionComplete/OutUpdateComplete/sns-out/data.js +62 -0
- package/src/TemplateManager/src/OutPerActionComplete/OutUpdateComplete/sqs-in-sns/data.js +58 -0
- package/src/TemplateManager/src/OutPerActionComplete/OutUpdateComplete/sqs-in-sns/template.ejs +47 -0
- package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrApi/data.js +22 -3
- package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrApi/template.ejs +2 -2
- package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrDsq/data.js +24 -1
- package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrInv/data.js +53 -2
- package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrSqs/data.js +25 -3
- package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrApi/data.js +5 -8
- package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrApi/getTemplate.ejs +76 -0
- package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrApi/updateTemplate.ejs +67 -0
- package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrDsq/data.js +47 -23
- package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrDsq/getTemplate.ejs +105 -0
- package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrDsq/updateTemplate.ejs +109 -0
- package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrInv/createTemplate.ejs +75 -0
- package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrInv/data.js +69 -21
- package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrInv/getTemplate.ejs +82 -0
- package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrInv/updateTemplate.ejs +75 -0
- package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrSqs/data.js +46 -17
- package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrSqs/getTemplate.ejs +124 -0
- package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrSqs/updateTemplate.ejs +133 -0
- package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Create/CreateObject_main.js +760 -0
- package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Create/data.js +67 -0
- package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Create/request.json +0 -0
- package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Create/template.ejs +575 -0
- package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Get/data.js +0 -6
- package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Get/template.ejs +17 -12
- package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Update/data.js +61 -0
- package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Update/request.json +0 -0
- package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Update/template.ejs +267 -0
- package/src/TemplateManager/src/ProcessLogical/Handler/data.js +49 -0
- package/src/TemplateManager/src/ProcessLogical/Handler/template.ejs +129 -0
- package/src/TemplateManager/src/ProcessLogical/ProcessLogicalYaml/data.js +175 -0
- package/src/TemplateManager/src/ProcessLogical/ProcessLogicalYaml/template.ejs +25 -0
- package/src/TemplateManager/src/ProcessLogical/mainFunction/data.js +47 -0
- package/src/TemplateManager/src/ProcessLogical/mainFunction/template.ejs +429 -0
- package/src/TemplateManager/src/ProcessLogicalPagination/DsqYaml/data.js +50 -0
- package/src/TemplateManager/src/ProcessLogicalPagination/DsqYaml/template.ejs +32 -0
- package/src/TemplateManager/src/ProcessLogicalPagination/FunctionYaml/HdrDsq/data.js +167 -0
- package/src/TemplateManager/src/ProcessLogicalPagination/FunctionYaml/HdrDsq/template.ejs +25 -0
- package/src/TemplateManager/src/ProcessLogicalPagination/FunctionYaml/HdrSqs/data.js +169 -0
- package/src/TemplateManager/src/ProcessLogicalPagination/FunctionYaml/HdrSqs/template.ejs +25 -0
- package/src/TemplateManager/src/ProcessLogicalPagination/Handler/HdrDsq/data.js +48 -0
- package/src/TemplateManager/src/ProcessLogicalPagination/Handler/HdrDsq/template.ejs +163 -0
- package/src/TemplateManager/src/ProcessLogicalPagination/Handler/HdrSqs/data.js +48 -0
- package/src/TemplateManager/src/ProcessLogicalPagination/Handler/HdrSqs/template.ejs +146 -0
- package/src/TemplateManager/src/ProcessLogicalPagination/mainFunction/data.js +48 -0
- package/src/TemplateManager/src/ProcessLogicalPagination/mainFunction/template.ejs +212 -0
- package/src/TemplateManager/src/ResourceYaml/CreateSourceData.js +2 -2
- package/src/TemplateManager/src/ResourceYaml/dynamodb/processLogicalAndFindData.js +2 -2
- package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/defaultSnsInSqsForFindDataAndProcessLogical.js +27 -12
- package/src/TemplateManager/src/ResourceYaml/sns-out/data.js +1 -1
- package/src/TemplateManager/src/ResourceYaml/sns-out/defaultSnsOutForFindDataAndProcessLogical.js +75 -0
- package/src/TemplateManager/src/TranslateIdReq/ProcessingTranslateIds/functionYaml/data.js +95 -0
- package/src/TemplateManager/src/TranslateIdReq/ProcessingTranslateIds/functionYaml/template.ejs +30 -0
- package/src/TemplateManager/src/TranslateIdReq/ProcessingTranslateIds/handler/dataHdrDsq.js +52 -0
- package/src/TemplateManager/src/TranslateIdReq/ProcessingTranslateIds/handler/template.ejs +194 -0
- package/src/TemplateManager/src/TranslateIdReq/ProcessingTranslateIds/mainFunction/data.js +48 -0
- package/src/TemplateManager/src/TranslateIdReq/ProcessingTranslateIds/mainFunction/template.ejs +330 -0
- package/src/TemplateManager/src/TranslateIdReq/ProcessingTranslateIds/sns-out/data.js +47 -0
- package/src/TemplateManager/src/TranslateIdReq/ProcessingTranslateIds/sqs-sns/data.js +58 -0
- package/src/TemplateManager/src/TranslateIdReq/ProcessingTranslateIds/sqs-sns/template.ejs +43 -0
- package/src/TemplateManager/src/TranslateIdReq/TranslateIds/functionYaml/HdrDsq/data.js +116 -0
- package/src/TemplateManager/src/TranslateIdReq/TranslateIds/functionYaml/HdrSqs/data.js +116 -0
- package/src/TemplateManager/src/TranslateIdReq/TranslateIds/handler/HdrDsq/data.js +60 -0
- package/src/TemplateManager/src/TranslateIdReq/TranslateIds/handler/HdrDsq/template.ejs +157 -0
- package/src/TemplateManager/src/TranslateIdReq/TranslateIds/handler/HdrSqs/data.js +59 -0
- package/src/TemplateManager/src/TranslateIdReq/TranslateIds/handler/HdrSqs/template.ejs +175 -0
- package/src/TemplateManager/src/TranslateIdReq/TranslateIds/mainFunction/data.js +61 -0
- package/src/TemplateManager/src/TranslateIdReq/TranslateIds/mainFunction/template.ejs +155 -0
- package/src/TemplateManager/src/TranslateIdReq/TranslateIds/resourceYaml/dynamoDb/data.js +120 -0
- package/src/TemplateManager/src/TranslateIdReq/TranslateIds/resourceYaml/sns-sqs/data.js +75 -0
- package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/functionYaml/data.js +2 -2
- package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/sns-out/data.js +1 -1
- package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrApi/data.js +10 -3
- package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrDsq/data.js +6 -4
- package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrInv/data.js +11 -1
- package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrSqs/data.js +7 -5
- package/src/TemplateManager/src/externalService/LambdaRole/data.js +150 -32
- package/src/TemplateManager/src/externalService/LambdaRole/template.ejs +16 -15
- package/src/TemplateManager/src/externalService/SnsTopicSubscriotions/data.js +35 -6
- package/src/TemplateManager/src/externalService/SnsTopicSubscriotions/template.ejs +3 -4
- package/src/TemplateManager/src/libs/Consts.js +122 -11
- package/src/TemplateManager/src/PerActionEndpoint/Handler/testRequest.json +0 -5
|
@@ -31,8 +31,6 @@ const sqsTemplatePath = path.join(__dirname, "../../../ResourceYaml/sns-in-sqs/s
|
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* create data for dynamoDbYaml tempalte from objectSchema
|
|
34
|
-
* return array of dynamoDb data
|
|
35
|
-
* because one objectSchema can create multiple dynamoDb table
|
|
36
34
|
*
|
|
37
35
|
* @param {Object} _izContext
|
|
38
36
|
* @param {String} saveFilePath
|
package/src/TemplateManager/src/CreateRelationship/createRelationshipComplete/functionYaml/data.js
CHANGED
|
@@ -95,8 +95,8 @@ function createParamForCreateSource(srcPath) {
|
|
|
95
95
|
]
|
|
96
96
|
},
|
|
97
97
|
[
|
|
98
|
-
resourceNames(RESOURCE_CLASSES.sqs, upperCase(functionName)
|
|
99
|
-
resourceNames(RESOURCE_CLASSES.sqs, upperCase(functionName) +
|
|
98
|
+
resourceNames(RESOURCE_CLASSES.sqs, upperCase(functionName)),
|
|
99
|
+
resourceNames(RESOURCE_CLASSES.sqs, upperCase(functionName) + "DLQ"),
|
|
100
100
|
resourceNames(RESOURCE_CLASSES.sns, "In" + upperCase(functionName)),
|
|
101
101
|
resourceNames(RESOURCE_CLASSES.sns, "Out" + upperCase(functionName))
|
|
102
102
|
],
|
package/src/TemplateManager/src/CreateRelationship/createRelationshipComplete/handler/HdrSqs/data.js
CHANGED
|
@@ -47,7 +47,6 @@ function createParamForCreateSource(srcPath) {
|
|
|
47
47
|
templateData: {
|
|
48
48
|
functionName: upperCase(functionName),
|
|
49
49
|
queueName: upperCase(functionName) + upperCase(handler),
|
|
50
|
-
isCreateMainFunction: false
|
|
51
50
|
},
|
|
52
51
|
setting: {
|
|
53
52
|
savePath: path.join(srcPath, SOURCE_PATH.relationshipPerAction),
|
package/src/TemplateManager/src/CreateRelationship/createRelationshipComplete/sns-out/data.js
CHANGED
|
@@ -47,7 +47,7 @@ const templatePath = path.join(__dirname, '../../../ResourceYaml/sns-out/templat
|
|
|
47
47
|
|
|
48
48
|
function createDefaultSnsOut(_izContext, srcPath) {
|
|
49
49
|
const createSourceParams = createParamsForCreateSource(_izContext, srcPath)
|
|
50
|
-
console.log("createSourceParamsCreateRelationshipComplete", createSourceParams)
|
|
50
|
+
// console.log("createSourceParamsCreateRelationshipComplete", createSourceParams)
|
|
51
51
|
|
|
52
52
|
return [createSourceParams]
|
|
53
53
|
}
|
|
@@ -0,0 +1,188 @@
|
|
|
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 path = require('path');
|
|
21
|
+
|
|
22
|
+
const templatePath = path.join(__dirname, "./template.ejs")
|
|
23
|
+
|
|
24
|
+
const { HANDLER, STORAGE_TYPES, ACTIONS } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
|
|
25
|
+
const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../MainLibs/src/Utils")
|
|
26
|
+
const { createIamRole, resourceNames, RESOURCE_CLASSES, DEFAULT_LAMBDA_ROLE_PER_ACTION, SQS_RESOURCE, SOURCE_PATH, SAVE_FILE_NAME, FUNCTION_NAME } = require("../../libs/Consts");
|
|
27
|
+
|
|
28
|
+
const serviceSchemas = require('@izara_project/izara-core-library-service-schemas');
|
|
29
|
+
const serviceConfig = serviceSchemas.serviceConfig;
|
|
30
|
+
|
|
31
|
+
function defaultIamRolePerAction() {
|
|
32
|
+
|
|
33
|
+
let defaultIamRole = [];
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
defaultIamRole.push(
|
|
37
|
+
createIamRole(
|
|
38
|
+
{
|
|
39
|
+
[RESOURCE_CLASSES.s3]: ["GetObject", "GetObjectVersion"],
|
|
40
|
+
},
|
|
41
|
+
[
|
|
42
|
+
resourceNames(RESOURCE_CLASSES.s3, "object-schema/perServiceSchemas/*"),
|
|
43
|
+
resourceNames(RESOURCE_CLASSES.s3, "object-schema/serviceConfig/ServiceNameConfig.json"),
|
|
44
|
+
resourceNames(RESOURCE_CLASSES.s3, "object-schema/serviceConfig/GraphServerTags.json"),
|
|
45
|
+
]
|
|
46
|
+
)
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
defaultIamRole.push(
|
|
50
|
+
createIamRole(
|
|
51
|
+
{ [RESOURCE_CLASSES.s3]: ["ListBucket"] },
|
|
52
|
+
[
|
|
53
|
+
resourceNames(RESOURCE_CLASSES.s3, "object-schema"),
|
|
54
|
+
]
|
|
55
|
+
)
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
defaultIamRole.push(
|
|
59
|
+
createIamRole(
|
|
60
|
+
{
|
|
61
|
+
[RESOURCE_CLASSES.sns]: ["Publish"]
|
|
62
|
+
},
|
|
63
|
+
[
|
|
64
|
+
resourceNames(RESOURCE_CLASSES.sns, "InFindData"),
|
|
65
|
+
resourceNames(RESOURCE_CLASSES.sns, "OutFindDataComplete")
|
|
66
|
+
]
|
|
67
|
+
)
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
defaultIamRole.push(
|
|
73
|
+
createIamRole(
|
|
74
|
+
{
|
|
75
|
+
[RESOURCE_CLASSES.dynamoDbTable]: [
|
|
76
|
+
DEFAULT_LAMBDA_ROLE_PER_ACTION[ACTIONS.get].dynamoDbPermission,
|
|
77
|
+
DEFAULT_LAMBDA_ROLE_PER_ACTION[ACTIONS.update].dynamoDbPermission,
|
|
78
|
+
DEFAULT_LAMBDA_ROLE_PER_ACTION[ACTIONS.delete].dynamoDbPermission
|
|
79
|
+
]
|
|
80
|
+
},
|
|
81
|
+
[
|
|
82
|
+
resourceNames(RESOURCE_CLASSES.dynamoDbTable, "FindDataMain")
|
|
83
|
+
]
|
|
84
|
+
)
|
|
85
|
+
)
|
|
86
|
+
// console.log("defaultIamRole Api", defaultIamRole)
|
|
87
|
+
return defaultIamRole
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* receive objectSchema
|
|
92
|
+
* create data for FindData Yaml template
|
|
93
|
+
*
|
|
94
|
+
* @param {Object} objectSchemas
|
|
95
|
+
* @return {{ templatePath, templateData, setting } }
|
|
96
|
+
*/
|
|
97
|
+
async function data(_izContext, objectSchemas, srcPath) {
|
|
98
|
+
|
|
99
|
+
let additionalResourcePermission = defaultIamRolePerAction();
|
|
100
|
+
let tableForGetItem = [];
|
|
101
|
+
let graphForGetNode = [];
|
|
102
|
+
let hasGraphStorage = false;
|
|
103
|
+
let functionName = upperCase(FUNCTION_NAME.findData);
|
|
104
|
+
|
|
105
|
+
// =======================================================================================
|
|
106
|
+
for (let objectSchema of objectSchemas.records) {
|
|
107
|
+
// console.log("objectSchema", objectSchemas)
|
|
108
|
+
|
|
109
|
+
for (let storageResource of Object.values(objectSchema.storageResources)) {
|
|
110
|
+
if (storageResource.storageType === STORAGE_TYPES.dynamoDB) {
|
|
111
|
+
// add IamRole for dynamodb depend on tableName in storageResources of objectSchema
|
|
112
|
+
tableForGetItem.push(resourceNames(RESOURCE_CLASSES.dynamoDbTable, storageResource.tableName));
|
|
113
|
+
|
|
114
|
+
} else if (storageResource.storageType === STORAGE_TYPES.graph) {
|
|
115
|
+
// find graph serviceName from graphServerTag or *GetNodeHdrInv ?
|
|
116
|
+
|
|
117
|
+
const graphHandlerServiceTag = await serviceConfig.getGraphServiceTagWithCache(
|
|
118
|
+
_izContext,
|
|
119
|
+
storageResource.graphServerTag
|
|
120
|
+
);
|
|
121
|
+
// _izContext.logger.debug("graphHandlerServiceTag: ", graphHandlerServiceTag)
|
|
122
|
+
|
|
123
|
+
if (hasGraphStorage) {
|
|
124
|
+
continue;
|
|
125
|
+
} else {
|
|
126
|
+
graphForGetNode.push(resourceNames(RESOURCE_CLASSES.lambda, graphHandlerServiceTag + "TestGetNodeV2HdrInv"))
|
|
127
|
+
hasGraphStorage = true;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
// =======================================================================================
|
|
133
|
+
if (tableForGetItem.length) {
|
|
134
|
+
additionalResourcePermission.push(
|
|
135
|
+
createIamRole(
|
|
136
|
+
{ [RESOURCE_CLASSES.dynamoDbTable]: [DEFAULT_LAMBDA_ROLE_PER_ACTION[ACTIONS.get].dynamoDbPermission] },
|
|
137
|
+
tableForGetItem
|
|
138
|
+
)
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (graphForGetNode.length) {
|
|
143
|
+
additionalResourcePermission.push(
|
|
144
|
+
createIamRole(
|
|
145
|
+
{ [RESOURCE_CLASSES.lambda]: ["InvokeFunction"] },
|
|
146
|
+
graphForGetNode
|
|
147
|
+
)
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
additionalResourcePermission.push(
|
|
152
|
+
createIamRole({
|
|
153
|
+
[RESOURCE_CLASSES.sqs]:
|
|
154
|
+
[
|
|
155
|
+
SQS_RESOURCE.deleteMessage,
|
|
156
|
+
SQS_RESOURCE.getQueueAttributes,
|
|
157
|
+
SQS_RESOURCE.receiveMessage,
|
|
158
|
+
SQS_RESOURCE.sendMessage,
|
|
159
|
+
SQS_RESOURCE.deleteMessageBatch,
|
|
160
|
+
SQS_RESOURCE.getQueueUrl
|
|
161
|
+
]
|
|
162
|
+
}, [
|
|
163
|
+
resourceNames(RESOURCE_CLASSES.sqs, functionName + upperCase(HANDLER.hdrSqs)),
|
|
164
|
+
resourceNames(RESOURCE_CLASSES.sqs, functionName + upperCase(HANDLER.hdrSqs) + "DLQ")
|
|
165
|
+
]
|
|
166
|
+
)
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
// console.log("additionalResourcePermission", additionalResourcePermission)
|
|
170
|
+
|
|
171
|
+
return {
|
|
172
|
+
templatePath: templatePath,
|
|
173
|
+
templateData: {
|
|
174
|
+
functionName: functionName,
|
|
175
|
+
resourceLocation: SOURCE_PATH.resourceLocationFindData,
|
|
176
|
+
handlerType: HANDLER.hdrSqs,
|
|
177
|
+
additionalResourcePermission
|
|
178
|
+
},
|
|
179
|
+
setting: {
|
|
180
|
+
savePath: path.join(srcPath, SOURCE_PATH.appYaml),
|
|
181
|
+
saveFileName: upperCase(SAVE_FILE_NAME.findData),
|
|
182
|
+
fileExtension: '.yml',
|
|
183
|
+
isAppend: false
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
module.exports = data;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<%_ const join = require('path').join; _%>
|
|
2
|
+
<%- functionName %><%- firstLetterUpperCase(handlerType) %>:
|
|
3
|
+
handler: <%- join(resourceLocation, `${functionName}_${firstLetterUpperCase(handlerType)}.main`)%>
|
|
4
|
+
name: ${self:custom.iz_resourcePrefix}<%- functionName %><%- firstLetterUpperCase(handlerType) %>
|
|
5
|
+
events:
|
|
6
|
+
- sqs:
|
|
7
|
+
arn: arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}<%- 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
|
+
} _%>
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
let identifiersBase = await identifierObj.identifiersBaseFromIdentifiers(
|
|
2
|
+
_izContext,
|
|
3
|
+
objType,
|
|
4
|
+
identifiers
|
|
5
|
+
);
|
|
6
|
+
_izContext.logger.debug("create identifiersBase from identifiers: ", identifiersBase) // object
|
|
7
|
+
|
|
8
|
+
<%- createNameTagBefore(objectType, fieldName) %>
|
|
9
|
+
|
|
10
|
+
let objInstanceBase = await dynamodbSharedLib.getItem(
|
|
11
|
+
_izContext,
|
|
12
|
+
await dynamodbSharedLib.tableName(_izContext, <%- JSON.stringify(tableName) %>),
|
|
13
|
+
identifiersBase
|
|
14
|
+
);
|
|
15
|
+
_izContext.logger.debug("objInstanceBase: ", objInstanceBase)
|
|
16
|
+
|
|
17
|
+
if (!objInstanceBase) {
|
|
18
|
+
errorsFound.push(`can't get data in dynamo by ${identifiersBase}`)
|
|
19
|
+
standardErrorParams.push(errorsFound)
|
|
20
|
+
await findDataSharedLib.completeFindDataMain(...standardErrorParams);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (!objInstanceBase.hasOwnProperty(fieldName)) {
|
|
25
|
+
errorsFound.push(`data in dynamoDB have no ${fieldName}`)
|
|
26
|
+
standardErrorParams.push(errorsFound)
|
|
27
|
+
await findDataSharedLib.completeFindDataMain(...standardErrorParams);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
<%- createNameTagAfter(objectType, fieldName) %>
|
|
32
|
+
|
|
33
|
+
let dataValue = objInstanceBase[fieldName];
|
|
34
|
+
_izContext.logger.debug("dataValue: ", dataValue)
|
|
35
|
+
|
|
36
|
+
await findDataSharedLib.completeFindDataMain(
|
|
37
|
+
_izContext,
|
|
38
|
+
findDataMain.fieldName,
|
|
39
|
+
findDataMain.objType,
|
|
40
|
+
findDataMain.identifiers,
|
|
41
|
+
findDataMain.requestProperties,
|
|
42
|
+
dataValue,
|
|
43
|
+
"complete"
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
<%_ function createNameTagBefore(objectType, fieldName){
|
|
47
|
+
return `//(<beforeGetItem${objectType}${fieldName}>)
|
|
48
|
+
//(</beforeGetItem${objectType}${fieldName}>)`
|
|
49
|
+
} _%>
|
|
50
|
+
<%_ function createNameTagAfter(objectType, fieldName){
|
|
51
|
+
return `//(<afterGetItem${objectType}${fieldName}>)
|
|
52
|
+
//(</afterGetItem${objectType}${fieldName}>)`
|
|
53
|
+
} _%>
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
<%- createNameTagBefore(objectType, fieldName) %>
|
|
2
|
+
|
|
3
|
+
const graphHandlerServiceTag = await serviceConfig.getGraphServiceTagWithCache(
|
|
4
|
+
_izContext,
|
|
5
|
+
<%- JSON.stringify(graphServerTag) %>
|
|
6
|
+
);
|
|
7
|
+
_izContext.logger.debug("graphHandlerServiceTag: ", graphHandlerServiceTag)
|
|
8
|
+
|
|
9
|
+
let getDataByGraph = await graphSharedLib.getNodeV2(
|
|
10
|
+
_izContext,
|
|
11
|
+
graphHandlerServiceTag,
|
|
12
|
+
objType,
|
|
13
|
+
{
|
|
14
|
+
identifiers: identifiers
|
|
15
|
+
},
|
|
16
|
+
<%- JSON.stringify(versionedDataLabel) %>
|
|
17
|
+
);
|
|
18
|
+
_izContext.logger.debug("getDataByGraph: ", getDataByGraph)
|
|
19
|
+
|
|
20
|
+
if (!getDataByGraph) {
|
|
21
|
+
errorsFound.push(`can't get data of ${objType.objectType} in graph`)
|
|
22
|
+
standardErrorParams.push(errorsFound)
|
|
23
|
+
await findDataSharedLib.completeFindDataMain(...standardErrorParams);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
<%- createNameTagAfter(objectType, fieldName) %>
|
|
28
|
+
|
|
29
|
+
<% if (versionedDataLabel.length > 0) { _%>
|
|
30
|
+
// The fieldName is a key in the versionedData object.
|
|
31
|
+
let versionedDataLabel = getDataByGraph.versionedDatas<%- JSON.stringify(versionedDataLabel) %>;
|
|
32
|
+
|
|
33
|
+
if (versionedDataLabel == null) {
|
|
34
|
+
errorsFound.push(`can't find versionedData of ${objType.objectType}`)
|
|
35
|
+
standardErrorParams.push(errorsFound)
|
|
36
|
+
await findDataSharedLib.completeFindDataMain(...standardErrorParams);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
let versionedProperties = versionedDataLabel.properties;
|
|
41
|
+
|
|
42
|
+
if (!versionedProperties.hasOwnProperty(fieldName)) {
|
|
43
|
+
errorsFound.push(`versionedData have no ${fieldName}`)
|
|
44
|
+
standardErrorParams.push(errorsFound)
|
|
45
|
+
await findDataSharedLib.completeFindDataMain(...standardErrorParams);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
let dataValue = versionedProperties[fieldName];
|
|
50
|
+
_izContext.logger.debug("dataValue: ", dataValue)
|
|
51
|
+
<% } else { _%>
|
|
52
|
+
let objInstanceFull = getDataByGraph.objInstanceFull;
|
|
53
|
+
_izContext.logger.debug("objInstanceFull: ", objInstanceFull)
|
|
54
|
+
<% if (getInIdentifiers) { _%>
|
|
55
|
+
|
|
56
|
+
// objInstanceFull.identifiers // Object
|
|
57
|
+
if (!objInstanceFull.identifiers.hasOwnProperty(fieldName)) {
|
|
58
|
+
errorsFound.push(`nodeProperties have no this ${fieldName}`)
|
|
59
|
+
standardErrorParams.push(errorsFound)
|
|
60
|
+
await findDataSharedLib.completeFindDataMain(...standardErrorParams);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
let dataValue = objInstanceFull.identifiers[fieldName];
|
|
65
|
+
_izContext.logger.debug("this fieldName is identifier, get dataValue in identifiers: ", dataValue)
|
|
66
|
+
|
|
67
|
+
<% } else { _%>
|
|
68
|
+
|
|
69
|
+
// objInstanceFull.fields // Object
|
|
70
|
+
if (!objInstanceFull.fields.hasOwnProperty(fieldName)) {
|
|
71
|
+
errorsFound.push(`nodeProperties have no this ${fieldName}`)
|
|
72
|
+
standardErrorParams.push(errorsFound)
|
|
73
|
+
await findDataSharedLib.completeFindDataMain(...standardErrorParams);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
let dataValue = objInstanceFull.fields[fieldName];
|
|
78
|
+
_izContext.logger.debug("this fieldName is not identifier, get dataValue in fields: ", dataValue)
|
|
79
|
+
|
|
80
|
+
<% }_%>
|
|
81
|
+
<% } _%>
|
|
82
|
+
await findDataSharedLib.completeFindDataMain(
|
|
83
|
+
_izContext,
|
|
84
|
+
findDataMain.fieldName,
|
|
85
|
+
findDataMain.objType,
|
|
86
|
+
findDataMain.identifiers,
|
|
87
|
+
findDataMain.requestProperties,
|
|
88
|
+
dataValue,
|
|
89
|
+
"complete"
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
<%_ function createNameTagBefore(objectType, fieldName){
|
|
93
|
+
return `//(<beforeGetNode${objectType}${fieldName}>)
|
|
94
|
+
//(</beforeGetNode${objectType}${fieldName}>)`
|
|
95
|
+
} _%>
|
|
96
|
+
<%_ function createNameTagAfter(objectType, fieldName){
|
|
97
|
+
return `//(<afterGetNode${objectType}${fieldName}>)
|
|
98
|
+
//(</afterGetNode${objectType}${fieldName}>)`
|
|
99
|
+
} _%>
|
|
@@ -0,0 +1,48 @@
|
|
|
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 path = require('path');
|
|
21
|
+
const fs = require('fs')
|
|
22
|
+
const templatePath = path.join(__dirname, "./template.ejs")
|
|
23
|
+
|
|
24
|
+
const { SOURCE_PATH, FUNCTION_NAME, HANDLER } = require("../../libs/Consts");
|
|
25
|
+
const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../MainLibs/src/Utils")
|
|
26
|
+
/**
|
|
27
|
+
* receive srcPath
|
|
28
|
+
* create data for FindData Handler template
|
|
29
|
+
*
|
|
30
|
+
* @param {Object} srcPath
|
|
31
|
+
* @return {{ templatePath, templateData, setting } }
|
|
32
|
+
*/
|
|
33
|
+
function data(_izContext, srcPath) {
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
templatePath: templatePath,
|
|
37
|
+
templateData: {
|
|
38
|
+
},
|
|
39
|
+
setting: {
|
|
40
|
+
savePath: path.join(srcPath, SOURCE_PATH.findData),
|
|
41
|
+
saveFileName: upperCase(FUNCTION_NAME.findData) + "_" + upperCase(HANDLER.hdrSqs),
|
|
42
|
+
fileExtension: '.js',
|
|
43
|
+
isAppend: false
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
module.exports = data;
|
|
@@ -0,0 +1,140 @@
|
|
|
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 AWS = require('aws-sdk');
|
|
21
|
+
// const sqs = new AWS.SQS({ apiVersion: '2012-11-05' });
|
|
22
|
+
|
|
23
|
+
const izara = require("@izara_project/izara-middleware");
|
|
24
|
+
const middleware = izara.middlewareHandler;
|
|
25
|
+
const recordHandlerSharedLib = require("@izara_project/izara-shared").recordHandlerSharedLib;
|
|
26
|
+
const Logger = require('@izara_project/izara-core-library-logger');
|
|
27
|
+
|
|
28
|
+
const findData = require('./FindData_Main');
|
|
29
|
+
|
|
30
|
+
// validate event properties in body.Message of sqs event
|
|
31
|
+
middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
|
|
32
|
+
|
|
33
|
+
// set schema for record.body.Message
|
|
34
|
+
const perRecordsValidatorSchema = {
|
|
35
|
+
type: "object",
|
|
36
|
+
required: [
|
|
37
|
+
'fieldName',
|
|
38
|
+
'objType',
|
|
39
|
+
'identifiers',
|
|
40
|
+
],
|
|
41
|
+
properties: {
|
|
42
|
+
fieldName: {
|
|
43
|
+
type: 'string'
|
|
44
|
+
},
|
|
45
|
+
objType: {
|
|
46
|
+
type: 'object',
|
|
47
|
+
required: ["serviceTag", "objectType"],
|
|
48
|
+
properties: {
|
|
49
|
+
serviceTag: {
|
|
50
|
+
type: "string",
|
|
51
|
+
enum: [process.env.iz_serviceTag]
|
|
52
|
+
},
|
|
53
|
+
objectType: izara.validatorSchema.stringNotEmpty()
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
identifiers: {
|
|
57
|
+
type: 'object'
|
|
58
|
+
},
|
|
59
|
+
requestProperties: {
|
|
60
|
+
type: 'object',
|
|
61
|
+
default: {}
|
|
62
|
+
},
|
|
63
|
+
callingFlow: {
|
|
64
|
+
type: 'string',
|
|
65
|
+
default: ''
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// set schema for record.body.MessageAttributes
|
|
72
|
+
// const messageAttributeValidatorSchema = {
|
|
73
|
+
// type: "object",
|
|
74
|
+
// required: ['msgAtrrParam1', 'msgAtrrParam2'],
|
|
75
|
+
// properties: {
|
|
76
|
+
// msgAtrrParam1: {
|
|
77
|
+
// type: "string"
|
|
78
|
+
// },
|
|
79
|
+
// msgAtrrParam2: {
|
|
80
|
+
// type: "object"
|
|
81
|
+
// }
|
|
82
|
+
// }
|
|
83
|
+
// };
|
|
84
|
+
|
|
85
|
+
module.exports.main = middleware.wrap(async (event, context, callback) => {
|
|
86
|
+
|
|
87
|
+
try {
|
|
88
|
+
|
|
89
|
+
let recordPromises = [];
|
|
90
|
+
|
|
91
|
+
// loop each record and send to mainFunction
|
|
92
|
+
await Promise.all(event.Records.map(async record => { // promise.all for map() function
|
|
93
|
+
|
|
94
|
+
let passOnProperties = [];
|
|
95
|
+
record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
|
|
96
|
+
|
|
97
|
+
// validate message (and MessageAttributes)
|
|
98
|
+
await recordHandlerSharedLib.validateRecord(
|
|
99
|
+
record, // one record will send to mainFunction
|
|
100
|
+
"FindDataHdrSqs", // queue name that need to retry or send to dlq
|
|
101
|
+
perRecordsValidatorSchema, // schema for record.Message
|
|
102
|
+
// messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
// add argument (to invoke lambda) to passOnProperties[]
|
|
106
|
+
passOnProperties.push(record.body.Message.fieldName)
|
|
107
|
+
passOnProperties.push(record.body.Message.objType)
|
|
108
|
+
passOnProperties.push(record.body.Message.identifiers)
|
|
109
|
+
passOnProperties.push(record.body.Message.requestProperties)
|
|
110
|
+
passOnProperties.push(record.body.Message.callingFlow)
|
|
111
|
+
record._izContext.logger.debug('passOnProperties in handler', passOnProperties);
|
|
112
|
+
|
|
113
|
+
// call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
|
|
114
|
+
let recordPromise = recordHandlerSharedLib.recordHandler(
|
|
115
|
+
record, // one record will send to mainFunction
|
|
116
|
+
findData.findData, // mainFunction that need to invoke.
|
|
117
|
+
"FindDataHdrSqs", // queue name that need to retry or send to dlq
|
|
118
|
+
passOnProperties, // all parameters that mainFunction needed.
|
|
119
|
+
);
|
|
120
|
+
record._izContext.logger.debug('after recordPromise in handler');
|
|
121
|
+
recordPromises.push(recordPromise); // push promise to recordPromises
|
|
122
|
+
}))
|
|
123
|
+
|
|
124
|
+
Logger.debug('before Promise.all(recordPromises) in handler');
|
|
125
|
+
try {
|
|
126
|
+
// --- main await all promises
|
|
127
|
+
await Promise.all(recordPromises); // await all promises
|
|
128
|
+
|
|
129
|
+
return event.Records // return all for local testing
|
|
130
|
+
|
|
131
|
+
} catch {
|
|
132
|
+
Logger.debug('Promise.all(recordPromises) in handler threw error (at least one record did no resolve)');
|
|
133
|
+
}
|
|
134
|
+
Logger.debug('after Promise.all(recordPromises) in handler');
|
|
135
|
+
|
|
136
|
+
} catch (err) {
|
|
137
|
+
Logger.error('Unhandled Error, FindDataHdrSqs: ', err);
|
|
138
|
+
throw (err);
|
|
139
|
+
}
|
|
140
|
+
});
|