@izara_project/izara-core-generate-service-code 1.0.30 → 1.0.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (22) hide show
  1. package/package.json +2 -2
  2. package/src/generateCode/generateFlowSchema/event/ownTopicComponent/flowSchemaComponent/functionYaml/data.js +1 -1
  3. package/src/generateCode/generateFlowSchema/event/ownTopicComponent/flowSchemaComponent/handler/template.ejs +1 -1
  4. package/src/generateCode/generateFlowSchema/event/ownTopicComponent/flowSchemaComponent/mainFunction/template.ejs +1 -1
  5. package/src/generateCode/generateFlowSchema/flowStep/afterPluginHook/handler/templateDsq.ejs +1 -0
  6. package/src/generateCode/generateFlowSchema/flowStep/afterPluginHook/handler/templateSqs.ejs +2 -5
  7. package/src/generateCode/generateFlowSchema/flowStep/afterPluginHook/templateMain.ejs +3 -3
  8. package/src/generateCode/generateFlowSchema/flowStep/firstFlowStep/templateMain.ejs +2 -2
  9. package/src/generateCode/generateFlowSchema/libs/template.ejs +8 -8
  10. package/src/generateCode/generateSchema/actionEndpointComponent/mainFunction/create/main/template.ejs +14 -18
  11. package/src/generateCode/generateSchema/actionEndpointComponent/mainFunction/get/template.ejs +0 -9
  12. package/src/generateCode/generateSchema/rbac/dynamoDb/data.js +1 -39
  13. package/src/generateCode/generateSchema/rbac/index.js +7 -13
  14. package/src/generateCode/generateSchema/rbac/lambda/{authApi → handler}/data.js +4 -4
  15. package/src/generateCode/generateSchema/rbac/lambda/{authApi/templateInv.ejs → handler/template.ejs} +1 -1
  16. package/src/generateCode/generateSchema/rbac/lambda/mainFunction/template.ejs +111 -0
  17. package/src/generateCode/generateSchema/rbac/lambda/yaml/data.js +26 -48
  18. package/src/libs/Utils.js +2 -2
  19. package/src/generateCode/generateSchema/rbac/lambda/authInv/handler/data.js +0 -70
  20. package/src/generateCode/generateSchema/rbac/lambda/authInv/handler/templateInv.ejs +0 -52
  21. package/src/generateCode/generateSchema/rbac/lambda/authInv/mainFunction/template.ejs +0 -42
  22. /package/src/generateCode/generateSchema/rbac/lambda/{authInv/mainFunction → mainFunction}/data.js +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.30",
3
+ "version": "1.0.32",
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.133",
30
+ "@izara_project/izara-core-library-service-schemas": "^1.0.135",
31
31
  "@izara_project/izara-shared-core": "^1.0.9",
32
32
  "ejs": "^5.0.1",
33
33
  "js-beautify": "^1.15.4",
@@ -105,7 +105,7 @@ function createSourceParams(_izContext, flowSchema, appPath) {
105
105
  templateData: {
106
106
  resourceLocation:
107
107
  savePath.flowSchemaFlowTag(flowSchema.flowTag) +
108
- upperCase(flowSchema.flowTag) +
108
+ upperCase(flowSchema.flowTag) + "_" +
109
109
  upperCase('hdrWbs'),
110
110
  functionName: upperCase(flowSchema.flowTag),
111
111
  handlerType: upperCase('hdrWbs'),
@@ -21,7 +21,7 @@ import { middlewareHandler as middleware, validatorSchema, consts, response } fr
21
21
  import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
22
22
  import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
23
23
  import { objectHash as hash } from '@izara_project/izara-shared-core';
24
- import { postToConnection } from '../../../libs/source/GenerateCodeLibs.js';
24
+ import { postToConnection } from '../../../../libs/source/GenerateCodeLibs.js';
25
25
  import <%- functionName %> from './<%- functionName %>_Main.js';
26
26
  import { utils, getObjectSchema } from "@izara_project/izara-core-library-service-schemas";
27
27
  const { createFlowTypeConcat } = utils
@@ -29,7 +29,7 @@ import { NoRetryError } from '@izara_project/izara-core-library-core';
29
29
  import { consts as coreConsts } from "@izara_project/izara-middleware";
30
30
  import { consts as generateCodeConsts } from '@izara_project/izara-core-generate-service-code';
31
31
  const { TOPIC_NAME_GENERATE_CODE } = generateCodeConsts;
32
- import { postToConnection } from '../../../libs/source/GenerateCodeLibs.js'
32
+ import { postToConnection } from '../../../../libs/source/GenerateCodeLibs.js';
33
33
 
34
34
  //(<optionalRequire>)
35
35
  //(</optionalRequire>)
@@ -118,6 +118,7 @@ export const main = middleware.wrap(async (event, context, callback) => {
118
118
 
119
119
  // add argument (to invoke lambda) to passOnProperties[]
120
120
  passOnProperties.push(record.body.Message);
121
+ passOnProperties.push(callingFlowSharedLib.addPassBackPropertiesToPassOnProperties(record.body.Message)) // is Ok PassBackProperties
121
122
  record._izContext.logger.debug('passOnProperties in handler', passOnProperties);
122
123
 
123
124
  // call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
@@ -51,11 +51,8 @@ export const main = middleware.wrap(async (event, context) => {
51
51
 
52
52
  // add argument (to invoke lambda) to passOnProperties[]
53
53
  passOnProperties.push(record.body.Message);
54
- passOnProperties.push(
55
- callingFlowSharedLib.addCallingFlowToPassOnProperties(
56
- record.body.Message
57
- )
58
- );
54
+ passOnProperties.push(callingFlowSharedLib.addPassBackPropertiesToPassOnProperties(record.body.Message));
55
+
59
56
  record._izContext.logger.debug(
60
57
  'passOnProperties in handler',
61
58
  passOnProperties
@@ -43,18 +43,18 @@ export default async function <%- functionName %>Main (
43
43
  requestParams,
44
44
  //(<additionalParams>)
45
45
  //(</additionalParams>)
46
- callingFlowConfig = {},
46
+ passBackProperties = {},
47
47
  ) {
48
48
  try {
49
49
  _izContext.logger.debug('<%- functionName %> _izContext', _izContext);
50
50
  _izContext.logger.debug('<%- functionName %> requestParams', requestParams);
51
- _izContext.logger.debug('<%- functionName %> callingFlowConfig', callingFlowConfig);
51
+ _izContext.logger.debug('<%- functionName %> passBackProperties', passBackProperties);
52
52
 
53
53
  const result = await receivePlugInHookTag(
54
54
  _izContext,
55
55
  '<%- plugInHookTag %>',
56
56
  requestParams,
57
- callingFlowConfig
57
+ passBackProperties
58
58
  );
59
59
 
60
60
  let plugInIdentifiers = null;
@@ -40,12 +40,12 @@ export default async function <%- functionName %>Main (
40
40
  requestParams,
41
41
  //(<additionalParams>)
42
42
  //(</additionalParams>)
43
- callingFlowConfig = {},
43
+ passBackProperties = {},
44
44
  ) {
45
45
  try {
46
46
  _izContext.logger.debug('<%- functionName %> _izContext', _izContext);
47
47
  _izContext.logger.debug('<%- functionName %> requestParams', requestParams);
48
- _izContext.logger.debug('<%- functionName %> callingFlowConfig', callingFlowConfig);
48
+ _izContext.logger.debug('<%- functionName %> passBackProperties', passBackProperties);
49
49
 
50
50
  //(<hookCode>)
51
51
  //(</hookCode>)
@@ -96,14 +96,14 @@ function getNestObject(_izContext, nestedObj, paths) {
96
96
  * @returns {string|null}
97
97
  */
98
98
  function getResourcePart(arnString, index) {
99
- try {
100
- const resourceId = arnString.split(':').pop();
101
- const parts = resourceId.split('_');
102
- return parts[index] || null;
103
- } catch (error) {
104
- console.error("Invalid ARN format", error);
105
- return null;
106
- }
99
+ try {
100
+ const resourceId = arnString.split(':').pop();
101
+ const parts = resourceId.split('_');
102
+ return parts[index] || null;
103
+ } catch (error) {
104
+ console.error("Invalid ARN format", error);
105
+ return null;
106
+ }
107
107
  }
108
108
 
109
109
  export {
@@ -89,9 +89,7 @@ const PREFIX = {
89
89
  }
90
90
 
91
91
  // ── Detect invocation type ────────────────────────────────────────────────
92
- const userAgent = !!_izContext.correlationIds.get(middlewareConsts.USER_AGENT);
93
- const directInvoke = !userAgent &&
94
- requestParams.hasOwnProperty('__context__') &&
92
+ const directInvoke = requestParams.hasOwnProperty('__context__') &&
95
93
  requestParams.izEventSource?.eventSourceTag === 'DirectInvoke';
96
94
 
97
95
  // ── Build createDataDetails ───────────────────────────────────────────────
@@ -220,17 +218,15 @@ const PREFIX = {
220
218
  }
221
219
 
222
220
  // ── Create awaiting multiple steps ────────────────────────────────────────
223
- if (!userAgent) {
224
- _izContext.logger.debug('not api will create awaitingStep');
225
- await asyncFlowSharedLib.createAwaitingMultipleStepsWithAdditionalAttributes(
226
- _izContext,
227
- allAwaitingStepsId,
228
- asyncFlowSharedLib.createPendingStepId(
229
- hash({ objType, identifiers: objInstanceFull.identifiers }),
230
- PREFIX.CREATE_OBJECT_ASYNC_COMPLETE
231
- )
232
- );
233
- }
221
+ _izContext.logger.debug('not api will create awaitingStep');
222
+ await asyncFlowSharedLib.createAwaitingMultipleStepsWithAdditionalAttributes(
223
+ _izContext,
224
+ allAwaitingStepsId,
225
+ asyncFlowSharedLib.createPendingStepId(
226
+ hash({ objType, identifiers: objInstanceFull.identifiers }),
227
+ PREFIX.CREATE_OBJECT_ASYNC_COMPLETE
228
+ )
229
+ );
234
230
 
235
231
  // ── Process graph objects ─────────────────────────────────────────────────
236
232
  let messageObject = {};
@@ -244,7 +240,8 @@ const PREFIX = {
244
240
  messageObject = {
245
241
  objType,
246
242
  objInstanceFull: objectForCreate.objInstanceFull,
247
- relationships: requestParams.relationships || []
243
+ setFieldConditionals: requestParams.setFieldConditionals || [],
244
+ relationships: requestParams.relationships || []
248
245
  };
249
246
  }
250
247
 
@@ -252,15 +249,14 @@ const PREFIX = {
252
249
 
253
250
  Object.assign(messageObject, { settings: { updatePropertiesOnMatch: false }, originTimestamp: Date.now() });
254
251
 
255
- if (userAgent || directInvoke) {
256
- _izContext.logger.debug(userAgent ? 'have userAgent will invoke GraphHandler' : 'DirectInvoke case will invoke GraphHandlerInv');
252
+ if (directInvoke) {
253
+ _izContext.logger.debug('DirectInvoke case will invoke GraphHandlerInv');
257
254
  return await graphSharedLibs.createNodeV2(
258
255
  _izContext, graphServiceName, objType, objInstanceFullForGraph,
259
256
  requestParams.relationships || [], Date.now(), { updatePropertiesOnMatch: false }
260
257
  );
261
258
  }
262
259
 
263
- _izContext.logger.debug('not have userAgent will send Message to GraphHandler');
264
260
  messageObject = callingFlowSharedLib.addCallingFlowToSnsRequestMessageObject(
265
261
  messageObject,
266
262
  callingFlowSharedLib.addParentCallingFlowConfig(
@@ -84,15 +84,6 @@ export default async function getMain(
84
84
  const objectSchema = await getObjSchemaS3WithHierarchy(_izContext, objType);
85
85
  _izContext.logger.debug('objectSchema:', objectSchema);
86
86
 
87
- // ── Validate user context ─────────────────────────────────────────────────
88
- if (objectSchema.generatedBy === 'userGenerated') {
89
- const userId = _izContext.correlationIds.get(coreConsts.BASE_USER_ID);
90
- const targetId = _izContext.correlationIds.get(coreConsts.TARGET_ID);
91
- if (!userId) throw new Error('Not have userId');
92
- if (objectSchema.hasOwnProperty('belongTo') && !targetId)
93
- throw new Error('not have targetId');
94
- }
95
-
96
87
  // ── Build getDataDetails ──────────────────────────────────────────────────
97
88
  const getDataDetails = await createGetDataDetails(_izContext, objectSchema);
98
89
  _izContext.logger.debug('getDataDetails:', getDataDetails);
@@ -36,47 +36,9 @@ const createAwaitingMultipleStepDynamoDbData = (_izContext, srcPath) => {
36
36
  const defaultDynamoDataLists = [];
37
37
 
38
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
39
  {
51
40
  tableName: 'RolePermissions',
52
41
  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
42
  attributes: [
81
43
  {
82
44
  keyType: 'partitionKey',
@@ -85,7 +47,7 @@ const createAwaitingMultipleStepDynamoDbData = (_izContext, srcPath) => {
85
47
  },
86
48
  {
87
49
  keyType: 'sortKey',
88
- AttributeName: 'roleIdKey',
50
+ AttributeName: 'flowTypeWithTargetIdConcat',
89
51
  AttributeType: 'S'
90
52
  }
91
53
  ]
@@ -20,12 +20,9 @@ import { join } from 'path';
20
20
  import { getObjectSchema } from '@izara_project/izara-core-library-service-schemas';
21
21
  const { getAllLocalObjectSchemasWithHierarchy } = getObjectSchema;
22
22
 
23
- // lambda
24
- import authInvHandler from './lambda/authInv/handler/data.js'
25
- import authInvMain from './lambda/authInv/mainFunction/data.js'
26
-
27
23
  // auth for api
28
- import authApi from './lambda/authApi/data.js'
24
+ import authHandler from './lambda/handler/data.js'
25
+ import authMainFunction from './lambda/mainFunction/data.js'
29
26
  // yaml
30
27
  import authYaml from './lambda/yaml/data.js';
31
28
  // dynamo
@@ -45,19 +42,16 @@ async function generateCodeWithTemplate(
45
42
  try {
46
43
  const createSourceParams = [];
47
44
  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
45
  const yamlInvComponent = await authYaml(_izContext, appPath);
52
46
  const dynamoRbacPermission = dynamo(_izContext, appPath);
53
-
47
+ const handler = authHandler(_izContext, appPath);
48
+ const mainFunction = authMainFunction(_izContext, appPath);
54
49
 
55
50
  createSourceParams.push(
56
- mainFunctionInvComponent,
57
- handlerInvComponent,
58
- authApiComponent,
59
51
  ...yamlInvComponent,
60
- ...dynamoRbacPermission
52
+ ...dynamoRbacPermission,
53
+ handler,
54
+ mainFunction
61
55
  );
62
56
 
63
57
  }
@@ -27,12 +27,14 @@ const __dirname = path.dirname(__filename);
27
27
 
28
28
  const {
29
29
  SOURCE_PATH,
30
+ HANDLER
30
31
  } = consts;
31
32
 
32
33
  const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } =
33
34
  utils;
34
35
 
35
- const templatePathInv = path.join(__dirname, 'templateInv.ejs');
36
+ const templatePathInv = path.join(__dirname, 'template.ejs');
37
+
36
38
 
37
39
  /**
38
40
  * Generates yaml source params for a given action and handler
@@ -50,9 +52,7 @@ function data(
50
52
  appPath,
51
53
  ) {
52
54
  const functionName = "Authorization";
53
-
54
-
55
- const fileName = upperCase(functionName);
55
+ const fileName = `${upperCase(functionName)}_${upperCase(HANDLER.hdrInv)}`;
56
56
 
57
57
  return {
58
58
  templatePath: templatePathInv,
@@ -37,7 +37,7 @@ export const main = middleware.wrap(async (event, context, callback) => {
37
37
  try {
38
38
 
39
39
  // invoke LambdaFunction
40
- return await <%- functionName %>.<%- functionName %>(
40
+ return await <%- functionName %>(
41
41
  event._izContext, // correlationId/logger/integrationTestDetail/uniqueRequestId
42
42
  event,
43
43
  callingFlowSharedLib.addCallingFlowToPassOnProperties(event)
@@ -0,0 +1,111 @@
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
+ import { consts } from '@izara_project/izara-core-library-core';
20
+ import dynamoDBSharedLibs from '@izara_project/izara-core-library-dynamodb';
21
+ import { utils } from '@izara_project/izara-core-library-service-schemas';
22
+ import snsSharedLib from '@izara_project/izara-core-library-sns';
23
+ import { sns } from '@izara_project/izara-core-library-external-request';
24
+ import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
25
+
26
+ //(<optionalRequire>)
27
+ //(</optionalRequire>)
28
+
29
+ /**
30
+ * Gets an object by processing storage resources (DynamoDB, Graph)
31
+ * @param {Object} _izContext - Context object with logger
32
+ * @param {Object} requestParams - { objectType, identifiers, additionalParams }
33
+ * @param {Object} callingFlowConfig - Calling flow configuration
34
+ * @returns {Promise<Object>} Collected get result
35
+ */
36
+ export default async function Authorization(
37
+ _izContext,
38
+ requestParams,
39
+ callingFlowConfig = {}
40
+ ) {
41
+ try {
42
+ _izContext.logger.debug('rbacValidator ::: ', {
43
+ requestParams,
44
+ callingFlowConfig
45
+ });
46
+
47
+ const identifier = requestParams?.identifier || null;
48
+ let flowTypeConcat = requestParams?.flowTypeConcat || null;
49
+
50
+ if (!identifier || !flowTypeConcat) {
51
+ throw new Error(
52
+ 'Missing required request parameters: identifier or flowTagConcat'
53
+ );
54
+ }
55
+ if (typeof flowTypeConcat === 'object') {
56
+ flowTypeConcat = utils.createFlowTypeConcat(flowTypeConcat)
57
+ }
58
+
59
+ if (typeof flowTypeConcat !== 'string') {
60
+ throw new Error('flowTypeConcat must be a string');
61
+ }
62
+
63
+ const userId = _izContext.correlationIds.get(consts.BASE_USER_ID);
64
+ _izContext.logger.debug('userId', userId);
65
+
66
+ if (!userId) {
67
+ throw new Error('User ID not found in correlation IDs');
68
+ };
69
+
70
+ const targetId = _izContext.correlationIds.get(consts.TARGET_ID);
71
+ _izContext.logger.debug('targetId', targetId);
72
+
73
+ if (!targetId) {
74
+ throw new Error('Target ID not found in correlation IDs');
75
+ };
76
+
77
+ const rolePermissionTableName = dynamoDBSharedLibs.tableName(_izContext, "RolePermission");
78
+
79
+ const resultRolePermissions = await dynamoDBSharedLibs.getItem(_izContext, rolePermissionTableName, {
80
+ userId: userId,
81
+ flowTypeWithTargetIdConcat: `${flowTypeConcat}_${targetId}`
82
+ });
83
+
84
+ if (!resultRolePermissions) {
85
+ throw new Error('User roles not found for the given user');
86
+ };
87
+
88
+ if (resultRolePermissions.permission === true) {
89
+ // will check app level permission
90
+ const messageObject = {
91
+ requestParams: {
92
+ identifier: identifier,
93
+ flowTypeConcat: flowTypeConcat,
94
+ },
95
+ callingFlow: callingFlowConfig || {}
96
+ };
97
+
98
+
99
+ const sendMessageToCheckRbacAppLevel = {
100
+ Message: JSON.stringify(messageObject),
101
+ TopicArn: snsSharedLib.snsTopicArnByFlowSchema(_izContext, "RbacValidator_In", "TestRbac")
102
+ };
103
+
104
+ await sns.publishAsync(_izContext, sendMessageToCheckRbacAppLevel)
105
+ };
106
+
107
+ } catch (err) {
108
+ _izContext.logger.error('error GetMain:', err);
109
+ throw err;
110
+ }
111
+ }
@@ -29,9 +29,8 @@ const {
29
29
  RESOURCE_CLASSES,
30
30
  SOURCE_PATH,
31
31
  SAVE_FILE_NAME,
32
- LAMBDA_RESOURCE,
33
32
  DYNAMO_RESOURCE,
34
- S3_RESOURCE
33
+ SNS_RESOURCE
35
34
  } = consts;
36
35
 
37
36
  const {
@@ -46,11 +45,6 @@ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } =
46
45
 
47
46
  const templatePath = path.join(__dirname, 'template.ejs');
48
47
 
49
- const HANDLER = {
50
- hdrInv: "hdrInv",
51
- hdrApi: "hdrApi"
52
- }
53
-
54
48
  /**
55
49
  * Generates yaml source params for a given action and handler
56
50
  * @param {Object} _izContext - Context object with logger
@@ -72,56 +66,40 @@ async function data(
72
66
 
73
67
  additionalResourcePermission.push(
74
68
  createIamRole({
75
- [RESOURCE_CLASSES.lambda]: LAMBDA_RESOURCE.invokeFunction
69
+ [RESOURCE_CLASSES.sns]: SNS_RESOURCE.publish,
76
70
  },
77
- externalResourceYaml(RESOURCE_CLASSES.lambda, "CheckPermissionHdrInv", "Permission")),
71
+ externalResourceYaml(RESOURCE_CLASSES.sns, "RbacValidator_In", "TestRbac")),
78
72
  createIamRole({
79
73
  [RESOURCE_CLASSES.dynamoDbTable]: [DYNAMO_RESOURCE.getItem, DYNAMO_RESOURCE.putItem]
80
74
  },
81
75
  [
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"),
76
+ resourceNames(RESOURCE_CLASSES.dynamoDbTable, "RolePermissions"),
92
77
  ])
93
78
  );
94
79
 
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
- }
80
+ allCreateSources.push(
81
+ {
82
+ templatePath,
83
+ templateData: {
84
+ functionName: functionName,
85
+ handlerPath: path.join(
86
+ SOURCE_PATH.resourceLocationRbac,
87
+ `${functionName}.main`
88
+ ),
89
+ additionalResourcePermission,
90
+ roleName: "Authorization",
91
+ hookTagSetting: `${functionName}FunctionSetting`,
92
+ functionNameConfig: functionName
93
+ },
94
+ setting: {
95
+ savePath: path.join(appPath, SOURCE_PATH.appYaml),
96
+ saveFileName: SAVE_FILE_NAME.rbac,
97
+ fileExtension: '.yml',
98
+ isAppend: true
122
99
  }
123
- );
124
- };
100
+ }
101
+ );
102
+
125
103
  return allCreateSources;
126
104
  };
127
105
 
package/src/libs/Utils.js CHANGED
@@ -82,7 +82,7 @@ function checkValidTableYaml(
82
82
  if (
83
83
  hash(
84
84
  existsTableSetting[
85
- firstLetterUpperCase(dynamoDbYamlSetting.templateData.tableName)
85
+ firstLetterUpperCase(dynamoDbYamlSetting.templateData.tableName)
86
86
  ]
87
87
  ) === hash(dynamoDbYamlSetting.templateData.attributes.sort())
88
88
  ) {
@@ -144,7 +144,7 @@ const savePath = {
144
144
  },
145
145
  flowSchemaFlowTag: function (flowTag) {
146
146
  return path.join(
147
- SOURCE_PATH.flowSchema,
147
+ SOURCE_PATH.resourceLocationFlowSchema,
148
148
  firstLetterUpperCase(flowTag),
149
149
  'MainHandler/',
150
150
  'source/'
@@ -1,70 +0,0 @@
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;
@@ -1,52 +0,0 @@
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
- });
@@ -1,42 +0,0 @@
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
- }