Skip to content

Commit

Permalink
fix: ensure aspects run for Pipeline stages
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimech committed Jul 15, 2022
1 parent a91e076 commit db2791d
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/identity/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"projen": "^0.58.29"
},
"dependencies": {
"@aws-prototyping-sdk/pdk-nag": "^0.3.9"
"@aws-prototyping-sdk/pdk-nag": "^0.3.11"
},
"keywords": [
"aws",
Expand Down
2 changes: 1 addition & 1 deletion packages/open-api-gateway/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"projen": "^0.58.29"
},
"dependencies": {
"@aws-prototyping-sdk/pdk-nag": "^0.3.9",
"@aws-prototyping-sdk/pdk-nag": "^0.3.11",
"fs-extra": "^10.1.0",
"openapi-types": "^12.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/pipeline/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"projen": "^0.58.29"
},
"dependencies": {
"@aws-prototyping-sdk/pdk-nag": "^0.3.9"
"@aws-prototyping-sdk/pdk-nag": "^0.3.11"
},
"keywords": [
"aws",
Expand Down
15 changes: 14 additions & 1 deletion packages/pipeline/src/pdk-pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
******************************************************************************************************************** */

import { PDKNag } from "@aws-prototyping-sdk/pdk-nag";
import { CfnOutput, RemovalPolicy, Stack } from "aws-cdk-lib";
import { Aspects, CfnOutput, RemovalPolicy, Stack, Stage } from "aws-cdk-lib";
import { Repository } from "aws-cdk-lib/aws-codecommit";
import { Pipeline } from "aws-cdk-lib/aws-codepipeline";
import {
Expand All @@ -24,11 +24,13 @@ import {
BucketEncryption,
} from "aws-cdk-lib/aws-s3";
import {
AddStageOpts,
CodePipeline,
CodePipelineProps,
CodePipelineSource,
ShellStep,
ShellStepProps,
StageDeployment,
} from "aws-cdk-lib/pipelines";
import { NagSuppressions } from "cdk-nag";
import { Construct } from "constructs";
Expand Down Expand Up @@ -175,6 +177,17 @@ export class PDKPipeline extends CodePipeline {
});
}

/**
* @inheritDoc
*/
addStage(stage: Stage, options?: AddStageOpts): StageDeployment {
// Add any root Aspects to the stage level as currently this doesn't happen automatically
Aspects.of(stage.node.root).all.forEach((aspect) =>
Aspects.of(stage).add(aspect)
);
return super.addStage(stage, options);
}

buildPipeline() {
super.buildPipeline();

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions packages/pipeline/test/pdk-pipeline.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import * as path from "path";
import { PDKNag } from "@aws-prototyping-sdk/pdk-nag";
import { Stack, Stage } from "aws-cdk-lib";
import { Template } from "aws-cdk-lib/assertions";
import { Bucket } from "aws-cdk-lib/aws-s3";
import { Asset } from "aws-cdk-lib/aws-s3-assets";
import { PDKPipeline } from "../src";

Expand Down Expand Up @@ -49,4 +50,34 @@ describe("PDK Pipeline Unit Tests", () => {

expect(Template.fromStack(stack)).toMatchSnapshot();
});

it("StageNagRuns", () => {
const app = PDKNag.app({ failOnError: false });
const stack = new Stack(app);

const pipeline = new PDKPipeline(stack, "StageNagRuns", {
primarySynthDirectory: "cdk.out",
repositoryName: "StageNagRuns",
synth: {},
sonarCodeScannerConfig: {
sonarqubeAuthorizedGroup: "dev",
sonarqubeDefaultProfileOrGateName: "dev",
sonarqubeEndpoint: "https://sonar.dev",
sonarqubeProjectName: "Default",
},
});

const stage = new Stage(app, "Stage");
const appStack = new Stack(stage, "AppStack");
new Bucket(appStack, "Non-Compliant");

pipeline.addStage(stage);
pipeline.buildPipeline();

app.synth();

expect(app.nagResults()[0].resource).toEqual(
"Stage/AppStack/Non-Compliant/Resource"
);
});
});
2 changes: 1 addition & 1 deletion packages/static-website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"projen": "^0.58.29"
},
"dependencies": {
"@aws-prototyping-sdk/pdk-nag": "^0.3.9"
"@aws-prototyping-sdk/pdk-nag": "^0.3.11"
},
"keywords": [
"aws",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit db2791d

Please sign in to comment.