@friggframework/devtools 2.0.0--canary.667.a0620c7.0 → 2.0.0--canary.682.451c957.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/frigg-cli/README.md +30 -77
- package/frigg-cli/__tests__/unit/commands/deploy.test.js +24 -30
- package/frigg-cli/__tests__/unit/commands/doctor.test.js +6 -10
- package/frigg-cli/__tests__/unit/commands/generate-iam.test.js +0 -18
- package/frigg-cli/__tests__/unit/commands/install.test.js +341 -601
- package/frigg-cli/__tests__/unit/commands/ui.test.js +30 -31
- package/frigg-cli/__tests__/unit/dependencies.test.js +2 -6
- package/frigg-cli/generate-command/index.js +0 -1
- package/frigg-cli/generate-iam-command.js +0 -1
- package/frigg-cli/index.js +4 -9
- package/frigg-cli/index.test.js +158 -0
- package/frigg-cli/init-command/backend-first-handler.js +554 -397
- package/frigg-cli/init-command/index.js +35 -82
- package/frigg-cli/install-command/commit-changes.js +8 -40
- package/frigg-cli/install-command/environment-variables.js +0 -15
- package/frigg-cli/install-command/index.js +21 -96
- package/frigg-cli/install-command/install-package.js +4 -77
- package/frigg-cli/install-command/integration-file.js +11 -20
- package/frigg-cli/install-command/template.js +75 -102
- package/frigg-cli/install-command/validate-package.js +4 -36
- package/frigg-cli/package.json +1 -1
- package/frigg-cli/test/init-command.test.js +2 -9
- package/infrastructure/__tests__/management-api-gateway-routes.test.js +94 -40
- package/infrastructure/__tests__/postgres-config.test.js +835 -241
- package/infrastructure/__tests__/template-generation.test.js +8 -36
- package/infrastructure/docs/POSTGRES-CONFIGURATION.md +1 -21
- package/infrastructure/domains/admin-scripts/admin-script-builder.js +2 -6
- package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +0 -30
- package/infrastructure/domains/database/aurora-builder.js +2 -13
- package/infrastructure/domains/database/aurora-builder.test.js +0 -22
- package/infrastructure/domains/health/application/use-cases/__tests__/mismatch-analyzer-method-name.test.js +8 -12
- package/infrastructure/domains/health/application/use-cases/__tests__/repair-via-import-use-case.test.js +7 -19
- package/infrastructure/domains/health/application/use-cases/run-health-check-use-case.test.js +8 -12
- package/infrastructure/domains/health/domain/services/__tests__/import-progress-monitor.test.js +18 -17
- package/infrastructure/domains/health/domain/services/__tests__/update-progress-monitor.test.js +2 -12
- package/infrastructure/domains/health/infrastructure/adapters/__tests__/orphan-detection-relationship-analysis.test.js +1 -8
- package/infrastructure/domains/health/infrastructure/adapters/aws-property-reconciler.test.js +2 -4
- package/infrastructure/domains/health/infrastructure/adapters/aws-resource-detector.test.js +0 -10
- package/infrastructure/domains/networking/vpc-builder.js +8 -18
- package/infrastructure/domains/networking/vpc-builder.test.js +12 -26
- package/infrastructure/domains/security/iam-generator.js +5 -112
- package/infrastructure/domains/security/iam-generator.test.js +0 -94
- package/infrastructure/domains/shared/cloudformation-discovery.test.js +6 -36
- package/infrastructure/domains/shared/utilities/base-definition-factory.js +27 -35
- package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +49 -22
- package/infrastructure/infrastructure-composer.test.js +794 -268
- package/infrastructure/integration.test.js +381 -0
- package/infrastructure/scripts/build-prisma-layer.test.js +7 -28
- package/infrastructure/scripts/build-time-discovery.test.js +3 -18
- package/package.json +8 -10
- package/frigg-cli/__tests__/unit/commands/init.test.js +0 -688
- package/frigg-cli/init-command/deployment-modes.js +0 -7
- package/frigg-cli/init-command/safe-path.js +0 -58
- package/frigg-cli/init-command/scaffold-dependencies.js +0 -202
- package/frigg-cli/install-command/app-definition.js +0 -174
- package/frigg-cli/install-command/resolve-module.js +0 -69
- package/frigg-cli/templates/backend/README.md +0 -267
- package/frigg-cli/templates/backend/env.example +0 -20
- package/frigg-cli/templates/backend/gitignore +0 -10
- package/frigg-cli/templates/backend/index.js +0 -114
- package/frigg-cli/templates/backend/infrastructure.js +0 -20
- package/infrastructure/__tests__/scaffold-default-infrastructure.test.js +0 -148
|
@@ -293,10 +293,10 @@ describe('VpcBuilder', () => {
|
|
|
293
293
|
]);
|
|
294
294
|
expect(result.resources.FriggPrivateSubnet1).toBeDefined();
|
|
295
295
|
expect(result.resources.FriggPrivateSubnet2).toBeDefined();
|
|
296
|
-
// In discover mode
|
|
297
|
-
|
|
298
|
-
expect(result.
|
|
299
|
-
expect(result.resources.FriggLambdaSecurityGroup).
|
|
296
|
+
// In discover mode, we create FriggLambdaSecurityGroup in the discovered VPC
|
|
297
|
+
expect(result.vpcConfig.securityGroupIds).toEqual([{ Ref: 'FriggLambdaSecurityGroup' }]);
|
|
298
|
+
expect(result.resources.FriggLambdaSecurityGroup).toBeDefined();
|
|
299
|
+
expect(result.resources.FriggLambdaSecurityGroup.Properties.VpcId).toBe('vpc-discovered');
|
|
300
300
|
});
|
|
301
301
|
|
|
302
302
|
it('should allow sharing discovered subnets when explicitly configured', async () => {
|
|
@@ -330,8 +330,6 @@ describe('VpcBuilder', () => {
|
|
|
330
330
|
management: 'discover',
|
|
331
331
|
selfHeal: true,
|
|
332
332
|
},
|
|
333
|
-
// The DynamoDB gateway endpoint is opt-in since 37a354e8
|
|
334
|
-
database: { dynamodb: { enable: true } },
|
|
335
333
|
};
|
|
336
334
|
|
|
337
335
|
const discoveredResources = {
|
|
@@ -464,8 +462,6 @@ describe('VpcBuilder', () => {
|
|
|
464
462
|
const appDefinition = {
|
|
465
463
|
vpc: { enable: true },
|
|
466
464
|
encryption: { fieldLevelEncryptionMethod: 'kms' },
|
|
467
|
-
// The DynamoDB gateway endpoint is opt-in since 37a354e8
|
|
468
|
-
database: { dynamodb: { enable: true } },
|
|
469
465
|
};
|
|
470
466
|
|
|
471
467
|
// Structured discovery from CloudFormation
|
|
@@ -526,8 +522,6 @@ describe('VpcBuilder', () => {
|
|
|
526
522
|
const appDefinition = {
|
|
527
523
|
vpc: { enable: true, enableVPCEndpoints: true, selfHeal: true },
|
|
528
524
|
encryption: { fieldLevelEncryptionMethod: 'kms' },
|
|
529
|
-
// The DynamoDB gateway endpoint is opt-in since 37a354e8
|
|
530
|
-
database: { dynamodb: { enable: true } },
|
|
531
525
|
};
|
|
532
526
|
const discoveredResources = {
|
|
533
527
|
defaultVpcId: 'vpc-123',
|
|
@@ -810,12 +804,7 @@ describe('VpcBuilder', () => {
|
|
|
810
804
|
expect(result.resources.FriggPrivateSubnet2RouteTableAssociation.Properties.RouteTableId).toEqual({ Ref: 'FriggLambdaRouteTable' });
|
|
811
805
|
});
|
|
812
806
|
|
|
813
|
-
|
|
814
|
-
// to FriggPrivateSubnetNRouteTableAssociation is unresolved. Since 37a354e8
|
|
815
|
-
// the source always uses the new IDs; this test (same commit) expects the old
|
|
816
|
-
// ones. Moving could hit Resource.AlreadyAssociated on upgrade.
|
|
817
|
-
// Tracked in https://github.com/friggframework/frigg/issues/714
|
|
818
|
-
it.skip('should add UpdateReplacePolicy to force association recreation on updates', async () => {
|
|
807
|
+
it('should add UpdateReplacePolicy to force association recreation on updates', async () => {
|
|
819
808
|
const appDefinition = {
|
|
820
809
|
vpc: {
|
|
821
810
|
enable: true,
|
|
@@ -826,9 +815,7 @@ describe('VpcBuilder', () => {
|
|
|
826
815
|
};
|
|
827
816
|
|
|
828
817
|
const discoveredResources = {
|
|
829
|
-
|
|
830
|
-
// the resolver refuses to create one implicitly (37a354e8).
|
|
831
|
-
defaultVpcId: 'vpc-123',
|
|
818
|
+
vpcId: 'vpc-123',
|
|
832
819
|
privateSubnetId1: 'subnet-existing-1',
|
|
833
820
|
privateSubnetId2: 'subnet-existing-2',
|
|
834
821
|
natGatewayId: 'nat-existing',
|
|
@@ -1535,7 +1522,7 @@ describe('VpcBuilder', () => {
|
|
|
1535
1522
|
});
|
|
1536
1523
|
|
|
1537
1524
|
it('should use OLD logical IDs for backwards compatibility (FriggNATRoute, VPCEndpointS3 pattern)', async () => {
|
|
1538
|
-
// CRITICAL TEST:
|
|
1525
|
+
// CRITICAL TEST: Real Frontify production stack uses OLD naming convention
|
|
1539
1526
|
// Stack currently has: FriggNATRoute, VPCEndpointS3, VPCEndpointDynamoDB
|
|
1540
1527
|
// We MUST use these same logical IDs to avoid AlreadyExists errors
|
|
1541
1528
|
const appDefinition = {
|
|
@@ -1554,7 +1541,7 @@ describe('VpcBuilder', () => {
|
|
|
1554
1541
|
}
|
|
1555
1542
|
};
|
|
1556
1543
|
|
|
1557
|
-
// Discovery results matching
|
|
1544
|
+
// Discovery results matching ACTUAL Frontify production stack
|
|
1558
1545
|
const discoveredResources = {
|
|
1559
1546
|
fromCloudFormationStack: true,
|
|
1560
1547
|
stackName: 'create-frigg-app-production',
|
|
@@ -1602,9 +1589,10 @@ describe('VpcBuilder', () => {
|
|
|
1602
1589
|
expect(result.resources.FriggNATRoute.Type).toBe('AWS::EC2::Route');
|
|
1603
1590
|
expect(result.resources.FriggPrivateRoute).toBeUndefined(); // Should NOT create new ID
|
|
1604
1591
|
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1592
|
+
expect(result.resources.FriggSubnet1RouteAssociation).toBeDefined();
|
|
1593
|
+
expect(result.resources.FriggSubnet2RouteAssociation).toBeDefined();
|
|
1594
|
+
expect(result.resources.FriggPrivateSubnet1RouteTableAssociation).toBeUndefined();
|
|
1595
|
+
expect(result.resources.FriggPrivateSubnet2RouteTableAssociation).toBeUndefined();
|
|
1608
1596
|
|
|
1609
1597
|
expect(result.resources.VPCEndpointS3).toBeDefined();
|
|
1610
1598
|
expect(result.resources.VPCEndpointS3.Type).toBe('AWS::EC2::VPCEndpoint');
|
|
@@ -1826,8 +1814,6 @@ describe('VpcBuilder', () => {
|
|
|
1826
1814
|
const appDefinition = {
|
|
1827
1815
|
vpc: { enable: true },
|
|
1828
1816
|
encryption: { fieldLevelEncryptionMethod: 'kms' },
|
|
1829
|
-
// The DynamoDB gateway endpoint is opt-in since 37a354e8
|
|
1830
|
-
database: { dynamodb: { enable: true } },
|
|
1831
1817
|
};
|
|
1832
1818
|
|
|
1833
1819
|
const discoveredResources = {
|
|
@@ -4,11 +4,6 @@ const path = require('path');
|
|
|
4
4
|
* Generate IAM CloudFormation template
|
|
5
5
|
* @param {Object} options - Generation options
|
|
6
6
|
* @param {string} [options.appName='Frigg'] - Application name
|
|
7
|
-
* @param {string} [options.serviceName] - The osls service name the app deploys
|
|
8
|
-
* under (Definition.name). Resource grants that match `*frigg*` are also
|
|
9
|
-
* granted for `*<serviceName>*`, because `frigg deploy` names the stack,
|
|
10
|
-
* functions, role, queues, topics, alarms, log groups, layer and buckets
|
|
11
|
-
* after the service, not after "frigg".
|
|
12
7
|
* @param {Object} [options.features={}] - Enabled features { vpc, kms, ssm, websockets }
|
|
13
8
|
* @param {string} [options.userPrefix='frigg-deployment-user'] - IAM user name prefix
|
|
14
9
|
* @param {string} [options.stackName='frigg-deployment-iam'] - CloudFormation stack name
|
|
@@ -21,8 +16,7 @@ function generateIAMCloudFormation(options = {}) {
|
|
|
21
16
|
features = {},
|
|
22
17
|
userPrefix = 'frigg-deployment-user',
|
|
23
18
|
stackName = 'frigg-deployment-iam',
|
|
24
|
-
ssmKmsKeyArn
|
|
25
|
-
serviceName,
|
|
19
|
+
ssmKmsKeyArn
|
|
26
20
|
} = options;
|
|
27
21
|
|
|
28
22
|
const deploymentUserName = userPrefix;
|
|
@@ -531,51 +525,6 @@ function generateIAMCloudFormation(options = {}) {
|
|
|
531
525
|
},
|
|
532
526
|
];
|
|
533
527
|
|
|
534
|
-
coreStatements.push(
|
|
535
|
-
{
|
|
536
|
-
Sid: 'FriggLambdaLayers',
|
|
537
|
-
Effect: 'Allow',
|
|
538
|
-
Action: [
|
|
539
|
-
'lambda:PublishLayerVersion',
|
|
540
|
-
'lambda:DeleteLayerVersion',
|
|
541
|
-
'lambda:GetLayerVersion',
|
|
542
|
-
],
|
|
543
|
-
Resource: [
|
|
544
|
-
{
|
|
545
|
-
'Fn::Sub':
|
|
546
|
-
'arn:aws:lambda:*:${AWS::AccountId}:layer:*frigg*',
|
|
547
|
-
},
|
|
548
|
-
{
|
|
549
|
-
'Fn::Sub':
|
|
550
|
-
'arn:aws:lambda:*:${AWS::AccountId}:layer:*frigg*:*',
|
|
551
|
-
},
|
|
552
|
-
],
|
|
553
|
-
},
|
|
554
|
-
{
|
|
555
|
-
// Buckets the app's stack creates (e.g. the migration-status
|
|
556
|
-
// bucket); CloudFormation names them after the stack, in lower case.
|
|
557
|
-
Sid: 'FriggAppBuckets',
|
|
558
|
-
Effect: 'Allow',
|
|
559
|
-
Action: [
|
|
560
|
-
's3:CreateBucket',
|
|
561
|
-
's3:DeleteBucket',
|
|
562
|
-
's3:PutBucketPolicy',
|
|
563
|
-
's3:DeleteBucketPolicy',
|
|
564
|
-
's3:PutBucketVersioning',
|
|
565
|
-
's3:PutBucketPublicAccessBlock',
|
|
566
|
-
's3:PutEncryptionConfiguration',
|
|
567
|
-
's3:PutLifecycleConfiguration',
|
|
568
|
-
's3:PutBucketTagging',
|
|
569
|
-
's3:GetBucketLocation',
|
|
570
|
-
's3:ListBucket',
|
|
571
|
-
's3:GetObject',
|
|
572
|
-
's3:PutObject',
|
|
573
|
-
's3:DeleteObject',
|
|
574
|
-
],
|
|
575
|
-
Resource: ['arn:aws:s3:::*frigg*', 'arn:aws:s3:::*frigg*/*'],
|
|
576
|
-
}
|
|
577
|
-
);
|
|
578
|
-
|
|
579
528
|
template.Resources.FriggCoreDeploymentPolicy = {
|
|
580
529
|
Type: 'AWS::IAM::ManagedPolicy',
|
|
581
530
|
Properties: {
|
|
@@ -819,59 +768,10 @@ function generateIAMCloudFormation(options = {}) {
|
|
|
819
768
|
},
|
|
820
769
|
};
|
|
821
770
|
|
|
822
|
-
expandResourceNamePatterns(template, serviceName);
|
|
823
|
-
|
|
824
771
|
// Convert to YAML
|
|
825
772
|
return convertToYAML(template);
|
|
826
773
|
}
|
|
827
774
|
|
|
828
|
-
const FRIGG_NAME_PATTERN = '*frigg*';
|
|
829
|
-
|
|
830
|
-
/**
|
|
831
|
-
* Next to every policy resource that matches `*frigg*`, add the same
|
|
832
|
-
* resource for `*<serviceName>*` (lower case for S3 bucket ARNs), so an app
|
|
833
|
-
* that is not named "frigg" can manage its own stack resources.
|
|
834
|
-
*
|
|
835
|
-
* @param {Object} template - CloudFormation template (mutated)
|
|
836
|
-
* @param {string} [serviceName]
|
|
837
|
-
*/
|
|
838
|
-
function expandResourceNamePatterns(template, serviceName) {
|
|
839
|
-
if (!serviceName || /frigg/i.test(serviceName)) {
|
|
840
|
-
return;
|
|
841
|
-
}
|
|
842
|
-
const servicePattern = `*${serviceName}*`;
|
|
843
|
-
const expand = (resource) => {
|
|
844
|
-
const value =
|
|
845
|
-
typeof resource === 'string'
|
|
846
|
-
? resource
|
|
847
|
-
: resource && resource['Fn::Sub'];
|
|
848
|
-
if (typeof value !== 'string' || !value.includes(FRIGG_NAME_PATTERN)) {
|
|
849
|
-
return [resource];
|
|
850
|
-
}
|
|
851
|
-
const pattern = value.startsWith('arn:aws:s3:::')
|
|
852
|
-
? servicePattern.toLowerCase()
|
|
853
|
-
: servicePattern;
|
|
854
|
-
const scoped = value.split(FRIGG_NAME_PATTERN).join(pattern);
|
|
855
|
-
return [
|
|
856
|
-
resource,
|
|
857
|
-
typeof resource === 'string' ? scoped : { 'Fn::Sub': scoped },
|
|
858
|
-
];
|
|
859
|
-
};
|
|
860
|
-
|
|
861
|
-
for (const resource of Object.values(template.Resources)) {
|
|
862
|
-
const statements = resource?.Properties?.PolicyDocument?.Statement;
|
|
863
|
-
if (!Array.isArray(statements)) continue;
|
|
864
|
-
for (const statement of statements) {
|
|
865
|
-
if (statement.Resource === undefined) continue;
|
|
866
|
-
const expanded = [].concat(statement.Resource).flatMap(expand);
|
|
867
|
-
statement.Resource =
|
|
868
|
-
Array.isArray(statement.Resource) || expanded.length > 1
|
|
869
|
-
? expanded
|
|
870
|
-
: expanded[0];
|
|
871
|
-
}
|
|
872
|
-
}
|
|
873
|
-
}
|
|
874
|
-
|
|
875
775
|
/**
|
|
876
776
|
* Convert JavaScript object to CloudFormation YAML
|
|
877
777
|
* @param {Object} obj - JavaScript object
|
|
@@ -896,7 +796,8 @@ function getFeatureSummary(appDefinition) {
|
|
|
896
796
|
const features = {
|
|
897
797
|
core: true, // Always enabled
|
|
898
798
|
vpc: appDefinition.vpc?.enable === true,
|
|
899
|
-
kms:
|
|
799
|
+
kms:
|
|
800
|
+
appDefinition.encryption?.fieldLevelEncryptionMethod === 'kms',
|
|
900
801
|
ssm: appDefinition.ssm?.enable === true,
|
|
901
802
|
websockets: appDefinition.websockets?.enable === true,
|
|
902
803
|
};
|
|
@@ -907,8 +808,6 @@ function getFeatureSummary(appDefinition) {
|
|
|
907
808
|
features,
|
|
908
809
|
integrationCount,
|
|
909
810
|
appName: appDefinition.name || 'Unnamed Frigg App',
|
|
910
|
-
// What createBaseDefinition uses as the osls service name.
|
|
911
|
-
serviceName: appDefinition.name || 'create-frigg-app',
|
|
912
811
|
ssmKmsKeyArn: appDefinition.ssm?.kmsKeyArn,
|
|
913
812
|
};
|
|
914
813
|
}
|
|
@@ -918,10 +817,7 @@ function getFeatureSummary(appDefinition) {
|
|
|
918
817
|
* @returns {Object} Basic IAM policy document
|
|
919
818
|
*/
|
|
920
819
|
function generateBasicIAMPolicy() {
|
|
921
|
-
const basicPolicyPath = path.join(
|
|
922
|
-
__dirname,
|
|
923
|
-
'templates/iam-policy-basic.json'
|
|
924
|
-
);
|
|
820
|
+
const basicPolicyPath = path.join(__dirname, 'templates/iam-policy-basic.json');
|
|
925
821
|
return require(basicPolicyPath);
|
|
926
822
|
}
|
|
927
823
|
|
|
@@ -930,10 +826,7 @@ function generateBasicIAMPolicy() {
|
|
|
930
826
|
* @returns {Object} Full IAM policy document
|
|
931
827
|
*/
|
|
932
828
|
function generateFullIAMPolicy() {
|
|
933
|
-
const fullPolicyPath = path.join(
|
|
934
|
-
__dirname,
|
|
935
|
-
'templates/iam-policy-full.json'
|
|
936
|
-
);
|
|
829
|
+
const fullPolicyPath = path.join(__dirname, 'templates/iam-policy-full.json');
|
|
937
830
|
return require(fullPolicyPath);
|
|
938
831
|
}
|
|
939
832
|
|
|
@@ -313,98 +313,4 @@ describe('IAM Generator', () => {
|
|
|
313
313
|
expect(yaml).toContain('CredentialsSecretArn:');
|
|
314
314
|
});
|
|
315
315
|
});
|
|
316
|
-
|
|
317
|
-
describe("scoping to the app's own resources", () => {
|
|
318
|
-
const yaml = require('js-yaml');
|
|
319
|
-
const policyResources = (template, policy) =>
|
|
320
|
-
template.Resources[
|
|
321
|
-
policy
|
|
322
|
-
].Properties.PolicyDocument.Statement.flatMap((statement) =>
|
|
323
|
-
[].concat(statement.Resource)
|
|
324
|
-
).map((r) => (typeof r === 'string' ? r : r['Fn::Sub']));
|
|
325
|
-
|
|
326
|
-
// `frigg deploy` names everything after the service (Definition.name):
|
|
327
|
-
// stack my-app-prod, functions my-app-prod-auth, role
|
|
328
|
-
// my-app-prod-us-east-1-lambdaRole, queues my-app-internal-error-queue-prod
|
|
329
|
-
// and my-app-prod-DbMigrationQueue, layer my-app-prisma-prod, and
|
|
330
|
-
// CloudFormation-named topics, alarms and buckets prefixed my-app-prod.
|
|
331
|
-
const generate = (appDefinition) => {
|
|
332
|
-
const summary = getFeatureSummary(appDefinition);
|
|
333
|
-
return yaml.load(
|
|
334
|
-
generateIAMCloudFormation({
|
|
335
|
-
appName: summary.appName,
|
|
336
|
-
serviceName: summary.serviceName,
|
|
337
|
-
features: summary.features,
|
|
338
|
-
})
|
|
339
|
-
);
|
|
340
|
-
};
|
|
341
|
-
|
|
342
|
-
it('reports the service name osls deploys under', () => {
|
|
343
|
-
expect(getFeatureSummary({ name: 'my-app' }).serviceName).toBe(
|
|
344
|
-
'my-app'
|
|
345
|
-
);
|
|
346
|
-
expect(getFeatureSummary({}).serviceName).toBe('create-frigg-app');
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
it('lets an app whose name does not contain "frigg" deploy its stack and resources', () => {
|
|
350
|
-
const resources = policyResources(
|
|
351
|
-
generate({ name: 'my-app' }),
|
|
352
|
-
'FriggCoreDeploymentPolicy'
|
|
353
|
-
);
|
|
354
|
-
|
|
355
|
-
for (const expected of [
|
|
356
|
-
'arn:aws:cloudformation:*:${AWS::AccountId}:stack/*my-app*/*',
|
|
357
|
-
'arn:aws:lambda:*:${AWS::AccountId}:function:*my-app*',
|
|
358
|
-
'arn:aws:iam::${AWS::AccountId}:role/*my-app*',
|
|
359
|
-
'arn:aws:sqs:*:${AWS::AccountId}:*my-app*',
|
|
360
|
-
'arn:aws:sns:*:${AWS::AccountId}:*my-app*',
|
|
361
|
-
'arn:aws:logs:*:${AWS::AccountId}:log-group:/aws/lambda/*my-app*',
|
|
362
|
-
'arn:aws:logs:*:${AWS::AccountId}:log-group:/aws/lambda/*my-app*:*',
|
|
363
|
-
'arn:aws:cloudwatch:*:${AWS::AccountId}:alarm:*my-app*',
|
|
364
|
-
'arn:aws:lambda:*:${AWS::AccountId}:layer:*my-app*',
|
|
365
|
-
'arn:aws:lambda:*:${AWS::AccountId}:layer:*my-app*:*',
|
|
366
|
-
'arn:aws:s3:::*my-app*',
|
|
367
|
-
'arn:aws:s3:::*my-app*/*',
|
|
368
|
-
]) {
|
|
369
|
-
expect(resources).toContain(expected);
|
|
370
|
-
}
|
|
371
|
-
// Existing grants for frigg-named resources are kept.
|
|
372
|
-
expect(resources).toContain(
|
|
373
|
-
'arn:aws:lambda:*:${AWS::AccountId}:function:*frigg*'
|
|
374
|
-
);
|
|
375
|
-
});
|
|
376
|
-
|
|
377
|
-
it('matches S3 bucket names in lower case', () => {
|
|
378
|
-
const resources = policyResources(
|
|
379
|
-
generate({ name: 'MyApp' }),
|
|
380
|
-
'FriggCoreDeploymentPolicy'
|
|
381
|
-
);
|
|
382
|
-
expect(resources).toContain('arn:aws:s3:::*myapp*');
|
|
383
|
-
});
|
|
384
|
-
|
|
385
|
-
it('scopes the SSM parameter grant to the app too', () => {
|
|
386
|
-
const template = generate({
|
|
387
|
-
name: 'my-app',
|
|
388
|
-
ssm: { enable: true },
|
|
389
|
-
});
|
|
390
|
-
const resources = policyResources(template, 'FriggSSMPolicy');
|
|
391
|
-
expect(resources).toContain(
|
|
392
|
-
'arn:aws:ssm:*:${AWS::AccountId}:parameter/*my-app*'
|
|
393
|
-
);
|
|
394
|
-
});
|
|
395
|
-
|
|
396
|
-
it('does not duplicate grants for an app named frigg', () => {
|
|
397
|
-
const resources = policyResources(
|
|
398
|
-
generate({ name: 'frigg' }),
|
|
399
|
-
'FriggCoreDeploymentPolicy'
|
|
400
|
-
);
|
|
401
|
-
expect(
|
|
402
|
-
resources.filter(
|
|
403
|
-
(r) =>
|
|
404
|
-
r ===
|
|
405
|
-
'arn:aws:lambda:*:${AWS::AccountId}:function:*frigg*'
|
|
406
|
-
)
|
|
407
|
-
).toHaveLength(1);
|
|
408
|
-
});
|
|
409
|
-
});
|
|
410
316
|
});
|
|
@@ -164,7 +164,7 @@ describe('CloudFormationDiscovery', () => {
|
|
|
164
164
|
expect(result.routeTableId).toBe('rtb-123');
|
|
165
165
|
expect(result.vpcEndpointSecurityGroupId).toBe('sg-vpce-123');
|
|
166
166
|
expect(result.s3VpcEndpointId).toBe('vpce-s3-123');
|
|
167
|
-
expect(result.
|
|
167
|
+
expect(result.dynamoDbVpcEndpointId).toBe('vpce-ddb-123');
|
|
168
168
|
expect(result.kmsVpcEndpointId).toBe('vpce-kms-123');
|
|
169
169
|
expect(result.secretsManagerVpcEndpointId).toBe('vpce-sm-123');
|
|
170
170
|
});
|
|
@@ -190,9 +190,6 @@ describe('CloudFormationDiscovery', () => {
|
|
|
190
190
|
|
|
191
191
|
expect(result).toEqual({
|
|
192
192
|
fromCloudFormationStack: true,
|
|
193
|
-
// _extractFromResources() initialises the structured endpoint map whenever
|
|
194
|
-
// the stack has resources (37a354e8)
|
|
195
|
-
vpcEndpoints: {},
|
|
196
193
|
stackName: 'test-stack',
|
|
197
194
|
auroraClusterId: 'test-cluster',
|
|
198
195
|
existingLogicalIds: ['FriggAuroraCluster'],
|
|
@@ -260,9 +257,6 @@ describe('CloudFormationDiscovery', () => {
|
|
|
260
257
|
|
|
261
258
|
expect(result).toEqual({
|
|
262
259
|
fromCloudFormationStack: true,
|
|
263
|
-
// _extractFromResources() initialises the structured endpoint map whenever
|
|
264
|
-
// the stack has resources (37a354e8)
|
|
265
|
-
vpcEndpoints: {},
|
|
266
260
|
stackName: 'test-stack',
|
|
267
261
|
migrationStatusBucket: 'test-migration-bucket',
|
|
268
262
|
existingLogicalIds: ['FriggMigrationStatusBucket'],
|
|
@@ -291,9 +285,6 @@ describe('CloudFormationDiscovery', () => {
|
|
|
291
285
|
|
|
292
286
|
expect(result).toEqual({
|
|
293
287
|
fromCloudFormationStack: true,
|
|
294
|
-
// _extractFromResources() initialises the structured endpoint map whenever
|
|
295
|
-
// the stack has resources (37a354e8)
|
|
296
|
-
vpcEndpoints: {},
|
|
297
288
|
stackName: 'test-stack',
|
|
298
289
|
migrationQueueUrl:
|
|
299
290
|
'https://sqs.us-east-1.amazonaws.com/123456789/test-queue',
|
|
@@ -322,9 +313,6 @@ describe('CloudFormationDiscovery', () => {
|
|
|
322
313
|
|
|
323
314
|
expect(result).toEqual({
|
|
324
315
|
fromCloudFormationStack: true,
|
|
325
|
-
// _extractFromResources() initialises the structured endpoint map whenever
|
|
326
|
-
// the stack has resources (37a354e8)
|
|
327
|
-
vpcEndpoints: {},
|
|
328
316
|
stackName: 'test-stack',
|
|
329
317
|
natGatewayId: 'nat-0123456789',
|
|
330
318
|
existingLogicalIds: ['FriggNatGateway'],
|
|
@@ -352,9 +340,6 @@ describe('CloudFormationDiscovery', () => {
|
|
|
352
340
|
|
|
353
341
|
expect(result).toEqual({
|
|
354
342
|
fromCloudFormationStack: true,
|
|
355
|
-
// _extractFromResources() initialises the structured endpoint map whenever
|
|
356
|
-
// the stack has resources (37a354e8)
|
|
357
|
-
vpcEndpoints: {},
|
|
358
343
|
stackName: 'test-stack',
|
|
359
344
|
defaultVpcId: 'vpc-037ec55fe87aec1e7',
|
|
360
345
|
existingLogicalIds: ['FriggVPC'],
|
|
@@ -393,9 +378,6 @@ describe('CloudFormationDiscovery', () => {
|
|
|
393
378
|
|
|
394
379
|
expect(result).toEqual({
|
|
395
380
|
fromCloudFormationStack: true,
|
|
396
|
-
// _extractFromResources() initialises the structured endpoint map whenever
|
|
397
|
-
// the stack has resources (37a354e8)
|
|
398
|
-
vpcEndpoints: {},
|
|
399
381
|
stackName: 'test-stack',
|
|
400
382
|
defaultVpcId: 'vpc-123', // VpcBuilder expects 'defaultVpcId'
|
|
401
383
|
defaultKmsKeyId: 'arn:aws:kms:us-east-1:123456789:key/abc',
|
|
@@ -424,9 +406,6 @@ describe('CloudFormationDiscovery', () => {
|
|
|
424
406
|
|
|
425
407
|
expect(result).toEqual({
|
|
426
408
|
fromCloudFormationStack: true,
|
|
427
|
-
// _extractFromResources() initialises the structured endpoint map whenever
|
|
428
|
-
// the stack has resources (37a354e8)
|
|
429
|
-
vpcEndpoints: {},
|
|
430
409
|
stackName: 'test-stack',
|
|
431
410
|
});
|
|
432
411
|
});
|
|
@@ -460,11 +439,6 @@ describe('CloudFormationDiscovery', () => {
|
|
|
460
439
|
SecurityGroups: [{ VpcId: 'vpc-123' }],
|
|
461
440
|
});
|
|
462
441
|
|
|
463
|
-
// Mock the VPC's default security group lookup (added in 37a354e8)
|
|
464
|
-
mockEC2Client.send.mockResolvedValueOnce({
|
|
465
|
-
SecurityGroups: [{ GroupId: 'sg-default-123' }],
|
|
466
|
-
});
|
|
467
|
-
|
|
468
442
|
// Mock subnet query
|
|
469
443
|
mockEC2Client.send.mockResolvedValueOnce({
|
|
470
444
|
Subnets: [
|
|
@@ -495,11 +469,9 @@ describe('CloudFormationDiscovery', () => {
|
|
|
495
469
|
|
|
496
470
|
const result = await cfDiscovery.discoverFromStack('test-stack');
|
|
497
471
|
|
|
498
|
-
expect(result.defaultVpcId).toBe('vpc-123');
|
|
499
|
-
expect(result.defaultSecurityGroupId).toBe('sg-default-123');
|
|
500
472
|
expect(result.privateSubnetId1).toBe('subnet-private-1');
|
|
501
473
|
expect(result.privateSubnetId2).toBe('subnet-private-2');
|
|
502
|
-
expect(mockEC2Client.send).toHaveBeenCalledTimes(
|
|
474
|
+
expect(mockEC2Client.send).toHaveBeenCalledTimes(2);
|
|
503
475
|
});
|
|
504
476
|
|
|
505
477
|
it('should handle EC2 subnet query errors gracefully', async () => {
|
|
@@ -767,7 +739,7 @@ describe('CloudFormationDiscovery', () => {
|
|
|
767
739
|
expect(result.vpcEndpoints.s3).toBe('vpce-0352ceac2124c14be');
|
|
768
740
|
expect(result.vpcEndpoints.dynamodb).toBe('vpce-0b06c4f631199ea68');
|
|
769
741
|
expect(result.s3VpcEndpointId).toBe('vpce-0352ceac2124c14be');
|
|
770
|
-
expect(result.
|
|
742
|
+
expect(result.dynamoDbVpcEndpointId).toBe('vpce-0b06c4f631199ea68');
|
|
771
743
|
|
|
772
744
|
// Verify NO VPC/KMS resources (they're external)
|
|
773
745
|
expect(result.defaultVpcId).toBeUndefined();
|
|
@@ -804,7 +776,7 @@ describe('CloudFormationDiscovery', () => {
|
|
|
804
776
|
expect(result.vpcEndpoints.s3).toBe('vpce-legacy-s3');
|
|
805
777
|
expect(result.vpcEndpoints.dynamodb).toBe('vpce-legacy-ddb');
|
|
806
778
|
expect(result.s3VpcEndpointId).toBe('vpce-legacy-s3');
|
|
807
|
-
expect(result.
|
|
779
|
+
expect(result.dynamoDbVpcEndpointId).toBe('vpce-legacy-ddb');
|
|
808
780
|
});
|
|
809
781
|
|
|
810
782
|
it('should extract FriggLambdaSecurityGroup from stack', async () => {
|
|
@@ -835,9 +807,7 @@ describe('CloudFormationDiscovery', () => {
|
|
|
835
807
|
|
|
836
808
|
// Lambda security group should be extracted
|
|
837
809
|
expect(result.lambdaSecurityGroupId).toBe('sg-01002240c6a446202');
|
|
838
|
-
|
|
839
|
-
// (defaultSecurityGroupId is only ever the VPC default; see 37a354e8).
|
|
840
|
-
expect(result.defaultSecurityGroupId).toBeUndefined();
|
|
810
|
+
expect(result.defaultSecurityGroupId).toBe('sg-01002240c6a446202');
|
|
841
811
|
expect(result.existingLogicalIds).toContain(
|
|
842
812
|
'FriggLambdaSecurityGroup'
|
|
843
813
|
);
|
|
@@ -929,7 +899,7 @@ describe('CloudFormationDiscovery', () => {
|
|
|
929
899
|
|
|
930
900
|
describe('existingLogicalIds tracking', () => {
|
|
931
901
|
it('should track OLD VPC endpoint logical IDs (VPCEndpointS3 pattern) for backwards compatibility', async () => {
|
|
932
|
-
// CRITICAL:
|
|
902
|
+
// CRITICAL: Frontify production uses OLD naming convention
|
|
933
903
|
const mockStack = {
|
|
934
904
|
StackName: 'create-frigg-app-production',
|
|
935
905
|
Outputs: [],
|
|
@@ -10,6 +10,24 @@
|
|
|
10
10
|
const { buildEnvironment } = require('../environment-builder');
|
|
11
11
|
const { nestedNodeModulesExcludes } = require('./nested-node-modules');
|
|
12
12
|
const { buildLoggingProviderConfig } = require('./logging-config');
|
|
13
|
+
const {
|
|
14
|
+
getGatewayRoutes,
|
|
15
|
+
} = require('@friggframework/core/management-api/route-registry');
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* HTTP API events for one function, from core's Management API route
|
|
19
|
+
* registry (ADR-053): the same registry mounts the Express routers and
|
|
20
|
+
* builds the OpenAPI documents, so the three cannot drift.
|
|
21
|
+
*/
|
|
22
|
+
function managementApiEvents(AppDefinition, functionName) {
|
|
23
|
+
const managementApi = AppDefinition.managementApi || {};
|
|
24
|
+
return getGatewayRoutes({
|
|
25
|
+
v1: managementApi.v1 !== false,
|
|
26
|
+
proxy: managementApi.proxy?.enable === true,
|
|
27
|
+
})
|
|
28
|
+
.filter((route) => route.function === functionName)
|
|
29
|
+
.map(({ method, path }) => ({ httpApi: { path, method } }));
|
|
30
|
+
}
|
|
13
31
|
|
|
14
32
|
/**
|
|
15
33
|
* Create base serverless definition with core functions and resources
|
|
@@ -286,35 +304,12 @@ function createBaseDefinition(
|
|
|
286
304
|
...(usePrismaLayer && { layers: [{ Ref: 'PrismaLambdaLayer' }] }),
|
|
287
305
|
skipEsbuild: true, // Handlers in node_modules don't need bundling
|
|
288
306
|
package: skipEsbuildPackageConfig,
|
|
289
|
-
// Every path
|
|
290
|
-
//
|
|
291
|
-
// HTTP API has no implicit catch-all, so an unlisted
|
|
292
|
-
// 404s at the gateway before Express sees it. Guarded by
|
|
307
|
+
// Every Management API path the auth Lambda serves (v1, v2 per
|
|
308
|
+
// resource, the OAuth redirect) comes from core's route
|
|
309
|
+
// registry. HTTP API has no implicit catch-all, so an unlisted
|
|
310
|
+
// prefix 404s at the gateway before Express sees it. Guarded by
|
|
293
311
|
// __tests__/management-api-gateway-routes.test.js.
|
|
294
|
-
events:
|
|
295
|
-
{ httpApi: { path: '/api/integrations', method: 'ANY' } },
|
|
296
|
-
{
|
|
297
|
-
httpApi: {
|
|
298
|
-
path: '/api/integrations/{proxy+}',
|
|
299
|
-
method: 'ANY',
|
|
300
|
-
},
|
|
301
|
-
},
|
|
302
|
-
{ httpApi: { path: '/api/authorize', method: 'ANY' } },
|
|
303
|
-
{ httpApi: { path: '/api/entity', method: 'ANY' } },
|
|
304
|
-
{
|
|
305
|
-
httpApi: {
|
|
306
|
-
path: '/api/entity/{proxy+}',
|
|
307
|
-
method: 'ANY',
|
|
308
|
-
},
|
|
309
|
-
},
|
|
310
|
-
{ httpApi: { path: '/api/entities', method: 'ANY' } },
|
|
311
|
-
{
|
|
312
|
-
httpApi: {
|
|
313
|
-
path: '/api/entities/{proxy+}',
|
|
314
|
-
method: 'ANY',
|
|
315
|
-
},
|
|
316
|
-
},
|
|
317
|
-
],
|
|
312
|
+
events: managementApiEvents(AppDefinition, 'auth'),
|
|
318
313
|
},
|
|
319
314
|
user: {
|
|
320
315
|
handler: 'node_modules/@friggframework/core/handlers/routers/user.handler',
|
|
@@ -331,6 +326,8 @@ function createBaseDefinition(
|
|
|
331
326
|
events: [
|
|
332
327
|
{ httpApi: { path: '/health', method: 'GET' } },
|
|
333
328
|
{ httpApi: { path: '/health/{proxy+}', method: 'GET' } },
|
|
329
|
+
// GET /api/meta and the OpenAPI documents: public, DB-free.
|
|
330
|
+
...managementApiEvents(AppDefinition, 'health'),
|
|
334
331
|
],
|
|
335
332
|
},
|
|
336
333
|
// Reporting is an admin operation (ADR-010): the report router runs on the admin-scripts Lambda, not as a standalone function here.
|
|
@@ -402,18 +399,12 @@ function createBaseDefinition(
|
|
|
402
399
|
},
|
|
403
400
|
},
|
|
404
401
|
},
|
|
405
|
-
// The functions above use `httpApi` events, so osls creates
|
|
406
|
-
// an HTTP API (API Gateway v2, logical ID HttpApi) with only
|
|
407
|
-
// the `$default` stage. HTTP APIs publish `5xx`, not the REST
|
|
408
|
-
// API metric `5XXError`, and the ApiId dimension identifies
|
|
409
|
-
// this API (a Stage dimension would have to be `$default`).
|
|
410
|
-
// https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-metrics.html
|
|
411
402
|
ApiGatewayAlarm5xx: {
|
|
412
403
|
Type: 'AWS::CloudWatch::Alarm',
|
|
413
404
|
Properties: {
|
|
414
405
|
AlarmDescription: 'API Gateway 5xx Errors',
|
|
415
406
|
Namespace: 'AWS/ApiGateway',
|
|
416
|
-
MetricName: '
|
|
407
|
+
MetricName: '5XXError',
|
|
417
408
|
Statistic: 'Sum',
|
|
418
409
|
Threshold: 0,
|
|
419
410
|
ComparisonOperator: 'GreaterThanThreshold',
|
|
@@ -422,6 +413,7 @@ function createBaseDefinition(
|
|
|
422
413
|
AlarmActions: [{ Ref: 'InternalErrorBridgeTopic' }],
|
|
423
414
|
Dimensions: [
|
|
424
415
|
{ Name: 'ApiId', Value: { Ref: 'HttpApi' } },
|
|
416
|
+
{ Name: 'Stage', Value: '${self:provider.stage}' },
|
|
425
417
|
],
|
|
426
418
|
},
|
|
427
419
|
},
|