@izara_project/izara-market-library-service-schemas 1.0.19 → 1.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/SourceManager/src/Utils.js +33 -9
- package/src/TemplateManager/src/FindData/FindDataYaml/data.js +4 -1
- package/src/TemplateManager/src/FindData/FindDataYaml/template.ejs +1 -14
- package/src/TemplateManager/src/GenerateCode.js +22 -5
- package/src/TemplateManager/src/OutPerActionComplete/OutCreateComplete/functionYaml/data.js +22 -2
- package/src/TemplateManager/src/OutPerActionComplete/OutCreateComplete/functionYaml/template.ejs +1 -14
- package/src/TemplateManager/src/OutPerActionComplete/OutDeleteComplete/functionYaml/data.js +21 -2
- package/src/TemplateManager/src/OutPerActionComplete/OutDeleteComplete/functionYaml/template.ejs +1 -14
- package/src/TemplateManager/src/OutPerActionComplete/OutGetComplete/functionYaml/data.js +23 -3
- package/src/TemplateManager/src/OutPerActionComplete/OutGetComplete/functionYaml/template.ejs +1 -14
- package/src/TemplateManager/src/OutPerActionComplete/OutUpdateComplete/functionYaml/data.js +22 -2
- package/src/TemplateManager/src/OutPerActionComplete/OutUpdateComplete/functionYaml/template.ejs +1 -14
- package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrApi/data.js +6 -6
- package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrApi/template.ejs +2 -15
- package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrDsq/data.js +2 -1
- package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrDsq/template.ejs +1 -14
- package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrInv/data.js +1 -1
- package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrInv/template.ejs +1 -14
- package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrSqs/data.js +3 -1
- package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrSqs/template.ejs +1 -14
- package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrWbs/data.js +1 -1
- package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Create/template.ejs +23 -3
- package/src/TemplateManager/src/ProcessLogical/ProcessLogicalYaml/data.js +18 -2
- package/src/TemplateManager/src/ProcessLogical/ProcessLogicalYaml/template.ejs +1 -14
- package/src/TemplateManager/src/ProcessLogicalPagination/FunctionYaml/HdrDsq/data.js +20 -3
- package/src/TemplateManager/src/ProcessLogicalPagination/FunctionYaml/HdrDsq/template.ejs +1 -14
- package/src/TemplateManager/src/ProcessLogicalPagination/FunctionYaml/HdrSqs/data.js +21 -3
- package/src/TemplateManager/src/ProcessLogicalPagination/FunctionYaml/HdrSqs/template.ejs +1 -14
- package/src/TemplateManager/src/ProcessLogicalPagination/mainFunction/template.ejs +1 -1
- package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationship/functionYaml/HdrApi/data.js +16 -2
- package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationship/functionYaml/HdrApi/template.ejs +1 -14
- package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationship/functionYaml/HdrDsq/data.js +17 -2
- package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationship/functionYaml/HdrDsq/template.ejs +1 -14
- package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationship/functionYaml/HdrInv/data.js +16 -2
- package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationship/functionYaml/HdrInv/template.ejs +1 -14
- package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationship/functionYaml/HdrSqs/data.js +18 -3
- package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationship/functionYaml/HdrSqs/template.ejs +1 -14
- package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationshipComplete/functionYaml/data.js +18 -3
- package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationshipComplete/functionYaml/template.ejs +1 -14
- package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationship/functionYaml/HdrApi/data.js +15 -2
- package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationship/functionYaml/HdrApi/template.ejs +1 -14
- package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationship/functionYaml/HdrDsq/data.js +17 -2
- package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationship/functionYaml/HdrDsq/template.ejs +1 -14
- package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationship/functionYaml/HdrInv/data.js +16 -2
- package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationship/functionYaml/HdrInv/template.ejs +1 -14
- package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationship/functionYaml/HdrSqs/data.js +18 -3
- package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationship/functionYaml/HdrSqs/template.ejs +1 -14
- package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationshipComplete/functionYaml/data.js +18 -3
- package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationshipComplete/functionYaml/template.ejs +1 -14
- package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRalationshipComplete/functionYaml/data.js +19 -4
- package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRalationshipComplete/functionYaml/template.ejs +1 -14
- package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrApi/data.js +19 -2
- package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrApi/template.ejs +1 -14
- package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrDsq/data.js +19 -2
- package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrDsq/template.ejs +1 -14
- package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrInv/data.js +20 -2
- package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrInv/template.ejs +1 -14
- package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrSqs/data.js +20 -2
- package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrSqs/template.ejs +1 -14
- package/src/TemplateManager/src/Role/createSharedResource.js +269 -0
- package/src/TemplateManager/src/Role/sharedResourceTemplate.ejs +58 -0
- package/src/TemplateManager/src/TranslateIdReq/TranslateIds/functionYaml/HdrDsq/data.js +1 -1
- package/src/TemplateManager/src/TranslateIdReq/TranslateIds/functionYaml/HdrSqs/data.js +1 -1
- package/src/TemplateManager/src/externalService/FunctionNameConfig/data.js +98 -22
- package/src/TemplateManager/src/externalService/FunctionNameConfig/templateIntTesting.ejs +5 -5
- package/src/TemplateManager/src/externalService/FunctionNameConfig/templateYaml.ejs +2 -2
- package/src/TemplateManager/src/externalService/LambdaRole/data.js +32 -22
- package/src/TemplateManager/src/externalService/LambdaRole/template.ejs +1 -1
- package/src/TemplateManager/src/flowSchema/UploadS3Case/createObject/functionYaml/data.js +16 -10
- package/src/TemplateManager/src/flowSchema/UploadS3Case/createObject/handler/data.js +8 -5
- package/src/TemplateManager/src/flowSchema/UploadS3Case/createObject/handler/template.ejs +22 -9
- package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode(old)/functionYaml/data.js +102 -0
- package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode(old)/functionYaml/template.ejs +43 -0
- package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode(old)/handler/data.js +94 -0
- package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode(old)/handler/templateAsyncHandler.ejs +110 -0
- package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode(old)/handler/templateSyncHandler.ejs +49 -0
- package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode(old)/hookLogic/data.js +65 -0
- package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode(old)/mainFunction/data.js +67 -0
- package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode(old)/mainFunction/template.ejs +30 -0
- package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode(old)/queue/data.js +125 -0
- package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode(old)/queue/snsTemplate.ejs +59 -0
- package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode(old)/queue/sqsTemplate.ejs +43 -0
- package/src/TemplateManager/src/libs/Consts.js +38 -12
- package/src/TemplateManager/src/reStructureExample/GenerateCodeTest.js +31 -0
- package/src/TemplateManager/src/reStructureExample/TemplateConfig.js +11 -0
- package/src/TemplateManager/src/reStructureExample/TemplateData/perAction/data.js +0 -0
- package/src/TemplateManager/src/reStructureExample/TemplateData/perAction/generateCodeShared.js +1 -0
- package/src/TemplateManager/src/reStructureExample/TemplateData/perAction/generatePerAction.js +5 -0
- package/src/TemplateManager/src/reStructureExample/TemplateData/perAction/template.ejs +0 -0
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2020 Sven Mason <http://izara.io>
|
|
3
|
+
This program is free software: you can redistribute it and/or modify
|
|
4
|
+
it under the terms of the GNU Affero General Public License as
|
|
5
|
+
published by the Free Software Foundation, either version 3 of the
|
|
6
|
+
License, or (at your option) any later version.
|
|
7
|
+
This program is distributed in the hope that it will be useful,
|
|
8
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
10
|
+
GNU Affero General Public License for more details.
|
|
11
|
+
You should have received a copy of the GNU Affero General Public License
|
|
12
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
13
|
+
*/
|
|
14
|
+
'use strict';
|
|
15
|
+
const { SOURCE_GENERATE_IAM_ROLE, SOURCE_PATH, SAVE_FILE_NAME } = require('../libs/Consts');
|
|
16
|
+
const { firstLetterUpperCase: upperCase } = require("../../../MainLibs/src/Utils")
|
|
17
|
+
const path = require('path');
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Process additional resource permissions for an object type
|
|
21
|
+
* @param {Array} resourcePermissions - Array of resource permissions to process
|
|
22
|
+
* @param {Object} targetResources - Resources object to update
|
|
23
|
+
*/
|
|
24
|
+
const processResourcePermissions = (resourcePermissions, targetResources) => {
|
|
25
|
+
if (!Array.isArray(resourcePermissions)) return;
|
|
26
|
+
resourcePermissions.forEach(resourcePermission => {
|
|
27
|
+
if (!resourcePermission.action) return;
|
|
28
|
+
const [key, value] = Object.entries(resourcePermission.action)[0];
|
|
29
|
+
if (!targetResources[key]) {
|
|
30
|
+
targetResources[key] = [];
|
|
31
|
+
}
|
|
32
|
+
const actionsList = Array.isArray(value) ? value : [value];
|
|
33
|
+
const resourcesList = Array.isArray(resourcePermission.resource)
|
|
34
|
+
? resourcePermission.resource
|
|
35
|
+
: [resourcePermission.resource];
|
|
36
|
+
// Check if entry with same actions exists
|
|
37
|
+
const existingEntry = targetResources[key].find(entry =>
|
|
38
|
+
JSON.stringify(entry.actions) === JSON.stringify(actionsList)
|
|
39
|
+
);
|
|
40
|
+
if (existingEntry) {
|
|
41
|
+
// Merge resources without duplicates
|
|
42
|
+
existingEntry.resource = [
|
|
43
|
+
...new Set([...existingEntry.resource, ...resourcesList])
|
|
44
|
+
];
|
|
45
|
+
} else {
|
|
46
|
+
// Add new entry
|
|
47
|
+
targetResources[key].push({
|
|
48
|
+
actions: actionsList,
|
|
49
|
+
resource: resourcesList
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Check if an item should be skipped based on templateData content
|
|
56
|
+
* @param {Object} templateData - Template data to check
|
|
57
|
+
* @returns {Boolean} True if item should be skipped
|
|
58
|
+
*/
|
|
59
|
+
const shouldSkipItem = (templateData) => {
|
|
60
|
+
return !templateData ||
|
|
61
|
+
Object.keys(templateData).length === 0 ||
|
|
62
|
+
!templateData.additionalResourcePermission;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Initialize object type structure if it doesn't exist
|
|
66
|
+
* @param {Object} groupedByObjectType - The grouped object
|
|
67
|
+
* @param {String} objectType - Object type to initialize
|
|
68
|
+
* @param {Array} objectTypeList - List to track object types
|
|
69
|
+
*/
|
|
70
|
+
const initializeObjectType = (groupedByObjectType, objectType, objectTypeList) => {
|
|
71
|
+
if (!groupedByObjectType[objectType]) {
|
|
72
|
+
groupedByObjectType[objectType] = {
|
|
73
|
+
functionNames: [],
|
|
74
|
+
actions: [],
|
|
75
|
+
resources: {},
|
|
76
|
+
actionHandler: []
|
|
77
|
+
};
|
|
78
|
+
objectTypeList.push(objectType);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
module.exports.createSharedResource = (_izContext, createSourceParams, srcPath) => {
|
|
82
|
+
// Initialize data structure
|
|
83
|
+
const groupedByObjectType = {
|
|
84
|
+
[SOURCE_GENERATE_IAM_ROLE.ProcessFindDataRole]: {
|
|
85
|
+
handlerType: [],
|
|
86
|
+
resources: {}
|
|
87
|
+
},
|
|
88
|
+
[SOURCE_GENERATE_IAM_ROLE.ObjectCompleteRole]: {
|
|
89
|
+
functionNames: [],
|
|
90
|
+
handlerType: [],
|
|
91
|
+
resources: {}
|
|
92
|
+
},
|
|
93
|
+
[SOURCE_GENERATE_IAM_ROLE.RelationshipRole]: {
|
|
94
|
+
handlerType: [],
|
|
95
|
+
resources: {}
|
|
96
|
+
},
|
|
97
|
+
[SOURCE_GENERATE_IAM_ROLE.RelationshipCompleteRole]: {
|
|
98
|
+
handlerType: [],
|
|
99
|
+
resources: []
|
|
100
|
+
},
|
|
101
|
+
Other: []
|
|
102
|
+
};
|
|
103
|
+
const objectTypeList = [];
|
|
104
|
+
// Ensure data is defined - assuming it comes from createSourceParams
|
|
105
|
+
const data = createSourceParams || [];
|
|
106
|
+
// Process each item in data
|
|
107
|
+
data.map((item) => {
|
|
108
|
+
const templateData = item.templateData;
|
|
109
|
+
if (shouldSkipItem(templateData)) return;
|
|
110
|
+
if (templateData.objectType) {
|
|
111
|
+
// Handle items with objectType
|
|
112
|
+
initializeObjectType(groupedByObjectType, templateData.objectType, objectTypeList);
|
|
113
|
+
// Add function name if it doesn't exist
|
|
114
|
+
if (templateData.functionName &&
|
|
115
|
+
!groupedByObjectType[templateData.objectType].functionNames?.includes(templateData.functionName)) {
|
|
116
|
+
groupedByObjectType[templateData.objectType].functionNames.push(templateData.functionName);
|
|
117
|
+
}
|
|
118
|
+
// Add action if it doesn't exist
|
|
119
|
+
if (templateData.action !== null &&
|
|
120
|
+
!groupedByObjectType[templateData.objectType].actions.includes(templateData.action)) {
|
|
121
|
+
groupedByObjectType[templateData.objectType].actions.push(templateData.action);
|
|
122
|
+
}
|
|
123
|
+
// Process additionalResourcePermission
|
|
124
|
+
processResourcePermissions(
|
|
125
|
+
templateData.additionalResourcePermission,
|
|
126
|
+
groupedByObjectType[templateData.objectType].resources
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
else if (templateData.functionName &&
|
|
130
|
+
(templateData.functionName.includes('ObjectComplete') ||
|
|
131
|
+
templateData.functionName.includes('NodeComplete'))) {
|
|
132
|
+
// Handle ObjectComplete items
|
|
133
|
+
groupedByObjectType[SOURCE_GENERATE_IAM_ROLE.ObjectCompleteRole].functionNames.push(templateData.functionName);
|
|
134
|
+
groupedByObjectType[SOURCE_GENERATE_IAM_ROLE.ObjectCompleteRole].handlerType.push(templateData.handlerType);
|
|
135
|
+
processResourcePermissions(
|
|
136
|
+
templateData.additionalResourcePermission,
|
|
137
|
+
groupedByObjectType[SOURCE_GENERATE_IAM_ROLE.ObjectCompleteRole].resources
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
else if (templateData.functionName && templateData.functionName.includes([SOURCE_GENERATE_IAM_ROLE.RelationshipRole])) {
|
|
141
|
+
if (templateData.functionName.includes([SOURCE_GENERATE_IAM_ROLE.RelationshipCompleteRole])) {
|
|
142
|
+
// Handle RelationshipComplete items
|
|
143
|
+
if (templateData.handlerType &&
|
|
144
|
+
!groupedByObjectType[SOURCE_GENERATE_IAM_ROLE.RelationshipCompleteRole].handlerType.includes(templateData.handlerType)) {
|
|
145
|
+
groupedByObjectType[SOURCE_GENERATE_IAM_ROLE.RelationshipCompleteRole].handlerType.push(templateData.handlerType);
|
|
146
|
+
}
|
|
147
|
+
processResourcePermissions(
|
|
148
|
+
templateData.additionalResourcePermission,
|
|
149
|
+
groupedByObjectType[SOURCE_GENERATE_IAM_ROLE.RelationshipCompleteRole].resources
|
|
150
|
+
);
|
|
151
|
+
} else {
|
|
152
|
+
// Handle regular Relationship items
|
|
153
|
+
if (templateData.handlerType &&
|
|
154
|
+
!groupedByObjectType[SOURCE_GENERATE_IAM_ROLE.RelationshipRole].handlerType.includes(templateData.handlerType)) {
|
|
155
|
+
groupedByObjectType[SOURCE_GENERATE_IAM_ROLE.RelationshipRole].handlerType.push(templateData.handlerType);
|
|
156
|
+
}
|
|
157
|
+
processResourcePermissions(
|
|
158
|
+
templateData.additionalResourcePermission,
|
|
159
|
+
groupedByObjectType[SOURCE_GENERATE_IAM_ROLE.RelationshipRole].resources
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
else if (templateData.functionName &&
|
|
164
|
+
(templateData.functionName.includes('PaginateProcessLogical') ||
|
|
165
|
+
templateData.functionName.includes('FindData') ||
|
|
166
|
+
templateData.functionName.includes('ProcessLogical'))) {
|
|
167
|
+
// Handle ProcessFindData items
|
|
168
|
+
groupedByObjectType[SOURCE_GENERATE_IAM_ROLE.ProcessFindDataRole].handlerType.push(templateData.handlerType);
|
|
169
|
+
processResourcePermissions(
|
|
170
|
+
templateData.additionalResourcePermission,
|
|
171
|
+
groupedByObjectType[SOURCE_GENERATE_IAM_ROLE.ProcessFindDataRole].resources
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
// Handle other items
|
|
176
|
+
groupedByObjectType.Other.push(item);
|
|
177
|
+
}
|
|
178
|
+
return item;
|
|
179
|
+
});
|
|
180
|
+
// Process "Other" items that might belong to existing object types
|
|
181
|
+
groupedByObjectType.Other = groupedByObjectType.Other.filter(item => {
|
|
182
|
+
const templateData = item.templateData;
|
|
183
|
+
if (!templateData.functionName) return true;
|
|
184
|
+
// Find matching objectType
|
|
185
|
+
const matchedObjectType = objectTypeList.find(objectType =>
|
|
186
|
+
templateData.functionName.toLowerCase().includes(objectType.toLowerCase()) ||
|
|
187
|
+
templateData.functionName.includes(objectType.charAt(0).toUpperCase() + objectType.slice(1))
|
|
188
|
+
);
|
|
189
|
+
if (matchedObjectType) {
|
|
190
|
+
// Move the item to the matched object type
|
|
191
|
+
groupedByObjectType[matchedObjectType].actionHandler.push(templateData.handlerType);
|
|
192
|
+
groupedByObjectType[matchedObjectType].resources = {
|
|
193
|
+
...groupedByObjectType[matchedObjectType].resources,
|
|
194
|
+
...templateData.additionalResourcePermission
|
|
195
|
+
};
|
|
196
|
+
return false; // Remove from Other
|
|
197
|
+
}
|
|
198
|
+
return true; // Keep in Other
|
|
199
|
+
});
|
|
200
|
+
// Prepare results
|
|
201
|
+
|
|
202
|
+
// Process and prepare data for role definitions and extract any resources
|
|
203
|
+
// that might be related to object types but weren't categorized properly
|
|
204
|
+
const roles = [];
|
|
205
|
+
const otherResources = []
|
|
206
|
+
Object.entries(groupedByObjectType).forEach(([objectType, data]) => {
|
|
207
|
+
if (objectType === 'Other' || !data.resources) return;
|
|
208
|
+
// สร้าง policy statements จาก resources
|
|
209
|
+
const rolePolicyStatement = [];
|
|
210
|
+
Object.entries(data.resources).forEach(([effect, permissionList]) => {
|
|
211
|
+
if (!Array.isArray(permissionList)) {
|
|
212
|
+
// permissionList might be in a different format
|
|
213
|
+
if (typeof permissionList === 'object' && !Array.isArray(permissionList)) {
|
|
214
|
+
// Handle non-standard format
|
|
215
|
+
const actions = [];
|
|
216
|
+
if (permissionList.action) {
|
|
217
|
+
const actionObj = permissionList.action;
|
|
218
|
+
Object.entries(actionObj).forEach(([service, actionList]) => {
|
|
219
|
+
const actionArray = Array.isArray(actionList) ? actionList : [actionList];
|
|
220
|
+
actionArray.forEach(action => actions.push(`${service}:${action}`));
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
rolePolicyStatement.push({
|
|
224
|
+
Effect: permissionList.effect || 'Allow',
|
|
225
|
+
Action: actions,
|
|
226
|
+
Resource: permissionList.resource
|
|
227
|
+
});
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
rolePolicyStatement.push({
|
|
231
|
+
Effect: permissionList.effect,
|
|
232
|
+
Action: actions,
|
|
233
|
+
Resource: permission.resource
|
|
234
|
+
});
|
|
235
|
+
return;
|
|
236
|
+
};
|
|
237
|
+
permissionList.forEach(permission => {
|
|
238
|
+
const actions = permission.actions.map(action => `${effect}:${action}`);
|
|
239
|
+
rolePolicyStatement.push({
|
|
240
|
+
Effect: 'Allow',
|
|
241
|
+
Action: actions,
|
|
242
|
+
Resource: permission.resource
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
if (rolePolicyStatement.length > 0) {
|
|
247
|
+
roles.push({
|
|
248
|
+
roleName: upperCase(objectType),
|
|
249
|
+
rolePolicyStatement
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
const reformattedData = {
|
|
254
|
+
roles,
|
|
255
|
+
};
|
|
256
|
+
const sharedResourceTemplatePath = path.join(__dirname, './sharedResourceTemplate.ejs')
|
|
257
|
+
|
|
258
|
+
return {
|
|
259
|
+
templatePath: sharedResourceTemplatePath,
|
|
260
|
+
templateData: reformattedData,
|
|
261
|
+
setting: {
|
|
262
|
+
initialData: 'Resources:\n',
|
|
263
|
+
savePath: path.join(srcPath, SOURCE_PATH.appYaml),
|
|
264
|
+
saveFileName: SAVE_FILE_NAME.sharedResourceYaml,
|
|
265
|
+
fileExtension: '.yml',
|
|
266
|
+
isAppend: true
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#IAM Role for Upload Schema functionality
|
|
2
|
+
UploadSchemaRole:
|
|
3
|
+
Type: AWS::IAM::Role
|
|
4
|
+
Properties:
|
|
5
|
+
RoleName: ${self:custom.iz_resourcePrefix}UploadSchemaRole
|
|
6
|
+
AssumeRolePolicyDocument:
|
|
7
|
+
Version: "2012-10-17"
|
|
8
|
+
Statement:
|
|
9
|
+
- Effect: Allow
|
|
10
|
+
Principal:
|
|
11
|
+
Service: "lambda.amazonaws.com"
|
|
12
|
+
Action: sts:AssumeRole
|
|
13
|
+
# this is the managed policy for lambda basic execution ex. logging to cloudwatch
|
|
14
|
+
ManagedPolicyArns:
|
|
15
|
+
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
|
|
16
|
+
- arn:aws:iam::${self:custom.iz_accountId}:policy/UploadSchemaSharedPolicy
|
|
17
|
+
Policies:
|
|
18
|
+
- PolicyName: ${self:custom.iz_resourcePrefix}UploadSchemaPolicy
|
|
19
|
+
PolicyDocument:
|
|
20
|
+
Version: "2012-10-17"
|
|
21
|
+
Statement:
|
|
22
|
+
- Effect: Allow
|
|
23
|
+
Action:
|
|
24
|
+
- s3:PutObject
|
|
25
|
+
- s3:GetObject
|
|
26
|
+
- s3:ListBucket
|
|
27
|
+
Resource:
|
|
28
|
+
- arn:aws:s3:::object-schema/*
|
|
29
|
+
- arn:aws:s3:::object-schema/perServiceSchemas/${self:custom.iz_serviceTag}/*
|
|
30
|
+
<% if (roles && roles.length > 0) { -%>
|
|
31
|
+
<% roles.forEach(function(role) { %>
|
|
32
|
+
<%= role.roleName %>Role:
|
|
33
|
+
Type: AWS::IAM::Role
|
|
34
|
+
Properties:
|
|
35
|
+
RoleName: ${self:custom.iz_resourcePrefix}<%= role.roleName %>Role
|
|
36
|
+
AssumeRolePolicyDocument:
|
|
37
|
+
Version: "2012-10-17"
|
|
38
|
+
Statement:
|
|
39
|
+
- Effect: Allow
|
|
40
|
+
Principal:
|
|
41
|
+
Service: "lambda.amazonaws.com"
|
|
42
|
+
Action: sts:AssumeRole
|
|
43
|
+
ManagedPolicyArns:
|
|
44
|
+
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
|
|
45
|
+
Policies:
|
|
46
|
+
- PolicyName: ${self:custom.iz_resourcePrefix}<%= role.roleName %>Policy
|
|
47
|
+
PolicyDocument:
|
|
48
|
+
Version: "2012-10-17"
|
|
49
|
+
Statement:<% role.rolePolicyStatement.forEach(function(statement) { %>
|
|
50
|
+
- Effect: <%= statement.Effect %><%_ if (Array.isArray(statement.Action)) { %>
|
|
51
|
+
Action:<% statement.Action.forEach(function(action) { %>
|
|
52
|
+
- <%= action %><% }); %><% } else { %>Action: <%= statement.Action %><% } -%>
|
|
53
|
+
<% if (Array.isArray(statement.Resource)) { %>
|
|
54
|
+
Resource:<% statement.Resource.forEach(function(resource) { %>
|
|
55
|
+
- <%= resource -%><% }); %><% } else { %>
|
|
56
|
+
Resource: <%= statement.Resource %><% } %><% }); %>
|
|
57
|
+
<% }); %>
|
|
58
|
+
<% } %>
|
|
@@ -23,61 +23,137 @@ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = req
|
|
|
23
23
|
const { SOURCE_PATH } = require('../../libs/Consts');
|
|
24
24
|
const templateYamlPath = path.join(__dirname, "./templateYaml.ejs");
|
|
25
25
|
const templatePathIntTestPath = path.join(__dirname, "./templateIntTesting.ejs");
|
|
26
|
+
const { SOURCE_GENERATE_IAM_ROLE } = require("../../libs/Consts");
|
|
26
27
|
|
|
27
28
|
|
|
28
29
|
function data(_izContext, createSourceParams, srcPath) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
|
|
31
|
+
// ! old code
|
|
32
|
+
// function createFunctionNameConfigFileYaml(functionNameConfigs, srcPath) {
|
|
33
|
+
// let createFunctionNameConfigYaml = []
|
|
34
|
+
// createFunctionNameConfigYaml.push(
|
|
35
|
+
// {
|
|
36
|
+
// templatePath: templateYamlPath,
|
|
37
|
+
// templateData: {
|
|
38
|
+
// functionNameConfigs: functionNameConfigs
|
|
39
|
+
// },
|
|
40
|
+
// setting: {
|
|
41
|
+
// savePath: path.join(srcPath, SOURCE_PATH.appYaml),
|
|
42
|
+
// saveFileName: "FunctionNameConfig",
|
|
43
|
+
// fileExtension: ".yml",
|
|
44
|
+
// isAppend: true
|
|
45
|
+
// }
|
|
46
|
+
// }
|
|
47
|
+
// )
|
|
48
|
+
// return createFunctionNameConfigYaml
|
|
49
|
+
// }
|
|
50
|
+
|
|
51
|
+
// Extract role names from object types in createSourceParams
|
|
52
|
+
const roleNameConfigs = new Set();
|
|
53
|
+
const roleNameConcatConfigs = new Set();
|
|
54
|
+
|
|
55
|
+
// Add default IAM roles from configuration
|
|
56
|
+
Object.entries(SOURCE_GENERATE_IAM_ROLE)
|
|
57
|
+
.filter(([_, enabled]) => enabled)
|
|
58
|
+
.forEach(([_, value]) => {
|
|
59
|
+
roleNameConfigs.add(`${upperCase(value)}Role`);
|
|
60
|
+
roleNameConcatConfigs.add(`${upperCase(value)}`);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
for (const { templateData } of createSourceParams) {
|
|
64
|
+
if (templateData?.objectType) {
|
|
65
|
+
roleNameConfigs.add(`${upperCase(templateData.objectType)}Role`);
|
|
66
|
+
roleNameConcatConfigs.add(`${upperCase(templateData.objectType)}`);
|
|
35
67
|
}
|
|
36
68
|
}
|
|
37
|
-
let createFunctionNameConfigYaml = createFunctionNameConfigFileYaml(functionNameConfigs, srcPath);
|
|
38
|
-
let createFunctionNameConfigJs = createFunctionNameConfigFileJs(functionNameConfigs, srcPath);
|
|
39
|
-
createFunctionNameConfig.push(...createFunctionNameConfigYaml, ...createFunctionNameConfigJs)
|
|
40
|
-
return createFunctionNameConfig
|
|
41
69
|
|
|
70
|
+
// Generate YAML and JS configurations
|
|
71
|
+
const roleConfigYaml = createRoleNameConfigFileYaml(roleNameConfigs, srcPath);
|
|
72
|
+
const roleConfigJs = createRoleNameConfigFileJs(roleNameConcatConfigs, srcPath);
|
|
73
|
+
|
|
74
|
+
// Combine and return all configurations
|
|
75
|
+
return [...roleConfigYaml, ...roleConfigJs];
|
|
42
76
|
}
|
|
43
77
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
78
|
+
|
|
79
|
+
// ! old code
|
|
80
|
+
// function createFunctionNameConfigFileYaml(functionNameConfigs, srcPath) {
|
|
81
|
+
// let createFunctionNameConfigYaml = []
|
|
82
|
+
// createFunctionNameConfigYaml.push(
|
|
83
|
+
// {
|
|
84
|
+
// templatePath: templateYamlPath,
|
|
85
|
+
// templateData: {
|
|
86
|
+
// functionNameConfigs: functionNameConfigs
|
|
87
|
+
// },
|
|
88
|
+
// setting: {
|
|
89
|
+
// savePath: path.join(srcPath, SOURCE_PATH.appYaml),
|
|
90
|
+
// saveFileName: "FunctionNameConfig",
|
|
91
|
+
// fileExtension: ".yml",
|
|
92
|
+
// isAppend: true
|
|
93
|
+
// }
|
|
94
|
+
// }
|
|
95
|
+
// )
|
|
96
|
+
// return createFunctionNameConfigYaml
|
|
97
|
+
// }
|
|
98
|
+
|
|
99
|
+
// ! old code
|
|
100
|
+
// function createFunctionNameConfigFileJs(functionNameConfigs, srcPath) {
|
|
101
|
+
// let createFunctionNameConfigJs = []
|
|
102
|
+
// createFunctionNameConfigJs.push(
|
|
103
|
+
// {
|
|
104
|
+
// templatePath: templatePathIntTestPath,
|
|
105
|
+
// templateData: {
|
|
106
|
+
// functionNameConfigs: functionNameConfigs
|
|
107
|
+
// },
|
|
108
|
+
// setting: {
|
|
109
|
+
// savePath: path.join(srcPath, SOURCE_PATH.externalService),
|
|
110
|
+
// saveFileName: "FunctionNameConfig",
|
|
111
|
+
// fileExtension: ".js",
|
|
112
|
+
// isAppend: true
|
|
113
|
+
// }
|
|
114
|
+
// }
|
|
115
|
+
// )
|
|
116
|
+
|
|
117
|
+
// return createFunctionNameConfigJs
|
|
118
|
+
// }
|
|
119
|
+
|
|
120
|
+
function createRoleNameConfigFileYaml(roleNameConfigs, srcPath) {
|
|
121
|
+
let createRoleNameConfigYaml = []
|
|
122
|
+
createRoleNameConfigYaml.push(
|
|
47
123
|
{
|
|
48
124
|
templatePath: templateYamlPath,
|
|
49
125
|
templateData: {
|
|
50
|
-
|
|
126
|
+
roleNameConfigs: roleNameConfigs
|
|
51
127
|
},
|
|
52
128
|
setting: {
|
|
53
129
|
savePath: path.join(srcPath, SOURCE_PATH.appYaml),
|
|
54
|
-
saveFileName: "
|
|
130
|
+
saveFileName: "RoleNameConfig",
|
|
55
131
|
fileExtension: ".yml",
|
|
56
132
|
isAppend: true
|
|
57
133
|
}
|
|
58
134
|
}
|
|
59
135
|
)
|
|
60
|
-
return
|
|
136
|
+
return createRoleNameConfigYaml
|
|
61
137
|
}
|
|
62
138
|
|
|
63
|
-
function
|
|
64
|
-
let
|
|
65
|
-
|
|
139
|
+
function createRoleNameConfigFileJs(roleNameConfigs, srcPath) {
|
|
140
|
+
let createRoleNameConfigJs = []
|
|
141
|
+
createRoleNameConfigJs.push(
|
|
66
142
|
{
|
|
67
143
|
templatePath: templatePathIntTestPath,
|
|
68
144
|
templateData: {
|
|
69
|
-
|
|
145
|
+
roleNameConfigs: roleNameConfigs
|
|
70
146
|
},
|
|
71
147
|
setting: {
|
|
72
148
|
savePath: path.join(srcPath, SOURCE_PATH.externalService),
|
|
73
|
-
saveFileName: "
|
|
149
|
+
saveFileName: "RoleNameConfig",
|
|
74
150
|
fileExtension: ".js",
|
|
75
151
|
isAppend: true
|
|
76
152
|
}
|
|
77
153
|
}
|
|
78
154
|
)
|
|
79
155
|
|
|
80
|
-
return
|
|
156
|
+
return createRoleNameConfigJs
|
|
81
157
|
}
|
|
82
158
|
|
|
83
159
|
module.exports = data;
|
|
@@ -17,13 +17,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
17
17
|
|
|
18
18
|
'use strict';
|
|
19
19
|
|
|
20
|
-
module.exports.
|
|
21
|
-
let
|
|
22
|
-
|
|
23
|
-
"<%- firstLetterUpperCase(
|
|
20
|
+
module.exports.generatedIntTestRoleNameConfig = () => {
|
|
21
|
+
let roleNameConfigIntTest = [
|
|
22
|
+
<% roleNameConfigs.forEach(roleNameConfig => { _%>
|
|
23
|
+
"<%- firstLetterUpperCase(roleNameConfig) %>",
|
|
24
24
|
<% }) _%>
|
|
25
25
|
]
|
|
26
|
-
return
|
|
26
|
+
return roleNameConfigIntTest
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
<%_function firstLetterUpperCase(text) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# for createIamRole
|
|
2
2
|
|
|
3
|
-
<%
|
|
4
|
-
-
|
|
3
|
+
<% roleNameConfigs.forEach(roleNameConfig => { _%>
|
|
4
|
+
- arn:aws:iam::${self:custom.iz_accountId}:role/${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(roleNameConfig) %>
|
|
5
5
|
<% }) _%>
|
|
6
6
|
|
|
7
7
|
|