@friggframework/devtools 2.0.0--canary.731.ffe61d3.0 → 2.0.0--canary.658.130b4ec.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 +31 -115
- package/frigg-cli/__tests__/unit/commands/build.test.js +0 -3
- package/frigg-cli/__tests__/unit/commands/deploy.test.js +24 -33
- 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/build-command/index.js +0 -6
- package/frigg-cli/deploy-command/index.js +0 -6
- package/frigg-cli/generate-command/index.js +0 -1
- package/frigg-cli/generate-iam-command.js +0 -1
- package/frigg-cli/index.js +5 -22
- package/frigg-cli/index.test.js +158 -0
- package/frigg-cli/init-command/backend-first-handler.js +551 -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 +0 -4
- package/frigg-cli/start-command/start-command.test.js +0 -3
- package/frigg-cli/test/init-command.test.js +2 -9
- package/infrastructure/README.md +5 -32
- package/infrastructure/__tests__/postgres-config.test.js +836 -245
- package/infrastructure/__tests__/scoped-environment.test.js +0 -3
- package/infrastructure/__tests__/ssm-preload-node-options.test.js +0 -3
- package/infrastructure/__tests__/template-generation.test.js +8 -39
- package/infrastructure/create-frigg-infrastructure.js +1 -4
- package/infrastructure/docs/POSTGRES-CONFIGURATION.md +98 -80
- package/infrastructure/domains/admin-scripts/admin-script-builder.js +2 -8
- package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +6 -52
- package/infrastructure/domains/database/aurora-builder.js +2 -13
- package/infrastructure/domains/database/aurora-builder.test.js +0 -22
- package/infrastructure/domains/database/migration-builder.js +2 -21
- package/infrastructure/domains/database/migration-builder.test.js +6 -61
- 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/integration/integration-builder.js +0 -2
- package/infrastructure/domains/integration/integration-builder.test.js +6 -22
- 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/environment-builder.js +5 -31
- package/infrastructure/domains/shared/environment-builder.test.js +7 -93
- package/infrastructure/domains/shared/utilities/base-definition-factory.js +3 -39
- package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +5 -85
- package/infrastructure/domains/shared/utilities/nested-node-modules.js +5 -6
- package/infrastructure/domains/shared/utilities/nested-node-modules.test.js +26 -20
- package/infrastructure/domains/shared/utilities/prisma-layer-manager.js +12 -92
- package/infrastructure/domains/shared/utilities/prisma-layer-manager.test.js +6 -158
- package/infrastructure/infrastructure-composer.js +1 -12
- package/infrastructure/infrastructure-composer.test.js +794 -339
- package/infrastructure/integration.test.js +381 -0
- package/infrastructure/scripts/build-prisma-layer.js +50 -136
- package/infrastructure/scripts/build-prisma-layer.test.js +7 -128
- package/infrastructure/scripts/build-time-discovery.test.js +3 -18
- package/package.json +10 -12
- package/frigg-cli/__tests__/unit/commands/init.test.js +0 -688
- package/frigg-cli/__tests__/unit/commands/validate-wiring.test.js +0 -92
- 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/frigg-cli/validate-command/__tests__/init-validation.test.js +0 -63
- package/frigg-cli/validate-command/__tests__/integrations-checks.test.js +0 -133
- package/frigg-cli/validate-command/__tests__/validate-app-definition.test.js +0 -443
- package/frigg-cli/validate-command/__tests__/validate-command.test.js +0 -262
- package/frigg-cli/validate-command/checks/config.js +0 -504
- package/frigg-cli/validate-command/checks/integrations.js +0 -274
- package/frigg-cli/validate-command/format-report.js +0 -58
- package/frigg-cli/validate-command/index.js +0 -107
- package/frigg-cli/validate-command/load-app-definition.js +0 -105
- package/frigg-cli/validate-command/schema-issues.js +0 -154
- package/frigg-cli/validate-command/validate-app-definition.js +0 -60
- package/infrastructure/__tests__/helpers/bundled-prisma-engine-excludes.js +0 -39
- package/infrastructure/__tests__/management-api-gateway-routes.test.js +0 -284
- package/infrastructure/__tests__/scaffold-default-infrastructure.test.js +0 -151
- package/infrastructure/app-definition-schema-contract.test.js +0 -634
- package/infrastructure/create-frigg-infrastructure.test.js +0 -51
- package/infrastructure/domains/database/migration-engines.js +0 -93
- package/infrastructure/domains/database/migration-engines.test.js +0 -142
- package/infrastructure/domains/shared/lambda-architectures.js +0 -113
- package/infrastructure/domains/shared/lambda-architectures.test.js +0 -164
|
@@ -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: [],
|
|
@@ -16,12 +16,9 @@ const {
|
|
|
16
16
|
const { normalizeLogLevel } = require('./utilities/logging-config');
|
|
17
17
|
|
|
18
18
|
// OTLP-family exporters read their endpoint/headers from these standard env
|
|
19
|
-
// vars (ADR-011). When such an exporter is configured
|
|
20
|
-
//
|
|
21
|
-
//
|
|
22
|
-
// them as Serverless passthroughs so the deployed Lambda inherits them from
|
|
23
|
-
// the deploy environment. An explicit exporter.type always wins: 'none' /
|
|
24
|
-
// 'console' do NOT register passthroughs even if the deploy shell has the env.
|
|
19
|
+
// vars (ADR-011). When such an exporter is configured we auto-register them as
|
|
20
|
+
// Serverless passthroughs so the deployed Lambda inherits them from the deploy
|
|
21
|
+
// environment — no need for the adopter to also list them under `environment`.
|
|
25
22
|
//
|
|
26
23
|
// NOTE (VPC egress): a Lambda in a private subnet needs a NAT gateway or a VPC
|
|
27
24
|
// endpoint to reach an external OTLP backend (Honeycomb/Datadog). Without egress
|
|
@@ -32,31 +29,9 @@ const OTEL_PASSTHROUGH_VARS = [
|
|
|
32
29
|
'OTEL_EXPORTER_OTLP_HEADERS',
|
|
33
30
|
];
|
|
34
31
|
|
|
35
|
-
function hasOtlpEndpointEnv() {
|
|
36
|
-
const endpoint = process.env.OTEL_EXPORTER_OTLP_ENDPOINT;
|
|
37
|
-
return typeof endpoint === 'string' && endpoint.trim().length > 0;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Zero-code OTLP is active when Definition.telemetry.exporter is omitted and
|
|
42
|
-
* either the deploy shell has a non-empty OTEL_EXPORTER_OTLP_ENDPOINT or that
|
|
43
|
-
* key is declared for SSM offload (`environment: 'ssm'` / `ssm.parameters`).
|
|
44
|
-
*/
|
|
45
|
-
function isZeroCodeOtlpActive(appDefinition) {
|
|
46
|
-
if (hasOtlpEndpointEnv()) return true;
|
|
47
|
-
return getOffloadedKeys(appDefinition).includes(
|
|
48
|
-
'OTEL_EXPORTER_OTLP_ENDPOINT'
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
32
|
function addTelemetryEnvPassthrough(appDefinition, envVars) {
|
|
53
33
|
const exporterType = appDefinition?.telemetry?.exporter?.type;
|
|
54
|
-
if (exporterType
|
|
55
|
-
// Explicit Definition.telemetry.exporter.type wins over the env var.
|
|
56
|
-
if (!OTLP_EXPORTER_TYPES.has(exporterType)) return;
|
|
57
|
-
} else if (!isZeroCodeOtlpActive(appDefinition)) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
34
|
+
if (!OTLP_EXPORTER_TYPES.has(exporterType)) return;
|
|
60
35
|
|
|
61
36
|
// Skip offloaded keys here: baking '${env:KEY, ''}' resolves to '' at
|
|
62
37
|
// deploy (the value lives only in SSM), and '' !== undefined then blocks
|
|
@@ -74,8 +49,7 @@ function addTelemetryEnvPassthrough(appDefinition, envVars) {
|
|
|
74
49
|
// the core default, so it emits no env var.
|
|
75
50
|
function addLoggingEnv(appDefinition, envVars) {
|
|
76
51
|
const level = appDefinition?.logging?.level;
|
|
77
|
-
const normalized =
|
|
78
|
-
level === undefined ? undefined : normalizeLogLevel(level);
|
|
52
|
+
const normalized = level === undefined ? undefined : normalizeLogLevel(level);
|
|
79
53
|
|
|
80
54
|
// serverless-offline copies only AWS_* shell vars into handlers, so under
|
|
81
55
|
// frigg start the shell level must travel through provider.environment.
|