@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.
Files changed (128) hide show
  1. package/package.json +2 -2
  2. package/src/GenerateCodeLibs/index.js +2 -1
  3. package/src/GenerateCodeLibs/src/Consts.js +12 -3
  4. package/src/GenerateCodeLibs/src/GenerateCodeLibs.js +232 -7
  5. package/src/GenerateCodeLibs/src/TranslateIdsLibs.js +89 -0
  6. package/src/MainLibs/src/Utils.js +10 -0
  7. package/src/TemplateManager/src/CreateRelationship/createRelationship/functionYaml/HdrApi/data.js +10 -2
  8. package/src/TemplateManager/src/CreateRelationship/createRelationship/functionYaml/HdrDsq/data.js +5 -4
  9. package/src/TemplateManager/src/CreateRelationship/createRelationship/functionYaml/HdrInv/data.js +11 -1
  10. package/src/TemplateManager/src/CreateRelationship/createRelationship/functionYaml/HdrSqs/data.js +4 -3
  11. package/src/TemplateManager/src/CreateRelationship/createRelationship/mainFunction/template.ejs +24 -22
  12. package/src/TemplateManager/src/CreateRelationship/createRelationship/perAction/HdrDsq/data.js +0 -1
  13. package/src/TemplateManager/src/CreateRelationship/createRelationship/perAction/HdrSqs/data.js +1 -1
  14. package/src/TemplateManager/src/CreateRelationship/createRelationship/sns-in-sqs/data.js +0 -2
  15. package/src/TemplateManager/src/CreateRelationship/createRelationshipComplete/functionYaml/data.js +2 -2
  16. package/src/TemplateManager/src/CreateRelationship/createRelationshipComplete/handler/HdrSqs/data.js +0 -1
  17. package/src/TemplateManager/src/CreateRelationship/createRelationshipComplete/sns-out/data.js +1 -1
  18. package/src/TemplateManager/src/FindData/FindDataYaml/data.js +188 -0
  19. package/src/TemplateManager/src/FindData/FindDataYaml/template.ejs +27 -0
  20. package/src/TemplateManager/src/FindData/GetByStorage/getByDynamo.ejs +53 -0
  21. package/src/TemplateManager/src/FindData/GetByStorage/getByGraph.ejs +99 -0
  22. package/src/TemplateManager/src/FindData/Handler/data.js +48 -0
  23. package/src/TemplateManager/src/FindData/Handler/template.ejs +140 -0
  24. package/src/TemplateManager/src/FindData/mainFunction/data.js +279 -0
  25. package/src/TemplateManager/src/FindData/mainFunction/template.ejs +158 -0
  26. package/src/TemplateManager/src/GenerateCode(Old).js +1 -1
  27. package/src/TemplateManager/src/GenerateCode.js +163 -42
  28. package/src/TemplateManager/src/OutPerActionComplete/OutCreateComplete/functionYaml/data.js +98 -0
  29. package/src/TemplateManager/src/OutPerActionComplete/OutCreateComplete/functionYaml/template.ejs +33 -0
  30. package/src/TemplateManager/src/OutPerActionComplete/OutCreateComplete/handler/data.js +59 -0
  31. package/src/TemplateManager/src/OutPerActionComplete/OutCreateComplete/handler/template.ejs +129 -0
  32. package/src/TemplateManager/src/OutPerActionComplete/OutCreateComplete/mainFunction/createObjectComplete_main.js +172 -0
  33. package/src/TemplateManager/src/OutPerActionComplete/OutCreateComplete/mainFunction/data.js +53 -0
  34. package/src/TemplateManager/src/OutPerActionComplete/OutCreateComplete/mainFunction/template.ejs +172 -0
  35. package/src/TemplateManager/src/OutPerActionComplete/OutCreateComplete/sns-in-sqs/data.js +58 -0
  36. package/src/TemplateManager/src/OutPerActionComplete/OutCreateComplete/sns-in-sqs/template.ejs +47 -0
  37. package/src/TemplateManager/src/OutPerActionComplete/OutCreateComplete/sns-out/data.js +62 -0
  38. package/src/TemplateManager/src/OutPerActionComplete/OutCreateComplete/sns-out/template.ejs +10 -0
  39. package/src/TemplateManager/src/OutPerActionComplete/OutUpdateComplete/functionYaml/data.js +98 -0
  40. package/src/TemplateManager/src/OutPerActionComplete/OutUpdateComplete/functionYaml/template.ejs +33 -0
  41. package/src/TemplateManager/src/OutPerActionComplete/OutUpdateComplete/handler/data.js +59 -0
  42. package/src/TemplateManager/src/OutPerActionComplete/OutUpdateComplete/handler/template.ejs +129 -0
  43. package/src/TemplateManager/src/OutPerActionComplete/OutUpdateComplete/mainFunction/data.js +53 -0
  44. package/src/TemplateManager/src/OutPerActionComplete/OutUpdateComplete/mainFunction/template.ejs +126 -0
  45. package/src/TemplateManager/src/OutPerActionComplete/OutUpdateComplete/sns-out/data.js +62 -0
  46. package/src/TemplateManager/src/OutPerActionComplete/OutUpdateComplete/sqs-in-sns/data.js +58 -0
  47. package/src/TemplateManager/src/OutPerActionComplete/OutUpdateComplete/sqs-in-sns/template.ejs +47 -0
  48. package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrApi/data.js +22 -3
  49. package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrApi/template.ejs +2 -2
  50. package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrDsq/data.js +24 -1
  51. package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrInv/data.js +53 -2
  52. package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrSqs/data.js +25 -3
  53. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrApi/data.js +5 -8
  54. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrApi/getTemplate.ejs +76 -0
  55. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrApi/updateTemplate.ejs +67 -0
  56. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrDsq/data.js +47 -23
  57. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrDsq/getTemplate.ejs +105 -0
  58. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrDsq/updateTemplate.ejs +109 -0
  59. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrInv/createTemplate.ejs +75 -0
  60. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrInv/data.js +69 -21
  61. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrInv/getTemplate.ejs +82 -0
  62. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrInv/updateTemplate.ejs +75 -0
  63. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrSqs/data.js +46 -17
  64. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrSqs/getTemplate.ejs +124 -0
  65. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrSqs/updateTemplate.ejs +133 -0
  66. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Create/CreateObject_main.js +760 -0
  67. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Create/data.js +67 -0
  68. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Create/request.json +0 -0
  69. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Create/template.ejs +575 -0
  70. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Get/data.js +0 -6
  71. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Get/template.ejs +17 -12
  72. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Update/data.js +61 -0
  73. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Update/request.json +0 -0
  74. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Update/template.ejs +267 -0
  75. package/src/TemplateManager/src/ProcessLogical/Handler/data.js +49 -0
  76. package/src/TemplateManager/src/ProcessLogical/Handler/template.ejs +129 -0
  77. package/src/TemplateManager/src/ProcessLogical/ProcessLogicalYaml/data.js +175 -0
  78. package/src/TemplateManager/src/ProcessLogical/ProcessLogicalYaml/template.ejs +25 -0
  79. package/src/TemplateManager/src/ProcessLogical/mainFunction/data.js +47 -0
  80. package/src/TemplateManager/src/ProcessLogical/mainFunction/template.ejs +429 -0
  81. package/src/TemplateManager/src/ProcessLogicalPagination/DsqYaml/data.js +50 -0
  82. package/src/TemplateManager/src/ProcessLogicalPagination/DsqYaml/template.ejs +32 -0
  83. package/src/TemplateManager/src/ProcessLogicalPagination/FunctionYaml/HdrDsq/data.js +167 -0
  84. package/src/TemplateManager/src/ProcessLogicalPagination/FunctionYaml/HdrDsq/template.ejs +25 -0
  85. package/src/TemplateManager/src/ProcessLogicalPagination/FunctionYaml/HdrSqs/data.js +169 -0
  86. package/src/TemplateManager/src/ProcessLogicalPagination/FunctionYaml/HdrSqs/template.ejs +25 -0
  87. package/src/TemplateManager/src/ProcessLogicalPagination/Handler/HdrDsq/data.js +48 -0
  88. package/src/TemplateManager/src/ProcessLogicalPagination/Handler/HdrDsq/template.ejs +163 -0
  89. package/src/TemplateManager/src/ProcessLogicalPagination/Handler/HdrSqs/data.js +48 -0
  90. package/src/TemplateManager/src/ProcessLogicalPagination/Handler/HdrSqs/template.ejs +146 -0
  91. package/src/TemplateManager/src/ProcessLogicalPagination/mainFunction/data.js +48 -0
  92. package/src/TemplateManager/src/ProcessLogicalPagination/mainFunction/template.ejs +212 -0
  93. package/src/TemplateManager/src/ResourceYaml/CreateSourceData.js +2 -2
  94. package/src/TemplateManager/src/ResourceYaml/dynamodb/processLogicalAndFindData.js +2 -2
  95. package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/defaultSnsInSqsForFindDataAndProcessLogical.js +27 -12
  96. package/src/TemplateManager/src/ResourceYaml/sns-out/data.js +1 -1
  97. package/src/TemplateManager/src/ResourceYaml/sns-out/defaultSnsOutForFindDataAndProcessLogical.js +75 -0
  98. package/src/TemplateManager/src/TranslateIdReq/ProcessingTranslateIds/functionYaml/data.js +95 -0
  99. package/src/TemplateManager/src/TranslateIdReq/ProcessingTranslateIds/functionYaml/template.ejs +30 -0
  100. package/src/TemplateManager/src/TranslateIdReq/ProcessingTranslateIds/handler/dataHdrDsq.js +52 -0
  101. package/src/TemplateManager/src/TranslateIdReq/ProcessingTranslateIds/handler/template.ejs +194 -0
  102. package/src/TemplateManager/src/TranslateIdReq/ProcessingTranslateIds/mainFunction/data.js +48 -0
  103. package/src/TemplateManager/src/TranslateIdReq/ProcessingTranslateIds/mainFunction/template.ejs +330 -0
  104. package/src/TemplateManager/src/TranslateIdReq/ProcessingTranslateIds/sns-out/data.js +47 -0
  105. package/src/TemplateManager/src/TranslateIdReq/ProcessingTranslateIds/sqs-sns/data.js +58 -0
  106. package/src/TemplateManager/src/TranslateIdReq/ProcessingTranslateIds/sqs-sns/template.ejs +43 -0
  107. package/src/TemplateManager/src/TranslateIdReq/TranslateIds/functionYaml/HdrDsq/data.js +116 -0
  108. package/src/TemplateManager/src/TranslateIdReq/TranslateIds/functionYaml/HdrSqs/data.js +116 -0
  109. package/src/TemplateManager/src/TranslateIdReq/TranslateIds/handler/HdrDsq/data.js +60 -0
  110. package/src/TemplateManager/src/TranslateIdReq/TranslateIds/handler/HdrDsq/template.ejs +157 -0
  111. package/src/TemplateManager/src/TranslateIdReq/TranslateIds/handler/HdrSqs/data.js +59 -0
  112. package/src/TemplateManager/src/TranslateIdReq/TranslateIds/handler/HdrSqs/template.ejs +175 -0
  113. package/src/TemplateManager/src/TranslateIdReq/TranslateIds/mainFunction/data.js +61 -0
  114. package/src/TemplateManager/src/TranslateIdReq/TranslateIds/mainFunction/template.ejs +155 -0
  115. package/src/TemplateManager/src/TranslateIdReq/TranslateIds/resourceYaml/dynamoDb/data.js +120 -0
  116. package/src/TemplateManager/src/TranslateIdReq/TranslateIds/resourceYaml/sns-sqs/data.js +75 -0
  117. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/functionYaml/data.js +2 -2
  118. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/sns-out/data.js +1 -1
  119. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrApi/data.js +10 -3
  120. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrDsq/data.js +6 -4
  121. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrInv/data.js +11 -1
  122. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrSqs/data.js +7 -5
  123. package/src/TemplateManager/src/externalService/LambdaRole/data.js +150 -32
  124. package/src/TemplateManager/src/externalService/LambdaRole/template.ejs +16 -15
  125. package/src/TemplateManager/src/externalService/SnsTopicSubscriotions/data.js +35 -6
  126. package/src/TemplateManager/src/externalService/SnsTopicSubscriotions/template.ejs +3 -4
  127. package/src/TemplateManager/src/libs/Consts.js +122 -11
  128. package/src/TemplateManager/src/PerActionEndpoint/Handler/testRequest.json +0 -5
@@ -0,0 +1,50 @@
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 { SOURCE_PATH, SAVE_FILE_NAME } = require("../../../libs/Consts");
22
+ const templatePath = path.join(__dirname, "./template.ejs");
23
+
24
+
25
+ /**
26
+ * receive srcPath
27
+ * not create data for ProcessLogical Main template
28
+ *
29
+ * @param {Object} srcPath
30
+ * @return {{ templatePath, templateData, setting } }
31
+ */
32
+
33
+ async function data(_izContext, srcPath) {
34
+
35
+ return {
36
+ templatePath: templatePath,
37
+ templateData: {
38
+ queueName: "PaginateProcessLogicalHdrDsq"
39
+ },
40
+ setting: {
41
+ initialData: "Resources:\n",
42
+ savePath: path.join(srcPath, SOURCE_PATH.resourceYaml),
43
+ saveFileName: SAVE_FILE_NAME.snsInSqsYaml,
44
+ fileExtension: ".yml",
45
+ isAppend: true
46
+ }
47
+ }
48
+ }
49
+
50
+ module.exports = data;
@@ -0,0 +1,32 @@
1
+ #------- queue ---------
2
+ <%- queueName %>:
3
+ Type: "AWS::SQS::Queue"
4
+ Properties:
5
+ QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>
6
+ RedrivePolicy:
7
+ deadLetterTargetArn: #!GetAtt
8
+ Fn::GetAtt:
9
+ - <%- queueName %>DLQ
10
+ - Arn
11
+ maxReceiveCount: 3
12
+ VisibilityTimeout: 120
13
+ <%- queueName %>DLQ:
14
+ Type: AWS::SQS::Queue
15
+ Properties:
16
+ QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>DLQ
17
+ <%- queueName %>Policy:
18
+ Type: AWS::SQS::QueuePolicy
19
+ Properties:
20
+ PolicyDocument:
21
+ Version: "2012-10-17"
22
+ Statement:
23
+ - Sid: "allow-sns-messages"
24
+ Effect: Allow
25
+ Principal: "*"
26
+ Resource: #!GetAtt
27
+ Fn::GetAtt:
28
+ - <%- queueName %>
29
+ - Arn
30
+ Action: "SQS:SendMessage"
31
+ Queues:
32
+ - Ref: <%- queueName %>
@@ -0,0 +1,167 @@
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 { createIamRole, resourceNames, RESOURCE_CLASSES, DEFAULT_LAMBDA_ROLE_PER_ACTION, SQS_RESOURCE, SOURCE_PATH, SAVE_FILE_NAME, FUNCTION_NAME } = require("../../../libs/Consts");
26
+ const { firstLetterUpperCase: upperCase } = require('../../../../../MainLibs/src/Utils');
27
+
28
+ function defaultIamRolePerAction() {
29
+
30
+ let defaultIamRole = [];
31
+
32
+
33
+ defaultIamRole.push(
34
+ createIamRole(
35
+ {
36
+ [RESOURCE_CLASSES.s3]: ["GetObject", "GetObjectVersion"],
37
+ },
38
+ [
39
+ resourceNames(RESOURCE_CLASSES.s3, "object-schema/perServiceSchemas/*"),
40
+ resourceNames(RESOURCE_CLASSES.s3, "object-schema/serviceConfig/ServiceNameConfig.json"),
41
+ resourceNames(RESOURCE_CLASSES.s3, "object-schema/serviceConfig/GraphServerTags.json"),
42
+ ]
43
+ )
44
+ );
45
+
46
+ defaultIamRole.push(
47
+ createIamRole(
48
+ { [RESOURCE_CLASSES.s3]: ["ListBucket"] },
49
+ [
50
+ resourceNames(RESOURCE_CLASSES.s3, "object-schema"),
51
+ ]
52
+ )
53
+ );
54
+
55
+ defaultIamRole.push(
56
+ createIamRole(
57
+ {
58
+ [RESOURCE_CLASSES.sns]: ["Publish"]
59
+ },
60
+ [
61
+ resourceNames(RESOURCE_CLASSES.sns, "OutProcessLogicalComplete")
62
+ ]
63
+ )
64
+ )
65
+
66
+ defaultIamRole.push(
67
+ createIamRole(
68
+ {
69
+ [RESOURCE_CLASSES.dynamoDbTable]: [
70
+ DEFAULT_LAMBDA_ROLE_PER_ACTION[ACTIONS.get].dynamoDbPermission,
71
+ DEFAULT_LAMBDA_ROLE_PER_ACTION[ACTIONS.update].dynamoDbPermission,
72
+ "Query"
73
+ ]
74
+ },
75
+ [
76
+ resourceNames(RESOURCE_CLASSES.dynamoDbTable, "LogicalResultsMain")
77
+ ]
78
+ )
79
+ )
80
+
81
+ defaultIamRole.push(
82
+ createIamRole(
83
+ {
84
+ [RESOURCE_CLASSES.dynamoDbTable]: [
85
+ DEFAULT_LAMBDA_ROLE_PER_ACTION[ACTIONS.create].dynamoDbPermission,
86
+ ]
87
+ },
88
+ [
89
+ resourceNames(RESOURCE_CLASSES.dynamoDbTable, "LogicalResultsData")
90
+ ]
91
+ )
92
+ )
93
+ // console.log("defaultIamRole Api", defaultIamRole)
94
+ return defaultIamRole
95
+ }
96
+
97
+ /**
98
+ * receive objectSchema
99
+ * create data for FindData Main template
100
+ *
101
+ * @param {Object} objectSchemas
102
+ * @return {{ templatePath, templateData, setting } }
103
+ */
104
+ async function data(_izContext, objectSchemas, srcPath) {
105
+
106
+ let additionalResourcePermission = defaultIamRolePerAction();
107
+ let functionName = upperCase(FUNCTION_NAME.paginateProcessLogical);
108
+ let tableForQuery = [];
109
+
110
+ for (let objectSchema of objectSchemas.records) {
111
+ // console.log("objectSchema", objectSchemas)
112
+
113
+ for (let storageResource of Object.values(objectSchema.storageResources)) {
114
+ if (storageResource.storageType === STORAGE_TYPES.dynamoDB) {
115
+ // add IamRole for dynamodb depend on tableName in storageResources of objectSchema
116
+ tableForQuery.push(resourceNames(RESOURCE_CLASSES.dynamoDbTable, storageResource.tableName));
117
+ }
118
+ }
119
+ }
120
+
121
+ if (tableForQuery.length) {
122
+ additionalResourcePermission.push(
123
+ createIamRole(
124
+ { [RESOURCE_CLASSES.dynamoDbTable]: "Query" },
125
+ tableForQuery
126
+ )
127
+ );
128
+ }
129
+
130
+ additionalResourcePermission.push(
131
+ createIamRole({
132
+ [RESOURCE_CLASSES.sqs]:
133
+ [
134
+ SQS_RESOURCE.deleteMessage,
135
+ SQS_RESOURCE.getQueueAttributes,
136
+ SQS_RESOURCE.receiveMessage,
137
+ SQS_RESOURCE.sendMessage,
138
+ SQS_RESOURCE.deleteMessageBatch,
139
+ SQS_RESOURCE.getQueueUrl
140
+ ]
141
+ }, [
142
+ resourceNames(RESOURCE_CLASSES.sqs, functionName + upperCase(HANDLER.hdrDsq)),
143
+ resourceNames(RESOURCE_CLASSES.sqs, functionName + upperCase(HANDLER.hdrDsq) + "DLQ")
144
+ ]
145
+ )
146
+ )
147
+
148
+ // console.log("additionalResourcePermission", additionalResourcePermission)
149
+
150
+ return {
151
+ templatePath: templatePath,
152
+ templateData: {
153
+ functionName: functionName,
154
+ resourceLocation: SOURCE_PATH.resourceLocationProcessLogical,
155
+ handlerType: HANDLER.hdrDsq,
156
+ additionalResourcePermission
157
+ },
158
+ setting: {
159
+ savePath: path.join(srcPath, SOURCE_PATH.appYaml),
160
+ saveFileName: upperCase(SAVE_FILE_NAME.processLogicalYaml),
161
+ fileExtension: '.yml',
162
+ isAppend: true
163
+ }
164
+ }
165
+ }
166
+
167
+ module.exports = data;
@@ -0,0 +1,25 @@
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){ return text.charAt(0).toUpperCase() + text.slice(1) } _%>
@@ -0,0 +1,169 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+
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 { createIamRole, resourceNames, RESOURCE_CLASSES, DEFAULT_LAMBDA_ROLE_PER_ACTION, SQS_RESOURCE, SOURCE_PATH, SAVE_FILE_NAME, FUNCTION_NAME } = require("../../../libs/Consts");
26
+ const { firstLetterUpperCase: upperCase } = require('../../../../../MainLibs/src/Utils');
27
+
28
+ function defaultIamRolePerAction() {
29
+
30
+ let defaultIamRole = [];
31
+
32
+
33
+ defaultIamRole.push(
34
+ createIamRole(
35
+ {
36
+ [RESOURCE_CLASSES.s3]: ["GetObject", "GetObjectVersion"],
37
+ },
38
+ [
39
+ resourceNames(RESOURCE_CLASSES.s3, "object-schema/perServiceSchemas/*"),
40
+ resourceNames(RESOURCE_CLASSES.s3, "object-schema/serviceConfig/ServiceNameConfig.json"),
41
+ resourceNames(RESOURCE_CLASSES.s3, "object-schema/serviceConfig/GraphServerTags.json"),
42
+ ]
43
+ )
44
+ );
45
+
46
+ defaultIamRole.push(
47
+ createIamRole(
48
+ { [RESOURCE_CLASSES.s3]: ["ListBucket"] },
49
+ [
50
+ resourceNames(RESOURCE_CLASSES.s3, "object-schema"),
51
+ ]
52
+ )
53
+ );
54
+
55
+ defaultIamRole.push(
56
+ createIamRole(
57
+ {
58
+ [RESOURCE_CLASSES.sns]: ["Publish"]
59
+ },
60
+ [
61
+ resourceNames(RESOURCE_CLASSES.sns, "InProcessLogical"),
62
+ resourceNames(RESOURCE_CLASSES.sns, "OutProcessLogicalComplete")
63
+ ]
64
+ )
65
+ )
66
+
67
+ defaultIamRole.push(
68
+ createIamRole(
69
+ {
70
+ [RESOURCE_CLASSES.dynamoDbTable]: [
71
+ DEFAULT_LAMBDA_ROLE_PER_ACTION[ACTIONS.get].dynamoDbPermission,
72
+ DEFAULT_LAMBDA_ROLE_PER_ACTION[ACTIONS.update].dynamoDbPermission,
73
+ "Query"
74
+ ]
75
+ },
76
+ [
77
+ resourceNames(RESOURCE_CLASSES.dynamoDbTable, "LogicalResultsMain")
78
+ ]
79
+ )
80
+ )
81
+
82
+ defaultIamRole.push(
83
+ createIamRole(
84
+ {
85
+ [RESOURCE_CLASSES.dynamoDbTable]: [
86
+ DEFAULT_LAMBDA_ROLE_PER_ACTION[ACTIONS.create].dynamoDbPermission,
87
+ ]
88
+ },
89
+ [
90
+ resourceNames(RESOURCE_CLASSES.dynamoDbTable, "LogicalResultsData")
91
+ ]
92
+ )
93
+ )
94
+ // console.log("defaultIamRole Api", defaultIamRole)
95
+ return defaultIamRole
96
+ }
97
+
98
+ /**
99
+ * receive objectSchema
100
+ * create data for FindData Main template
101
+ *
102
+ * @param {Object} objectSchemas
103
+ * @return {{ templatePath, templateData, setting } }
104
+ */
105
+ async function data(_izContext, objectSchemas, srcPath) {
106
+
107
+ let additionalResourcePermission = defaultIamRolePerAction();
108
+ let functionName = upperCase(FUNCTION_NAME.paginateProcessLogical);
109
+ let tableForQuery = [];
110
+
111
+ for (let objectSchema of objectSchemas.records) {
112
+ // console.log("objectSchema", objectSchemas)
113
+
114
+ for (let storageResource of Object.values(objectSchema.storageResources)) {
115
+ if (storageResource.storageType === STORAGE_TYPES.dynamoDB) {
116
+ // add IamRole for dynamodb depend on tableName in storageResources of objectSchema
117
+ tableForQuery.push(resourceNames(RESOURCE_CLASSES.dynamoDbTable, storageResource.tableName));
118
+ }
119
+ }
120
+ }
121
+
122
+ if (tableForQuery.length) {
123
+ additionalResourcePermission.push(
124
+ createIamRole(
125
+ { [RESOURCE_CLASSES.dynamoDbTable]: "Query" },
126
+ tableForQuery
127
+ )
128
+ );
129
+ }
130
+
131
+ additionalResourcePermission.push(
132
+ createIamRole({
133
+ [RESOURCE_CLASSES.sqs]:
134
+ [
135
+ SQS_RESOURCE.deleteMessage,
136
+ SQS_RESOURCE.getQueueAttributes,
137
+ SQS_RESOURCE.receiveMessage,
138
+ SQS_RESOURCE.sendMessage,
139
+ SQS_RESOURCE.deleteMessageBatch,
140
+ SQS_RESOURCE.getQueueUrl
141
+ ]
142
+ }, [
143
+ resourceNames(RESOURCE_CLASSES.sqs, functionName + upperCase(HANDLER.hdrDsq)),
144
+ resourceNames(RESOURCE_CLASSES.sqs, functionName + upperCase(HANDLER.hdrSqs)),
145
+ resourceNames(RESOURCE_CLASSES.sqs, functionName + upperCase(HANDLER.hdrSqs) + "DLQ")
146
+ ]
147
+ )
148
+ )
149
+
150
+ // console.log("additionalResourcePermission", additionalResourcePermission)
151
+
152
+ return {
153
+ templatePath: templatePath,
154
+ templateData: {
155
+ functionName: functionName,
156
+ resourceLocation: SOURCE_PATH.resourceLocationProcessLogical,
157
+ handlerType: HANDLER.hdrSqs,
158
+ additionalResourcePermission
159
+ },
160
+ setting: {
161
+ savePath: path.join(srcPath, SOURCE_PATH.appYaml),
162
+ saveFileName: upperCase(SAVE_FILE_NAME.processLogicalYaml),
163
+ fileExtension: '.yml',
164
+ isAppend: true
165
+ }
166
+ }
167
+ }
168
+
169
+ module.exports = data;
@@ -0,0 +1,25 @@
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){ return text.charAt(0).toUpperCase() + text.slice(1) } _%>
@@ -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 { SOURCE_PATH, FUNCTION_NAME, HANDLER } = require("../../../libs/Consts");
22
+ const { firstLetterUpperCase: upperCase } = require('../../../../../MainLibs/src/Utils');
23
+ const templatePath = path.join(__dirname, "./template.ejs");
24
+
25
+
26
+ /**
27
+ * receive srcPath
28
+ * not create data for ProcessLogical Main template
29
+ *
30
+ * @param {Object} srcPath
31
+ * @return {{ templatePath, templateData, setting } }
32
+ */
33
+
34
+ function data(_izContext, srcPath) {
35
+
36
+ return {
37
+ templatePath: templatePath,
38
+ templateData: {},
39
+ setting: {
40
+ savePath: path.join(srcPath, SOURCE_PATH.processLogical),
41
+ saveFileName: `${upperCase(FUNCTION_NAME.paginateProcessLogical)}_${upperCase(HANDLER.hdrDsq)}`,
42
+ fileExtension: '.js',
43
+ isAppend: false
44
+ }
45
+ }
46
+ }
47
+
48
+ module.exports = data;
@@ -0,0 +1,163 @@
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 paginateProcessLogical = require('./PaginateProcessLogical_Main');
29
+
30
+ // validate event properties in body.Message of sqs event
31
+ middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema(
32
+ {
33
+ type: "object",
34
+ required: ['body', 'messageAttributes'],
35
+ properties: {
36
+ body: {
37
+ type: 'object',
38
+ },
39
+ messageAttributes: {
40
+ type: 'object'
41
+ }
42
+ }
43
+ }
44
+ ));
45
+
46
+ // set schema for record.body.Message
47
+ const perRecordsValidatorSchema = {
48
+ type: "object",
49
+ required: [
50
+ 'logicalResultId',
51
+ 'tableName',
52
+ 'partitionKeyFieldName',
53
+ 'sortKeyFieldName',
54
+ 'startKey',
55
+ 'overwriteUniqueRequestId'
56
+ ],
57
+ properties: {
58
+ logicalResultId: {
59
+ type: "string"
60
+ },
61
+ tableName: {
62
+ type: "string"
63
+ },
64
+ partitionKeyFieldName: {
65
+ type: "string"
66
+ },
67
+ sortKeyFieldName: {
68
+ type: "string"
69
+ },
70
+ comparison: {
71
+ type: "string",
72
+ default: ""
73
+ },
74
+ startKey: {
75
+ type: "object"
76
+ },
77
+ overwriteUniqueRequestId: {
78
+ type: "string"
79
+ },
80
+ callingFlow: {
81
+ type: 'string',
82
+ default: ""
83
+ }
84
+ }
85
+ };
86
+
87
+ // set schema for record.body.MessageAttributes
88
+ // const messageAttributeValidatorSchema = {
89
+ // type: "object",
90
+ // required: ['msgAtrrParam1', 'msgAtrrParam2'],
91
+ // properties: {
92
+ // msgAtrrParam1: {
93
+ // type: "string"
94
+ // },
95
+ // msgAtrrParam2: {
96
+ // type: "object"
97
+ // }
98
+ // }
99
+ // };
100
+
101
+ module.exports.main = middleware.wrap(async (event, context, callback) => {
102
+
103
+ try {
104
+
105
+ let recordPromises = [];
106
+
107
+ // loop each record and send to mainFunction
108
+ await Promise.all(event.Records.map(async record => { // promise.all for map() function
109
+
110
+ // --- reforming record.body for Dsq request
111
+ record = recordHandlerSharedLib.reformatDsqMessage(record._izContext, record);
112
+ record._izContext.logger.debug('record PaginateProcessLogicalHdrDsq after reform', record);
113
+
114
+ let passOnProperties = []
115
+
116
+
117
+ // validate message (and MessageAttributes)
118
+ await recordHandlerSharedLib.validateRecord(
119
+ record, // one record will send to mainFunction
120
+ "PaginateProcessLogicalHdrDsq", // queue name that need to retry or send to dlq
121
+ perRecordsValidatorSchema, // schema for record.Message
122
+ // messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
123
+ );
124
+
125
+ // add argument (to invoke lambda) to passOnProperties[]
126
+ passOnProperties.push(record.body.Message.logicalResultId)
127
+ passOnProperties.push(record.body.Message.tableName)
128
+ passOnProperties.push(record.body.Message.partitionKeyFieldName)
129
+ passOnProperties.push(record.body.Message.sortKeyFieldName)
130
+ passOnProperties.push(record.body.Message.comparison)
131
+ passOnProperties.push(record.body.Message.startKey)
132
+ passOnProperties.push(record.body.Message.overwriteUniqueRequestId)
133
+ passOnProperties.push(record.body.Message.callingFlow)
134
+ record._izContext.logger.debug('passOnProperties in handler', passOnProperties);
135
+
136
+ // call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
137
+ let recordPromise = recordHandlerSharedLib.recordHandler(
138
+ record, // one record will send to mainFunction
139
+ paginateProcessLogical.paginateProcessLogical, // mainFunction that need to invoke.
140
+ "PaginateProcessLogicalHdrDsq", // queue name that need to retry or send to dlq
141
+ passOnProperties, // all parameters that mainFunction needed.
142
+ );
143
+ record._izContext.logger.debug('after recordPromise in handler');
144
+ recordPromises.push(recordPromise); // push promise to recordPromises
145
+ }))
146
+
147
+ Logger.debug('before Promise.all(recordPromises) in handler');
148
+ try {
149
+ // --- main await all promises
150
+ await Promise.all(recordPromises); // await all promises
151
+
152
+ return event.Records // return all for local testing
153
+
154
+ } catch {
155
+ Logger.debug('Promise.all(recordPromises) in handler threw error (at least one record did no resolve)');
156
+ }
157
+ Logger.debug('after Promise.all(recordPromises) in handler');
158
+
159
+ } catch (err) {
160
+ Logger.error('Unhandled Error, PaginateProcessLogicalHdrDsq: ', err);
161
+ throw (err);
162
+ }
163
+ });