@friggframework/devtools 2.0.0--canary.402.d2f4ae6.0 → 2.0.0--canary.395.c089c7d.0
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/infrastructure/create-frigg-infrastructure.js +0 -2
- package/infrastructure/iam-generator.js +2 -0
- package/infrastructure/iam-policy-basic.json +2 -0
- package/infrastructure/iam-policy-full.json +2 -0
- package/infrastructure/serverless-template.js +41 -25
- package/package.json +6 -5
- package/test/index.js +2 -4
- package/test/mock-integration.js +4 -14
- package/test/auther-definition-tester.js +0 -125
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
2
|
const fs = require('fs-extra');
|
|
3
3
|
const { composeServerlessDefinition } = require('./serverless-template');
|
|
4
|
-
|
|
5
4
|
const { findNearestBackendPackageJson } = require('@friggframework/core');
|
|
6
5
|
|
|
7
6
|
async function createFriggInfrastructure() {
|
|
@@ -25,7 +24,6 @@ async function createFriggInfrastructure() {
|
|
|
25
24
|
// ));
|
|
26
25
|
const definition = await composeServerlessDefinition(
|
|
27
26
|
appDefinition,
|
|
28
|
-
backend.IntegrationFactory
|
|
29
27
|
);
|
|
30
28
|
|
|
31
29
|
return {
|
|
@@ -431,6 +431,8 @@ function generateIAMCloudFormation(appDefinition, options = {}) {
|
|
|
431
431
|
Resource: [
|
|
432
432
|
'arn:aws:apigateway:*::/restapis',
|
|
433
433
|
'arn:aws:apigateway:*::/restapis/*',
|
|
434
|
+
'arn:aws:apigateway:*::/apis',
|
|
435
|
+
'arn:aws:apigateway:*::/apis/*',
|
|
434
436
|
'arn:aws:apigateway:*::/domainnames',
|
|
435
437
|
'arn:aws:apigateway:*::/domainnames/*'
|
|
436
438
|
]
|
|
@@ -204,6 +204,8 @@
|
|
|
204
204
|
"Resource": [
|
|
205
205
|
"arn:aws:apigateway:*::/restapis",
|
|
206
206
|
"arn:aws:apigateway:*::/restapis/*",
|
|
207
|
+
"arn:aws:apigateway:*::/apis",
|
|
208
|
+
"arn:aws:apigateway:*::/apis/*",
|
|
207
209
|
"arn:aws:apigateway:*::/domainnames",
|
|
208
210
|
"arn:aws:apigateway:*::/domainnames/*"
|
|
209
211
|
]
|
|
@@ -204,6 +204,8 @@
|
|
|
204
204
|
"Resource": [
|
|
205
205
|
"arn:aws:apigateway:*::/restapis",
|
|
206
206
|
"arn:aws:apigateway:*::/restapis/*",
|
|
207
|
+
"arn:aws:apigateway:*::/apis",
|
|
208
|
+
"arn:aws:apigateway:*::/apis/*",
|
|
207
209
|
"arn:aws:apigateway:*::/domainnames",
|
|
208
210
|
"arn:aws:apigateway:*::/domainnames/*"
|
|
209
211
|
]
|
|
@@ -724,37 +724,53 @@ const composeServerlessDefinition = async (AppDefinition) => {
|
|
|
724
724
|
|
|
725
725
|
// KMS Configuration based on App Definition
|
|
726
726
|
if (AppDefinition.encryption?.useDefaultKMSForFieldLevelEncryption === true) {
|
|
727
|
-
//
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
727
|
+
// Check if a KMS key was discovered
|
|
728
|
+
if (discoveredResources.defaultKmsKeyId) {
|
|
729
|
+
// Use the existing discovered KMS key
|
|
730
|
+
console.log(`Using existing KMS key: ${discoveredResources.defaultKmsKeyId}`);
|
|
731
|
+
|
|
732
|
+
definition.provider.iamRoleStatements.push({
|
|
733
|
+
Effect: 'Allow',
|
|
734
|
+
Action: ['kms:GenerateDataKey', 'kms:Decrypt'],
|
|
735
|
+
Resource: [discoveredResources.defaultKmsKeyId]
|
|
736
|
+
});
|
|
737
|
+
|
|
738
|
+
definition.provider.environment.KMS_KEY_ARN = discoveredResources.defaultKmsKeyId;
|
|
739
|
+
} else {
|
|
740
|
+
// No existing key found, provision a dedicated KMS key
|
|
741
|
+
console.log('No existing KMS key found, creating a new one...');
|
|
742
|
+
|
|
743
|
+
definition.resources.Resources.FriggKMSKey = {
|
|
744
|
+
Type: 'AWS::KMS::Key',
|
|
745
|
+
Properties: {
|
|
746
|
+
EnableKeyRotation: true,
|
|
747
|
+
KeyPolicy: {
|
|
748
|
+
Version: '2012-10-17',
|
|
749
|
+
Statement: [
|
|
750
|
+
{
|
|
751
|
+
Sid: 'AllowRootAccountAdmin',
|
|
752
|
+
Effect: 'Allow',
|
|
753
|
+
Principal: { AWS: { 'Fn::Sub': 'arn:aws:iam::${AWS::AccountId}:root' } },
|
|
754
|
+
Action: 'kms:*',
|
|
755
|
+
Resource: '*'
|
|
756
|
+
}
|
|
757
|
+
]
|
|
758
|
+
}
|
|
743
759
|
}
|
|
744
|
-
}
|
|
745
|
-
};
|
|
760
|
+
};
|
|
746
761
|
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
762
|
+
definition.provider.iamRoleStatements.push({
|
|
763
|
+
Effect: 'Allow',
|
|
764
|
+
Action: ['kms:GenerateDataKey', 'kms:Decrypt'],
|
|
765
|
+
Resource: [{ 'Fn::GetAtt': ['FriggKMSKey', 'Arn'] }]
|
|
766
|
+
});
|
|
752
767
|
|
|
753
|
-
|
|
768
|
+
definition.provider.environment.KMS_KEY_ARN = { 'Fn::GetAtt': ['FriggKMSKey', 'Arn'] };
|
|
769
|
+
}
|
|
754
770
|
|
|
755
771
|
definition.plugins.push('serverless-kms-grants');
|
|
756
772
|
|
|
757
|
-
// Configure KMS grants with discovered default key
|
|
773
|
+
// Configure KMS grants with discovered default key or environment variable
|
|
758
774
|
definition.custom.kmsGrants = {
|
|
759
775
|
kmsKeyId: discoveredResources.defaultKmsKeyId || '${env:AWS_DISCOVERY_KMS_KEY_ID}'
|
|
760
776
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@friggframework/devtools",
|
|
3
3
|
"prettier": "@friggframework/prettier-config",
|
|
4
|
-
"version": "2.0.0--canary.
|
|
4
|
+
"version": "2.0.0--canary.395.c089c7d.0",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@aws-sdk/client-ec2": "^3.835.0",
|
|
7
7
|
"@aws-sdk/client-kms": "^3.835.0",
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
"@babel/eslint-parser": "^7.18.9",
|
|
10
10
|
"@babel/parser": "^7.25.3",
|
|
11
11
|
"@babel/traverse": "^7.25.3",
|
|
12
|
-
"@friggframework/
|
|
12
|
+
"@friggframework/schemas": "2.0.0--canary.395.c089c7d.0",
|
|
13
|
+
"@friggframework/test": "2.0.0--canary.395.c089c7d.0",
|
|
13
14
|
"@hapi/boom": "^10.0.1",
|
|
14
15
|
"@inquirer/prompts": "^5.3.8",
|
|
15
16
|
"axios": "^1.7.2",
|
|
@@ -31,8 +32,8 @@
|
|
|
31
32
|
"serverless-http": "^2.7.0"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
|
-
"@friggframework/eslint-config": "2.0.0--canary.
|
|
35
|
-
"@friggframework/prettier-config": "2.0.0--canary.
|
|
35
|
+
"@friggframework/eslint-config": "2.0.0--canary.395.c089c7d.0",
|
|
36
|
+
"@friggframework/prettier-config": "2.0.0--canary.395.c089c7d.0",
|
|
36
37
|
"prettier": "^2.7.1",
|
|
37
38
|
"serverless": "3.39.0",
|
|
38
39
|
"serverless-dotenv-plugin": "^6.0.0",
|
|
@@ -64,5 +65,5 @@
|
|
|
64
65
|
"publishConfig": {
|
|
65
66
|
"access": "public"
|
|
66
67
|
},
|
|
67
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "c089c7d850dab85bd2b1619d27e67e6761144191"
|
|
68
69
|
}
|
package/test/index.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
const {testDefinitionRequiredAuthMethods} = require('./auther-definition-method-tester');
|
|
2
|
-
const {createMockIntegration, createMockApiObject} = require('./mock-integration');
|
|
3
|
-
const { testAutherDefinition } = require('./auther-definition-tester');
|
|
1
|
+
const { testDefinitionRequiredAuthMethods } = require('./auther-definition-method-tester');
|
|
2
|
+
const { createMockIntegration, createMockApiObject } = require('./mock-integration');
|
|
4
3
|
|
|
5
4
|
|
|
6
5
|
module.exports = {
|
|
7
6
|
createMockIntegration,
|
|
8
7
|
createMockApiObject,
|
|
9
8
|
testDefinitionRequiredAuthMethods,
|
|
10
|
-
testAutherDefinition,
|
|
11
9
|
};
|
package/test/mock-integration.js
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
const {
|
|
2
|
-
Auther,
|
|
3
|
-
Credential,
|
|
4
|
-
Entity,
|
|
5
|
-
IntegrationFactory,
|
|
6
2
|
createObjectId,
|
|
7
3
|
} = require('@friggframework/core');
|
|
8
4
|
|
|
@@ -11,7 +7,6 @@ async function createMockIntegration(
|
|
|
11
7
|
userId = null,
|
|
12
8
|
config = { type: IntegrationClass.Definition.name }
|
|
13
9
|
) {
|
|
14
|
-
const integrationFactory = new IntegrationFactory([IntegrationClass]);
|
|
15
10
|
userId = userId || createObjectId();
|
|
16
11
|
|
|
17
12
|
const insertOptions = {
|
|
@@ -24,10 +19,8 @@ async function createMockIntegration(
|
|
|
24
19
|
const entities = [];
|
|
25
20
|
for (const moduleName in IntegrationClass.modules) {
|
|
26
21
|
const ModuleDef = IntegrationClass.Definition.modules[moduleName];
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
userId: userId,
|
|
30
|
-
});
|
|
22
|
+
// todo: create module using the new architecture
|
|
23
|
+
const module = {}
|
|
31
24
|
const credential = await module.CredentialModel.findOneAndUpdate(
|
|
32
25
|
user,
|
|
33
26
|
{ $set: user },
|
|
@@ -51,11 +44,8 @@ async function createMockIntegration(
|
|
|
51
44
|
);
|
|
52
45
|
}
|
|
53
46
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
userId,
|
|
57
|
-
config
|
|
58
|
-
);
|
|
47
|
+
// todo: create integration using the new architecture
|
|
48
|
+
const integration = {}
|
|
59
49
|
|
|
60
50
|
integration.id = integration.record._id;
|
|
61
51
|
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
const {
|
|
2
|
-
Auther,
|
|
3
|
-
ModuleConstants,
|
|
4
|
-
createObjectId,
|
|
5
|
-
connectToDatabase,
|
|
6
|
-
disconnectFromDatabase,
|
|
7
|
-
} = require('@friggframework/core');
|
|
8
|
-
const { createMockApiObject } = require("./mock-integration");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
function testAutherDefinition(definition, mocks) {
|
|
12
|
-
const getModule = async (params) => {
|
|
13
|
-
const module = await Auther.getInstance({
|
|
14
|
-
definition,
|
|
15
|
-
userId: createObjectId(),
|
|
16
|
-
...params,
|
|
17
|
-
});
|
|
18
|
-
if (mocks.tokenResponse) {
|
|
19
|
-
mocks.getTokenFrom = async function(code) {
|
|
20
|
-
await this.setTokens(mocks.tokenResponse);
|
|
21
|
-
return mocks.tokenResponse
|
|
22
|
-
}
|
|
23
|
-
mocks.getTokenFromCode = mocks.getTokenFromCode || mocks.getTokenFrom
|
|
24
|
-
mocks.getTokenFromCodeBasicAuthHeader = mocks.getTokenFromCodeBasicAuthHeader || mocks.getTokenFrom
|
|
25
|
-
mocks.getTokenFromClientCredentials = mocks.getTokenFromClientCredentials || mocks.getTokenFrom
|
|
26
|
-
mocks.getTokenFromUsernamePassword = mocks.getTokenFromUsernamePassword || mocks.getTokenFrom
|
|
27
|
-
}
|
|
28
|
-
if (mocks.refreshResponse) {
|
|
29
|
-
mocks.refreshAccessToken = async function(code) {
|
|
30
|
-
await this.setTokens(mocks.refreshResponse);
|
|
31
|
-
return mocks.refreshResponse
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
module.api = createMockApiObject(jest, module.api, mocks);
|
|
35
|
-
return module
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
describe(`${definition.moduleName} Module Tests`, () => {
|
|
40
|
-
let module, authUrl;
|
|
41
|
-
beforeAll(async () => {
|
|
42
|
-
await connectToDatabase();
|
|
43
|
-
module = await getModule();
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
afterAll(async () => {
|
|
47
|
-
await disconnectFromDatabase();
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
let requirements, authCallbackParams;
|
|
51
|
-
if (definition.API.requesterType === ModuleConstants.authType.oauth2) {
|
|
52
|
-
authCallbackParams = mocks.authorizeResponse || mocks.authorizeParams;
|
|
53
|
-
describe('getAuthorizationRequirements() test', () => {
|
|
54
|
-
it('should return auth requirements', async () => {
|
|
55
|
-
requirements = await module.getAuthorizationRequirements();
|
|
56
|
-
expect(requirements).toBeDefined();
|
|
57
|
-
expect(requirements.type).toEqual(ModuleConstants.authType.oauth2);
|
|
58
|
-
expect(requirements.url).toBeDefined();
|
|
59
|
-
authUrl = requirements.url;
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
} else if (definition.API.requesterType === ModuleConstants.authType.basic) {
|
|
63
|
-
// could also confirm authCallbackParams against the auth requirements
|
|
64
|
-
authCallbackParams = mocks.authorizeParams
|
|
65
|
-
describe('getAuthorizationRequirements() test', () => {
|
|
66
|
-
it('should return auth requirements', async () => {
|
|
67
|
-
requirements = module.getAuthorizationRequirements();
|
|
68
|
-
expect(requirements).toBeDefined();
|
|
69
|
-
expect(requirements.type).toEqual(ModuleConstants.authType.basic);
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
} else if (definition.API.requesterType === ModuleConstants.authType.apiKey) {
|
|
73
|
-
// could also confirm authCallbackParams against the auth requirements
|
|
74
|
-
authCallbackParams = mocks.authorizeParams
|
|
75
|
-
describe('getAuthorizationRequirements() test', () => {
|
|
76
|
-
it('should return auth requirements', async () => {
|
|
77
|
-
requirements = module.getAuthorizationRequirements();
|
|
78
|
-
expect(requirements).toBeDefined();
|
|
79
|
-
expect(requirements.type).toEqual(ModuleConstants.authType.apiKey);
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
describe('Authorization requests', () => {
|
|
85
|
-
let firstRes;
|
|
86
|
-
it('processAuthorizationCallback()', async () => {
|
|
87
|
-
firstRes = await module.processAuthorizationCallback(authCallbackParams);
|
|
88
|
-
expect(firstRes).toBeDefined();
|
|
89
|
-
expect(firstRes.entity_id).toBeDefined();
|
|
90
|
-
expect(firstRes.credential_id).toBeDefined();
|
|
91
|
-
});
|
|
92
|
-
it('retrieves existing entity on subsequent calls', async () => {
|
|
93
|
-
const res = await module.processAuthorizationCallback(authCallbackParams);
|
|
94
|
-
expect(res).toEqual(firstRes);
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
describe('Test credential retrieval and module instantiation', () => {
|
|
99
|
-
it('retrieve by entity id', async () => {
|
|
100
|
-
const newModule = await getModule({
|
|
101
|
-
userId: module.userId,
|
|
102
|
-
entityId: module.entity.id
|
|
103
|
-
});
|
|
104
|
-
expect(newModule).toBeDefined();
|
|
105
|
-
expect(newModule.entity).toBeDefined();
|
|
106
|
-
expect(newModule.credential).toBeDefined();
|
|
107
|
-
expect(await newModule.testAuth()).toBeTruthy();
|
|
108
|
-
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it('retrieve by credential id', async () => {
|
|
112
|
-
const newModule = await getModule({
|
|
113
|
-
userId: module.userId,
|
|
114
|
-
credentialId: module.credential.id
|
|
115
|
-
});
|
|
116
|
-
expect(newModule).toBeDefined();
|
|
117
|
-
expect(newModule.credential).toBeDefined();
|
|
118
|
-
expect(await newModule.testAuth()).toBeTruthy();
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
module.exports = { testAutherDefinition }
|
|
125
|
-
|