@friggframework/devtools 2.0.0--canary.710.91495fa.0 → 2.0.0--canary.702.ef0dc8c.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/README.md +1 -0
- package/frigg-cli/README.md +76 -78
- package/frigg-cli/__tests__/unit/commands/build.test.js +3 -0
- package/frigg-cli/__tests__/unit/commands/deploy.test.js +27 -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/commands/validate-wiring.test.js +92 -0
- package/frigg-cli/__tests__/unit/dependencies.test.js +2 -6
- package/frigg-cli/build-command/index.js +6 -0
- package/frigg-cli/deploy-command/index.js +6 -0
- package/frigg-cli/generate-command/index.js +0 -1
- package/frigg-cli/generate-iam-command.js +0 -1
- package/frigg-cli/index.js +23 -10
- package/frigg-cli/index.test.js +158 -0
- package/frigg-cli/init-command/backend-first-handler.js +531 -395
- 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/start-command/index.js +4 -0
- package/frigg-cli/start-command/start-command.test.js +3 -0
- package/frigg-cli/test/init-command.test.js +2 -9
- package/frigg-cli/validate-command/__tests__/init-validation.test.js +63 -0
- package/frigg-cli/validate-command/__tests__/integrations-checks.test.js +133 -0
- package/frigg-cli/validate-command/__tests__/validate-app-definition.test.js +326 -0
- package/frigg-cli/validate-command/__tests__/validate-command.test.js +241 -0
- package/frigg-cli/validate-command/__tests__/validate-module-command.test.js +119 -0
- package/frigg-cli/validate-command/checks/config.js +468 -0
- package/frigg-cli/validate-command/checks/integrations.js +274 -0
- package/frigg-cli/validate-command/fixtures/bad-module/index.js +18 -0
- package/frigg-cli/validate-command/fixtures/fathom-module/definition.js +76 -0
- package/frigg-cli/validate-command/fixtures/fathom-module/index.js +6 -0
- package/frigg-cli/validate-command/format-report.js +60 -0
- package/frigg-cli/validate-command/index.js +151 -0
- package/frigg-cli/validate-command/load-app-definition.js +93 -0
- package/frigg-cli/validate-command/load-module-definition.js +64 -0
- package/frigg-cli/validate-command/schema-issues.js +154 -0
- package/frigg-cli/validate-command/validate-app-definition.js +60 -0
- package/frigg-cli/validate-command/validate-module-definition.js +46 -0
- package/infrastructure/__tests__/postgres-config.test.js +835 -241
- package/infrastructure/__tests__/template-generation.test.js +8 -36
- package/infrastructure/app-definition-schema-contract.test.js +607 -0
- package/infrastructure/create-frigg-infrastructure.js +4 -1
- package/infrastructure/create-frigg-infrastructure.test.js +51 -0
- package/infrastructure/docs/POSTGRES-CONFIGURATION.md +60 -118
- 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 +13 -32
- 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 +2 -7
- package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +0 -21
- 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
|
@@ -439,14 +439,8 @@ class VpcBuilder extends InfrastructureBuilder {
|
|
|
439
439
|
translated.vpc.ownership.subnets = 'external';
|
|
440
440
|
}
|
|
441
441
|
|
|
442
|
-
// Legacy options that warnIgnoredOptions() reports as ignored under
|
|
443
|
-
// managementMode='managed' must really be ignored: applying them would
|
|
444
|
-
// undo the ownership chosen above (e.g. vpc.management='discover' turning
|
|
445
|
-
// managed+isolated's ownership.vpc='stack' back into 'auto').
|
|
446
|
-
const honorLegacyModes = globalMode !== 'managed';
|
|
447
|
-
|
|
448
442
|
// Handle legacy vpc.management modes
|
|
449
|
-
const vpcManagement =
|
|
443
|
+
const vpcManagement = appDefinition.vpc?.management;
|
|
450
444
|
if (vpcManagement === 'create-new') {
|
|
451
445
|
translated.vpc.ownership.vpc = 'stack';
|
|
452
446
|
translated.vpc.ownership.securityGroup = 'stack';
|
|
@@ -472,7 +466,7 @@ class VpcBuilder extends InfrastructureBuilder {
|
|
|
472
466
|
}
|
|
473
467
|
|
|
474
468
|
// Handle legacy shareAcrossStages
|
|
475
|
-
if (
|
|
469
|
+
if (appDefinition.vpc?.shareAcrossStages !== undefined) {
|
|
476
470
|
if (appDefinition.vpc.shareAcrossStages) {
|
|
477
471
|
// Shared VPC - discover and reuse
|
|
478
472
|
translated.vpc.ownership.vpc = 'auto';
|
|
@@ -487,7 +481,7 @@ class VpcBuilder extends InfrastructureBuilder {
|
|
|
487
481
|
}
|
|
488
482
|
|
|
489
483
|
// Handle legacy NAT Gateway management
|
|
490
|
-
if (
|
|
484
|
+
if (appDefinition.vpc?.natGateway?.management === 'createAndManage') {
|
|
491
485
|
// Use 'auto' to allow discovering and reusing properly placed external NAT Gateways
|
|
492
486
|
// The resolver will check if there's a good external NAT Gateway and reuse it,
|
|
493
487
|
// or create a new one if needed (or if the existing one is misplaced)
|
|
@@ -499,10 +493,9 @@ class VpcBuilder extends InfrastructureBuilder {
|
|
|
499
493
|
}
|
|
500
494
|
|
|
501
495
|
// Handle legacy subnet management
|
|
502
|
-
|
|
503
|
-
if (subnetManagement === 'create') {
|
|
496
|
+
if (appDefinition.vpc?.subnets?.management === 'create') {
|
|
504
497
|
translated.vpc.ownership.subnets = 'stack';
|
|
505
|
-
} else if (
|
|
498
|
+
} else if (appDefinition.vpc?.subnets?.management === 'use-existing' && appDefinition.vpc.subnets.ids) {
|
|
506
499
|
translated.vpc.ownership.subnets = 'external';
|
|
507
500
|
translated.vpc.external.subnetIds = appDefinition.vpc.subnets.ids;
|
|
508
501
|
}
|
|
@@ -698,11 +691,8 @@ class VpcBuilder extends InfrastructureBuilder {
|
|
|
698
691
|
result.vpcConfig.securityGroupIds = [{ Ref: 'FriggLambdaSecurityGroup' }];
|
|
699
692
|
console.log(' ✅ Security Group added to template');
|
|
700
693
|
} else if (decision.ownership === ResourceOwnership.EXTERNAL) {
|
|
701
|
-
// Use external security group IDs
|
|
702
|
-
|
|
703
|
-
const sgIds = decision.physicalIds?.length
|
|
704
|
-
? decision.physicalIds
|
|
705
|
-
: Array.isArray(decision.physicalId) ? decision.physicalId : [decision.physicalId];
|
|
694
|
+
// Use external security group IDs
|
|
695
|
+
const sgIds = Array.isArray(decision.physicalId) ? decision.physicalId : [decision.physicalId];
|
|
706
696
|
result.vpcConfig.securityGroupIds = sgIds;
|
|
707
697
|
console.log(` ✓ Using external security group(s): ${sgIds.join(', ')}`);
|
|
708
698
|
}
|
|
@@ -1185,7 +1175,7 @@ class VpcBuilder extends InfrastructureBuilder {
|
|
|
1185
1175
|
const vpcId = result.vpcId;
|
|
1186
1176
|
|
|
1187
1177
|
// Determine logical IDs based on what exists in stack for backwards compatibility
|
|
1188
|
-
// CRITICAL:
|
|
1178
|
+
// CRITICAL: Frontify production uses OLD naming (VPCEndpointS3, not FriggS3VPCEndpoint)
|
|
1189
1179
|
const existingLogicalIds = discoveredResources?.existingLogicalIds || [];
|
|
1190
1180
|
|
|
1191
1181
|
|
|
@@ -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',
|
|
@@ -821,9 +815,7 @@ describe('VpcBuilder', () => {
|
|
|
821
815
|
};
|
|
822
816
|
|
|
823
817
|
const discoveredResources = {
|
|
824
|
-
|
|
825
|
-
// the resolver refuses to create one implicitly (37a354e8).
|
|
826
|
-
defaultVpcId: 'vpc-123',
|
|
818
|
+
vpcId: 'vpc-123',
|
|
827
819
|
privateSubnetId1: 'subnet-existing-1',
|
|
828
820
|
privateSubnetId2: 'subnet-existing-2',
|
|
829
821
|
natGatewayId: 'nat-existing',
|
|
@@ -833,15 +825,9 @@ describe('VpcBuilder', () => {
|
|
|
833
825
|
|
|
834
826
|
const result = await vpcBuilder.build(appDefinition, discoveredResources);
|
|
835
827
|
|
|
836
|
-
// The builder always emits the new association logical IDs, even when
|
|
837
|
-
// the stack still has the old FriggSubnetNRouteAssociation ones, so
|
|
838
|
-
// CloudFormation replaces drifted associations (see createNatGatewayRouting).
|
|
839
|
-
expect(result.resources.FriggSubnet1RouteAssociation).toBeUndefined();
|
|
840
|
-
expect(result.resources.FriggSubnet2RouteAssociation).toBeUndefined();
|
|
841
|
-
|
|
842
828
|
// Verify associations have UpdateReplacePolicy to force recreation
|
|
843
|
-
expect(result.resources.
|
|
844
|
-
expect(result.resources.
|
|
829
|
+
expect(result.resources.FriggSubnet1RouteAssociation.UpdateReplacePolicy).toBe('Delete');
|
|
830
|
+
expect(result.resources.FriggSubnet2RouteAssociation.UpdateReplacePolicy).toBe('Delete');
|
|
845
831
|
|
|
846
832
|
// This forces CloudFormation to delete old associations and create new ones
|
|
847
833
|
// instead of trying to update them in-place (which doesn't work)
|
|
@@ -1536,7 +1522,7 @@ describe('VpcBuilder', () => {
|
|
|
1536
1522
|
});
|
|
1537
1523
|
|
|
1538
1524
|
it('should use OLD logical IDs for backwards compatibility (FriggNATRoute, VPCEndpointS3 pattern)', async () => {
|
|
1539
|
-
// CRITICAL TEST:
|
|
1525
|
+
// CRITICAL TEST: Real Frontify production stack uses OLD naming convention
|
|
1540
1526
|
// Stack currently has: FriggNATRoute, VPCEndpointS3, VPCEndpointDynamoDB
|
|
1541
1527
|
// We MUST use these same logical IDs to avoid AlreadyExists errors
|
|
1542
1528
|
const appDefinition = {
|
|
@@ -1555,7 +1541,7 @@ describe('VpcBuilder', () => {
|
|
|
1555
1541
|
}
|
|
1556
1542
|
};
|
|
1557
1543
|
|
|
1558
|
-
// Discovery results matching
|
|
1544
|
+
// Discovery results matching ACTUAL Frontify production stack
|
|
1559
1545
|
const discoveredResources = {
|
|
1560
1546
|
fromCloudFormationStack: true,
|
|
1561
1547
|
stackName: 'create-frigg-app-production',
|
|
@@ -1603,13 +1589,10 @@ describe('VpcBuilder', () => {
|
|
|
1603
1589
|
expect(result.resources.FriggNATRoute.Type).toBe('AWS::EC2::Route');
|
|
1604
1590
|
expect(result.resources.FriggPrivateRoute).toBeUndefined(); // Should NOT create new ID
|
|
1605
1591
|
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
expect(result.resources.
|
|
1610
|
-
expect(result.resources.FriggSubnet2RouteAssociation).toBeUndefined();
|
|
1611
|
-
expect(result.resources.FriggPrivateSubnet1RouteTableAssociation).toBeDefined();
|
|
1612
|
-
expect(result.resources.FriggPrivateSubnet2RouteTableAssociation).toBeDefined();
|
|
1592
|
+
expect(result.resources.FriggSubnet1RouteAssociation).toBeDefined();
|
|
1593
|
+
expect(result.resources.FriggSubnet2RouteAssociation).toBeDefined();
|
|
1594
|
+
expect(result.resources.FriggPrivateSubnet1RouteTableAssociation).toBeUndefined();
|
|
1595
|
+
expect(result.resources.FriggPrivateSubnet2RouteTableAssociation).toBeUndefined();
|
|
1613
1596
|
|
|
1614
1597
|
expect(result.resources.VPCEndpointS3).toBeDefined();
|
|
1615
1598
|
expect(result.resources.VPCEndpointS3.Type).toBe('AWS::EC2::VPCEndpoint');
|
|
@@ -1831,8 +1814,6 @@ describe('VpcBuilder', () => {
|
|
|
1831
1814
|
const appDefinition = {
|
|
1832
1815
|
vpc: { enable: true },
|
|
1833
1816
|
encryption: { fieldLevelEncryptionMethod: 'kms' },
|
|
1834
|
-
// The DynamoDB gateway endpoint is opt-in since 37a354e8
|
|
1835
|
-
database: { dynamodb: { enable: true } },
|
|
1836
1817
|
};
|
|
1837
1818
|
|
|
1838
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: [],
|
|
@@ -383,18 +383,12 @@ function createBaseDefinition(
|
|
|
383
383
|
},
|
|
384
384
|
},
|
|
385
385
|
},
|
|
386
|
-
// The functions above use `httpApi` events, so osls creates
|
|
387
|
-
// an HTTP API (API Gateway v2, logical ID HttpApi) with only
|
|
388
|
-
// the `$default` stage. HTTP APIs publish `5xx`, not the REST
|
|
389
|
-
// API metric `5XXError`, and the ApiId dimension identifies
|
|
390
|
-
// this API (a Stage dimension would have to be `$default`).
|
|
391
|
-
// https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-metrics.html
|
|
392
386
|
ApiGatewayAlarm5xx: {
|
|
393
387
|
Type: 'AWS::CloudWatch::Alarm',
|
|
394
388
|
Properties: {
|
|
395
389
|
AlarmDescription: 'API Gateway 5xx Errors',
|
|
396
390
|
Namespace: 'AWS/ApiGateway',
|
|
397
|
-
MetricName: '
|
|
391
|
+
MetricName: '5XXError',
|
|
398
392
|
Statistic: 'Sum',
|
|
399
393
|
Threshold: 0,
|
|
400
394
|
ComparisonOperator: 'GreaterThanThreshold',
|
|
@@ -403,6 +397,7 @@ function createBaseDefinition(
|
|
|
403
397
|
AlarmActions: [{ Ref: 'InternalErrorBridgeTopic' }],
|
|
404
398
|
Dimensions: [
|
|
405
399
|
{ Name: 'ApiId', Value: { Ref: 'HttpApi' } },
|
|
400
|
+
{ Name: 'Stage', Value: '${self:provider.stage}' },
|
|
406
401
|
],
|
|
407
402
|
},
|
|
408
403
|
},
|
|
@@ -121,27 +121,6 @@ describe('Base Definition Factory', () => {
|
|
|
121
121
|
expect(result.resources.Resources.ApiGatewayAlarm5xx).toBeDefined();
|
|
122
122
|
});
|
|
123
123
|
|
|
124
|
-
it('alarms on the HTTP API 5xx metric of the API osls creates', () => {
|
|
125
|
-
// The Frigg functions use `httpApi` events, so osls creates an
|
|
126
|
-
// API Gateway v2 HTTP API (logical ID HttpApi) with only the
|
|
127
|
-
// `$default` stage. HTTP APIs publish `5xx` (REST APIs publish
|
|
128
|
-
// `5XXError`) with the ApiId dimension; a Stage dimension set to
|
|
129
|
-
// the deploy stage name would never match `$default`.
|
|
130
|
-
const result = createBaseDefinition({}, {}, {});
|
|
131
|
-
const usesHttpApi = Object.values(result.functions).some((fn) =>
|
|
132
|
-
(fn.events || []).some((event) => event.httpApi)
|
|
133
|
-
);
|
|
134
|
-
expect(usesHttpApi).toBe(true);
|
|
135
|
-
|
|
136
|
-
const alarm = result.resources.Resources.ApiGatewayAlarm5xx;
|
|
137
|
-
expect(alarm.Properties).toMatchObject({
|
|
138
|
-
Namespace: 'AWS/ApiGateway',
|
|
139
|
-
MetricName: '5xx',
|
|
140
|
-
Dimensions: [{ Name: 'ApiId', Value: { Ref: 'HttpApi' } }],
|
|
141
|
-
AlarmActions: [{ Ref: 'InternalErrorBridgeTopic' }],
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
|
|
145
124
|
it('should include base IAM permissions', () => {
|
|
146
125
|
const result = createBaseDefinition({}, {}, {});
|
|
147
126
|
|