@izara_project/izara-core-generate-service-code 1.0.28 → 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/generateSchema/relationshipPerActionComponent/changeRelationship/action/mainFunction/template.ejs +36 -12
- package/src/generateCode/generateSchema/relationshipPerActionComponent/moveRelationship/action/mainFunction/template.ejs +10 -0
- package/src/generateCode/generateSchema/relationshipPerActionComponent/update/action/mainFunction/template.ejs +6 -6
- 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
|
@@ -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;
|
|
@@ -15,8 +15,6 @@ You should have received a copy of the GNU Affero General Public License
|
|
|
15
15
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
18
|
import { objectHash as hash } from '@izara_project/izara-shared-core';
|
|
21
19
|
|
|
22
20
|
import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
|
|
@@ -124,10 +122,36 @@ export default async function <%- functionName %> (
|
|
|
124
122
|
//(<afterValidateChangeRel>)
|
|
125
123
|
//(</afterValidateChangeRel>)
|
|
126
124
|
|
|
127
|
-
|
|
128
|
-
_izContext
|
|
125
|
+
// check old relType canChangeToRelType
|
|
126
|
+
const oldRelationshipSchema = await getRelationshipSchemaWithCache(_izContext, oldRelTypeAndDirection.relType);
|
|
127
|
+
_izContext.logger.debug("oldRelationshipSchema ", oldRelationshipSchema);
|
|
128
|
+
|
|
129
|
+
const newRelationshipSchema = await getRelationshipSchemaWithCache(_izContext, newRelType);
|
|
130
|
+
_izContext.logger.debug("newRelationshipSchema: ", newRelationshipSchema);
|
|
131
|
+
if (!oldRelationshipSchema.hasOwnProperty('canChangeToRelTypes')) {
|
|
132
|
+
errorsFound.push(`${oldRelTypeAndDirection.relType} not have property to change to another relType`);
|
|
133
|
+
} else {
|
|
134
|
+
if (!newRelationshipSchema) {
|
|
135
|
+
errorsFound.push(`${newRelationshipSchema} not exists can't changeToRelType`);
|
|
136
|
+
} else {
|
|
137
|
+
oldRelationshipSchema.canChangeToRelTypes.find(canChangeToRelType => {
|
|
138
|
+
if (canChangeToRelType.relType.serviceTag === newRelType.serviceTag &&
|
|
139
|
+
canChangeToRelType.relType.relationshipTag === newRelType.relationshipTag) {
|
|
140
|
+
// check changeBy
|
|
141
|
+
if (canChangeToRelType.changeBy === "user") {
|
|
142
|
+
// if changeBy is user will check for importBatch callingFlow
|
|
143
|
+
if (callingFlowConfig) {
|
|
144
|
+
if (callingFlowConfig.callingFlow !== "ImportDataTestExternalUpdateRelationshipHdrSqs") {
|
|
145
|
+
errorsFound.push(`CanChangeToRelType changeBy is user but it's not user process with importData`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
};
|
|
129
153
|
|
|
130
|
-
const links = await findLinksByObjTypes(_izContext, [firstObject.objType, secondObject.objType],
|
|
154
|
+
const links = await findLinksByObjTypes(_izContext, [firstObject.objType, secondObject.objType], newRelationshipSchema.links)
|
|
131
155
|
_izContext.logger.debug("links", links)
|
|
132
156
|
if (!links.length) {
|
|
133
157
|
errorsFound.push(`not found link between ${JSON.stringify({ firstObject: firstObject.objType })} ${JSON.stringify({ secondObject: secondObject.objType })}`)
|
|
@@ -147,8 +171,8 @@ export default async function <%- functionName %> (
|
|
|
147
171
|
const matchToFrom = fromServiceTag === secondServiceTag && fromObjectType === secondObjectType &&
|
|
148
172
|
toServiceTag === firstServiceTag && toObjType === firstObjectType;
|
|
149
173
|
|
|
150
|
-
if ((
|
|
151
|
-
(
|
|
174
|
+
if ((newRelationshipSchema.relationshipDirection === "from" && matchFromTo) ||
|
|
175
|
+
(newRelationshipSchema.relationshipDirection === "to" && matchToFrom)) {
|
|
152
176
|
checkCorrectLink = true
|
|
153
177
|
break;
|
|
154
178
|
}
|
|
@@ -160,10 +184,10 @@ export default async function <%- functionName %> (
|
|
|
160
184
|
|
|
161
185
|
let targetStorageResources = [];
|
|
162
186
|
|
|
163
|
-
if (
|
|
187
|
+
if (newRelationshipSchema) {
|
|
164
188
|
// find targetStorageResources and validate each storageResources
|
|
165
189
|
await Promise.all(
|
|
166
|
-
|
|
190
|
+
newRelationshipSchema.links.map(async ({ from, to, storageResourceTags }) => {
|
|
167
191
|
const { serviceTag: fromServiceTag, objectType: fromObjectType } = from.objType
|
|
168
192
|
const { serviceTag: toServiceTag, objectType: toObjectType } = to.objType
|
|
169
193
|
|
|
@@ -184,7 +208,7 @@ export default async function <%- functionName %> (
|
|
|
184
208
|
|
|
185
209
|
// check founded storageResource of link and collect used storageResources
|
|
186
210
|
await Promise.all(storageResourceTags.map(async storageResourceTag => {
|
|
187
|
-
const usedStorageResource =
|
|
211
|
+
const usedStorageResource = newRelationshipSchema.storageResources[storageResourceTag];
|
|
188
212
|
|
|
189
213
|
if (usedStorageResource.storageType === consts.STORAGE_TYPES.graph) {
|
|
190
214
|
const graphServiceTag = await getGraphServiceTagWithCache(_izContext, usedStorageResource.graphServerTag);
|
|
@@ -213,8 +237,8 @@ export default async function <%- functionName %> (
|
|
|
213
237
|
|
|
214
238
|
|
|
215
239
|
// validate properties exists with schema
|
|
216
|
-
for (const propKey in oldRelTypeAndDirection.
|
|
217
|
-
if (!
|
|
240
|
+
for (const propKey in oldRelTypeAndDirection.fieldNames) {
|
|
241
|
+
if (!newRelationshipSchema.fieldNames.hasOwnProperty(propKey)) {
|
|
218
242
|
errorsFound.push(`property: ${propKey} not exists in relationshipSchema`);
|
|
219
243
|
}
|
|
220
244
|
}
|
|
@@ -128,6 +128,16 @@ export default async function <%- functionName %> (
|
|
|
128
128
|
const relationshipSchema = await getRelationshipSchemaWithCache(_izContext, relType);
|
|
129
129
|
_izContext.logger.debug("relationshipSchema: ", relationshipSchema);
|
|
130
130
|
|
|
131
|
+
if (!relationshipSchema.hasOwnProperty("moveBy") || relationshipSchema.moveBy === "none") {
|
|
132
|
+
errorsFound.push(`relationship: ${relType.relationshipTag} can't move`);
|
|
133
|
+
} else if (relationshipSchema.moveBy === "user") {
|
|
134
|
+
if (callingFlowConfig) {
|
|
135
|
+
if (callingFlowConfig.callingFlow !== "ImportDataTestExternalUpdateRelationshipHdrSqs") {
|
|
136
|
+
errorsFound.push(`moveBy is user but it's not user process with importData`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
131
141
|
const links = await findLinksByObjTypes(_izContext, [firstObject.objType, secondObject.objType], relationshipSchema.links)
|
|
132
142
|
_izContext.logger.debug("links", links)
|
|
133
143
|
if (!links.length) {
|
|
@@ -193,18 +193,18 @@ export default async function updateRelationship(
|
|
|
193
193
|
_izContext.logger.debug("propValue: ", propValue);
|
|
194
194
|
|
|
195
195
|
if (relationshipSchema.fieldNames[propKey]) {
|
|
196
|
-
if (relationshipSchema.fieldNames[propKey].
|
|
197
|
-
|
|
196
|
+
if (relationshipSchema.fieldNames[propKey].updateBy === "user") {
|
|
197
|
+
if (callingFlowConfig) {
|
|
198
|
+
if (callingFlowConfig.callingFlow !== "ImportDataTestExternalUpdateRelationshipHdrSqs") {
|
|
199
|
+
errorsFound.push(`property:${propKey} can update user but it's not user process with importData`)
|
|
200
|
+
}
|
|
201
|
+
}
|
|
198
202
|
}
|
|
199
203
|
} else {
|
|
200
204
|
errorsFound.push(`property:${propKey} not exists in relationshipSchema`);
|
|
201
205
|
}
|
|
202
206
|
}
|
|
203
207
|
|
|
204
|
-
} else {
|
|
205
|
-
errorsFound.push(`relationshipSchema not exists`);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
208
|
|
|
209
209
|
// if found errors will stop processing
|
|
210
210
|
if (errorsFound.length) {
|