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

#241 First pass at CloudFormation parameter validation #242

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
- name: DoesNotApplyToEmptyFiles
input: []
expectations:
rules:
has_correct_keys: SKIP
has_likely_valid_arn: 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: FindsUnsupportedKeys
input: [
{"ParameterKey": "pIgnore", "ParameterValue": "whatever", "UsePreviousValue": "true"}
]
expectations:
rules:
has_correct_keys: FAIL
has_likely_valid_arn: SKIP
- 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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 >>
UsePreviousValue not exists
ResolvedValue not exists
}
}

# 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 >>
}
}