-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pre-commit-hook): Use filenames from hook, update api, and add m…
…ore tests #22
- Loading branch information
1 parent
4b60889
commit 5d23c99
Showing
7 changed files
with
218 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
# TODO: Update this to use the release from CFN once merged | ||
repos: | ||
- repo: https://github.com/dannyvassallo/cloudformation-guard | ||
rev: pre-commit-v0.0.62 | ||
rev: pre-commit-v0.0.96 | ||
hooks: | ||
- id: cfn-guard | ||
args: | ||
- validate | ||
- --rules=./guard/resources/validate/rules-dir/ | ||
- --data=./guard/resources/validate/data-dir/ | ||
- "--operation=validate" | ||
- "--rules=guard/resources/validate/rules-dir/" | ||
files: ^guard/resources/validate/data-dir/.* | ||
- id: cfn-guard | ||
args: | ||
- "--operation=test" | ||
- "--dir=pre_commit_hooks_tests/resources/" | ||
files: ^pre_commit_hooks_tests/resources.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,4 @@ | |
language: python | ||
verbose: true | ||
always_run: true | ||
pass_filenames: false | ||
pass_filenames: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
pre_commit_hooks_tests/resources/s3_bucket_logging_enabled.guard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# | ||
##################################### | ||
## Gherkin ## | ||
##################################### | ||
# Rule Identifier: | ||
# S3_BUCKET_LOGGING_ENABLED | ||
# | ||
# Description: | ||
# Checks whether logging is enabled for your S3 buckets. | ||
# | ||
# Reports on: | ||
# AWS::S3::Bucket | ||
# | ||
# Evaluates: | ||
# AWS CloudFormation | ||
# | ||
# Rule Parameters: | ||
# NA | ||
# | ||
# Scenarios: | ||
# a) SKIP: when there are no S3 resource present | ||
# b) PASS: when all S3 resources Logging Configuration exists | ||
# c) FAIL: when all S3 resources have Logging Configuration is not set | ||
# d) SKIP: when metadata includes the suppression for rule S3_BUCKET_LOGGING_ENABLED | ||
|
||
# | ||
# Select all S3 resources from incoming template (payload) | ||
# | ||
|
||
let s3_buckets_bucket_logging_enabled = Resources.*[ Type == 'AWS::S3::Bucket' | ||
Metadata.guard.SuppressedRules not exists or | ||
Metadata.guard.SuppressedRules.* != "S3_BUCKET_LOGGING_ENABLED" | ||
] | ||
|
||
rule S3_BUCKET_LOGGING_ENABLED when %s3_buckets_bucket_logging_enabled !empty { | ||
%s3_buckets_bucket_logging_enabled.Properties.LoggingConfiguration exists | ||
<< | ||
Violation: S3 Bucket Logging needs to be configured to enable logging. | ||
Fix: Set the S3 Bucket property LoggingConfiguration to start logging into S3 bucket. | ||
>> | ||
} |
18 changes: 18 additions & 0 deletions
18
pre_commit_hooks_tests/resources/tests/s3_bucket_logging_enabled_tests.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
### | ||
# S3_BUCKET_LOGGING_ENABLED failing tests | ||
### | ||
--- | ||
- name: S3 Bucket with Logging Configuration missing with suppression, SKIP | ||
input: | ||
Resources: | ||
ExampleS3: | ||
Type: AWS::S3::Bucket | ||
Metadata: | ||
guard: | ||
SuppressedRules: | ||
- S3_BUCKET_LOGGING_ENABLED | ||
Properties: | ||
BucketName: my-bucket | ||
expectations: | ||
rules: | ||
S3_BUCKET_LOGGING_ENABLED: FAIL |
Oops, something went wrong.