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

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 (31) hide show
  1. package/index.js +25 -0
  2. package/package.json +6 -2
  3. package/src/GenerateCodeLibs/index.js +24 -0
  4. package/src/GenerateCodeLibs/src/GenerateCodeLibs.js +1373 -0
  5. package/src/MainLibs/index.js +24 -0
  6. package/src/MainLibs/src/Consts.js +0 -0
  7. package/src/MainLibs/src/Utils.js +27 -0
  8. package/src/SourceManager/index.js +23 -0
  9. package/src/SourceManager/src/CreateSource.js +182 -0
  10. package/src/SourceManager/src/Utils.js +50 -0
  11. package/src/TemplateManager/index.js +23 -0
  12. package/src/TemplateManager/src/GenerateCode.js +135 -0
  13. package/src/TemplateManager/src/MainResourcesYaml/CreateSourceData.js +76 -0
  14. package/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Data/MainDynamoDbYamlData.js +153 -0
  15. package/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Template/DynamoDb.ejs +31 -0
  16. package/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Template/DynamoDb.exampleData.js +12 -0
  17. package/src/TemplateManager/src/PerActionEndpoint/CreateSourceData.js +131 -0
  18. package/src/TemplateManager/src/PerActionEndpoint/DataPerActionEndpoint.js +0 -0
  19. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/Handler/Handler.js +0 -0
  20. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/MainFunction/MainFunctionTemplate/Create.js +18 -0
  21. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/MainFunction/MainFunctionTemplate/Delete.js +18 -0
  22. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/MainFunction/MainFunctionTemplate/Get.js +18 -0
  23. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/MainFunction/MainFunctionTemplate/Update.js +18 -0
  24. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/MainFunction/MainFunctionTemplateData.js +0 -0
  25. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Data/LambdaYamlData.js +166 -0
  26. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Template/HdrApi.ejs +0 -0
  27. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Template/HdrDsq.ejs +0 -0
  28. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Template/HdrInv.ejs +26 -0
  29. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Template/HdrInv.exampleData.js +15 -0
  30. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Template/HdrSqs.ejs +0 -0
  31. package/src/TemplateManager/src/libs/Consts.js +108 -0
@@ -0,0 +1,153 @@
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 {
23
+ // HANDLER,
24
+ // STORAGE_TYPES
25
+ // } = require('@izara_project/izara-core-library-service-schemas/src/Consts');
26
+
27
+
28
+ const STORAGE_TYPES = {
29
+ dynamoDB: "dynamoDB",
30
+ graph: "graph"
31
+ }
32
+
33
+
34
+ // ---------- End Per Lambda Handler IamRole Data ----------
35
+
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 {Object} objectSchema
45
+ * @returns {Object[]} - data of multiple dynamoDb template
46
+ */
47
+ function dataForMainDynamoDbYamlFromObjectSchema(_izContext, objectSchema) {
48
+ let dynamoDbYamlTemplateData = [];
49
+
50
+ // store detail for create dynamoDb table
51
+ let identifiersDetail = {};
52
+
53
+ // add identifiersDetail for dynamoDb storage
54
+ for (let identifier of objectSchema.identifiers) {
55
+ if (identifier.type === "partitionKey" || identifier.type === "sortKey") {
56
+ identifiersDetail[identifier.type] = {};
57
+
58
+ if (identifier.name) {
59
+ Object.assign(
60
+ identifiersDetail[identifier.type],
61
+ {
62
+ AttributeName: identifier.name,
63
+ AttributeType: "S"
64
+ }
65
+ );
66
+ } else {
67
+ let fieldNameType = objectSchema.fieldNames[identifier.fieldName].type;
68
+ let attributeType;
69
+
70
+ if (fieldNameType === "string") {
71
+ attributeType = "S"
72
+ } else if (fieldNameType === "number") {
73
+ attributeType = "N"
74
+ }
75
+
76
+ Object.assign(
77
+ identifiersDetail[identifier.type],
78
+ {
79
+ AttributeName: identifier.fieldName,
80
+ AttributeType: attributeType
81
+ }
82
+ );
83
+ }
84
+ }
85
+ }
86
+
87
+ if (!identifiersDetail.hasOwnProperty("partitionKey")) {
88
+ return [];
89
+ }
90
+
91
+
92
+ // start create dynamoDb template data
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
+
100
+
101
+ if (storageResource.hasOwnProperty("groupByPartitionKeyField")) {
102
+ templateData.attributes.push(
103
+ {
104
+ keyType: "partitionKey",
105
+ AttributeName: storageResource.groupByPartitionKeyField,
106
+ AttributeType: "S"
107
+ }
108
+ );
109
+ } else {
110
+ for (let identifierType in identifiersDetail) {
111
+ templateData.attributes.push(
112
+ {
113
+ keyType: identifierType,
114
+ AttributeName: identifiersDetail[identifierType].AttributeName,
115
+ AttributeType: identifiersDetail[identifierType].AttributeType
116
+ }
117
+ );
118
+ }
119
+ }
120
+ dynamoDbYamlTemplateData.push(templateData);
121
+ }
122
+ }
123
+
124
+ return dynamoDbYamlTemplateData
125
+ }
126
+
127
+
128
+ // return array of table data
129
+ // because one relSchema can create multiple dynamoDb table
130
+ function dataForMainDynamoDbYamlFromRelSchema(_izContext, relSchema) {
131
+ let relTag = Object.keys(relSchema)[0];
132
+ let relData = relSchema[relTag];
133
+
134
+ for (let parents of relData.parents) {
135
+ let parentObjectType = parent.objType.objectType;
136
+
137
+
138
+ }
139
+
140
+ return
141
+ }
142
+
143
+
144
+ module.exports = {
145
+ dynamoDbMainYamlFromObjectSchema: {
146
+ templatePath: path.join(__dirname, '../Template/DynamoDb.ejs'),
147
+ templateDataFunction: dataForMainDynamoDbYamlFromObjectSchema
148
+ },
149
+ dynamoDbMainYamlFromRelSchema: {
150
+ templatePath: path.join(__dirname, '../Template/DynamoDb.ejs'),
151
+ templateDataFunction: dataForMainDynamoDbYamlFromRelSchema
152
+ },
153
+ }
@@ -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,12 @@
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
+ }
@@ -0,0 +1,131 @@
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 schemaConsts = require('@izara_project/izara-core-library-service-schemas/src/Consts');
23
+
24
+ const consts = require('../libs/Consts')
25
+
26
+
27
+ const lambdaYaml = require("./TemplateAndData/ResourceYaml/Lambda/Data/LambdaYamlData")
28
+
29
+
30
+ /**
31
+ * receive objectSchema
32
+ *
33
+ * return array of object for function createSource
34
+ * eg:
35
+ * [
36
+ * { // main function
37
+ * templatePath:"path of template",
38
+ * data: "data of template",
39
+ * setting: "setting of createSourceFunction"
40
+ * },
41
+ * // ... data of hdr, resource ...etc.
42
+ * ]
43
+ *
44
+ *
45
+ *
46
+ * @param {Object} _izContext
47
+ * @param {Object} objectSchema
48
+ */
49
+ module.exports.createSourceDataObjectSchema = (_izContext, objectSchema, saveFilePath) => {
50
+
51
+ let resultsForCreateSource = [];
52
+ /*
53
+ receive objectSchema
54
+
55
+ check setting of overwrite main function
56
+ if not exists will create new main function
57
+
58
+ check overWriteHandlers
59
+ create handler depend on overWriteHandlers setting or default setting
60
+ - create lambda Yaml depend on handler
61
+ - add dynamodb iam role to lambda iam role
62
+ */
63
+
64
+ // create main function per action
65
+ for (let action of Object.values(consts.ACTIONS)) {
66
+ console.log("action: ", action);
67
+
68
+ let overWriteMainFunction = (objectSchema.overwriteGeneratedMainFunction && Array.isArray(objectSchema.overwriteGeneratedMainFunction))
69
+ ? objectSchema.overwriteGeneratedMainFunction : [];
70
+
71
+ // avoid generate main function
72
+ if (overWriteMainFunction.includes(action)) {
73
+ continue;
74
+ }
75
+
76
+ // -> start generate main function Per action here
77
+ }
78
+
79
+
80
+ // create handler and iam role of handler per action
81
+ for (let [action, handlerList] of Object.entries(consts.DEFAULT_HANDLER_PER_ACTION)) {
82
+
83
+ let useHandler = (objectSchema.overWriteHandlers && objectSchema.overWriteHandlers[action])
84
+ ? objectSchema.overWriteHandlers[action]
85
+ : handlerList;
86
+
87
+ console.log("useHandler: ", useHandler);
88
+
89
+
90
+ // start to create handler
91
+ // if overWriteHandlers[action] is empty array will not create handler
92
+ for (let hdr of useHandler) {
93
+ // -> create handler here
94
+
95
+ // -> create iam role of handler here
96
+ resultsForCreateSource.push({
97
+ templatePath: lambdaYaml[hdr].templatePath,
98
+ templateData: lambdaYaml[hdr].templateDataFunction(_izContext, objectSchema, action),
99
+ setting: {
100
+ savePath: path.join(saveFilePath, consts.SOURCE_PATH.appYaml),
101
+ saveFileName: 'generate-function',
102
+ fileExtension: '.yml',
103
+ isAppend: true
104
+ }
105
+ });
106
+
107
+ // -> create sns sqs here
108
+ // -> ideas for below
109
+ // resultsForCreateSource.push({
110
+ // templatePath: "xx",
111
+ // templateData: "xx",
112
+ // setting: {
113
+ // savePath: path.join(saveFilePath, config.SOURCE_PATH.appYaml),
114
+ // saveFileName: 'sns-in-sqs',
115
+ // fileExtension: '.yml',
116
+ // isAppend: true
117
+ // }
118
+ // });
119
+
120
+ }
121
+ }
122
+
123
+
124
+
125
+ // create resource for handler
126
+
127
+ // create resource for all handler, eg: dynamo
128
+
129
+
130
+ return resultsForCreateSource;
131
+ }
@@ -0,0 +1,18 @@
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';
@@ -0,0 +1,18 @@
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';
@@ -0,0 +1,18 @@
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';
@@ -0,0 +1,18 @@
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';
@@ -0,0 +1,166 @@
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 {
23
+ // HANDLER
24
+ // } = require('@izara_project/izara-core-library-service-schemas/src/Consts');
25
+
26
+ const {
27
+ createIamRole,
28
+ resourceNames,
29
+ RESOURCE_CLASSES,
30
+ DEFAULT_HANDLER_PER_ACTION
31
+ } = require("../../../../../libs/Consts");
32
+
33
+ const {
34
+ firstLetterLowerCase,
35
+ firstLetterUpperCase
36
+ } = require("../../../../../../../MainLibs/src/Utils");
37
+
38
+ const defaultGeneratedLambdaLocation = "src/generatedCode/lambdaPerObjectType/source/"
39
+
40
+ const HANDLER = { // mock
41
+ hdrApi: "hdrApi",
42
+ hdrInv: "hdrInv",
43
+ hdrDsq: "hdrDsq",
44
+ hdrSqs: "hdrSqs"
45
+ }
46
+
47
+ const STORAGE_TYPES = {
48
+ dynamoDB: "dynamoDB",
49
+ graph: "graph"
50
+ }
51
+
52
+ function defaultIamRolePerAction() {
53
+
54
+ let defaultIamRole = [];
55
+
56
+
57
+ defaultIamRole.push(
58
+ createIamRole(
59
+ { [RESOURCE_CLASSES.s3]: ["GetObject", "GetObjectVersion"] },
60
+ [
61
+ resourceNames(RESOURCE_CLASSES.s3, "object-schema/perServiceSchemas/*"),
62
+ resourceNames(RESOURCE_CLASSES.s3, "object-schema/serviceConfig/ServiceNameConfig.json"),
63
+ resourceNames(RESOURCE_CLASSES.s3, "object-schema/serviceConfig/GraphServerTags.json"),
64
+ ]
65
+ )
66
+ );
67
+
68
+ defaultIamRole.push(
69
+ createIamRole(
70
+ { [RESOURCE_CLASSES.s3]: ["ListBucket"] },
71
+ [
72
+ resourceNames(RESOURCE_CLASSES.s3, "object-schema"),
73
+ ]
74
+ )
75
+ );
76
+
77
+ return defaultIamRole
78
+ }
79
+
80
+ // ---------- Per Lambda Handler IamRole Data ----------
81
+
82
+ function lambdaIamRoleForHdrInv(_izContext, objectSchema, action) {
83
+ console.log("lambdaIamRoleForHdrInv");
84
+ console.log("action: ", action);
85
+
86
+ // add lambda role
87
+
88
+ let additionalResourcePermission = defaultIamRolePerAction();
89
+
90
+ let hasGraphStorage = false;
91
+ for (let storageResource of Object.values(objectSchema.storageResources)) {
92
+ if (storageResource.storageType === STORAGE_TYPES.dynamoDB) {
93
+ // add IamRole for dynamodb depend on tableName in storageResources of objectSchema
94
+ additionalResourcePermission.push(
95
+ createIamRole(
96
+ { [RESOURCE_CLASSES.dynamoDbTable]: [DEFAULT_HANDLER_PER_ACTION[action].dynamoDbPermission] },
97
+ [resourceNames(RESOURCE_CLASSES.dynamoDbTable, storageResource.tableName)]
98
+ )
99
+ );
100
+ } else if (storageResource.storageType === STORAGE_TYPES.graph) {
101
+ // find graph serviceName from graphServerTag or *GetNodeHdrInv ?
102
+
103
+ if (hasGraphStorage) {
104
+ continue;
105
+ } else {
106
+ hasGraphStorage = true;
107
+ }
108
+
109
+ additionalResourcePermission.push(
110
+ createIamRole(
111
+ { [RESOURCE_CLASSES.lambda]: ["InvokeFunction"] },
112
+ [resourceNames(RESOURCE_CLASSES.lambda, "*GetNodeHdrInv")]
113
+ )
114
+ );
115
+ }
116
+ }
117
+
118
+ // finished add lambda role
119
+
120
+
121
+ return {
122
+ resourceName: `${objectSchema.objectType}${firstLetterUpperCase(action)}`,
123
+ handlerType: HANDLER.hdrInv,
124
+ resourceLocation: `${path.join(defaultGeneratedLambdaLocation, objectSchema.objectType)}`,
125
+ additionalResourcePermission
126
+ }
127
+ }
128
+
129
+ function lambdaIamRoleForHdrApi(_izContext, objectSchema, action) {
130
+ console.log("lambdaIamRoleForHdrApi");
131
+ console.log("action: ", action);
132
+
133
+ }
134
+
135
+
136
+ function lambdaIamRoleForHdrSqs(_izContext, objectSchema, action) {
137
+ console.log("lambdaIamRoleForHdrSqs");
138
+ console.log("action: ", action);
139
+ }
140
+
141
+
142
+ function lambdaIamRoleForHdrDsq(_izContext, objectSchema, action) {
143
+ console.log("lambdaIamRoleForHdrDsq");
144
+ console.log("action: ", action);
145
+
146
+ }
147
+
148
+ // ---------- End Per Lambda Handler IamRole Data ----------
149
+ module.exports = {
150
+ [HANDLER.hdrInv]: {
151
+ templatePath: path.join(__dirname, "../Template/HdrInv.ejs"),
152
+ templateDataFunction: lambdaIamRoleForHdrInv
153
+ },
154
+ [HANDLER.hdrApi]: {
155
+ templatePath: path.join(__dirname, "../Template/HdrApi.ejs"),
156
+ templateDataFunction: lambdaIamRoleForHdrApi
157
+ },
158
+ [HANDLER.hdrSqs]: {
159
+ templatePath: path.join(__dirname, "../Template/HdrSqs.ejs"),
160
+ templateDataFunction: lambdaIamRoleForHdrSqs
161
+ },
162
+ [HANDLER.hdrDsq]: {
163
+ templatePath: path.join(__dirname, "../Template/HdrDsq.ejs"),
164
+ templateDataFunction: lambdaIamRoleForHdrDsq
165
+ }
166
+ }
@@ -0,0 +1,26 @@
1
+ <%_ const join = require('path').join; _%>
2
+ <%- firstLetterUpperCase(resourceName) %><%- firstLetterUpperCase(handlerType) %>:
3
+ handler: <%- join(resourceLocation, `${firstLetterUpperCase(resourceName)}_${firstLetterUpperCase(handlerType)}.main`)%>
4
+ name: ${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(resourceName) %><%- firstLetterUpperCase(handlerType) %>
5
+ iamRoleStatements:
6
+ <%_ additionalResourcePermission.forEach(resourcePermission => { _%>
7
+ - Effect: <%- resourcePermission.effect %>
8
+ Action:
9
+ <%_ Object.keys(resourcePermission.action).forEach(resourcePerAction => { _%>
10
+ <%_ resourcePermission.action[resourcePerAction].forEach(permission => { _%>
11
+ - <%- resourcePerAction %>:<%- permission %>
12
+ <%_}) _%>
13
+ <%_ }) _%>
14
+ Resource:
15
+ <%_ resourcePermission.resource.forEach(resource => { _%>
16
+ - <%- resource %>
17
+ <%_ }) _%>
18
+ <%_}) _%>
19
+ #<#<%- resourceName %><%- handlerType %>IamRole#>
20
+ #<#/<%- resourceName %><%- handlerType %>IamRole#>
21
+ <%_ function firstLetterUpperCase(text){
22
+ return text.charAt(0).toUpperCase() + text.slice(1)
23
+ } _%>
24
+ <%_ function firstLetterLowerCase(str) {
25
+ return str.charAt(0).toLowerCase() + str.slice(1)
26
+ } _%>
@@ -0,0 +1,15 @@
1
+ // example template data
2
+ const templateData = {
3
+ resourceName: "xx",
4
+ handlerType: "xx",
5
+ resourceLocation: "xx",
6
+ additionalResourcePermission: [
7
+ {
8
+ effect: "xx",
9
+ action: {
10
+ sqs: ["sendMessage", "receiveMessage"],
11
+ },
12
+ resource: ["aws:sqs", "..."]
13
+ }
14
+ ]
15
+ }