-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathlint.sh
executable file
·86 lines (66 loc) · 1.75 KB
/
lint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
# Custom prompt messages
source ./prompt
# Check command error codes and add info to report summary
report() {
if [[ $? -eq 0 ]]
then
success "$1 linting looks good!" >> report.txt
else
fail "$1 linting failed! Please check the logs for more info." >> report.txt
fi
}
linebreak() {
echo ''
}
# Check the repo pattern content against our defined schemas
lintContent() {
info "Linting content";
node ./lint/lint.js
report 'Pattern content'
}
# Lint CloudFormation templates
cfnLint() {
linebreak
info "Linting CloudFormation"
linebreak
# Install latest release of cfn-lint
if ! command -v cfn-lint &> /dev/null
then
pip install cfn-lint
success 'cfn-lint installed successfully!' >> report.txt
fi
# Check for common CloudFormation issues according
# to the rules in .cfnlintrc.yml
cfn-lint -f pretty
report 'CloudFormation'
}
# Check CloudFormation templates against defined policy
cfnPolicyCheck() {
linebreak
info "Checking CloudFormation against policy as code rules"
linebreak
# Install latest release of cfn-guard
if ! command -v ~/.guard/bin/cfn-guard &> /dev/null
then
curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/aws-cloudformation/cloudformation-guard/main/install-guard.sh | sh
success "cfn-guard installed successfully!" >> report.txt
fi
# Validate CFN files against included policy as code rules
~/.guard/bin/cfn-guard validate --data ./pattern/**/files/*.yml --rules ./lint/guard
report 'CloudFormation policy'
}
# Call functions
lintContent
cfnLint
cfnPolicyCheck
# Print summary report
cat report.txt
# Cleanup summary report
if grep -q "FAIL" report.txt
then
rm -rf report.txt
exit 1
else
rm -rf report.txt
fi