@izara_project/izara-market-library-service-schemas 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/package.json +5 -5
  2. package/src/GenerateCodeLibs/src/Consts.js +40 -0
  3. package/src/SourceManager/src/CreateSource.js +0 -1
  4. package/src/SourceManager/src/Utils.js +15 -1
  5. package/src/TemplateManager/src/FunctionYaml/HdrApi/data.js +170 -0
  6. package/src/TemplateManager/src/FunctionYaml/HdrApi/request.json +14 -0
  7. package/src/TemplateManager/src/FunctionYaml/HdrApi/template.ejs +33 -0
  8. package/src/TemplateManager/src/FunctionYaml/HdrDsq/data.js +180 -0
  9. package/src/TemplateManager/src/FunctionYaml/HdrDsq/request.json +19 -0
  10. package/src/TemplateManager/src/FunctionYaml/HdrDsq/template.ejs +30 -0
  11. package/src/TemplateManager/src/FunctionYaml/HdrInv/data.js +169 -0
  12. package/src/TemplateManager/src/{PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Template/HdrInv.exampleData.js → FunctionYaml/HdrInv/example req.js } +3 -3
  13. package/src/TemplateManager/src/FunctionYaml/HdrInv/request.json +14 -0
  14. package/src/TemplateManager/src/{PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Template/HdrInv.ejs → FunctionYaml/HdrInv/template.ejs} +5 -5
  15. package/src/TemplateManager/src/FunctionYaml/HdrSqs/data.js +182 -0
  16. package/src/TemplateManager/src/FunctionYaml/HdrSqs/request.json +19 -0
  17. package/src/TemplateManager/src/FunctionYaml/HdrSqs/template.ejs +30 -0
  18. package/src/TemplateManager/src/GenerateCode(Old).js +135 -0
  19. package/src/TemplateManager/src/GenerateCode.js +175 -15
  20. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrApi/data.js +100 -0
  21. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrApi/request.json +7 -0
  22. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrApi/template.ejs +76 -0
  23. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrDsq/data.js +109 -0
  24. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrDsq/request.json +7 -0
  25. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrDsq/template.ejs +105 -0
  26. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrInv/data.js +102 -0
  27. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrInv/request.json +7 -0
  28. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrInv/template.ejs +82 -0
  29. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrSqs/data.js +102 -0
  30. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrSqs/request.json +7 -0
  31. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrSqs/template.ejs +124 -0
  32. package/src/TemplateManager/src/PerActionEndpoint/Handler/testRequest.json +5 -0
  33. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Get/data.js +88 -0
  34. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Get/request.json +5 -0
  35. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Get/template.ejs +219 -0
  36. package/src/TemplateManager/src/ResourceYaml/dynamodb/awaitingMultipleStepData.js +98 -0
  37. package/src/TemplateManager/src/{MainResourcesYaml/TemplateAndData/DynamoDbMain/Data/MainDynamoDbYamlData.js → ResourceYaml/dynamodb/mainResourcePerObjectSchemaData.js} +66 -46
  38. package/src/TemplateManager/src/ResourceYaml/dynamodb/processLogicalAndFindData.js +103 -0
  39. package/src/TemplateManager/src/ResourceYaml/dynamodb/request.json +7 -0
  40. package/src/TemplateManager/src/ResourceYaml/dynamodb/template.ejs +31 -0
  41. package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/defaultSnsInSqsForFindDataAndProcessLogical.js +81 -0
  42. package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/request.json +4 -0
  43. package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/snsAndSqsPerActiondata.js +108 -0
  44. package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/snsTemplate.ejs +59 -0
  45. package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/sqsTemplate.ejs +43 -0
  46. package/src/TemplateManager/src/ResourceYaml/sns-out/data.js +89 -0
  47. package/src/TemplateManager/src/ResourceYaml/sns-out/request.json +3 -0
  48. package/src/TemplateManager/src/ResourceYaml/sns-out/template.ejs +10 -0
  49. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/functionYaml/data.js +151 -0
  50. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/functionYaml/request.json +3 -0
  51. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/functionYaml/template.ejs +33 -0
  52. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/handler/HdrSqs/data.js +76 -0
  53. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/handler/HdrSqs/template.ejs +127 -0
  54. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/mainFunction/data.js +55 -0
  55. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/mainFunction/request.json +1 -0
  56. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/mainFunction/template.ejs +140 -0
  57. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/sns-in-sqs/data.js +75 -0
  58. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/sns-in-sqs/request.json +3 -0
  59. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/sns-in-sqs/template.ejs +45 -0
  60. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/sns-out/data.js +70 -0
  61. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/sns-out/request.json +3 -0
  62. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrApi/data.js +127 -0
  63. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrApi/template.ejs +33 -0
  64. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrDsq/data.js +148 -0
  65. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrInv/data.js +125 -0
  66. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrSqs/data.js +148 -0
  67. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/mainFunction/data.js +80 -0
  68. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/mainFunction/request.json +1 -0
  69. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/mainFunction/template.ejs +324 -0
  70. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrApi/data.js +72 -0
  71. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrApi/request.json +7 -0
  72. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrApi/template.ejs +120 -0
  73. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrDsq/data.js +73 -0
  74. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrDsq/request.json +7 -0
  75. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrDsq/template.ejs +167 -0
  76. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrInv/data.js +73 -0
  77. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrInv/request.json +5 -0
  78. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrInv/template.ejs +126 -0
  79. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrSqs/data.js +73 -0
  80. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrSqs/request.json +7 -0
  81. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrSqs/template.ejs +146 -0
  82. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/request.json +31 -0
  83. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/sns-in-sqs/data.js +91 -0
  84. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/sns-in-sqs/request.json +3 -0
  85. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/sns-out/data.js +70 -0
  86. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/sns-out/request.json +3 -0
  87. package/src/TemplateManager/src/externalService/LambdaRole/data.js +193 -0
  88. package/src/TemplateManager/src/externalService/LambdaRole/request.json +18 -0
  89. package/src/TemplateManager/src/externalService/LambdaRole/template.ejs +56 -0
  90. package/src/TemplateManager/src/externalService/SnsTopicSubscriotions/data.js +96 -0
  91. package/src/TemplateManager/src/externalService/SnsTopicSubscriotions/request.json +12 -0
  92. package/src/TemplateManager/src/externalService/SnsTopicSubscriotions/template.ejs +10 -0
  93. package/src/TemplateManager/src/libs/Consts.js +32 -3
  94. package/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Template/DynamoDb.ejs +0 -31
  95. package/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Template/DynamoDb.exampleData.js +0 -12
  96. package/src/TemplateManager/src/PerActionEndpoint/CreateSourceData.js +0 -131
  97. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/MainFunction/MainFunctionTemplate/Create.js +0 -18
  98. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/MainFunction/MainFunctionTemplate/Delete.js +0 -18
  99. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/MainFunction/MainFunctionTemplate/Get.js +0 -18
  100. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/MainFunction/MainFunctionTemplate/Update.js +0 -18
  101. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Data/LambdaYamlData.js +0 -166
  102. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Template/HdrSqs.ejs +0 -0
  103. /package/src/TemplateManager/src/{MainResourcesYaml → ResourceYaml}/CreateSourceData.js +0 -0
  104. /package/src/TemplateManager/src/{PerActionEndpoint/DataPerActionEndpoint.js → UpdateRelationshipSchema/updateRalationshipComplete/handler/HdrSqs/request.json} +0 -0
  105. /package/src/TemplateManager/src/{PerActionEndpoint/TemplateAndData/Handler/Handler.js → UpdateRelationshipSchema/updateRelationship/functionYaml/HdrApi/request.json} +0 -0
  106. /package/src/TemplateManager/src/{PerActionEndpoint/TemplateAndData/MainFunction/MainFunctionTemplateData.js → UpdateRelationshipSchema/updateRelationship/functionYaml/HdrDsq/request.json} +0 -0
  107. /package/src/TemplateManager/src/{PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Template/HdrApi.ejs → UpdateRelationshipSchema/updateRelationship/functionYaml/HdrInv/request.json} +0 -0
  108. /package/src/TemplateManager/src/{PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Template/HdrDsq.ejs → UpdateRelationshipSchema/updateRelationship/functionYaml/HdrSqs/request.json} +0 -0
@@ -0,0 +1,91 @@
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 { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase, firstLetterUpperCase } = require("../../../../../MainLibs/src/Utils")
35
+ const { DEFAULT_HANDLER_PER_ACTION, SOURCE_PATH } = require("../../../libs/Consts");
36
+ const snsTemplatePath = path.join(__dirname, "../../../ResourceYaml/sns-in-sqs/snsTemplate.ejs")
37
+ const sqsTemplatePath = path.join(__dirname, "../../../ResourceYaml/sns-in-sqs/sqsTemplate.ejs")
38
+
39
+ /**
40
+ * create data for dynamoDbYaml tempalte from objectSchema
41
+ * return array of dynamoDb data
42
+ * because one objectSchema can create multiple dynamoDb table
43
+ *
44
+ * @param {Object} _izContext
45
+ * @param {String} saveFilePath
46
+ * @returns {Object[]} - data of multiple dynamoDb template
47
+ */
48
+
49
+ function createDataForDefaultSnsInSqs(_izContext, srcPath) {
50
+ let resultsForCreateDefaultSnsInSqs = [];
51
+ const defaultSnsInSqsDataList = [
52
+ {
53
+ "queueName": "UpdateRelationship"
54
+ },
55
+ {
56
+ "queueName": "UpdateRelationshipHdrDsq"
57
+ }
58
+ ]
59
+
60
+ for (let defaultSnsInSqsData of defaultSnsInSqsDataList) {
61
+ if (defaultSnsInSqsData.queueName.includes("HdrDsq")) {
62
+ resultsForCreateDefaultSnsInSqs.push({
63
+ templatePath: sqsTemplatePath,
64
+ templateData: defaultSnsInSqsData,
65
+ setting: {
66
+ initialData: "Resources:\n",
67
+ savePath: path.join(srcPath, SOURCE_PATH.resourceYaml),
68
+ saveFileName: 'generated-sns-in-sqs',
69
+ fileExtension: '.yml',
70
+ isAppend: true
71
+ }
72
+ })
73
+ } else {
74
+ resultsForCreateDefaultSnsInSqs.push({
75
+ templatePath: snsTemplatePath,
76
+ templateData: defaultSnsInSqsData,
77
+ setting: {
78
+ initialData: "Resources:\n",
79
+ savePath: path.join(srcPath, SOURCE_PATH.resourceYaml),
80
+ saveFileName: "generated-sns-in-sqs",
81
+ fileExtension: ".yml",
82
+ isAppend: true
83
+ }
84
+ })
85
+ }
86
+ }
87
+ // console.log("resultsForCreateDefaultSnsInSqs", resultsForCreateDefaultSnsInSqs);
88
+ return resultsForCreateDefaultSnsInSqs;
89
+ }
90
+
91
+ module.exports = createDataForDefaultSnsInSqs;
@@ -0,0 +1,70 @@
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 { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase, firstLetterUpperCase } = require("../../../../../MainLibs/src/Utils")
35
+ const { DEFAULT_HANDLER_PER_ACTION, SOURCE_PATH } = require("../../../libs/Consts");
36
+ const templatePath = path.join(__dirname, '../../../ResourceYaml/sns-out/template.ejs')
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 createDefaultSnsOut(_izContext, srcPath) {
49
+ const createSourceParams = createParamsForCreateSource(_izContext, srcPath)
50
+ return [createSourceParams]
51
+ }
52
+
53
+ function createParamsForCreateSource(_izContext, srcPath) {
54
+ let queueName = "updateRelationshipSchema"
55
+ return {
56
+ templatePath: templatePath,
57
+ templateData: {
58
+ queueName
59
+ },
60
+ setting: {
61
+ initialData: 'Resources:\n',
62
+ savePath: path.join(srcPath, SOURCE_PATH.resourceYaml),
63
+ saveFileName: "generated-sns-out",
64
+ fileExtension: '.yml',
65
+ isAppend: true
66
+ }
67
+ }
68
+ }
69
+
70
+ module.exports = createDefaultSnsOut
@@ -0,0 +1,193 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+ const path = require('path');
20
+ const fs = require('fs');
21
+
22
+ const { ACTIONS, HANDLER, STORAGE_TYPES } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
23
+ const { getGraphServiceNameFromGraphServerTagWithCache } = require('@izara_project/izara-core-library-service-schemas/src/ServiceConfig')
24
+
25
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../MainLibs/src/Utils")
26
+ const { DEFAULT_HANDLER_PER_ACTION, createIamRole, resourceNames, RESOURCE_CLASSES, DEFAULT_LAMBDA_ROLE_PER_ACTION, SOURCE_PATH, externalResourceName, externalResourceSns, } = require("../../libs/Consts");
27
+ const templatePath = path.join(__dirname, "./template.ejs");
28
+
29
+
30
+ async function dataForGenerateLambdaRole(_izContext, allObjSchemas, allRelSchemas, srcPath) {
31
+ const externalLambdaIamRoleArray = [];
32
+ for (const objectSchema of allObjSchemas) {
33
+
34
+ // per action external lambda role
35
+ for (const action of Object.values(ACTIONS)) {
36
+ if (objectSchema.overWriteHandlers?.[action]) {
37
+ for (const handler of objectSchema.overWriteHandlers[action]) {
38
+ const externalLambdaIamRole = await externalLambdaIamRoleDataPerAction(_izContext, objectSchema, action, handler)
39
+ externalLambdaIamRole && externalLambdaIamRoleArray.push(externalLambdaIamRole);
40
+ }
41
+
42
+ } else {
43
+ for (const handler of DEFAULT_HANDLER_PER_ACTION[action]) {
44
+ const externalLambdaIamRole = await externalLambdaIamRoleDataPerAction(_izContext, objectSchema, action, handler)
45
+ externalLambdaIamRole && externalLambdaIamRoleArray.push(externalLambdaIamRole);
46
+ }
47
+ }
48
+ }
49
+
50
+ }
51
+
52
+
53
+ // updateRelationship external lambda role
54
+ for (const handler of Object.values(HANDLER)) {
55
+ if (handler !== HANDLER.hdrApi) {
56
+ const externalLambdaIamRoleUpdateRelationship = await externalLambdaIamRoleDataUpdateRelationshipSchema(_izContext, allRelSchemas, handler)
57
+ externalLambdaIamRoleUpdateRelationship && externalLambdaIamRoleArray.push(externalLambdaIamRoleUpdateRelationship)
58
+ }
59
+ }
60
+
61
+
62
+ // findData external lambda role
63
+
64
+ // processLogical
65
+
66
+
67
+ // updateRelationshipComplete external lambda role
68
+
69
+ // ... another external lambda role data
70
+
71
+
72
+ console.log("createSourceArrayIamRole", JSON.stringify(externalLambdaIamRoleArray))
73
+ // return externalLambdaIamRoleArray
74
+
75
+ return {
76
+ templatePath: templatePath,
77
+ templateData: { datas: externalLambdaIamRoleArray },
78
+ setting: {
79
+ savePath: path.join(srcPath, SOURCE_PATH.externalService),
80
+ saveFileName: "generatedLambdaRoleServiceConfig",
81
+ fileExtension: ".js",
82
+ isAppend: false
83
+ }
84
+ }
85
+ }
86
+
87
+ async function externalLambdaIamRoleDataPerAction(_izContext, objectSchema, action, handler) {
88
+ const objectType = objectSchema.objectType;
89
+ const additionalResourcePermission = [];
90
+ // let functionNameArray = [];
91
+ const graphServiceNames = [];
92
+ for (const storgaeResource of Object.values(objectSchema.storageResources)) {
93
+ if (storgaeResource.storageType === STORAGE_TYPES.graph) {
94
+ // console.log("graphServerTag", storgaeResource.graphServerTag)
95
+ let getGraphServiceName = await getGraphServiceNameFromGraphServerTagWithCache(_izContext, storgaeResource.graphServerTag)
96
+ if (!graphServiceNames.includes(getGraphServiceName)) {
97
+ graphServiceNames.push(getGraphServiceName)
98
+ }
99
+ }
100
+ }
101
+
102
+ let functionName = upperCase(objectType) + upperCase(action) + upperCase(handler);
103
+
104
+ if (action === ACTIONS.get) {
105
+ // create functionName
106
+ // functionNameArray.push(functionName)
107
+ // create additionalResourcePermission
108
+ additionalResourcePermission.push(
109
+ createIamRole(
110
+ { [RESOURCE_CLASSES.lambda]: ["InvokeFunction"] },
111
+ graphServiceNames.map(graphServiceName =>
112
+ externalResourceName(RESOURCE_CLASSES.lambda, "GetNodeHdrInv", graphServiceName)
113
+ )
114
+ )
115
+ )
116
+
117
+ // }else if (action === ACTIONS.create) {
118
+
119
+
120
+ // } else if (action === ACTIONS.update) {
121
+
122
+
123
+ // } else if (action === ACTIONS.delete) {
124
+
125
+ } else {
126
+ return
127
+ // throw Error("invalid action")
128
+ }
129
+
130
+ // console.log("additionalResourcePermissionExtraLambdaRole:", JSON.stringify(additionalResourcePermission))
131
+ console.log("additionalResourcePermissionInExternalRolePerAction", JSON.stringify(additionalResourcePermission))
132
+ return {
133
+ functionName: functionName,
134
+ action: action,
135
+ additionalResourcePermission
136
+ }
137
+ }
138
+
139
+
140
+
141
+ async function externalLambdaIamRoleDataUpdateRelationshipSchema(_izContext, allRelSchemas, handler) {
142
+ const functionName = "UpdateRelationship" + upperCase(handler);
143
+ const additionalResourcePermission = [];
144
+ const graphServiceNames = [];
145
+ for (const allRelSchema of Object.values(allRelSchemas)) {
146
+ for (const relationship of Object.values(allRelSchema)) {
147
+ for (const storageResource of Object.values(relationship.storageResources)) {
148
+ if (storageResource.storageType === STORAGE_TYPES.graph) {
149
+ let getGraphServiceTag = await getGraphServiceNameFromGraphServerTagWithCache(_izContext, storageResource.graphServerTag)
150
+ if (!graphServiceNames.includes(getGraphServiceTag)) {
151
+ graphServiceNames.push(getGraphServiceTag)
152
+ }
153
+ }
154
+ }
155
+ }
156
+ }
157
+ console.log("graphServiceNames", graphServiceNames)
158
+ additionalResourcePermission.push(
159
+ createIamRole(
160
+ {
161
+ [RESOURCE_CLASSES.sns]: ["Publish"]
162
+ },
163
+ graphServiceNames.map(graphServiceName =>
164
+ externalResourceSns("InUpdateRelationship", graphServiceName)
165
+ )
166
+ )
167
+ )
168
+
169
+ console.log("additionalResourcePermissionInexternalLambdaIamRoleDataUpdateRelationshipSchema", JSON.stringify(additionalResourcePermission))
170
+ return {
171
+ functionName,
172
+ additionalResourcePermission
173
+ }
174
+ }
175
+
176
+ module.exports = dataForGenerateLambdaRole;
177
+
178
+
179
+
180
+ // for (const action of Object.values(ACTIONS)) {
181
+ // if (objectSchema.overWriteHandlers?.[action]) {
182
+ // // create template data
183
+ // // const createSourceParam = createParamForCreateSource(objectSchema, action, savePath)
184
+ // // createSourceArray.push(createSourceParam)
185
+ // } else {
186
+ // // if not have overWriteHander of action will use default handler
187
+ // const defaultHandler = DEFAULT_HANDLER_PER_ACTION[action]
188
+
189
+ // // const createSourceParam = createParamForCreateSource(objectSchema, action, savePath)
190
+ // // createSourceArray.push(createSourceParam)
191
+
192
+ // }
193
+ // }
@@ -0,0 +1,18 @@
1
+ {
2
+ "functionName": "xx",
3
+ "additionalResourcePermission": [
4
+ {
5
+ "effect": "Allow",
6
+ "action": {
7
+ "dynamodb": [
8
+ "GetItem",
9
+ "PutItem"
10
+ ]
11
+ },
12
+ "resource": [
13
+ "aws:sqs",
14
+ "..."
15
+ ]
16
+ }
17
+ ]
18
+ }
@@ -0,0 +1,56 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+
20
+ const Logger = require('@izara_project/izara-core-library-logger')
21
+ const izaraShared = require('@izara_project/izara-shared')
22
+ const dynamodbSharedLib = izaraShared.dynamodbSharedLib
23
+ const lambdaSharedLib = izaraShared.lambdaSharedLib
24
+ const snsSharedLib = izaraShared.snsSharedLib
25
+ const initialSetupConfig = require('../../config/Config') // config external serviceName
26
+ const basicNodeSchemaLib = require('@izara_project/izara-attribute-tree').basicNodeSchemaLib
27
+ const _izContext = {logger : Logger}
28
+
29
+ module.exports.generatedLambdaRole = async () => {
30
+ let externalLambdaRole = [ <%_ datas.forEach((data,dataIndex) => { %>
31
+ {
32
+ functionName: "<%- data.functionName %>",
33
+ statement: [
34
+ {
35
+ "Sid": "<%- data.functionName %>Test<%- dataIndex %>",
36
+ "Effect": <%_ data.additionalResourcePermission.forEach(resourcePermission => { _%>
37
+ "<%- resourcePermission.effect %>",
38
+ "Action": <%_ Object.keys(resourcePermission.action).forEach(resourcePerAction => { _%>
39
+ <%_ resourcePermission.action[resourcePerAction].forEach(permission => { _%>
40
+ [
41
+ "<%- resourcePerAction %>:<%- permission %>",
42
+ ],
43
+ "Resource": [
44
+ <%_ resourcePermission.resource.forEach(resource => { _%>
45
+ `<%- resource _%>`,
46
+ <%_ }) _%>
47
+ ]
48
+ <%_ }) _%>
49
+ <%_ }) _%>
50
+ <%_ }) _%>
51
+ }
52
+ ]
53
+ }, <%_ }) -%>
54
+ ]
55
+ return externalLambdaRole
56
+ }
@@ -0,0 +1,96 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+ const path = require('path');
20
+ const fs = require('fs');
21
+
22
+ const { ACTIONS, HANDLER, STORAGE_TYPES } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
23
+ const { getGraphServiceNameFromGraphServerTagWithCache, getServiceNameWithCache } = require('@izara_project/izara-core-library-service-schemas/src/ServiceConfig')
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, externalResourceName } = require("../../libs/Consts");
26
+
27
+ const templatePath = path.join(__dirname, "./template.ejs");
28
+
29
+ async function getGraphServiceTagFromRelSchema(_izContext, allRelSchemas) {
30
+ let graphServiceNames = [];
31
+ // for (const allRelSchema of Object.values(allRelSchemas)) {
32
+ // for (const relationship of Object.values(allRelSchema)) {
33
+ // for (const storageResource of Object.values(relationship.storageResources)) {
34
+ // if (storageResource.storageType === STORAGE_TYPES.graph) {
35
+ // let getGraphServiceTag = await getGraphServiceNameFromGraphServerTagWithCache(_izContext, storageResource.graphServerTag)
36
+ // if (!graphServiceNames.includes(getGraphServiceTag)) {
37
+ // graphServiceNames.push(getGraphServiceTag);
38
+ // }
39
+ // }
40
+ // }
41
+ // }
42
+ // }
43
+
44
+
45
+ await Promise.all(allRelSchemas.map(async relSchema => {
46
+ let relTag = Object.keys(relSchema)[0];
47
+ let relSchemaData = relSchema[relTag];
48
+
49
+ await Promise.all(Object.values(relSchemaData.storageResources).map(async storageResource => {
50
+ if (storageResource.storageType === STORAGE_TYPES.graph) {
51
+ let getGraphServiceTag = await getGraphServiceNameFromGraphServerTagWithCache(_izContext, storageResource.graphServerTag)
52
+ graphServiceNames.push(getGraphServiceTag);
53
+ }
54
+ }))
55
+ }));
56
+
57
+ return [...new Set(graphServiceNames)];
58
+ }
59
+
60
+
61
+
62
+ async function createExternalSnsSubscriptions(_izContext, allRelSchemas, srcPath) {
63
+ const snsServiceConfigArray = [];
64
+ const snsServiceConfigUpdateRelationshipComplete = await snsSubScriptionUpdateRelationship(_izContext, allRelSchemas)
65
+ snsServiceConfigUpdateRelationshipComplete && snsServiceConfigArray.push(snsServiceConfigUpdateRelationshipComplete)
66
+
67
+
68
+ return {
69
+ templatePath: templatePath,
70
+ templateData: { datas: snsServiceConfigArray },
71
+ setting: {
72
+ savePath: path.join(srcPath, SOURCE_PATH.externalService),
73
+ saveFileName: "generatedSnsServiceConfig",
74
+ fileExtension: ".js",
75
+ isAppend: false
76
+ }
77
+ }
78
+ }
79
+ // update Relationship
80
+ async function snsSubScriptionUpdateRelationship(_izContext, allRelSchemas) {
81
+ let serviceNames = await getGraphServiceTagFromRelSchema(_izContext, allRelSchemas)
82
+
83
+ return {
84
+ serviceNames: serviceNames,
85
+ topicName: "OutUpdateRelationship",
86
+ sqsEndpoint: "OutUpdateRelationshipComplete"
87
+ }
88
+ }
89
+
90
+
91
+ // create Relationship
92
+
93
+
94
+ module.exports = createExternalSnsSubscriptions
95
+
96
+ // not done yet wait for comfirmation
@@ -0,0 +1,12 @@
1
+ [
2
+ {
3
+ "serviceName": "externalService",
4
+ "topicName": "sns of external service",
5
+ "sqsEndpoint": "sqs inside this service"
6
+ },
7
+ {
8
+ "serviceName": [],
9
+ "topicName": [],
10
+ "sqsEndpoint": []
11
+ }
12
+ ]
@@ -0,0 +1,10 @@
1
+ module.exports.generatedSnsTopicSubscription = [ <% datas.forEach(data => { -%>
2
+ <% data.serviceNames.forEach(serviceName => { _%>
3
+ {
4
+ serviceName: "<%- serviceName %>",
5
+ topicName: "<%- data.topicName %>",
6
+ sqsEndpoint: "<%- data.sqsEndpoint %>"
7
+ },
8
+ <% }) _%>
9
+ <% }) _%>
10
+ ]
@@ -73,8 +73,13 @@ function createIamRole(action, resource = [], effect = "Allow") {
73
73
  const SOURCE_PATH = {
74
74
  appYaml: `../sls_yaml/generatedCode/source/`,
75
75
  resourceYaml: `../../resource/sls_yaml/generatedCode/source/`,
76
- lambdaPerObjectTypePath: `/generatedCode/lambdaPerObjectType/source/`,
77
- lamdaPerCombindActionPath: `/generatedCode/lamdaPerCombindAction/source/`,
76
+ lambdaPerObjectTypePath: `/generatedCode/lambdaPerObjectType/source/`, // test
77
+ lamdaPerCombindActionPath: `/generatedCode/lamdaPerCombindAction/source/`, // test
78
+ externalService: '../initial_setup/generatedCode/source/',
79
+ lambdaPerAction: '../src/generatedCode/ObjectTypePerActionEndpoint/source/',
80
+ updateRelationshipSchema: '../src/generatedCode/RelationshipPerAction/source/',
81
+ resourceLocationPerAction: 'src/generatedCode/ObjectTypePerActionEndpoint/source/',
82
+ resourceLocationUpdateRelationshipSchema: 'src/generatedCode/RelationshipPerAction/source/',
78
83
  };
79
84
 
80
85
 
@@ -97,6 +102,26 @@ const DEFAULT_LAMBDA_ROLE_PER_ACTION = {
97
102
  }
98
103
  }
99
104
 
105
+ const SQS_RESOURCE = {
106
+ sendMessage: "SendMessage",
107
+ receiveMessage: "ReceiveMessage",
108
+ deleteMessage: "DeleteMessage",
109
+ getQueueAttributes: "GetQueueAttributes",
110
+ deleteMessageBatch: "DeleteMessageBatch",
111
+ getQueueUrl: "GetQueueUrl"
112
+ }
113
+
114
+ function externalResourceName(resourceClass, functionName, serviceTag) {
115
+ return {
116
+ [RESOURCE_CLASSES.dynamoDbTable]: "arn:aws:dynamodb:${process.env.iz_region}:${process.env.iz_accountId}:table/${await dynamoSharedLib.tableName(_izContext, " + `"${functionName}" ,"${serviceTag}")}`,
117
+ [RESOURCE_CLASSES.lambda]: "arn:aws:lambda:${process.env.iz_region}:${process.env.iz_accountId}:function:${await lambdaSharedLib.lambdaFunctionName(_izContext, " + `"${functionName}" ,"${serviceTag}")}`,
118
+ }[resourceClass]
119
+ }
120
+
121
+ function externalResourceSns(functionName, serviceTag) {
122
+ return "arn:aws:sns:${process.env.iz_region}:${process.env.iz_accountId}:${await snsSharedLib.snsTopicName(_izContext, " + `"${functionName}", "${serviceTag}")}`
123
+ }
124
+
100
125
  module.exports = {
101
126
  ACTIONS,
102
127
  DEFAULT_HANDLER_PER_ACTION,
@@ -104,5 +129,9 @@ module.exports = {
104
129
  resourceNames,
105
130
  createIamRole,
106
131
  SOURCE_PATH,
107
- DEFAULT_LAMBDA_ROLE_PER_ACTION
132
+ DEFAULT_LAMBDA_ROLE_PER_ACTION,
133
+ SQS_RESOURCE,
134
+ HANDLER,
135
+ externalResourceName,
136
+ externalResourceSns
108
137
  }
@@ -1,31 +0,0 @@
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
- } _%>
@@ -1,12 +0,0 @@
1
- // example template data for dynamoDb
2
- const templateData = {
3
- tableName: "xx",
4
- attributes: [
5
- {
6
- keyType: "xx", // partitionKey || sortKey
7
- AttributeName: "", // any
8
- AttributeType: "" // S, N, B
9
- },
10
- //...
11
- ]
12
- }