Skip to content

Commit 4af3206

Browse files
committed
Converted CdkNag to 3.0 structures
1 parent b737ddf commit 4af3206

1 file changed

Lines changed: 26 additions & 29 deletions

File tree

labs/unicorn-store/infrastructure/cdk/src/main/java/com/unicorn/UnicornStoreApp.java

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.unicorn;
22

3+
import java.util.Collections;
34
import java.util.List;
45

56
import com.unicorn.alternatives.UnicornAuditService;
@@ -9,11 +10,7 @@
910
import com.unicorn.core.InfrastructureStack;
1011

1112
import io.github.cdklabs.cdknag.AwsSolutionsChecks;
12-
import io.github.cdklabs.cdknag.NagPackSuppression;
13-
import io.github.cdklabs.cdknag.NagSuppressions;
14-
import software.amazon.awscdk.App;
15-
import software.amazon.awscdk.Aspects;
16-
import software.amazon.awscdk.StackProps;
13+
import software.amazon.awscdk.*;
1714

1815
public class UnicornStoreApp {
1916

@@ -41,33 +38,33 @@ public static void main(final String[] args) {
4138

4239
//Add CDK-NAG checks: https://github.com/cdklabs/cdk-nag
4340
//Add suppression to exclude certain findings that are not needed for Workshop environment
44-
Aspects.of(app).add(new AwsSolutionsChecks());
41+
Validations.of(app).addPlugins(new AwsSolutionsChecks());
4542
var suppression = List.of(
46-
new NagPackSuppression.Builder().id("AwsSolutions-APIG4").reason("The workshop environment does not require API-Gateway authorization").build(),
47-
new NagPackSuppression.Builder().id("AwsSolutions-COG4").reason("The workshop environment does not require Cognito User Pool authorization").build(),
48-
new NagPackSuppression.Builder().id("AwsSolutions-RDS3").reason("Workshop environment does not need a Multi-AZ setup to reduce cost").build(),
49-
new NagPackSuppression.Builder().id("AwsSolutions-IAM4").reason("AWS Managed policies are acceptable for the workshop").build(),
50-
new NagPackSuppression.Builder().id("AwsSolutions-IAM5").reason("A wildcard is acceptable for this workshop to allow parallel creation of resources").build(),
51-
new NagPackSuppression.Builder().id("AwsSolutions-RDS10").reason("Workshop environment is ephemeral and the database should be deleted by the end of the workshop").build(),
52-
new NagPackSuppression.Builder().id("AwsSolutions-RDS11").reason("Database is in a private subnet and can use the default port").build(),
53-
new NagPackSuppression.Builder().id("AwsSolutions-APIG2").reason("API Gateway request validation is not needed for workshop").build(),
54-
new NagPackSuppression.Builder().id("AwsSolutions-APIG1").reason("API Gateway access logging not needed for workshop setup").build(),
55-
new NagPackSuppression.Builder().id("AwsSolutions-APIG6").reason("API Gateway access logging not needed for workshop setup").build(),
56-
new NagPackSuppression.Builder().id("AwsSolutions-VPC7").reason("Workshop environment does not need VPC flow logs").build(),
57-
new NagPackSuppression.Builder().id("AwsSolutions-SMG4").reason("Ephemeral workshop environment does not need to rotate secrets").build(),
58-
new NagPackSuppression.Builder().id("AwsSolutions-RDS2").reason("Workshop non-sensitive test database does not need encryption at rest").build(),
59-
new NagPackSuppression.Builder().id("AwsSolutions-APIG3").reason("Workshop API Gateways do not need AWS WAF assigned").build(),
60-
new NagPackSuppression.Builder().id("AwsSolutions-EC23").reason("Not needed").build(),
61-
new NagPackSuppression.Builder().id("AwsSolutions-RDS13").reason("Workshop Database does not need backups").build(),
62-
new NagPackSuppression.Builder().id("CdkNagValidationFailure").reason("Suppress warnings see: https://github.com/cdklabs/cdk-nag/issues/817").build()
43+
new Acknowledgment.Builder().id("AwsSolutions-APIG4").reason("The workshop environment does not require API-Gateway authorization").build(),
44+
new Acknowledgment.Builder().id("AwsSolutions-COG4").reason("The workshop environment does not require Cognito User Pool authorization").build(),
45+
new Acknowledgment.Builder().id("AwsSolutions-RDS3").reason("Workshop environment does not need a Multi-AZ setup to reduce cost").build(),
46+
new Acknowledgment.Builder().id("AwsSolutions-IAM4").reason("AWS Managed policies are acceptable for the workshop").build(),
47+
new Acknowledgment.Builder().id("AwsSolutions-IAM5").reason("A wildcard is acceptable for this workshop to allow parallel creation of resources").build(),
48+
new Acknowledgment.Builder().id("AwsSolutions-RDS10").reason("Workshop environment is ephemeral and the database should be deleted by the end of the workshop").build(),
49+
new Acknowledgment.Builder().id("AwsSolutions-RDS11").reason("Database is in a private subnet and can use the default port").build(),
50+
new Acknowledgment.Builder().id("AwsSolutions-APIG2").reason("API Gateway request validation is not needed for workshop").build(),
51+
new Acknowledgment.Builder().id("AwsSolutions-APIG1").reason("API Gateway access logging not needed for workshop setup").build(),
52+
new Acknowledgment.Builder().id("AwsSolutions-APIG6").reason("API Gateway access logging not needed for workshop setup").build(),
53+
new Acknowledgment.Builder().id("AwsSolutions-VPC7").reason("Workshop environment does not need VPC flow logs").build(),
54+
new Acknowledgment.Builder().id("AwsSolutions-SMG4").reason("Ephemeral workshop environment does not need to rotate secrets").build(),
55+
new Acknowledgment.Builder().id("AwsSolutions-RDS2").reason("Workshop non-sensitive test database does not need encryption at rest").build(),
56+
new Acknowledgment.Builder().id("AwsSolutions-APIG3").reason("Workshop API Gateways do not need AWS WAF assigned").build(),
57+
new Acknowledgment.Builder().id("AwsSolutions-EC23").reason("Not needed").build(),
58+
new Acknowledgment.Builder().id("AwsSolutions-RDS13").reason("Workshop Database does not need backups").build(),
59+
new Acknowledgment.Builder().id("CdkNagValidationFailure").reason("Suppress warnings see: https://github.com/cdklabs/cdk-nag/issues/817").build()
6360
);
6461

65-
NagSuppressions.addStackSuppressions(infrastructureStack, suppression);
66-
NagSuppressions.addStackSuppressions(unicornStoreSpring, suppression);
67-
NagSuppressions.addStackSuppressions(unicornStoreMicronaut, suppression);
68-
NagSuppressions.addStackSuppressions(unicornStoreSpringGraalVM, suppression);
69-
NagSuppressions.addStackSuppressions(unicornStoreQuarkus, suppression);
70-
NagSuppressions.addStackSuppressions(unicornAuditService, suppression);
62+
Validations.of(infrastructureStack).acknowledge(suppression.toArray(new Acknowledgment[0]));
63+
Validations.of(unicornStoreSpring).acknowledge(suppression.toArray(new Acknowledgment[0]));
64+
Validations.of(unicornStoreMicronaut).acknowledge(suppression.toArray(new Acknowledgment[0]));
65+
Validations.of(unicornStoreSpringGraalVM).acknowledge(suppression.toArray(new Acknowledgment[0]));
66+
Validations.of(unicornStoreQuarkus).acknowledge(suppression.toArray(new Acknowledgment[0]));
67+
Validations.of(unicornAuditService).acknowledge(suppression.toArray(new Acknowledgment[0]));
7168

7269
app.synth();
7370
}

0 commit comments

Comments
 (0)