forked from aws-cloudformation/cloudformation-guard
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
aws-cloudformation#241 First pass at CloudFormation parameter validation
- Loading branch information
1 parent
2a41f44
commit ab42796
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
guard-examples/external-cfn-parameters/check-wellformed-parameters-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,30 @@ | ||
--- | ||
- name: DoesNotApplyToEmptyFiles | ||
input: [] | ||
expectations: | ||
rules: | ||
has_correct_keys: SKIP | ||
- name: FindsRequiredKeys | ||
input: [ | ||
{"ParameterKey": "pIgnore", "ParameterValue": "arn:aws:s3:::bucket_name/key_name"} | ||
] | ||
expectations: | ||
rules: | ||
has_correct_keys: PASS | ||
has_likely_valid_arn: PASS | ||
- name: FindsMalformedArn | ||
input: [ | ||
{"ParameterKey": "pIgnore", "ParameterValue": "arn:aws:foo:bar:baz"} | ||
] | ||
expectations: | ||
rules: | ||
has_correct_keys: PASS | ||
has_likely_valid_arn: FAIL | ||
- name: ChecksForMissingKeys | ||
input: [ | ||
{"ParameterKey": "pIgnore", "ParmeterValue": "arn:aws:s3:::bucket_name/key_name"} | ||
] | ||
expectations: | ||
rules: | ||
has_correct_keys: FAIL | ||
has_likely_valid_arn: SKIP |
20 changes: 20 additions & 0 deletions
20
guard-examples/external-cfn-parameters/check-wellformed-parameters.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,20 @@ | ||
let all_parameters = this[*] | ||
let arn_parameters = this[ParameterValue == /^arn:aws/] | ||
|
||
rule has_correct_keys when %all_parameters !empty { | ||
%all_parameters[*] { | ||
ParameterKey exists | ||
ParameterValue exists | ||
<< Required keys exist >> | ||
} | ||
} | ||
|
||
# Check that parameters that contain an ARN value conform to | ||
# defined ARN format: | ||
# arn:partition:service:region:namespace:relative-id | ||
rule has_likely_valid_arn when %arn_parameters !empty { | ||
%arn_parameters.ParameterValue { | ||
this == /^arn:\w+:\w+:[^:]*:[^:]*:\S+$/ | ||
<< ARN parameter appears valid >> | ||
} | ||
} |