@izara_project/izara-core-generate-service-code 1.0.29 → 1.0.30
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/generateCode/generateFlowSchema/event/lambdaSyncApiComponent/handler/template.ejs +4 -4
- package/src/generateCode/generateFlowSchema/event/s3Component/upload/processFile/handler/handlerS3/template.ejs +4 -4
- package/src/generateCode/generateInitialSetup/GenerateCodeExternalService.js +0 -1
- package/src/generateCode/generateInitialSetup/externalServiceComponent/index.js +9 -3
- package/src/generateCode/generateInitialSetup/externalServiceComponent/tableNameConfig/data.js +90 -0
- package/src/generateCode/generateInitialSetup/externalServiceComponent/tableNameConfig/template.ejs +43 -0
- package/src/generateCode/generateSchema/GenerateCodeSchema.js +13 -4
- package/src/generateCode/generateSchema/actionEndpointCompleteComponent/update/mainFunction/template.ejs +4 -4
- package/src/generateCode/generateSchema/actionEndpointComponent/yaml/data.js +3 -3
- package/src/generateCode/{generateTranslation/generateTranslation.js → generateSchema/generateTextTag/index.js} +10 -7
- package/src/generateCode/{generateTranslation/translations → generateSchema/generateTextTag/systemText}/data.js +46 -11
- package/src/generateCode/generateSchema/rbac/dynamoDb/data.js +112 -0
- package/src/generateCode/generateSchema/rbac/index.js +74 -0
- package/src/generateCode/generateSchema/rbac/lambda/authApi/data.js +69 -0
- package/src/generateCode/generateSchema/rbac/lambda/authApi/templateInv.ejs +52 -0
- package/src/generateCode/generateSchema/rbac/lambda/authInv/handler/data.js +70 -0
- package/src/generateCode/generateSchema/rbac/lambda/authInv/handler/templateInv.ejs +52 -0
- package/src/generateCode/generateSchema/rbac/lambda/authInv/mainFunction/data.js +82 -0
- package/src/generateCode/generateSchema/rbac/lambda/authInv/mainFunction/template.ejs +42 -0
- package/src/generateCode/generateSchema/rbac/lambda/yaml/data.js +128 -0
- package/src/generateCode/generateSchema/rbac/lambda/yaml/template.ejs +6 -0
- package/src/generateCode.js +5 -12
- package/src/libs/Consts.js +10 -4
- package/src/libs/Libs.js +7 -1
- /package/src/generateCode/{generateTranslation/translations → generateSchema/generateTextTag/systemText}/template.ejs +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@izara_project/izara-core-generate-service-code",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.30",
|
|
4
4
|
"description": "Code for locally generating per service files",
|
|
5
5
|
"author": "Sven Mason <thebarbariansven@gmail.com>",
|
|
6
6
|
"license": "AGPL-3.0-or-later",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"@izara_project/izara-core-library-core": "^1.0.31",
|
|
28
28
|
"@izara_project/izara-core-library-logger": "^1.0.8",
|
|
29
29
|
"@izara_project/izara-core-library-s3": "^1.0.5",
|
|
30
|
-
"@izara_project/izara-core-library-service-schemas": "^1.0.
|
|
30
|
+
"@izara_project/izara-core-library-service-schemas": "^1.0.133",
|
|
31
31
|
"@izara_project/izara-shared-core": "^1.0.9",
|
|
32
32
|
"ejs": "^5.0.1",
|
|
33
33
|
"js-beautify": "^1.15.4",
|
package/src/generateCode/generateFlowSchema/event/lambdaSyncApiComponent/handler/template.ejs
CHANGED
|
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
17
17
|
|
|
18
18
|
const RBAC_TARGET_ID = process.env.iz_rbacTargetIdUser // iz_rbacTargetIdUser | iz_rbacDeliveryMethodId
|
|
19
19
|
|
|
20
|
-
import { middlewareHandler as middleware } from "@izara_project/izara-middleware";
|
|
20
|
+
import { middlewareHandler as middleware, response } from "@izara_project/izara-middleware";
|
|
21
21
|
import Logger from '@izara_project/izara-core-library-logger';
|
|
22
22
|
import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
|
|
23
23
|
|
|
@@ -71,14 +71,14 @@ export const main = middleware.wrap(async (event, context, callback) => {
|
|
|
71
71
|
|
|
72
72
|
// return error to client
|
|
73
73
|
if (lambdaFunctionResponse instanceof Error) {
|
|
74
|
-
return (
|
|
74
|
+
return (response.failure(lambdaFunctionResponse));
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
// return success to client
|
|
78
|
-
return (
|
|
78
|
+
return (response.success(lambdaFunctionResponse));
|
|
79
79
|
|
|
80
80
|
} catch (err) {
|
|
81
81
|
event._izContext.logger.error('Error, LambdaFunctionHdrApi: ', err);
|
|
82
|
-
return (
|
|
82
|
+
return (response.failure(err));
|
|
83
83
|
}
|
|
84
84
|
});
|
|
@@ -16,7 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
import { middlewareHandler as middleware } from "@izara_project/izara-middleware";
|
|
19
|
+
import { middlewareHandler as middleware, response } from "@izara_project/izara-middleware";
|
|
20
20
|
import Logger from '@izara_project/izara-core-library-logger';
|
|
21
21
|
import recordHandlerS3SharedLib from '@izara_project/izara-core-library-record-handler';
|
|
22
22
|
|
|
@@ -38,13 +38,13 @@ export const main = middleware.wrap(async (event, context) => {
|
|
|
38
38
|
);
|
|
39
39
|
|
|
40
40
|
if (processImageResponse instanceof Error) {
|
|
41
|
-
return (
|
|
41
|
+
return (response.failure(processImageResponse));
|
|
42
42
|
};
|
|
43
43
|
|
|
44
|
-
return (
|
|
44
|
+
return (response.success(processImageResponse));
|
|
45
45
|
|
|
46
46
|
} catch (err) {
|
|
47
47
|
event._izContext.logger.error('Error, processAfterUploadHdrS3: ', err);
|
|
48
|
-
return (
|
|
48
|
+
return (response.failure(err));
|
|
49
49
|
}
|
|
50
50
|
});
|
|
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
17
17
|
|
|
18
18
|
import createExternalLambdaRole from './lambdaRole/data.js';
|
|
19
19
|
import createExternalSnsSubscriptions from './snsTopicSubscriptions/data.js';
|
|
20
|
-
|
|
20
|
+
import createTableNameConfig from './tableNameConfig/data.js';
|
|
21
21
|
/**
|
|
22
22
|
* Generates code with templates for different actions
|
|
23
23
|
* @param {Object} _izContext - Context object
|
|
@@ -29,7 +29,7 @@ async function generateCodeWithTemplate(
|
|
|
29
29
|
rootServicePath,
|
|
30
30
|
allObjSchemas,
|
|
31
31
|
allObjectRelationships,
|
|
32
|
-
allLocalFlowSchemas
|
|
32
|
+
allLocalFlowSchemas,
|
|
33
33
|
) {
|
|
34
34
|
try {
|
|
35
35
|
const createSourceParams = [];
|
|
@@ -51,7 +51,13 @@ async function generateCodeWithTemplate(
|
|
|
51
51
|
rootServicePath
|
|
52
52
|
);
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
const createTableName = createTableNameConfig(_izContext,
|
|
55
|
+
allObjSchemas,
|
|
56
|
+
allObjectRelationships,
|
|
57
|
+
rootServicePath
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
createSourceParams.push(createFunctionIamRole, createSnsSubscription, createTableName);
|
|
55
61
|
|
|
56
62
|
return createSourceParams;
|
|
57
63
|
} catch (error) {
|
package/src/generateCode/generateInitialSetup/externalServiceComponent/tableNameConfig/data.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
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
|
+
import path from 'path';
|
|
19
|
+
import { fileURLToPath } from 'url';
|
|
20
|
+
import consts from '#libs/Consts.js';
|
|
21
|
+
import libs from '#libs/Libs.js';
|
|
22
|
+
import utils from '#libs/Utils.js';
|
|
23
|
+
|
|
24
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
25
|
+
const __dirname = path.dirname(__filename);
|
|
26
|
+
|
|
27
|
+
const {
|
|
28
|
+
STORAGE_TYPES,
|
|
29
|
+
SOURCE_PATH,
|
|
30
|
+
SAVE_FILE_NAME
|
|
31
|
+
} = consts;
|
|
32
|
+
|
|
33
|
+
const { createDynamoDbComponentByLinks } = libs;
|
|
34
|
+
|
|
35
|
+
const templatePath = path.join(__dirname, 'template.ejs');
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Creates external SNS subscription configuration
|
|
39
|
+
* @param {Object} _izContext - Context object
|
|
40
|
+
* @param {Array} allObjSchemas - All object schemas
|
|
41
|
+
* @param {Array} allRelSchemas - All relationship schemas
|
|
42
|
+
* @param {Array} allLocalFlowSchemas - All local flow schemas
|
|
43
|
+
* @param {string} rootSchemasPath
|
|
44
|
+
* @returns {Promise<Object>} SNS subscription template config
|
|
45
|
+
*/
|
|
46
|
+
function createTableNameConfig(
|
|
47
|
+
_izContext,
|
|
48
|
+
allObjSchemas,
|
|
49
|
+
allRelationshipSchemas,
|
|
50
|
+
appPath
|
|
51
|
+
) {
|
|
52
|
+
|
|
53
|
+
const tableNames = [];
|
|
54
|
+
|
|
55
|
+
if (allObjSchemas.some(objSchema => objSchema.addOnDataStructure?.some(addOn => addOn.type === 'rbac'))) {
|
|
56
|
+
tableNames.push("Permission", "RolePermissions", "Roles", "UserRoles")
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
for (const objSchema of allObjSchemas) {
|
|
60
|
+
for (const storageResource of Object.values(objSchema.storageResources)) {
|
|
61
|
+
if (storageResource.storageType === STORAGE_TYPES.dynamoDB) {
|
|
62
|
+
tableNames.push(storageResource.tableName)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
for (const relSchema of allRelationshipSchemas) {
|
|
68
|
+
const relData = Object.values(relSchema);
|
|
69
|
+
for (const storageResource of Object.values(relData[0].storageResources)) {
|
|
70
|
+
if (storageResource.storagetype === STORAGE_TYPES.dynamoDB) {
|
|
71
|
+
const { resourceNameFrom, resourceNameTo } = createDynamoDbComponentByLinks(relData.links, Object.keys(relSchema)[0])
|
|
72
|
+
tableNames.push(resourceNameFrom, resourceNameTo)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// console.log("tableNames", tableNames)
|
|
78
|
+
return {
|
|
79
|
+
templatePath,
|
|
80
|
+
templateData: { tableNames },
|
|
81
|
+
setting: {
|
|
82
|
+
savePath: path.join(appPath, SOURCE_PATH.externalService),
|
|
83
|
+
saveFileName: SAVE_FILE_NAME.tableName,
|
|
84
|
+
fileExtension: '.js',
|
|
85
|
+
isAppend: true
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export default createTableNameConfig;
|
package/src/generateCode/generateInitialSetup/externalServiceComponent/tableNameConfig/template.ejs
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
/*
|
|
19
|
+
Copyright (C) 2020 Sven Mason <http://izara.io>
|
|
20
|
+
|
|
21
|
+
This program is free software: you can redistribute it and/or modify
|
|
22
|
+
it under the terms of the GNU Affero General Public License as
|
|
23
|
+
published by the Free Software Foundation, either version 3 of the
|
|
24
|
+
License, or (at your option) any later version.
|
|
25
|
+
|
|
26
|
+
This program is distributed in the hope that it will be useful,
|
|
27
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
28
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
29
|
+
GNU Affero General Public License for more details.
|
|
30
|
+
|
|
31
|
+
You should have received a copy of the GNU Affero General Public License
|
|
32
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
const generatedTableNameConfig = [
|
|
36
|
+
<% tableNames.forEach(tableName => { %>
|
|
37
|
+
{<%- tableName %>: {},},
|
|
38
|
+
<% }) %>
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
export {
|
|
42
|
+
generatedTableNameConfig
|
|
43
|
+
}
|
|
@@ -5,6 +5,8 @@ import relationshipPerActionComponent from './relationshipPerActionComponent/ind
|
|
|
5
5
|
import processLogicalComponent from './processLogicalComponent/index.js';
|
|
6
6
|
import processLogicalPaginateComponent from './processLogicalPaginationComponent/index.js';
|
|
7
7
|
import findDataComponent from './findDataComponent/index.js';
|
|
8
|
+
import systemTextTagComponent from './generateTextTag/index.js';
|
|
9
|
+
import rbacComponent from './rbac/index.js'
|
|
8
10
|
|
|
9
11
|
/**
|
|
10
12
|
* Generates code from templates based on object schemas
|
|
@@ -21,6 +23,7 @@ async function generateTemplateDataFromSchema(
|
|
|
21
23
|
allObjSchemas,
|
|
22
24
|
allRelationshipSchemas,
|
|
23
25
|
allLocalFlowSchemas,
|
|
26
|
+
localNotificationSystem,
|
|
24
27
|
settings
|
|
25
28
|
) {
|
|
26
29
|
try {
|
|
@@ -50,7 +53,9 @@ async function generateTemplateDataFromSchema(
|
|
|
50
53
|
relationshipParams,
|
|
51
54
|
processLogicalParams,
|
|
52
55
|
processLogicalPaginateParams,
|
|
53
|
-
findDataParams
|
|
56
|
+
findDataParams,
|
|
57
|
+
systemTextParams,
|
|
58
|
+
rbacParams,
|
|
54
59
|
] = await Promise.all([
|
|
55
60
|
endpointComponent(
|
|
56
61
|
_izContext,
|
|
@@ -79,11 +84,13 @@ async function generateTemplateDataFromSchema(
|
|
|
79
84
|
appPath,
|
|
80
85
|
allObjSchemas.records
|
|
81
86
|
),
|
|
82
|
-
findDataComponent(_izContext, appPath, allObjSchemas, settings)
|
|
87
|
+
findDataComponent(_izContext, appPath, allObjSchemas, settings),
|
|
88
|
+
systemTextTagComponent(_izContext, appPath, allObjSchemas, allRelationshipSchemas, allLocalFlowSchemas, localNotificationSystem),
|
|
89
|
+
rbacComponent(_izContext, appPath, allObjSchemas, settings)
|
|
83
90
|
]);
|
|
84
91
|
|
|
85
92
|
console.info(
|
|
86
|
-
`[Schema] components generated endpoint=${endpointParams.length}
|
|
93
|
+
`[Schema] components generated endpoint=${endpointParams.length} \nendpointComplete=${endpointCompleteParams.length} \nresourceYaml=${resourceYamlParams.length} \nrelationship=${relationshipParams.length} \nprocessLogical=${processLogicalParams.length} \nprocessLogicalPaginate=${processLogicalPaginateParams.length} \nfindData=${findDataParams.length} \nsystemText=${systemTextParams.length} \nrbac=${rbacParams.length}`
|
|
87
94
|
);
|
|
88
95
|
|
|
89
96
|
const allCreateSourceParams = [
|
|
@@ -93,7 +100,9 @@ async function generateTemplateDataFromSchema(
|
|
|
93
100
|
...relationshipParams,
|
|
94
101
|
...processLogicalParams,
|
|
95
102
|
...processLogicalPaginateParams,
|
|
96
|
-
...findDataParams
|
|
103
|
+
...findDataParams,
|
|
104
|
+
...systemTextParams,
|
|
105
|
+
...rbacParams
|
|
97
106
|
];
|
|
98
107
|
|
|
99
108
|
const uniqueSortedTargetFiles = Array.from(
|
|
@@ -25,10 +25,10 @@ import {
|
|
|
25
25
|
consts,
|
|
26
26
|
} from '@izara_project/izara-core-library-service-schemas';
|
|
27
27
|
|
|
28
|
-
const { TOPIC_NAME_GENERATE_CODE } = consts;
|
|
29
|
-
const PREFIX = {
|
|
30
|
-
|
|
31
|
-
};
|
|
28
|
+
const { TOPIC_NAME_GENERATE_CODE, PREFIX } = consts;
|
|
29
|
+
// const PREFIX = {
|
|
30
|
+
// updateNode: 'updateNode',
|
|
31
|
+
// };
|
|
32
32
|
|
|
33
33
|
//(<optionalRequire>)
|
|
34
34
|
//(</optionalRequire>)
|
|
@@ -253,9 +253,9 @@ async function data(
|
|
|
253
253
|
const resourceApis =
|
|
254
254
|
handler === HANDLER.hdrApi
|
|
255
255
|
? allObjSchemas.map(objectSchema => ({
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
256
|
+
event: lowerCase(objectSchema.objectType),
|
|
257
|
+
method: HTTP_METHOD[action]
|
|
258
|
+
}))
|
|
259
259
|
: [];
|
|
260
260
|
|
|
261
261
|
// ── External topic SNS permissions (create only) ──────────────────────────
|
|
@@ -19,23 +19,26 @@ import { join } from 'path';
|
|
|
19
19
|
|
|
20
20
|
import libs from '#libs/Utils.js';
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
import createSourceTranslations from './translations/data.js';
|
|
22
|
+
import createSourceSystemText from './systemText/data.js';
|
|
24
23
|
|
|
25
|
-
async function
|
|
24
|
+
async function systemTextComponent(
|
|
26
25
|
_izContext,
|
|
27
26
|
appPath,
|
|
28
27
|
allObjSchemas,
|
|
29
|
-
|
|
28
|
+
allRelationshipSchemas,
|
|
29
|
+
allFlowSchemas,
|
|
30
|
+
notificationSchemas
|
|
30
31
|
) {
|
|
31
32
|
try {
|
|
32
33
|
const objSchemaPath = join(appPath, '/src/schemas');
|
|
33
34
|
|
|
34
35
|
const createSources = [];
|
|
35
|
-
const translationComponent = await
|
|
36
|
+
const translationComponent = await createSourceSystemText(
|
|
36
37
|
_izContext,
|
|
37
|
-
allObjSchemas,
|
|
38
|
+
allObjSchemas.records,
|
|
39
|
+
allRelationshipSchemas,
|
|
38
40
|
allFlowSchemas,
|
|
41
|
+
notificationSchemas,
|
|
39
42
|
objSchemaPath
|
|
40
43
|
);
|
|
41
44
|
|
|
@@ -52,4 +55,4 @@ async function translationComponent(
|
|
|
52
55
|
}
|
|
53
56
|
}
|
|
54
57
|
|
|
55
|
-
export default
|
|
58
|
+
export default systemTextComponent;
|
|
@@ -40,47 +40,82 @@ import { utils as coreUtils } from '@izara_project/izara-core-library-service-sc
|
|
|
40
40
|
*
|
|
41
41
|
* @return {{ templatePath, templateData, setting } }
|
|
42
42
|
*/
|
|
43
|
-
function
|
|
43
|
+
function createSourceSystemText(
|
|
44
44
|
_izContext,
|
|
45
45
|
allObjectSchema,
|
|
46
|
+
allRelSchema,
|
|
46
47
|
allFlowSchemas,
|
|
48
|
+
notificationSchemas,
|
|
47
49
|
schemaPath
|
|
48
50
|
) {
|
|
49
51
|
const createSourceArray = [];
|
|
50
52
|
// console.log("params objSchema", JSON.stringify(allObjectSchema, null, 2));
|
|
51
|
-
for (const objectSchema of allObjectSchema
|
|
52
|
-
|
|
53
|
+
for (const objectSchema of allObjectSchema) {
|
|
54
|
+
const fieldNames = [...Object.keys(objectSchema.fieldNames)];
|
|
55
|
+
if (objectSchema.hasOwnProperty("addOnDataStructure")) {
|
|
56
|
+
for (const addOn of objectSchema.addOnDataStructure) {
|
|
57
|
+
if (addOn.type === "versionedData") {
|
|
58
|
+
fieldNames.push(...Object.keys(addOn.fieldNames))
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
for (const fieldName of fieldNames) {
|
|
53
64
|
const objType = {
|
|
54
65
|
objectType: objectSchema.objectType,
|
|
55
66
|
serviceTag: getLocalConfig('iz_serviceTag')
|
|
56
67
|
};
|
|
57
|
-
const
|
|
68
|
+
const systemTextObjectSchemas = {
|
|
58
69
|
nameSpace: `${coreUtils.createObjTypeConcat(_izContext, objType)}_description`, // for each objectType
|
|
59
70
|
systemTextTag: `${fieldName}_${coreUtils.createObjTypeConcat(_izContext, objType)}` // for each fieldName
|
|
60
71
|
};
|
|
61
|
-
createSourceArray.push(
|
|
72
|
+
createSourceArray.push(systemTextObjectSchemas);
|
|
62
73
|
}
|
|
63
74
|
}
|
|
64
75
|
|
|
65
|
-
for (const flowSchema of allFlowSchemas
|
|
76
|
+
for (const flowSchema of allFlowSchemas) {
|
|
66
77
|
const flowType = {
|
|
67
78
|
flowTag: flowSchema.flowTag,
|
|
68
79
|
serviceTag: getLocalConfig('iz_serviceTag')
|
|
69
80
|
};
|
|
70
|
-
const
|
|
81
|
+
const systemTextFlowSchemas = {
|
|
71
82
|
nameSpace: `${coreUtils.createFlowTypeConcat(_izContext, flowType)}`, // for each flowType
|
|
72
83
|
systemTextTag: `errors_${coreUtils.createFlowTypeConcat(_izContext, flowType)}`
|
|
73
84
|
};
|
|
74
|
-
createSourceArray.push(
|
|
85
|
+
createSourceArray.push(systemTextFlowSchemas);
|
|
75
86
|
}
|
|
76
87
|
|
|
88
|
+
for (const relSchema of allRelSchema) {
|
|
89
|
+
const relTag = Object.keys(relSchema)[0]
|
|
90
|
+
const relType = {
|
|
91
|
+
serviceTag: getLocalConfig('iz_serviceTag'),
|
|
92
|
+
relationshipTag: relTag
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
for (const fieldName of Object.keys(relSchema[relTag].fieldNames)) {
|
|
96
|
+
const systemTextRelSchemas = {
|
|
97
|
+
nameSpace: `${coreUtils.createRelTypeConcat(_izContext, relType)}_description`,
|
|
98
|
+
systemTextTag: `${fieldName}_${coreUtils.createRelTypeConcat(_izContext, relType)}`
|
|
99
|
+
}
|
|
100
|
+
createSourceArray.push(systemTextRelSchemas);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
console.log("notificationSchemas", notificationSchemas);
|
|
104
|
+
for (const notification of notificationSchemas) {
|
|
105
|
+
const notificationSystemText = {
|
|
106
|
+
nameSpace: `sysNotification_${notification.notificationGrouping}`,
|
|
107
|
+
systemTextTag: notification.notificationTag
|
|
108
|
+
}
|
|
109
|
+
createSourceArray.push(notificationSystemText)
|
|
110
|
+
}
|
|
111
|
+
// console.log("schemaPath", schemaPath)
|
|
77
112
|
// console.log("createSourceArray", createSourceArray)
|
|
78
113
|
return {
|
|
79
114
|
templatePath: templatePath,
|
|
80
115
|
templateData: { datas: createSourceArray },
|
|
81
116
|
setting: {
|
|
82
|
-
savePath: path.join(schemaPath, SOURCE_PATH.
|
|
83
|
-
saveFileName: SAVE_FILE_NAME.
|
|
117
|
+
savePath: path.join(schemaPath, SOURCE_PATH.systemTextSchema),
|
|
118
|
+
saveFileName: SAVE_FILE_NAME.systemTextSchema,
|
|
84
119
|
fileExtension: '.js',
|
|
85
120
|
isAppend: true,
|
|
86
121
|
generateHookFile: false
|
|
@@ -88,4 +123,4 @@ function createSourceTranslations(
|
|
|
88
123
|
};
|
|
89
124
|
}
|
|
90
125
|
|
|
91
|
-
export default
|
|
126
|
+
export default createSourceSystemText;
|
|
@@ -0,0 +1,112 @@
|
|
|
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
|
+
import path from 'path';
|
|
19
|
+
import { fileURLToPath } from 'url';
|
|
20
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
21
|
+
const __dirname = path.dirname(__filename);
|
|
22
|
+
|
|
23
|
+
import consts from '#libs/Consts.js';
|
|
24
|
+
const { SOURCE_PATH, SAVE_FILE_NAME } = consts;
|
|
25
|
+
const templatePath = path.join(__dirname, '../../../resourceYamlComponent/dynamodb/template.ejs');
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* create param of crateSouce for FindData And processLogical
|
|
29
|
+
*
|
|
30
|
+
* @param {Object} _izContext
|
|
31
|
+
* @param {String} srcPath
|
|
32
|
+
* @returns {Object[]}
|
|
33
|
+
*/
|
|
34
|
+
const createAwaitingMultipleStepDynamoDbData = (_izContext, srcPath) => {
|
|
35
|
+
let resultsForCreateSource = [];
|
|
36
|
+
const defaultDynamoDataLists = [];
|
|
37
|
+
|
|
38
|
+
defaultDynamoDataLists.push(
|
|
39
|
+
{
|
|
40
|
+
tableName: 'Permission',
|
|
41
|
+
resourceName: 'Permission',
|
|
42
|
+
attributes: [
|
|
43
|
+
{
|
|
44
|
+
keyType: 'partitionKey',
|
|
45
|
+
AttributeName: 'targetObjTypeConcat',
|
|
46
|
+
AttributeType: 'S'
|
|
47
|
+
}
|
|
48
|
+
]
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
tableName: 'RolePermissions',
|
|
52
|
+
resourceName: 'RolePermissions',
|
|
53
|
+
attributes: [
|
|
54
|
+
{
|
|
55
|
+
keyType: 'partitionKey',
|
|
56
|
+
AttributeName: 'roleIdKey',
|
|
57
|
+
AttributeType: 'S'
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
keyType: 'sortKey',
|
|
61
|
+
AttributeName: 'service_resource_action',
|
|
62
|
+
AttributeType: 'S'
|
|
63
|
+
}
|
|
64
|
+
]
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
tableName: 'Roles',
|
|
68
|
+
resourceName: 'Roles',
|
|
69
|
+
attributes: [
|
|
70
|
+
{
|
|
71
|
+
keyType: 'partitionKey',
|
|
72
|
+
AttributeName: 'roleIdKey',
|
|
73
|
+
AttributeType: 'S'
|
|
74
|
+
}
|
|
75
|
+
]
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
tableName: 'UserRoles',
|
|
79
|
+
resourceName: 'UserRoles',
|
|
80
|
+
attributes: [
|
|
81
|
+
{
|
|
82
|
+
keyType: 'partitionKey',
|
|
83
|
+
AttributeName: 'userId',
|
|
84
|
+
AttributeType: 'S'
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
keyType: 'sortKey',
|
|
88
|
+
AttributeName: 'roleIdKey',
|
|
89
|
+
AttributeType: 'S'
|
|
90
|
+
}
|
|
91
|
+
]
|
|
92
|
+
}
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
for (let defaultlDynamoData of defaultDynamoDataLists) {
|
|
96
|
+
resultsForCreateSource.push({
|
|
97
|
+
templatePath: templatePath,
|
|
98
|
+
templateData: defaultlDynamoData,
|
|
99
|
+
setting: {
|
|
100
|
+
initialData: 'Resources:\n',
|
|
101
|
+
savePath: path.join(srcPath, SOURCE_PATH.resourceYaml),
|
|
102
|
+
saveFileName: SAVE_FILE_NAME.dynamoDbYaml,
|
|
103
|
+
fileExtension: '.yml',
|
|
104
|
+
isAppend: true
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
return resultsForCreateSource;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export default createAwaitingMultipleStepDynamoDbData;
|
|
@@ -0,0 +1,74 @@
|
|
|
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
|
+
// Import required modules
|
|
19
|
+
import { join } from 'path';
|
|
20
|
+
import { getObjectSchema } from '@izara_project/izara-core-library-service-schemas';
|
|
21
|
+
const { getAllLocalObjectSchemasWithHierarchy } = getObjectSchema;
|
|
22
|
+
|
|
23
|
+
// lambda
|
|
24
|
+
import authInvHandler from './lambda/authInv/handler/data.js'
|
|
25
|
+
import authInvMain from './lambda/authInv/mainFunction/data.js'
|
|
26
|
+
|
|
27
|
+
// auth for api
|
|
28
|
+
import authApi from './lambda/authApi/data.js'
|
|
29
|
+
// yaml
|
|
30
|
+
import authYaml from './lambda/yaml/data.js';
|
|
31
|
+
// dynamo
|
|
32
|
+
import dynamo from './dynamoDb/data.js';
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Generates code with templates for different actions
|
|
36
|
+
* @param {Object} _izContext - Context object
|
|
37
|
+
* @param {string} appPath - Path to the schema
|
|
38
|
+
* @returns {Array} Array of generated code parameters
|
|
39
|
+
*/
|
|
40
|
+
async function generateCodeWithTemplate(
|
|
41
|
+
_izContext,
|
|
42
|
+
appPath,
|
|
43
|
+
allObjSchemas,
|
|
44
|
+
) {
|
|
45
|
+
try {
|
|
46
|
+
const createSourceParams = [];
|
|
47
|
+
if (allObjSchemas.records.some(objectSchema => objectSchema.addOnDataStructure?.some(addOn => addOn.type === 'rbac'))) {
|
|
48
|
+
const handlerInvComponent = authInvHandler(_izContext, appPath);
|
|
49
|
+
const mainFunctionInvComponent = authInvMain(_izContext, appPath);
|
|
50
|
+
const authApiComponent = authApi(_izContext, appPath);
|
|
51
|
+
const yamlInvComponent = await authYaml(_izContext, appPath);
|
|
52
|
+
const dynamoRbacPermission = dynamo(_izContext, appPath);
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
createSourceParams.push(
|
|
56
|
+
mainFunctionInvComponent,
|
|
57
|
+
handlerInvComponent,
|
|
58
|
+
authApiComponent,
|
|
59
|
+
...yamlInvComponent,
|
|
60
|
+
...dynamoRbacPermission
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
return createSourceParams;
|
|
68
|
+
} catch (error) {
|
|
69
|
+
_izContext.logger.error('Error generating code with template:', error);
|
|
70
|
+
return [];
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export default generateCodeWithTemplate;
|
|
@@ -0,0 +1,69 @@
|
|
|
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
|
+
// yaml data.js
|
|
19
|
+
import path from 'path';
|
|
20
|
+
import { fileURLToPath } from 'url';
|
|
21
|
+
import consts from '#libs/Consts.js';
|
|
22
|
+
import utils from '#libs/Utils.js';
|
|
23
|
+
import libs from '#libs/Libs.js';
|
|
24
|
+
|
|
25
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
26
|
+
const __dirname = path.dirname(__filename);
|
|
27
|
+
|
|
28
|
+
const {
|
|
29
|
+
SOURCE_PATH,
|
|
30
|
+
} = consts;
|
|
31
|
+
|
|
32
|
+
const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } =
|
|
33
|
+
utils;
|
|
34
|
+
|
|
35
|
+
const templatePathInv = path.join(__dirname, 'templateInv.ejs');
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Generates yaml source params for a given action and handler
|
|
39
|
+
* @param {Object} _izContext - Context object with logger
|
|
40
|
+
* @param {Array} allObjSchemas - All object schemas
|
|
41
|
+
* @param {string} appPath - Source path
|
|
42
|
+
* @param {string} action - Action name (create/update/get/delete)
|
|
43
|
+
* @param {string} handler - Handler type (hdrApi/hdrSqs/hdrDsq/hdrInv)
|
|
44
|
+
* @param {string|null} functionNameConfig - Override for yaml key (null = derive from action+handler)
|
|
45
|
+
* @param {string} handlerSuffix - Suffix for fnName across all fields (e.g. 'BeforeLogical')
|
|
46
|
+
* @returns {Promise<Array>} Array containing source param object
|
|
47
|
+
*/
|
|
48
|
+
function data(
|
|
49
|
+
_izContext,
|
|
50
|
+
appPath,
|
|
51
|
+
) {
|
|
52
|
+
const functionName = "Authorization";
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
const fileName = upperCase(functionName);
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
templatePath: templatePathInv,
|
|
59
|
+
templateData: { functionName },
|
|
60
|
+
setting: {
|
|
61
|
+
savePath: path.join(appPath, SOURCE_PATH.rbac),
|
|
62
|
+
saveFileName: fileName,
|
|
63
|
+
fileExtension: '.js',
|
|
64
|
+
isAppend: true
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export default data;
|
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
|
|
19
|
+
|
|
20
|
+
import { middlewareHandler as middleware } from "@izara_project/izara-middleware";
|
|
21
|
+
import Logger from '@izara_project/izara-core-library-logger';
|
|
22
|
+
import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
|
|
23
|
+
|
|
24
|
+
import <%- functionName %> from './<%- functionName %>_Main.js';
|
|
25
|
+
|
|
26
|
+
// validate event params in middleware before into function.
|
|
27
|
+
const validatorSchema = {
|
|
28
|
+
//(<validatorSchema>)
|
|
29
|
+
//(</validatorSchema>)
|
|
30
|
+
};
|
|
31
|
+
middleware.setValidatorSchema(validatorSchema)
|
|
32
|
+
|
|
33
|
+
export const main = middleware.wrap(async (event, context, callback) => {
|
|
34
|
+
event._izContext.logger.debug('Event:', event);
|
|
35
|
+
event._izContext.logger.debug('context:', context);
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
|
|
39
|
+
// invoke LambdaFunction
|
|
40
|
+
return await <%- functionName %>.<%- functionName %>(
|
|
41
|
+
event._izContext, // correlationId/logger/integrationTestDetail/uniqueRequestId
|
|
42
|
+
event,
|
|
43
|
+
callingFlowSharedLib.addCallingFlowToPassOnProperties(event)
|
|
44
|
+
//(<additionalParams>)
|
|
45
|
+
//(</additionalParams>)
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
} catch (err) {
|
|
49
|
+
event._izContext.logger.error('Error, LambdaFunctionHdrInv: ', err);
|
|
50
|
+
throw (err);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
@@ -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
|
+
// yaml data.js
|
|
19
|
+
import path from 'path';
|
|
20
|
+
import { fileURLToPath } from 'url';
|
|
21
|
+
import consts from '#libs/Consts.js';
|
|
22
|
+
import utils from '#libs/Utils.js';
|
|
23
|
+
import libs from '#libs/Libs.js';
|
|
24
|
+
|
|
25
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
26
|
+
const __dirname = path.dirname(__filename);
|
|
27
|
+
|
|
28
|
+
const {
|
|
29
|
+
SOURCE_PATH,
|
|
30
|
+
HANDLER
|
|
31
|
+
} = consts;
|
|
32
|
+
|
|
33
|
+
const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } =
|
|
34
|
+
utils;
|
|
35
|
+
|
|
36
|
+
const templatePathInv = path.join(__dirname, 'templateInv.ejs');
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Generates yaml source params for a given action and handler
|
|
41
|
+
* @param {Object} _izContext - Context object with logger
|
|
42
|
+
* @param {Array} allObjSchemas - All object schemas
|
|
43
|
+
* @param {string} appPath - Source path
|
|
44
|
+
* @param {string} action - Action name (create/update/get/delete)
|
|
45
|
+
* @param {string} handler - Handler type (hdrApi/hdrSqs/hdrDsq/hdrInv)
|
|
46
|
+
* @param {string|null} functionNameConfig - Override for yaml key (null = derive from action+handler)
|
|
47
|
+
* @param {string} handlerSuffix - Suffix for fnName across all fields (e.g. 'BeforeLogical')
|
|
48
|
+
* @returns {Promise<Array>} Array containing source param object
|
|
49
|
+
*/
|
|
50
|
+
function data(
|
|
51
|
+
_izContext,
|
|
52
|
+
appPath,
|
|
53
|
+
) {
|
|
54
|
+
const functionName = "Authorization";
|
|
55
|
+
const handler = HANDLER.hdrInv;
|
|
56
|
+
const fileName = upperCase(functionName) + '_' + upperCase(handler);
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
templatePath: templatePathInv,
|
|
60
|
+
templateData: { functionName },
|
|
61
|
+
setting: {
|
|
62
|
+
savePath: path.join(appPath, SOURCE_PATH.rbac),
|
|
63
|
+
saveFileName: fileName,
|
|
64
|
+
fileExtension: '.js',
|
|
65
|
+
isAppend: true
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export default data;
|
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
|
|
19
|
+
|
|
20
|
+
import { middlewareHandler as middleware } from "@izara_project/izara-middleware";
|
|
21
|
+
import Logger from '@izara_project/izara-core-library-logger';
|
|
22
|
+
import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
|
|
23
|
+
|
|
24
|
+
import <%- functionName %> from './<%- functionName %>_Main.js';
|
|
25
|
+
|
|
26
|
+
// validate event params in middleware before into function.
|
|
27
|
+
const validatorSchema = {
|
|
28
|
+
//(<validatorSchema>)
|
|
29
|
+
//(</validatorSchema>)
|
|
30
|
+
};
|
|
31
|
+
middleware.setValidatorSchema(validatorSchema)
|
|
32
|
+
|
|
33
|
+
export const main = middleware.wrap(async (event, context, callback) => {
|
|
34
|
+
event._izContext.logger.debug('Event:', event);
|
|
35
|
+
event._izContext.logger.debug('context:', context);
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
|
|
39
|
+
// invoke LambdaFunction
|
|
40
|
+
return await <%- functionName %>.<%- functionName %>(
|
|
41
|
+
event._izContext, // correlationId/logger/integrationTestDetail/uniqueRequestId
|
|
42
|
+
event,
|
|
43
|
+
callingFlowSharedLib.addCallingFlowToPassOnProperties(event)
|
|
44
|
+
//(<additionalParams>)
|
|
45
|
+
//(</additionalParams>)
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
} catch (err) {
|
|
49
|
+
event._izContext.logger.error('Error, LambdaFunctionHdrInv: ', err);
|
|
50
|
+
throw (err);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
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
|
+
// yaml data.js
|
|
19
|
+
import path from 'path';
|
|
20
|
+
import { fileURLToPath } from 'url';
|
|
21
|
+
import fs from 'fs';
|
|
22
|
+
import yaml from 'yaml';
|
|
23
|
+
import { objectHash as hash } from '@izara_project/izara-shared-core';
|
|
24
|
+
import consts from '#libs/Consts.js';
|
|
25
|
+
import utils from '#libs/Utils.js';
|
|
26
|
+
import libs from '#libs/Libs.js';
|
|
27
|
+
|
|
28
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
29
|
+
const __dirname = path.dirname(__filename);
|
|
30
|
+
|
|
31
|
+
const {
|
|
32
|
+
RESOURCE_CLASSES,
|
|
33
|
+
SOURCE_PATH,
|
|
34
|
+
SAVE_FILE_NAME,
|
|
35
|
+
LAMBDA_RESOURCE
|
|
36
|
+
} = consts;
|
|
37
|
+
|
|
38
|
+
const {
|
|
39
|
+
createIamRole,
|
|
40
|
+
defaultIamRolePerAction,
|
|
41
|
+
externalResourceYaml
|
|
42
|
+
} = libs;
|
|
43
|
+
|
|
44
|
+
const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } =
|
|
45
|
+
utils;
|
|
46
|
+
|
|
47
|
+
const templatePath = path.join(__dirname, 'template.ejs');
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Generates yaml source params for a given action and handler
|
|
51
|
+
* @param {Object} _izContext - Context object with logger
|
|
52
|
+
* @param {Array} allObjSchemas - All object schemas
|
|
53
|
+
* @param {string} appPath - Source path
|
|
54
|
+
* @param {string} action - Action name (create/update/get/delete)
|
|
55
|
+
* @param {string} handler - Handler type (hdrApi/hdrSqs/hdrDsq/hdrInv)
|
|
56
|
+
* @param {string|null} functionNameConfig - Override for yaml key (null = derive from action+handler)
|
|
57
|
+
* @param {string} handlerSuffix - Suffix for fnName across all fields (e.g. 'BeforeLogical')
|
|
58
|
+
* @returns {Promise<Array>} Array containing source param object
|
|
59
|
+
*/
|
|
60
|
+
function data(
|
|
61
|
+
_izContext,
|
|
62
|
+
appPath,
|
|
63
|
+
) {
|
|
64
|
+
const functionName = "Authorization";
|
|
65
|
+
const fileName = upperCase(functionName) + '_Main';
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
templatePath,
|
|
69
|
+
templateData: {
|
|
70
|
+
functionName
|
|
71
|
+
},
|
|
72
|
+
setting: {
|
|
73
|
+
savePath: path.join(appPath, SOURCE_PATH.rbac),
|
|
74
|
+
saveFileName: fileName,
|
|
75
|
+
fileExtension: '.js',
|
|
76
|
+
isAppend: true
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export default data;
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
|
16
|
+
<http: //www.gnu.org/licenses />.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
//(<optionalRequire>)
|
|
21
|
+
//(</optionalRequire>)
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Gets an object by processing storage resources (DynamoDB, Graph)
|
|
25
|
+
* @param {Object} _izContext - Context object with logger
|
|
26
|
+
* @param {Object} requestParams - { objectType, identifiers, additionalParams }
|
|
27
|
+
* @param {Object} callingFlowConfig - Calling flow configuration
|
|
28
|
+
* @returns {Promise<Object>} Collected get result
|
|
29
|
+
*/
|
|
30
|
+
export default async function <%- functionName %>(
|
|
31
|
+
_izContext,
|
|
32
|
+
requestParams,
|
|
33
|
+
callingFlowConfig = {}
|
|
34
|
+
|
|
35
|
+
) {
|
|
36
|
+
try {
|
|
37
|
+
|
|
38
|
+
} catch (err) {
|
|
39
|
+
_izContext.logger.error('error GetMain:', err);
|
|
40
|
+
throw err;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
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
|
+
// yaml data.js
|
|
19
|
+
import path from 'path';
|
|
20
|
+
import { fileURLToPath } from 'url';
|
|
21
|
+
import consts from '#libs/Consts.js';
|
|
22
|
+
import utils from '#libs/Utils.js';
|
|
23
|
+
import libs from '#libs/Libs.js';
|
|
24
|
+
|
|
25
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
26
|
+
const __dirname = path.dirname(__filename);
|
|
27
|
+
|
|
28
|
+
const {
|
|
29
|
+
RESOURCE_CLASSES,
|
|
30
|
+
SOURCE_PATH,
|
|
31
|
+
SAVE_FILE_NAME,
|
|
32
|
+
LAMBDA_RESOURCE,
|
|
33
|
+
DYNAMO_RESOURCE,
|
|
34
|
+
S3_RESOURCE
|
|
35
|
+
} = consts;
|
|
36
|
+
|
|
37
|
+
const {
|
|
38
|
+
createIamRole,
|
|
39
|
+
defaultIamRolePerAction,
|
|
40
|
+
externalResourceYaml,
|
|
41
|
+
resourceNames
|
|
42
|
+
} = libs;
|
|
43
|
+
|
|
44
|
+
const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } =
|
|
45
|
+
utils;
|
|
46
|
+
|
|
47
|
+
const templatePath = path.join(__dirname, 'template.ejs');
|
|
48
|
+
|
|
49
|
+
const HANDLER = {
|
|
50
|
+
hdrInv: "hdrInv",
|
|
51
|
+
hdrApi: "hdrApi"
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Generates yaml source params for a given action and handler
|
|
56
|
+
* @param {Object} _izContext - Context object with logger
|
|
57
|
+
* @param {Array} allObjSchemas - All object schemas
|
|
58
|
+
* @param {string} appPath - Source path
|
|
59
|
+
* @param {string} action - Action name (create/update/get/delete)
|
|
60
|
+
* @param {string} handler - Handler type (hdrApi/hdrSqs/hdrDsq/hdrInv)
|
|
61
|
+
* @param {string|null} functionNameConfig - Override for yaml key (null = derive from action+handler)
|
|
62
|
+
* @param {string} handlerSuffix - Suffix for fnName across all fields (e.g. 'BeforeLogical')
|
|
63
|
+
* @returns {Promise<Array>} Array containing source param object
|
|
64
|
+
*/
|
|
65
|
+
async function data(
|
|
66
|
+
_izContext,
|
|
67
|
+
appPath,
|
|
68
|
+
) {
|
|
69
|
+
const allCreateSources = [];
|
|
70
|
+
const functionName = "Authorization";
|
|
71
|
+
const additionalResourcePermission = defaultIamRolePerAction();
|
|
72
|
+
|
|
73
|
+
additionalResourcePermission.push(
|
|
74
|
+
createIamRole({
|
|
75
|
+
[RESOURCE_CLASSES.lambda]: LAMBDA_RESOURCE.invokeFunction
|
|
76
|
+
},
|
|
77
|
+
externalResourceYaml(RESOURCE_CLASSES.lambda, "CheckPermissionHdrInv", "Permission")),
|
|
78
|
+
createIamRole({
|
|
79
|
+
[RESOURCE_CLASSES.dynamoDbTable]: [DYNAMO_RESOURCE.getItem, DYNAMO_RESOURCE.putItem]
|
|
80
|
+
},
|
|
81
|
+
[
|
|
82
|
+
resourceNames(RESOURCE_CLASSES.dynamoDbTable, "User"),
|
|
83
|
+
resourceNames(RESOURCE_CLASSES.dynamoDbTable, "UserRoles"),
|
|
84
|
+
]),
|
|
85
|
+
createIamRole({
|
|
86
|
+
[RESOURCE_CLASSES.s3]: [S3_RESOURCE.getObject]
|
|
87
|
+
},
|
|
88
|
+
[
|
|
89
|
+
resourceNames(RESOURCE_CLASSES.s3, "perServiceSchemas/*/Relationships/*.json"),
|
|
90
|
+
resourceNames(RESOURCE_CLASSES.s3, "perServiceSchemas/*/ObjectSchemaAll/*.json"),
|
|
91
|
+
resourceNames(RESOURCE_CLASSES.s3, "perServiceSchemas/*/FlowSchema/*.json"),
|
|
92
|
+
])
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
for (const handler of Object.values(HANDLER)) {
|
|
97
|
+
const fileName = upperCase(functionName) + '_' + upperCase(handler);
|
|
98
|
+
const functionNameConfig = functionName + upperCase(handler);
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
allCreateSources.push(
|
|
102
|
+
{
|
|
103
|
+
templatePath,
|
|
104
|
+
templateData: {
|
|
105
|
+
functionName: functionName + upperCase(handler),
|
|
106
|
+
handlerPath: path.join(
|
|
107
|
+
SOURCE_PATH.resourceLocationRbac,
|
|
108
|
+
`${fileName}.main`
|
|
109
|
+
),
|
|
110
|
+
additionalResourcePermission,
|
|
111
|
+
roleName: "Authorization",
|
|
112
|
+
hookTagSetting: `${functionName}FunctionSetting`,
|
|
113
|
+
handlerType: handler,
|
|
114
|
+
functionNameConfig
|
|
115
|
+
},
|
|
116
|
+
setting: {
|
|
117
|
+
savePath: path.join(appPath, SOURCE_PATH.appYaml),
|
|
118
|
+
saveFileName: SAVE_FILE_NAME.rbac,
|
|
119
|
+
fileExtension: '.yml',
|
|
120
|
+
isAppend: true
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
);
|
|
124
|
+
};
|
|
125
|
+
return allCreateSources;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
export default data;
|
package/src/generateCode.js
CHANGED
|
@@ -37,7 +37,6 @@ import generateTemplateDataInitialSetup from './generateCode/generateInitialSetu
|
|
|
37
37
|
import generateTemplateDataOther from './generateCode/generateOther/generateCodeOther.js';
|
|
38
38
|
|
|
39
39
|
import generateTemplateDataRole from './generateCode/generateRole/generateCodeRole.js';
|
|
40
|
-
import generateTemplateTranslations from './generateCode/generateTranslation/generateTranslation.js';
|
|
41
40
|
|
|
42
41
|
const __filename = fileURLToPath(import.meta.url);
|
|
43
42
|
const __dirname = dirname(__filename);
|
|
@@ -73,14 +72,15 @@ async function generateCodeWithTemplate(
|
|
|
73
72
|
// ── 1. Fetch all schemas ─────────────────────────────────────────────────
|
|
74
73
|
console.info('[INFO] [generateCode] STATUS=FETCHING | schemas...');
|
|
75
74
|
const fetchStartTime = Date.now();
|
|
76
|
-
const [allLocalFlowSchemas, allObjSchemas, allLocalRelationshipSchemas] =
|
|
75
|
+
const [allLocalFlowSchemas, allObjSchemas, allLocalRelationshipSchemas, allLocalNotificationSystem] =
|
|
77
76
|
await Promise.all([
|
|
78
77
|
getObjectSchema.getAllLocalFlowSchemas(_izContext, schemasPath),
|
|
79
78
|
getObjectSchema.getAllLocalObjectSchemasWithHierarchy(
|
|
80
79
|
_izContext,
|
|
81
80
|
schemasPath
|
|
82
81
|
),
|
|
83
|
-
getObjectSchema.getAllLocalRelationshipSchema(_izContext, schemasPath)
|
|
82
|
+
getObjectSchema.getAllLocalRelationshipSchema(_izContext, schemasPath),
|
|
83
|
+
getObjectSchema.getLocalNotificationSystemSchemas(_izContext, schemasPath)
|
|
84
84
|
]);
|
|
85
85
|
|
|
86
86
|
const fetchDuration = Date.now() - fetchStartTime;
|
|
@@ -98,7 +98,6 @@ async function generateCodeWithTemplate(
|
|
|
98
98
|
schemaResult,
|
|
99
99
|
initialSetupResult,
|
|
100
100
|
otherResult,
|
|
101
|
-
translationResult
|
|
102
101
|
] = await Promise.all([
|
|
103
102
|
generateTemplateDataFromFlowSchema(
|
|
104
103
|
_izContext,
|
|
@@ -112,6 +111,7 @@ async function generateCodeWithTemplate(
|
|
|
112
111
|
allObjSchemas,
|
|
113
112
|
allLocalRelationshipSchemas,
|
|
114
113
|
allLocalFlowSchemas.records,
|
|
114
|
+
allLocalNotificationSystem,
|
|
115
115
|
settings
|
|
116
116
|
).catch(error => {
|
|
117
117
|
console.error('[generateCode] schemaResult error:', error);
|
|
@@ -126,13 +126,7 @@ async function generateCodeWithTemplate(
|
|
|
126
126
|
allLocalFlowSchemas.records,
|
|
127
127
|
settings
|
|
128
128
|
),
|
|
129
|
-
generateTemplateDataOther(_izContext, appPath)
|
|
130
|
-
generateTemplateTranslations(
|
|
131
|
-
_izContext,
|
|
132
|
-
appPath,
|
|
133
|
-
allObjSchemas,
|
|
134
|
-
allLocalFlowSchemas
|
|
135
|
-
)
|
|
129
|
+
generateTemplateDataOther(_izContext, appPath)
|
|
136
130
|
]);
|
|
137
131
|
|
|
138
132
|
const genDuration = Date.now() - genStartTime;
|
|
@@ -146,7 +140,6 @@ async function generateCodeWithTemplate(
|
|
|
146
140
|
...schemaResult,
|
|
147
141
|
...initialSetupResult,
|
|
148
142
|
...otherResult,
|
|
149
|
-
...translationResult
|
|
150
143
|
];
|
|
151
144
|
|
|
152
145
|
// ── 3. Generate role configs ─────────────────────────────────────────────
|
package/src/libs/Consts.js
CHANGED
|
@@ -93,8 +93,12 @@ const SOURCE_PATH = {
|
|
|
93
93
|
resourceLocationCreateRecordComplete:
|
|
94
94
|
'src/generatedCode/CreateRecordComplete/',
|
|
95
95
|
|
|
96
|
-
//
|
|
97
|
-
|
|
96
|
+
// systemText
|
|
97
|
+
systemTextSchema: 'SystemTextSchema/generatedCode/',
|
|
98
|
+
|
|
99
|
+
// rbac
|
|
100
|
+
rbac: '/src/generatedCode/Rbac/source/',
|
|
101
|
+
resourceLocationRbac: 'src/generatedCode/Rbac/source/'
|
|
98
102
|
};
|
|
99
103
|
|
|
100
104
|
const SQS_RESOURCE = {
|
|
@@ -146,16 +150,18 @@ const SAVE_FILE_NAME = {
|
|
|
146
150
|
sharedResourceYaml: 'generate-shared-resource',
|
|
147
151
|
authorizerYaml: 'authorizer',
|
|
148
152
|
findData: 'find-data',
|
|
153
|
+
rbac: 'rbac',
|
|
149
154
|
|
|
150
155
|
externalLambdaRole: 'generatedLambdaRoleServiceConfig',
|
|
151
156
|
snsSubscription: 'generatedSnsServiceConfig',
|
|
152
|
-
|
|
157
|
+
tableName: "generatedTableNameConfig",
|
|
158
|
+
// translateId: 'TranslateIdsRequest',
|
|
153
159
|
S3Bucket: 'generated-s3-bucket',
|
|
154
160
|
objectRelationship: 'ObjectRelationships',
|
|
155
161
|
refObjectRelationship: 'RefObjectRelationships',
|
|
156
162
|
objectSchema: 'ObjectFieldSchema',
|
|
157
163
|
roleNameConfig: 'RoleNameConfig',
|
|
158
|
-
|
|
164
|
+
systemTextSchema: 'SystemTextSchema'
|
|
159
165
|
};
|
|
160
166
|
|
|
161
167
|
const FUNCTION_NAME = {
|
package/src/libs/Libs.js
CHANGED
|
@@ -50,7 +50,9 @@ function resourceNames(resourceClass, resourceName) {
|
|
|
50
50
|
'arn:aws:lambda:${self:custom.iz_region}:${self:custom.iz_accountId}:function:${self:custom.iz_resourcePrefix}' +
|
|
51
51
|
resourceName,
|
|
52
52
|
[RESOURCE_CLASSES.webSocket]:
|
|
53
|
-
'arn:aws:execute-api:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_webSocketHostId}/${self:custom.iz_stage}/POST/@connections/{connectionId}'
|
|
53
|
+
'arn:aws:execute-api:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_webSocketHostId}/${self:custom.iz_stage}/POST/@connections/{connectionId}',
|
|
54
|
+
[RESOURCE_CLASSES.s3]:
|
|
55
|
+
'arn:aws:s3:::${self:custom.iz_serviceSchemaBucketName}/' + resourceName,
|
|
54
56
|
}[resourceClass];
|
|
55
57
|
}
|
|
56
58
|
|
|
@@ -62,6 +64,10 @@ function resourceNames(resourceClass, resourceName) {
|
|
|
62
64
|
* @returns {{ effect, action, resource}}
|
|
63
65
|
*/
|
|
64
66
|
function createIamRole(action, resource = [], effect = 'Allow') {
|
|
67
|
+
if (!Array.isArray(resource)) {
|
|
68
|
+
resource = [resource];
|
|
69
|
+
};
|
|
70
|
+
|
|
65
71
|
if (Array.isArray(action)) {
|
|
66
72
|
const actionObj = {};
|
|
67
73
|
action.forEach(act => {
|