-
Notifications
You must be signed in to change notification settings - Fork 1
/
pdt
189 lines (177 loc) · 7.45 KB
/
pdt
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#! /bin/bash
# Hello! Welcome to the Pet Diary Tooling or pdt for short!
# This tooling is designed to make the development process a bit easier.
source ./tooling.sh
pdt-help() {
echo " ____ ____ _____ "
echo "| _ \| _ \_ _|"
echo "| |_) | | | || | "
echo "| __/| |_| || | "
echo "|_| |____/ |_| "
echo
echo "Pet Diary Tooling"
echo
echo "Hi, you've found the help page!"
echo "Enter the command 'pdt help' if you wish to see this message again."
echo "You will also see this message anytime you fail to spell a pdt command correctly too."
echo
echo "Usage: pdt [COMMAND]"
echo
echo "COMMANDS:"
# Blue: cloud stuff
echo -e "\033[0;34m"
echo -e "\033[0;34m aws-login"
echo -e "\033[0;34m This logs you in via SSO after selecting a profile from you AWS config"
echo -e "\033[0;34m"
echo -e "\033[0;34m sam-deploy"
echo -e "\033[0;34m This will deploy you application"
echo -e "\033[0;34m"
echo -e "\033[0;34m sam-destroy"
echo -e "\033[0;34m This will tear down the application leaving nothing in AWS"
echo -e "\033[0;34m"
echo -e "\033[0;34m describe-deployment"
echo -e "\033[0;34m This will tell you what you have deplyed in the cloud"
echo -e "\033[0;34m"
echo -e "\033[0;34m lint-sam"
echo -e "\033[0;34m This will validate your SAM template for you, using the alerady available SAM tooling."
# Yellow: Python stuff
echo -e "\033[0;33m"
echo -e "\033[0;33m lint-python"
echo -e "\033[0;33m This will lint your Python code using flake8,"
echo -e "\033[0;33m it will start in the current directory and exclude the venv"
echo -e "\033[0;33m"
echo -e "\033[0;33m test-python"
echo -e "\033[0;33m This will run pytest against the tests/ directory in very verbose mode"
echo -e "\033[0;33m"
echo -e "\033[0;33m coverage-python [OPTION]"
echo -e "\033[0;33m This will generate a test coverage report for you"
echo -e "\033[0;33m OPTIONS:"
echo -e "\033[0;33m html"
echo -e "\033[0;33m - Generates an interactive coverage report and opens it in your browser"
echo -e "\033[0;33m term"
echo -e "\033[0;33m - Generates a tabular output directly to the terminal (handy if you don't have a"
echo -e "\033[0;33m browser)"
# Red: Security stuf
echo -e "\033[0;31m"
echo -e "\033[0;31m security-cloud"
echo -e "\033[0;31m This will run the chekov security scanner against your sam-template"
echo -e "\033[0;31m"
echo -e "\033[0;31m security-libraries"
echo -e "\033[0;31m This will run Grype against the project directory, which will find 3rd party security"
echo -e "\033[0;31m issues. These 3rd party issues will be in imported and installed libraries and such"
echo -e "\033[0;31m"
echo -e "\033[0;31m security-python"
echo -e "\033[0;31m This will run Bandit on the app/ directory. Bandit scans your Python code for secuirty"
echo -e "\033[0;31m issues, it does not check any imported or installed libraries for secuirty flaws though,"
echo -e "\033[0;31m that has to be done with 'pdt third-party-security-check'."
echo -e "\033[0;31m"
echo -e "\033[0;31m security-all"
echo -e "\033[0;31m This will run each of the security checks consecutively and can be redirected into a text"
echo -e "\033[0;31m file to form a security audit report."
echo -e "\033[0;31m The included security checks are:"
echo -e "\033[0;31m - Bandit (for Python code)"
echo -e "\033[0;31m - Checkov (for SAM template)"
echo -e "\033[0;31m - Grype (for 3rd party vulnerabilities)"
# Green: Set-up stuff
echo -e "\033[0;32m"
echo -e "\033[0;32m help"
echo -e "\033[0;32m Shows this message but in the 'less' reader and exits with status 0"
echo -e "\033[0;32m"
echo -e "\033[0;32m activate"
echo -e "\033[0;32m This is just a shortcut for activating your Python Virtual Environment"
echo -e "\033[0;32m"
echo -e "\033[0;32m configure-venv"
echo -e "\033[0;32m This will set up your virtual environment for you, it is the reccomended way to do so"
echo -e "\033[0;32m It can also be used to update your pip packages"
echo -e "\033[0;32m"
echo -e "\033[0;32m aws-add-test-profile"
echo -e "\033[0;32m This simply adds an exra profile to ~/.aws/config. The profile should be broken enough"
echo -e "\033[0;32m that it won't work, but not so broken that botocore will refuse to make the API call."
echo -e "\033[0;32m This test profile is used in certain test scenarios."
echo -e "\033[0;32m"
echo -e "\033[0;32m install-grype"
echo -e "\033[0;32m This will install the security tooling needed for 3rd party dependency checking"
# Purple: Local use stuff
echo -e "\033[0;35m"
echo -e "\033[0;35m subscribe"
echo -e "\033[0;35m This opens up a small script which lets you submit a subscription to one of the SNS"
echo -e "\033[0;35m topics."
echo -e "\033[0;35m - Weekly Reminder"
echo -e "\033[0;35m This topic sends a weekly email to remind you of anything that needs doing in the"
echo -e "\033[0;35m next two weeks (i.e. medicines to administer, vet appointments to keep, etc)."
echo -e "\033[0;35m - Daily Reminder"
echo -e "\033[0;35m This topic sends a text message if and only if there is something to be reminded"
echo -e "\033[0;35m about for that day."
echo -e "\033[0;35m"
echo -e "\033[0;35m db-query"
echo -e "\033[0;35m This opens up a small script which lets you mae simple database queries in lieu of a front end"
}
pdt() {
case "$1" in
"activate")
. ./pet-diary-venv/bin/activate
;;
"aws-login")
aws-login
;;
"aws-add-test-profile")
aws-add-test-profile
;;
"security-cloud")
sam-check
;;
"sam-deploy")
sam-deploy
;;
"sam-destroy")
sam-destroy
;;
"describe-deployment")
describe-deployment
;;
"lint-python")
python-lint
;;
"lint-sam")
sam-validate-template
;;
"test-python")
python-test
;;
"coverage-python")
coverage-python "$2"
;;
"security-python")
python-security-check
;;
"configure-venv")
configure-venv
;;
"security-libraries")
third-party-security-check
;;
"security-all")
full-security-check
;;
"install-grype")
install-anchore-security-tools
;;
"subscribe")
subscribe-to-sns-topic
;;
"db-query")
basic-db-query
;;
"help")
pdt-help | less -R
;;
"alt-help")
pdt-help
;;
*)
echo "Try 'pdt help'"
return 1 # Just to point out that you done biffed it
;;
esac
}
pdt "$1"