@izara_project/izara-market-library-service-schemas 1.0.2 → 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/package.json +1 -1
- 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 +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/{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 +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 +86 -14
- package/src/TemplateManager/src/MainResourcesYaml/CreateSourceData.js +2 -2
- package/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Data/MainDynamoDbYamlData.js +3 -1
- 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/{PerActionEndpoint/TemplateAndData/MainFunction/MainFunctionTemplate/Delete.js → externalService/SnsTopicSubscriotions/data.js} +13 -0
- package/src/TemplateManager/src/externalService/SnsTopicSubscriotions/template.ejs +14 -0
- package/src/TemplateManager/src/libs/Consts.js +39 -1
- package/src/TemplateManager/src/PerActionEndpoint/CreateSourceData.js +0 -131
- package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/Handler/Handler.js +0 -0
- package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/MainFunction/MainFunctionTemplate/Create.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/MainFunction/MainFunctionTemplateData.js +0 -0
- package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Data/LambdaYamlData.js +0 -166
- package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Template/HdrApi.ejs +0 -0
- package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Template/HdrDsq.ejs +0 -0
- package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Template/HdrSqs.ejs +0 -0
- /package/src/TemplateManager/src/{PerActionEndpoint/DataPerActionEndpoint.js → externalService/SnsTopicSubscriotions/request.json} +0 -0
|
@@ -0,0 +1,173 @@
|
|
|
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
|
+
|
|
23
|
+
// const {
|
|
24
|
+
// HANDLER,
|
|
25
|
+
// STORAGE_TYPES
|
|
26
|
+
// } = require('@izara_project/izara-core-library-service-schemas/src/Consts');
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
const STORAGE_TYPES = {
|
|
30
|
+
dynamoDB: "dynamoDB",
|
|
31
|
+
graph: "graph"
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const { SOURCE_PATH } = require('../../libs/Consts')
|
|
35
|
+
const templatePath = path.join(__dirname, './template.ejs')
|
|
36
|
+
|
|
37
|
+
// ---------- End Per Lambda Handler IamRole Data ----------
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* create data for dynamoDbYaml tempalte from objectSchema
|
|
43
|
+
* return array of dynamoDb data
|
|
44
|
+
* because one objectSchema can create multiple dynamoDb table
|
|
45
|
+
*
|
|
46
|
+
* @param {Object} _izContext
|
|
47
|
+
* @param {Object} objectSchema
|
|
48
|
+
* @returns {Object[]} - data of multiple dynamoDb template
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
function dataForMainDynamoDbYamlFromObjectSchema(_izContext, objectSchema) {
|
|
52
|
+
let dynamoDbYamlTempleteData = [];
|
|
53
|
+
|
|
54
|
+
let identifierDetail = {};
|
|
55
|
+
|
|
56
|
+
for (let identifier of objectSchema.identifiers) { //check identifiers from objectSchema
|
|
57
|
+
console.log("identifier");
|
|
58
|
+
if (identifier.type === "partitionKey" || identifier.type === 'sortKey') {
|
|
59
|
+
identifierDetail[identifier.type] = {};
|
|
60
|
+
|
|
61
|
+
if (identifier.name) {
|
|
62
|
+
Object.assign(
|
|
63
|
+
identifierDetail[identifier.type],
|
|
64
|
+
{
|
|
65
|
+
AttributeName: identifier.name,
|
|
66
|
+
AttributeType: "S"
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
} else {
|
|
70
|
+
let fieldNameType = objectSchema.fieldNames[identifier.fieldName].type;
|
|
71
|
+
let attributeType;
|
|
72
|
+
if (fieldNameType === 'string') {
|
|
73
|
+
attributeType = "S"
|
|
74
|
+
} else if (fieldNameType === 'number') {
|
|
75
|
+
attributeType = "N"
|
|
76
|
+
}
|
|
77
|
+
Object.assign(
|
|
78
|
+
identifierDetail[identifier.type],
|
|
79
|
+
{
|
|
80
|
+
AttributeName: identifier.fieldName,
|
|
81
|
+
AttributeType: attributeType
|
|
82
|
+
}
|
|
83
|
+
)
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
console.log("identifierDetail :", identifierDetail)
|
|
89
|
+
if (!identifierDetail.hasOwnProperty("partitionKey")) {
|
|
90
|
+
return []
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
for (let storageResource of Object.values(objectSchema.storageResources)) {
|
|
94
|
+
if (storageResource.storageType === STORAGE_TYPES.dynamoDB) {
|
|
95
|
+
let templateData = {
|
|
96
|
+
tableName: storageResource.tableName,
|
|
97
|
+
attributes: []
|
|
98
|
+
};
|
|
99
|
+
if (storageResource.hasOwnProperty("groupByPartitionKeyField")) {
|
|
100
|
+
templateData.attributes.push(
|
|
101
|
+
{
|
|
102
|
+
keyType: "partitionKey",
|
|
103
|
+
AttributeName: storageResource.groupByPartitionKeyField,
|
|
104
|
+
AttributeType: "S"
|
|
105
|
+
}
|
|
106
|
+
);
|
|
107
|
+
} else {
|
|
108
|
+
for (let identifierType in identifierDetail) {
|
|
109
|
+
templateData.attributes.push(
|
|
110
|
+
{
|
|
111
|
+
keyType: identifierType,
|
|
112
|
+
AttributeName: identifierDetail[identifierType].AttributeName,
|
|
113
|
+
AttributeType: identifierDetail[identifierType].AttributeType
|
|
114
|
+
}
|
|
115
|
+
)
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
dynamoDbYamlTempleteData.push(templateData)
|
|
120
|
+
console.log("templateData")
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return dynamoDbYamlTempleteData
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
// data for MainDynamo from RelSchema
|
|
128
|
+
// function dataForMainDynamoDbYamlFromRelSchema(_izContext, relSchema) {
|
|
129
|
+
// let relTag = Object.keys(relSchema)[0];
|
|
130
|
+
// let relData = relSchema[relTag];
|
|
131
|
+
|
|
132
|
+
// for (let parents of relData.parents) {
|
|
133
|
+
// let parentObjectType = parent.objType.objectType;
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
// }
|
|
137
|
+
|
|
138
|
+
// return
|
|
139
|
+
// }
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
module.exports.createSourceDataDynamoDB = (_izContext, objectSchema, srcPath) => {
|
|
143
|
+
|
|
144
|
+
let resultsForCreateSource = [];
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
const dynamoDbMainYamlDataList = dataForMainDynamoDbYamlFromObjectSchema(_izContext, objectSchema, srcPath)
|
|
148
|
+
console.log("dynamoDbMainYamlDataList: ", dynamoDbMainYamlDataList);
|
|
149
|
+
|
|
150
|
+
for (let dynamoDbMainYamlData of dynamoDbMainYamlDataList) {
|
|
151
|
+
// create iam role of handler here
|
|
152
|
+
resultsForCreateSource.push({
|
|
153
|
+
templatePath: templatePath,
|
|
154
|
+
templateData: dynamoDbMainYamlData,
|
|
155
|
+
setting: {
|
|
156
|
+
initialData: 'Resources:\n',
|
|
157
|
+
savePath: path.join(srcPath, SOURCE_PATH.resourceYaml),
|
|
158
|
+
saveFileName: 'dynamoDB-table',
|
|
159
|
+
fileExtension: '.yml',
|
|
160
|
+
isAppend: true
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
console.log("resultsForCreateSource: ", resultsForCreateSource);
|
|
166
|
+
|
|
167
|
+
return resultsForCreateSource;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// module.exports.createSourceDataRelSchema = (_izContext, relSchema, saveFilePath) => {
|
|
171
|
+
|
|
172
|
+
// return []
|
|
173
|
+
// }
|
|
@@ -0,0 +1,102 @@
|
|
|
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
|
+
|
|
23
|
+
// const {
|
|
24
|
+
// HANDLER,
|
|
25
|
+
// STORAGE_TYPES
|
|
26
|
+
// } = require('@izara_project/izara-core-library-service-schemas/src/Consts');
|
|
27
|
+
|
|
28
|
+
const STORAGE_TYPES = {
|
|
29
|
+
dynamoDB: "dynamoDB",
|
|
30
|
+
graph: "graph"
|
|
31
|
+
}
|
|
32
|
+
const templatePath = path.join(__dirname, './template.ejs')
|
|
33
|
+
const { SOURCE_PATH } = require('../../libs/Consts');
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* create param of crateSouce for FindData And processLogical
|
|
37
|
+
*
|
|
38
|
+
* @param {Object} _izContext
|
|
39
|
+
* @param {String} srcPath
|
|
40
|
+
* @returns {Object[]}
|
|
41
|
+
*/
|
|
42
|
+
module.exports.createDefaultSourceDataDynamoDB = (_izContext, srcPath) => {
|
|
43
|
+
|
|
44
|
+
let resultsForCreateSource = [];
|
|
45
|
+
|
|
46
|
+
const defaultDynamoDataList = [
|
|
47
|
+
{
|
|
48
|
+
"tableName": "FindData",
|
|
49
|
+
"attributes": [
|
|
50
|
+
{
|
|
51
|
+
"keyType": "partitionKey",
|
|
52
|
+
"AttributeName": "findDataId",
|
|
53
|
+
"AttributeType": "S"
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"tableName": "LogicalResultsMain",
|
|
59
|
+
"attributes": [
|
|
60
|
+
{
|
|
61
|
+
"keyType": "partitionKey",
|
|
62
|
+
"AttributeName": "logicalResultId",
|
|
63
|
+
"AttributeType": "S"
|
|
64
|
+
}
|
|
65
|
+
]
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
"tableName": "LogicalResultsData",
|
|
69
|
+
"attributes": [
|
|
70
|
+
{
|
|
71
|
+
"keyType": "partitionKey",
|
|
72
|
+
"AttributeName": "logicalResultId",
|
|
73
|
+
"AttributeType": "S"
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"keyType": "sortKey",
|
|
77
|
+
"AttributeName": "dataId",
|
|
78
|
+
"AttributeType": "S"
|
|
79
|
+
}
|
|
80
|
+
]
|
|
81
|
+
}
|
|
82
|
+
];
|
|
83
|
+
|
|
84
|
+
console.log("defaultlDynamoDataList: ", (defaultDynamoDataList));
|
|
85
|
+
|
|
86
|
+
for (let defaultlDynamoData of defaultDynamoDataList) {
|
|
87
|
+
resultsForCreateSource.push({
|
|
88
|
+
templatePath: templatePath,
|
|
89
|
+
templateData: defaultlDynamoData,
|
|
90
|
+
setting: {
|
|
91
|
+
savePath: path.join(srcPath, SOURCE_PATH.resourceYaml),
|
|
92
|
+
saveFileName: 'dynamoDB-table',
|
|
93
|
+
fileExtension: '.yml',
|
|
94
|
+
isAppend: true
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
console.log("resultForCreateDefaultDynamoDb: ", (resultsForCreateSource));
|
|
100
|
+
|
|
101
|
+
return resultsForCreateSource;
|
|
102
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<%- tableName %>Table:
|
|
2
|
+
Type: "AWS::DynamoDB::Table"
|
|
3
|
+
Properties:
|
|
4
|
+
TableName: ${self:custom.iz_resourcePrefix}<%- tableName %>
|
|
5
|
+
AttributeDefinitions:
|
|
6
|
+
<%_ attributes.forEach(attribute => { -%>
|
|
7
|
+
- AttributeName: <%- attribute['AttributeName'] %>
|
|
8
|
+
AttributeType: <%- attribute['AttributeType'] %>
|
|
9
|
+
<%_ }) _%>
|
|
10
|
+
KeySchema:
|
|
11
|
+
<%_ attributes.forEach(attribute => { -%>
|
|
12
|
+
<%_ if (attribute.keyType === 'partitionKey') { -%>
|
|
13
|
+
- AttributeName: <%- attribute["AttributeName"] %>
|
|
14
|
+
KeyType: HASH
|
|
15
|
+
<%_ } -%>
|
|
16
|
+
<%_ if(attribute.keyType === "sortKey") { -%>
|
|
17
|
+
- AttributeName: <%- attribute["AttributeName"] %>
|
|
18
|
+
KeyType: RANGE
|
|
19
|
+
<%_ } -%>
|
|
20
|
+
<%_ }) _%>
|
|
21
|
+
ProvisionedThroughput:
|
|
22
|
+
ReadCapacityUnits: 1
|
|
23
|
+
WriteCapacityUnits: 1
|
|
24
|
+
#<#<%- firstLetterUpperCase(tableName) %>DynamoDbSetting#>
|
|
25
|
+
#<#/<%- firstLetterUpperCase(tableName) %>DynamoDbSetting#>
|
|
26
|
+
<%_ function firstLetterUpperCase(text){
|
|
27
|
+
return text.charAt(0).toUpperCase() + text.slice(1)
|
|
28
|
+
} _%>
|
|
29
|
+
<%_ function firstLetterLowerCase(str) {
|
|
30
|
+
return str.charAt(0).toLowerCase() + str.slice(1)
|
|
31
|
+
} _%>
|
|
@@ -0,0 +1,81 @@
|
|
|
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
|
+
|
|
23
|
+
// const {
|
|
24
|
+
// HANDLER,
|
|
25
|
+
// STORAGE_TYPES
|
|
26
|
+
// } = require('@izara_project/izara-core-library-service-schemas/src/Consts');
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
const STORAGE_TYPES = {
|
|
30
|
+
dynamoDB: "dynamoDB",
|
|
31
|
+
graph: "graph"
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const templatePath = path.join(__dirname, './snsTemplate.ejs');
|
|
35
|
+
const { SOURCE_PATH } = require('../../libs/Consts')
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* create data for dynamoDbYaml tempalte from objectSchema
|
|
40
|
+
* return array of dynamoDb data
|
|
41
|
+
* because one objectSchema can create multiple dynamoDb table
|
|
42
|
+
*
|
|
43
|
+
* @param {Object} _izContext
|
|
44
|
+
* @param {String} saveFilePath
|
|
45
|
+
* @returns {Object[]} - data of multiple dynamoDb template
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
function createDataForDefaultSnsInSqs(_izContext, srcPath) {
|
|
49
|
+
let resultsForCreateDefaultSnsInSqs = [];
|
|
50
|
+
const defaultSnsInSqsDataList = [
|
|
51
|
+
{
|
|
52
|
+
"queueName": "FindData"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"queueName": "LogicalResultsMain"
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"queueName": "LogicalResultsData"
|
|
59
|
+
}
|
|
60
|
+
]
|
|
61
|
+
|
|
62
|
+
console.log("defaultSnsInSqsDataList", defaultSnsInSqsDataList);
|
|
63
|
+
|
|
64
|
+
for (let defaultSnsInSqsData of defaultSnsInSqsDataList) {
|
|
65
|
+
resultsForCreateDefaultSnsInSqs.push({
|
|
66
|
+
templatePath,
|
|
67
|
+
templateData: defaultSnsInSqsData,
|
|
68
|
+
setting: {
|
|
69
|
+
// initialData: "",
|
|
70
|
+
savePath: path.join(srcPath, SOURCE_PATH.resourceYaml),
|
|
71
|
+
saveFileName: "sns-in-sqs",
|
|
72
|
+
fileExtension: ".yml",
|
|
73
|
+
isAppend: true
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
console.log("resultsForCreateDefaultSnsInSqs", resultsForCreateDefaultSnsInSqs);
|
|
78
|
+
return resultsForCreateDefaultSnsInSqs;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
module.exports = createDataForDefaultSnsInSqs;
|
|
@@ -0,0 +1,108 @@
|
|
|
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
|
+
|
|
23
|
+
// const {
|
|
24
|
+
// HANDLER,
|
|
25
|
+
// STORAGE_TYPES
|
|
26
|
+
// } = require('@izara_project/izara-core-library-service-schemas/src/Consts');
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
const { ACTIONS, HANDLER, SOURCE_PATH, DEFAULT_HANDLER_PER_ACTION } = require('../../libs/Consts');
|
|
30
|
+
const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require('../../../../MainLibs/src/Utils')
|
|
31
|
+
const snsTemplatePath = path.join(__dirname, './snsTemplate.ejs')
|
|
32
|
+
const sqsTemplatePath = path.join(__dirname, './sqsTemplate.ejs')
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* create data for dynamoDbYaml tempalte from objectSchema
|
|
36
|
+
* return array of dynamoDb data
|
|
37
|
+
* because one objectSchema can create multiple dynamoDb table
|
|
38
|
+
*
|
|
39
|
+
* @param {Object} _izContext
|
|
40
|
+
* @param {Object} objectSchema
|
|
41
|
+
* @returns {Object[]} - data of multiple dynamoDb template
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
function dataForCreateSnsAndSqsQueueFromObjectSchema(_izContext, objectSchema, srcPath) {
|
|
45
|
+
const snsAndSqsDataArray = [];
|
|
46
|
+
for (const action of Object.values(ACTIONS)) {
|
|
47
|
+
if (objectSchema.overWriteHandlers[action]) {
|
|
48
|
+
for (const handler of objectSchema.overWriteHandlers[action]) {
|
|
49
|
+
const snsAndSqsData = {
|
|
50
|
+
queueName: createQueueNameForSnsAndSqsQueue(_izContext, objectSchema, action, handler, srcPath)
|
|
51
|
+
}
|
|
52
|
+
snsAndSqsData.queueName && snsAndSqsDataArray.push(snsAndSqsData);
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
for (const handler of DEFAULT_HANDLER_PER_ACTION[action]) {
|
|
56
|
+
const snsAndSqsData = {
|
|
57
|
+
queueName: createQueueNameForSnsAndSqsQueue(_izContext, objectSchema, action, handler, srcPath)
|
|
58
|
+
}
|
|
59
|
+
snsAndSqsData.queueName && snsAndSqsDataArray.push(snsAndSqsData);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
console.log("snsAndSqsQueueArray", (snsAndSqsDataArray))
|
|
64
|
+
return snsAndSqsDataArray
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function createQueueNameForSnsAndSqsQueue(_izContext, objectSchema, action, handler) {
|
|
68
|
+
let objectType = objectSchema.objectType
|
|
69
|
+
let queueName = upperCase(objectType) + upperCase(action) + upperCase(handler)
|
|
70
|
+
if (queueName.includes('HdrSqs')) {
|
|
71
|
+
queueName = upperCase(objectType) + upperCase(action)
|
|
72
|
+
} else if (queueName.includes('HdrDsq')) {
|
|
73
|
+
queueName = upperCase(objectType) + upperCase(action) + upperCase(handler)
|
|
74
|
+
} else {
|
|
75
|
+
return
|
|
76
|
+
}
|
|
77
|
+
return queueName
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
module.exports.createSourceSnsAndSqs = (_izContext, objectSchema, srcPath) => {
|
|
82
|
+
let resultsForCreateSnsAndSqsSource = [];
|
|
83
|
+
let setting = {
|
|
84
|
+
initialData:'Resources:\n',
|
|
85
|
+
savePath: path.join(srcPath, SOURCE_PATH.resourceYaml),
|
|
86
|
+
saveFileName: 'sns-in-sqs',
|
|
87
|
+
fileExtension: '.yml',
|
|
88
|
+
isAppend: true
|
|
89
|
+
}
|
|
90
|
+
const snsAndSqsDataList = dataForCreateSnsAndSqsQueueFromObjectSchema(_izContext, objectSchema, srcPath);
|
|
91
|
+
for (let snsAndSqsData of snsAndSqsDataList) {
|
|
92
|
+
if (snsAndSqsData.queueName.includes('HdrDsq')) {
|
|
93
|
+
resultsForCreateSnsAndSqsSource.push({
|
|
94
|
+
templatePath: sqsTemplatePath,
|
|
95
|
+
templateData: snsAndSqsData,
|
|
96
|
+
setting: setting
|
|
97
|
+
})
|
|
98
|
+
} else {
|
|
99
|
+
resultsForCreateSnsAndSqsSource.push({
|
|
100
|
+
templatePath: snsTemplatePath,
|
|
101
|
+
templateData: snsAndSqsData,
|
|
102
|
+
setting: setting
|
|
103
|
+
})
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
console.log("resultsForCreateSnsAndSqsSource", resultsForCreateSnsAndSqsSource);
|
|
107
|
+
return resultsForCreateSnsAndSqsSource
|
|
108
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
##===== [Create topic in]
|
|
2
|
+
In<%- queueName %>:
|
|
3
|
+
Type: AWS::SNS::Topic
|
|
4
|
+
Properties:
|
|
5
|
+
DisplayName: "SNS Message in"
|
|
6
|
+
TopicName: ${self:custom.iz_resourcePrefix}In<%- queueName %>
|
|
7
|
+
##===== SNS Subscription
|
|
8
|
+
##===== [Topic In]
|
|
9
|
+
SubscriptionIn<%- queueName %>:
|
|
10
|
+
Type: AWS::SNS::Subscription
|
|
11
|
+
Properties:
|
|
12
|
+
TopicArn: !Ref In<%- queueName %>
|
|
13
|
+
Endpoint: "arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}<%- queueName %>HdrSqs"
|
|
14
|
+
Protocol: "sqs"
|
|
15
|
+
##===== [Queue]
|
|
16
|
+
<%- queueName %>HdrSqs:
|
|
17
|
+
Type: "AWS::SQS::Queue"
|
|
18
|
+
Properties:
|
|
19
|
+
QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>HdrSqs
|
|
20
|
+
RedrivePolicy:
|
|
21
|
+
deadLetterTargetArn:
|
|
22
|
+
# !GetAtt
|
|
23
|
+
Fn::GetAtt:
|
|
24
|
+
- <%- queueName %>HdrSqsDLQ
|
|
25
|
+
- Arn
|
|
26
|
+
maxReceiveCount: 3
|
|
27
|
+
VisibilityTimeout: 120
|
|
28
|
+
##==== [QueueDLQ]
|
|
29
|
+
<%- queueName %>HdrSqsDLQ:
|
|
30
|
+
Type: AWS::SQS::Queue
|
|
31
|
+
Properties:
|
|
32
|
+
QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>HdrSqsDLQ
|
|
33
|
+
##==== [QueuePolicy]
|
|
34
|
+
<%- queueName %>HdrSqsPolicy:
|
|
35
|
+
Type: AWS::SQS::QueuePolicy
|
|
36
|
+
Properties:
|
|
37
|
+
PolicyDocument:
|
|
38
|
+
Version: "2012-10-17"
|
|
39
|
+
Statement:
|
|
40
|
+
- Sid: "allow-sns-messages"
|
|
41
|
+
Effect: Allow
|
|
42
|
+
Principal: "*"
|
|
43
|
+
Resource:
|
|
44
|
+
# !GetAtt
|
|
45
|
+
Fn::GetAtt:
|
|
46
|
+
- <%- queueName %>HdrSqs
|
|
47
|
+
- Arn
|
|
48
|
+
Action: "SQS:SendMessage"
|
|
49
|
+
Queues:
|
|
50
|
+
- Ref: <%- queueName %>HdrSqs
|
|
51
|
+
#<#<%- firstLetterUpperCase(queueName) %>QueueSetting#>
|
|
52
|
+
#<#/<%- firstLetterUpperCase(queueName) %>QueueSetting#>
|
|
53
|
+
|
|
54
|
+
<%_ function firstLetterUpperCase(text){
|
|
55
|
+
return text.charAt(0).toUpperCase() + text.slice(1)
|
|
56
|
+
} _%>
|
|
57
|
+
<%_ function firstLetterLowerCase(str) {
|
|
58
|
+
return str.charAt(0).toLowerCase() + str.slice(1)
|
|
59
|
+
} _%>
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
<%- queueName %>:
|
|
2
|
+
Type: "AWS::SQS::Queue"
|
|
3
|
+
Properties:
|
|
4
|
+
QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>
|
|
5
|
+
RedrivePolicy:
|
|
6
|
+
deadLetterTargetArn: #!GetAtt
|
|
7
|
+
Fn::GetAtt:
|
|
8
|
+
- <%- queueName %>DLQ
|
|
9
|
+
- Arn
|
|
10
|
+
maxReceiveCount: 3
|
|
11
|
+
VisibilityTimeout: 120
|
|
12
|
+
|
|
13
|
+
<%- queueName %>DLQ:
|
|
14
|
+
Type: AWS::SQS::Queue
|
|
15
|
+
Properties:
|
|
16
|
+
QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>DLQ
|
|
17
|
+
|
|
18
|
+
<%- queueName %>Policy:
|
|
19
|
+
Type: AWS::SQS::QueuePolicy
|
|
20
|
+
Properties:
|
|
21
|
+
PolicyDocument:
|
|
22
|
+
Version: "2012-10-17"
|
|
23
|
+
Statement:
|
|
24
|
+
- Sid: "allow-sns-messages"
|
|
25
|
+
Effect: Allow
|
|
26
|
+
Principal: "*"
|
|
27
|
+
Resource: #!GetAtt
|
|
28
|
+
Fn::GetAtt:
|
|
29
|
+
- <%- queueName %>
|
|
30
|
+
- Arn
|
|
31
|
+
Action: "SQS:SendMessage"
|
|
32
|
+
Queues:
|
|
33
|
+
- Ref: <%- queueName %>
|
|
34
|
+
#<#<%- firstLetterUpperCase(queueName) %>QueueSetting#>
|
|
35
|
+
#<#/<%- firstLetterUpperCase(queueName) %>QueueSetting#>
|
|
36
|
+
|
|
37
|
+
<%_ function firstLetterUpperCase(text){
|
|
38
|
+
return text.charAt(0).toUpperCase() + text.slice(1)
|
|
39
|
+
} _%>
|
|
40
|
+
<%_ function firstLetterLowerCase(str) {
|
|
41
|
+
return str.charAt(0).toLowerCase() + str.slice(1)
|
|
42
|
+
} _%>
|