@izara_project/izara-core-generate-service-code 1.0.67 → 1.0.69
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/.prettierrc +11 -0
- package/package.json +16 -12
- package/scripts/format-ejs.js +104 -0
- package/src/compile/compileProject.js +40 -9
- package/src/compile/loadSchemas.js +120 -11
- package/src/emit/crud/emitCrudApplicationArtifacts.js +188 -41
- package/src/emit/crud/emitDynamicCrudFlowSchemas.js +34 -18
- package/src/emit/crud/generateCrudApplicationArtifacts.js +14 -6
- package/src/emit/crud/generateDynamicCrudFlowSchemas.js +4 -1
- package/src/emit/crud/templates/CreateEndpoint_Main.ejs +296 -105
- package/src/emit/crud/templates/DeleteEndpoint_Main.ejs +222 -144
- package/src/emit/crud/templates/FlowEndpointBeforeLogical_Main.ejs +22 -6
- package/src/emit/crud/templates/FlowEndpointComplete_Main.ejs +134 -43
- package/src/emit/crud/templates/FlowEndpoint_HdrWbs.ejs +51 -31
- package/src/emit/crud/templates/FlowHandler_HdrApi.ejs +53 -45
- package/src/emit/crud/templates/FlowHandler_HdrInv.ejs +28 -26
- package/src/emit/crud/templates/FlowHandler_HdrSqs.ejs +15 -11
- package/src/emit/crud/templates/FlowMain_Wbs.ejs +53 -38
- package/src/emit/crud/templates/GetEndpoint_Main.ejs +6 -3
- package/src/emit/crud/templates/GetRangeEndpoint_Main.ejs +2 -2
- package/src/emit/crud/templates/UpdateEndpoint_Main.ejs +402 -249
- package/src/emit/custom/customFlows.js +68 -28
- package/src/emit/custom/emitCustomFlowApplicationArtifacts.js +520 -123
- package/src/emit/custom/generateCustomFlowApplicationArtifacts.js +28 -8
- package/src/emit/custom/templates/FlowEndpoint_Main.ejs +48 -36
- package/src/emit/custom/templates/FlowStep_Main.ejs +7 -9
- package/src/emit/custom/templates/s3/ConfirmReserved_HdrSqs.ejs +59 -54
- package/src/emit/custom/templates/s3/ConfirmReserved_Main.ejs +33 -23
- package/src/emit/custom/templates/s3/CreateObject_HdrWbs.ejs +30 -23
- package/src/emit/custom/templates/s3/CreateObject_Main.ejs +56 -39
- package/src/emit/custom/templates/s3/CreatePreSignUrl_HdrSqs.ejs +56 -51
- package/src/emit/custom/templates/s3/CreatePreSignUrl_Main.ejs +112 -75
- package/src/emit/custom/templates/s3/FlowHandler_HdrS3.ejs +14 -9
- package/src/emit/custom/templates/s3/ProcessS3File_Main.ejs +11 -8
- package/src/emit/custom/templates/s3/ReservedLimit_HdrSqs.ejs +65 -56
- package/src/emit/custom/templates/s3/ReservedLimit_Main.ejs +74 -52
- package/src/emit/custom/templates/triggerCache/CheckTriggerCache_HdrSqs.ejs +58 -14
- package/src/emit/custom/templates/triggerCache/CheckTriggerCache_Main.ejs +12 -17
- package/src/emit/custom/templates/triggerCache/TriggerCacheComplete_Main.ejs +20 -13
- package/src/emit/custom/templates/triggerCache/TriggerCache_Main.ejs +4 -1
- package/src/emit/function/functionYamlArtifact.js +272 -79
- package/src/emit/function/templates/ApiFunction_Yaml.ejs +7 -0
- package/src/emit/function/templates/EventBridgeFunction_Yaml.ejs +6 -0
- package/src/emit/function/templates/InvFunction_Yaml.ejs +5 -0
- package/src/emit/function/templates/S3Function_Yaml.ejs +16 -0
- package/src/emit/function/templates/SqsFunction_Yaml.ejs +10 -0
- package/src/emit/function/templates/WbsFunction_Yaml.ejs +10 -0
- package/src/emit/rbac/emitDynamicRbacFlowSchemas.js +40 -29
- package/src/emit/rbac/emitRbacApplicationArtifacts.js +171 -72
- package/src/emit/rbac/generateCreateTargetRoleHandler.js +6 -4
- package/src/emit/rbac/generateDynamicRbacFlowSchemas.js +8 -2
- package/src/emit/rbac/rbacFlowTag.js +3 -1
- package/src/emit/rbac/templates/CreateTargetRole_HdrSqs.ejs +41 -18
- package/src/emit/rbac/templates/CreateTargetRole_Main.ejs +23 -3
- package/src/emit/rbac/templates/ListRbac_HdrApi.ejs +27 -5
- package/src/emit/rbac/templates/ListRbac_HdrSqs.ejs +41 -8
- package/src/emit/rbac/templates/ListRbac_Main.ejs +26 -6
- package/src/emit/rbac/templates/RbacMutation_Main.ejs +23 -3
- package/src/emit/rbac/templates/UserRbacFlow_HdrSqs.ejs +46 -0
- package/src/emit/rbac/templates/UserRbacFlow_Main.ejs +152 -33
- package/src/emit/rbac/templates/UserRoleMutation_Main.ejs +24 -4
- package/src/emit/relationship/emitDynamicRelationshipFlowSchemas.js +26 -11
- package/src/emit/relationship/emitRelationshipApplicationArtifacts.js +179 -37
- package/src/emit/relationship/generateDynamicRelationshipFlowSchemas.js +8 -2
- package/src/emit/relationship/generateRelationshipApplicationArtifacts.js +15 -6
- package/src/emit/relationship/templates/ChangeRelationshipComplete_Main.ejs +64 -37
- package/src/emit/relationship/templates/ChangeRelationship_Main.ejs +258 -142
- package/src/emit/relationship/templates/CreateRelationshipComplete_Main.ejs +68 -43
- package/src/emit/relationship/templates/CreateRelationship_Main.ejs +315 -171
- package/src/emit/relationship/templates/DeleteRelationshipComplete_Main.ejs +67 -41
- package/src/emit/relationship/templates/DeleteRelationship_Main.ejs +226 -115
- package/src/emit/relationship/templates/FlowHandler_HdrApi.ejs +41 -33
- package/src/emit/relationship/templates/FlowHandler_HdrDsq.ejs +15 -11
- package/src/emit/relationship/templates/FlowHandler_HdrInv.ejs +28 -26
- package/src/emit/relationship/templates/FlowHandler_HdrSqs.ejs +15 -11
- package/src/emit/relationship/templates/GetRelationshipComplete_Main.ejs +46 -26
- package/src/emit/relationship/templates/GetRelationship_Main.ejs +233 -126
- package/src/emit/relationship/templates/MoveRelationshipComplete_Main.ejs +72 -44
- package/src/emit/relationship/templates/MoveRelationship_Main.ejs +266 -150
- package/src/emit/relationship/templates/UpdateRelationshipComplete_Main.ejs +74 -45
- package/src/emit/relationship/templates/UpdateRelationship_Main.ejs +285 -152
- package/src/emit/resource/emitResourceArtifacts.js +274 -105
- package/src/emit/resource/generateResourceArtifacts.js +15 -6
- package/src/emit/resource/templates/GeneratedLambdaRoleServiceConfig.ejs +139 -0
- package/src/emit/resource/templates/S3Bucket_Yaml.ejs +19 -0
- package/src/emit/resource/templates/S3Subscription_Yaml.ejs +7 -0
- package/src/emit/resource/templates/WebSocketSubscription_Yaml.ejs +7 -0
- package/src/emit/system/emitSystemWebSocketArtifacts.js +61 -165
- package/src/emit/system/templates/WebSocketComplete_HdrSqs.ejs +32 -0
- package/src/emit/system/templates/WebSocketComplete_Main.ejs +46 -0
- package/src/emit/system/templates/WebSocketComplete_Yaml.ejs +19 -0
- package/src/emit/system/templates/WebSocketConnect.ejs +25 -0
- package/src/emit/system/templates/WebSocketConnect_Yaml.ejs +11 -0
- package/src/generate.js +141 -34
- package/src/generateIntTest.js +76 -28
- package/src/generateResourceIntTest.js +35 -12
- package/src/generateResources/IntTest/generateResources/generateResources.js +5 -2
- package/src/generateResources/IntTest/generateResources/templateResources.ejs +18 -30
- package/src/generateResources/IntTest/generateTests/events/events.js +1 -1
- package/src/generateResources/IntTest/generateTests/events/templateEvents.ejs +13 -10
- package/src/generateResources/IntTest/generateTests/generateTemplate.js +2 -2
- package/src/generateResources/IntTest/generateTests/pathIntTest/pathIntTest.js +2 -1
- package/src/generateResources/IntTest/generateTests/pathIntTest/template.ejs +1 -3
- package/src/generateResources/IntTest/generateTests/tests/templateTests.ejs +1 -1
- package/src/generateResources/IntTest/generateTests/tests/tests.js +7 -3
- package/src/generateResources/IntTest/libs/{libs.js → IntTestGenerateLib.js} +34 -23
- package/src/generateResources/IntTest/upload/uploadIntTest.js +33 -19
- package/src/intTestGeneratorShared.js +15 -10
- package/src/output/commitArtifacts.js +99 -39
- package/src/output/mergeHooks.js +24 -10
- package/src/output/validateArtifacts.js +37 -27
- package/src/plan/buildGenerationPlan.js +24 -13
- package/test/core.test.js +116 -49
- package/test/createTargetRoleHandler.test.js +63 -14
- package/test/crudApplicationArtifacts.test.js +128 -23
- package/test/customFlowApplicationArtifacts.test.js +391 -84
- package/test/dynamicCrudFlowSchemas.test.js +74 -26
- package/test/dynamicRbacFlowSchemas.test.js +63 -20
- package/test/dynamicRelationshipFlowSchemas.test.js +65 -18
- package/test/functionYamlArtifact.test.js +67 -10
- package/test/intTestApi.test.js +9 -10
- package/test/publicApi.test.js +184 -44
- package/test/relationshipApplicationArtifacts.test.js +90 -19
- package/test/resourceArtifacts.test.js +183 -33
- package/docs/test.png +0 -0
- package/src/emit/rbac/templates/UserRbacFlow_HdrInv.ejs +0 -10
- package/src/emit/relationship/dynamicRelationshipFlowSchemaTemplate.js +0 -11
- /package/docs/{test.mmd → TriggeredCacheFlow.mmd} +0 -0
|
@@ -1,18 +1,35 @@
|
|
|
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
|
+
|
|
1
18
|
import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
|
|
2
19
|
import snsSharedLib from '@izara_project/izara-core-library-sns';
|
|
3
20
|
import { sns } from '@izara_project/izara-core-library-external-request';
|
|
4
21
|
import { consts, NoRetryError } from '@izara_project/izara-core-library-core';
|
|
5
22
|
|
|
6
|
-
export default async function
|
|
23
|
+
export default async function <%- flowTag %>(_izContext, requestParams) {
|
|
7
24
|
try {
|
|
8
|
-
<% if (useContextUserId) { -%>
|
|
25
|
+
<% if (useContextUserId) { -%>
|
|
9
26
|
const userId = _izContext.correlationIds.get(consts.BASE_USER_ID);
|
|
10
27
|
if (!userId) throw new NoRetryError('User Id not found.');
|
|
11
28
|
const queryParams = { userId };
|
|
12
|
-
<% } else { -%>
|
|
29
|
+
<% } else { -%>
|
|
13
30
|
const { <%- requestProperty %> } = requestParams;
|
|
14
31
|
const queryParams = { <%- requestProperty %> };
|
|
15
|
-
<% } -%>
|
|
32
|
+
<% } -%>
|
|
16
33
|
const resultQuery = await dynamodbSharedLib.query(
|
|
17
34
|
_izContext,
|
|
18
35
|
dynamodbSharedLib.tableName(_izContext, '<%- tableName %>'),
|
|
@@ -20,10 +37,13 @@ export default async function Process<%- flowTag %>(_izContext, requestParams) {
|
|
|
20
37
|
);
|
|
21
38
|
await sns.publishMessage(_izContext, {
|
|
22
39
|
message: { returnResult: { records: resultQuery.Items || [] } },
|
|
23
|
-
TopicArn: snsSharedLib.snsTopicArnByFlowSchema(
|
|
40
|
+
TopicArn: snsSharedLib.snsTopicArnByFlowSchema(
|
|
41
|
+
_izContext,
|
|
42
|
+
'<%- flowTag %>_Out'
|
|
43
|
+
)
|
|
24
44
|
});
|
|
25
45
|
} catch (error) {
|
|
26
|
-
_izContext.logger.error('[Rbac
|
|
46
|
+
_izContext.logger.error('[Rbac:<%- flowTag %>] error:', error);
|
|
27
47
|
throw error;
|
|
28
48
|
}
|
|
29
49
|
}
|
|
@@ -1,9 +1,26 @@
|
|
|
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
|
+
|
|
1
18
|
<% const fieldList = fields.join(', '); -%>
|
|
2
19
|
import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
|
|
3
20
|
import snsSharedLib from '@izara_project/izara-core-library-sns';
|
|
4
21
|
import { sns } from '@izara_project/izara-core-library-external-request';
|
|
5
22
|
|
|
6
|
-
export default async function
|
|
23
|
+
export default async function <%- flowTag %>(_izContext, requestParams) {
|
|
7
24
|
try {
|
|
8
25
|
const { <%- fieldList %> } = requestParams;
|
|
9
26
|
await dynamodbSharedLib.<%- method %>(
|
|
@@ -13,10 +30,13 @@ export default async function Process<%- flowTag %>(_izContext, requestParams) {
|
|
|
13
30
|
);
|
|
14
31
|
await sns.publishMessage(_izContext, {
|
|
15
32
|
message: { returnResult: { <%- fieldList %> } },
|
|
16
|
-
TopicArn: snsSharedLib.snsTopicArnByFlowSchema(
|
|
33
|
+
TopicArn: snsSharedLib.snsTopicArnByFlowSchema(
|
|
34
|
+
_izContext,
|
|
35
|
+
'<%- flowTag %>_Out'
|
|
36
|
+
)
|
|
17
37
|
});
|
|
18
38
|
} catch (error) {
|
|
19
|
-
_izContext.logger.error('[Rbac
|
|
39
|
+
_izContext.logger.error('[Rbac:<%- flowTag %>] error:', error);
|
|
20
40
|
throw error;
|
|
21
41
|
}
|
|
22
42
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
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 { middlewareHandler as middleware } from '@izara_project/izara-middleware';
|
|
19
|
+
import { recordHandlerSharedLib } from '@izara_project/izara-core-library-record-handler';
|
|
20
|
+
import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
|
|
21
|
+
import <%- flowTag %> from './<%- flowTag %>_Main.js';
|
|
22
|
+
|
|
23
|
+
middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
|
|
24
|
+
export const main = middleware.wrap(async (event) =>
|
|
25
|
+
Promise.all(
|
|
26
|
+
event.Records.map(async (record) => {
|
|
27
|
+
await recordHandlerSharedLib.validateRecord(
|
|
28
|
+
record,
|
|
29
|
+
'<%- flowTag %>HdrSqs',
|
|
30
|
+
{},
|
|
31
|
+
null
|
|
32
|
+
);
|
|
33
|
+
return recordHandlerSharedLib.recordHandler(
|
|
34
|
+
record,
|
|
35
|
+
<%- flowTag %>,
|
|
36
|
+
'<%- flowTag %>HdrSqs',
|
|
37
|
+
[
|
|
38
|
+
record.body.Message,
|
|
39
|
+
callingFlowSharedLib.addCallingFlowToPassOnProperties(
|
|
40
|
+
record.body.Message
|
|
41
|
+
)
|
|
42
|
+
]
|
|
43
|
+
);
|
|
44
|
+
})
|
|
45
|
+
)
|
|
46
|
+
);
|
|
@@ -1,44 +1,163 @@
|
|
|
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
|
+
|
|
1
18
|
import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
|
|
2
19
|
import { coreConsts } from '@izara_project/izara-core-library-core';
|
|
20
|
+
import { sns } from '@izara_project/izara-core-library-external-request';
|
|
21
|
+
import snsSharedLib from '@izara_project/izara-core-library-sns';
|
|
22
|
+
|
|
23
|
+
export default async function <%- flowTag %>(_izContext, requestParams = {}) {
|
|
24
|
+
const userId = _izContext.correlationIds.get(coreConsts.BASE_USER_ID);
|
|
25
|
+
const targetId = _izContext.correlationIds.get(coreConsts.TARGET_ID);
|
|
26
|
+
if (!userId || !targetId) {
|
|
27
|
+
throw new Error('Missing required request parameters: userId or targetId');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const { flowTypeConcat, inputParameterGroups } = requestParams;
|
|
31
|
+
if (!flowTypeConcat) {
|
|
32
|
+
throw new Error('Missing flowTypeConcat in requestParams');
|
|
33
|
+
}
|
|
3
34
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
35
|
+
const userRolesResult = await dynamodbSharedLib.query(
|
|
36
|
+
_izContext,
|
|
37
|
+
dynamodbSharedLib.tableName(_izContext, 'UserRoles'),
|
|
38
|
+
{ userId }
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
let userRoles = [];
|
|
42
|
+
if (Array.isArray(userRolesResult)) {
|
|
43
|
+
userRoles = userRolesResult;
|
|
44
|
+
} else if (userRolesResult && userRolesResult.Items) {
|
|
45
|
+
userRoles = userRolesResult.Items;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const targetIdPrefix = `${targetId}_`;
|
|
49
|
+
const targetRoles = [];
|
|
50
|
+
for (const role of userRoles) {
|
|
51
|
+
if (role && role.roleIdKey && role.roleIdKey.startsWith(targetIdPrefix)) {
|
|
52
|
+
targetRoles.push(role);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (targetRoles.length === 0) {
|
|
57
|
+
await _publicMessageOut(_izContext, {
|
|
58
|
+
permission: false,
|
|
59
|
+
roleIdKey: ''
|
|
60
|
+
});
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const rolePermissionsTable = dynamodbSharedLib.tableName(
|
|
65
|
+
_izContext,
|
|
66
|
+
'RolePermissions'
|
|
67
|
+
);
|
|
68
|
+
const rolePermissions = await Promise.all(
|
|
69
|
+
targetRoles.map(async (role) => {
|
|
70
|
+
return await dynamodbSharedLib.getItem(_izContext, rolePermissionsTable, {
|
|
71
|
+
roleIdKey: role.roleIdKey,
|
|
72
|
+
flowTypeConcat
|
|
73
|
+
});
|
|
74
|
+
})
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
let matched = null;
|
|
78
|
+
for (const permission of rolePermissions) {
|
|
79
|
+
if (permission && permission.permission === true) {
|
|
80
|
+
const isMatched = _matchesParameterGroups(
|
|
81
|
+
permission.parameterGroups,
|
|
82
|
+
inputParameterGroups
|
|
22
83
|
);
|
|
23
|
-
if (
|
|
24
|
-
|
|
84
|
+
if (isMatched) {
|
|
85
|
+
matched = permission;
|
|
86
|
+
break;
|
|
25
87
|
}
|
|
26
88
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (matched) {
|
|
92
|
+
await _publicMessageOut(_izContext, {
|
|
93
|
+
permission: true,
|
|
94
|
+
roleIdKey: matched.roleIdKey
|
|
95
|
+
});
|
|
96
|
+
} else {
|
|
97
|
+
await _publicMessageOut(_izContext, {
|
|
98
|
+
permission: false,
|
|
99
|
+
roleIdKey: ''
|
|
100
|
+
});
|
|
31
101
|
}
|
|
32
102
|
}
|
|
33
103
|
|
|
34
|
-
function
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
104
|
+
async function _publicMessageOut(_izContext, message) {
|
|
105
|
+
const topicOut = snsSharedLib.snsTopicArnByFlowSchema(
|
|
106
|
+
_izContext,
|
|
107
|
+
process.env.iz_flowTag + '_Out'
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
await sns.publishAsync(_izContext, {
|
|
111
|
+
topicArn: topicOut,
|
|
112
|
+
message: JSON.stringify(message)
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function _matchesParameterGroups(groups, input) {
|
|
117
|
+
if (!groups || typeof groups !== 'object' || Array.isArray(groups)) {
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const groupValues = Object.values(groups);
|
|
122
|
+
if (groupValues.length === 0) {
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
for (const group of groupValues) {
|
|
127
|
+
if (!Array.isArray(group)) {
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
let isGroupMatched = true;
|
|
132
|
+
for (const check of group) {
|
|
133
|
+
if (
|
|
134
|
+
!Array.isArray(check.parameterNames) ||
|
|
135
|
+
!Array.isArray(check.parameterValues)
|
|
136
|
+
) {
|
|
137
|
+
isGroupMatched = false;
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
let val = input || {};
|
|
142
|
+
for (const key of check.parameterNames) {
|
|
143
|
+
if (val && typeof val === 'object') {
|
|
144
|
+
val = val[key];
|
|
145
|
+
} else {
|
|
146
|
+
val = null;
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (!check.parameterValues.includes(val)) {
|
|
152
|
+
isGroupMatched = false;
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
41
155
|
}
|
|
42
|
-
|
|
43
|
-
|
|
156
|
+
|
|
157
|
+
if (isGroupMatched) {
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return false;
|
|
44
163
|
}
|
|
@@ -1,11 +1,28 @@
|
|
|
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
|
+
|
|
1
18
|
<%
|
|
2
19
|
const itemType = operation === 'Put' ? 'Item' : 'Key';
|
|
3
20
|
const roleUsersKey = operation === 'Put' ? 'userId, roleIdKey' : 'roleIdKey, userId';
|
|
4
|
-
-%>import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
|
|
21
|
+
-%> import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
|
|
5
22
|
import snsSharedLib from '@izara_project/izara-core-library-sns';
|
|
6
23
|
import { sns } from '@izara_project/izara-core-library-external-request';
|
|
7
24
|
|
|
8
|
-
export default async function
|
|
25
|
+
export default async function <%- flowTag %>(_izContext, requestParams) {
|
|
9
26
|
try {
|
|
10
27
|
const { roleIdKey, userId } = requestParams;
|
|
11
28
|
await dynamodbSharedLib.transactWriteItems(_izContext, [
|
|
@@ -24,10 +41,13 @@ export default async function Process<%- flowTag %>(_izContext, requestParams) {
|
|
|
24
41
|
]);
|
|
25
42
|
await sns.publishMessage(_izContext, {
|
|
26
43
|
message: { returnResult: { userId, roleIdKey } },
|
|
27
|
-
TopicArn: snsSharedLib.snsTopicArnByFlowSchema(
|
|
44
|
+
TopicArn: snsSharedLib.snsTopicArnByFlowSchema(
|
|
45
|
+
_izContext,
|
|
46
|
+
'<%- flowTag %>_Out'
|
|
47
|
+
)
|
|
28
48
|
});
|
|
29
49
|
} catch (error) {
|
|
30
|
-
_izContext.logger.error('[Rbac
|
|
50
|
+
_izContext.logger.error('[Rbac:<%- flowTag %>] error:', error);
|
|
31
51
|
throw error;
|
|
32
52
|
}
|
|
33
53
|
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { renderDynamicRelationshipFlowSchema } from './dynamicRelationshipFlowSchemaTemplate.js';
|
|
2
|
-
|
|
3
1
|
const ACTIONS = [
|
|
4
2
|
'CreateRelationship',
|
|
5
3
|
'UpdateRelationship',
|
|
@@ -11,17 +9,33 @@ const ACTIONS = [
|
|
|
11
9
|
const MESSAGE_ATTRIBUTES = ['userId', 'correlationId'];
|
|
12
10
|
|
|
13
11
|
export const dynamicRelationshipFlowSchemaPaths = ACTIONS.map(
|
|
14
|
-
action =>
|
|
12
|
+
(action) =>
|
|
13
|
+
`app/src/schemas/FlowSchemas/generateCode/FlowRelationship/${action}.js`
|
|
15
14
|
);
|
|
16
15
|
|
|
17
16
|
export function emitDynamicRelationshipFlowSchemas() {
|
|
18
17
|
// Keep legacy compatibility: relationship flow endpoints exist even before a relationship is declared.
|
|
19
18
|
return ACTIONS.map((action, index) => ({
|
|
20
19
|
path: dynamicRelationshipFlowSchemaPaths[index],
|
|
21
|
-
content:
|
|
20
|
+
content: _renderDynamicRelationshipFlowSchema(
|
|
21
|
+
action,
|
|
22
|
+
createDynamicRelationshipFlow(action)
|
|
23
|
+
)
|
|
22
24
|
}));
|
|
23
25
|
}
|
|
24
26
|
|
|
27
|
+
function _renderDynamicRelationshipFlowSchema(action, flow) {
|
|
28
|
+
return [
|
|
29
|
+
'/**',
|
|
30
|
+
' * GENERATED DYNAMIC RELATIONSHIP FLOW SCHEMA',
|
|
31
|
+
` * Action: ${action}`,
|
|
32
|
+
' * Description: Handles dynamic relationship actions for all allowed RelationshipTypes via SQS/DSQ',
|
|
33
|
+
' */',
|
|
34
|
+
`export default ${JSON.stringify(flow, null, 2)};`,
|
|
35
|
+
''
|
|
36
|
+
].join('\n');
|
|
37
|
+
}
|
|
38
|
+
|
|
25
39
|
function createDynamicRelationshipFlow(action) {
|
|
26
40
|
const outputTopic = action !== 'GetRelationship';
|
|
27
41
|
const flowSteps = [
|
|
@@ -29,12 +43,14 @@ function createDynamicRelationshipFlow(action) {
|
|
|
29
43
|
stepName: 'start',
|
|
30
44
|
properties: [],
|
|
31
45
|
messageAttributes: MESSAGE_ATTRIBUTES,
|
|
32
|
-
...(outputTopic
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
46
|
+
...(outputTopic
|
|
47
|
+
? {
|
|
48
|
+
returnValues: {
|
|
49
|
+
properties: [],
|
|
50
|
+
messageAttributes: MESSAGE_ATTRIBUTES
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
: {})
|
|
38
54
|
}
|
|
39
55
|
];
|
|
40
56
|
|
|
@@ -49,7 +65,6 @@ function createDynamicRelationshipFlow(action) {
|
|
|
49
65
|
|
|
50
66
|
return {
|
|
51
67
|
flowTag: action,
|
|
52
|
-
isDynamicRelationshipType: true,
|
|
53
68
|
initiateBy: 'system',
|
|
54
69
|
handleObj: 'one',
|
|
55
70
|
statusType: 'none',
|