Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: export rules as package #485

Merged
merged 1 commit into from
Nov 24, 2021
Merged

feat: export rules as package #485

merged 1 commit into from
Nov 24, 2021

Conversation

dontirun
Copy link
Collaborator

Related to #482

Examples for rule imports

import { apigw } from 'cdk-nag/lib/rules'
import { rules } from 'cdk-nag';
rules.apigw.APIGWAccessLogging
apigw.APIGWAccessLogging

Example for creating a NagPack with an included rule

import { Stack, App, StackProps, IConstruct, CfnResource, Aspects } from '@aws-cdk/core';
import { Vpc } from '@aws-cdk/aws-ec2';
import { NagMessageLevel, NagPack, NagPackProps, rules } from 'cdk-nag';


class TestPack extends NagPack {
    constructor(props?: NagPackProps) {
        super(props);
        this.packName = 'Test';
    }
    public visit(node: IConstruct): void {
        if (node instanceof CfnResource) {
            this.applyRule({
                info: 'My brief info.',
                explanation: 'My detailed explanation.',
                level: NagMessageLevel.ERROR,
                rule: rules.vpc.VPCDefaultSecurityGroupClosed,
                node: node,
            });
        }
    }
}
export class CdkTestStack extends Stack {
    constructor(scope: App, id: string, props?: StackProps) {
        super(scope, id, props);
        Aspects.of(this).add(new TestPack())
        new Vpc(this, 'rVpc')
    }
}

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

mergify bot pushed a commit that referenced this pull request Nov 24, 2021
Closes #482
See #485  for more details

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@mergify mergify bot merged commit 6ed6783 into main Nov 24, 2021
@mergify mergify bot deleted the feat-v1-rules-package branch November 24, 2021 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant