forked from DataDog/dd-asm-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·130 lines (114 loc) · 2.91 KB
/
run.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
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
#!/bin/bash
set -eu
tests=(webgoat benchmark insecure-bank)
basedir=$(dirname "$0")
print_help() {
echo "Usage: $0 start [webgoat|benchmark|insecure-bank]"
echo " $0 stop"
echo " $0 logs"
}
print() {
level=$1
message=$2
message="[$level] $message"
if [ "$level" = "ERROR" ]; then
>&2 echo "$message"
else
echo "$message"
fi
}
wait_for() {
app=$1
url=$2
print "INFO" "$app: Waiting for application to be ready at $url"
curl --silent --no-progress-meter --insecure --fail --head -X GET --retry 24 --retry-all-errors --retry-delay 5 "$url" >/dev/null
print "INFO" "$app: Ready at $url"
}
run_web_goat() {
print "INFO" "WebGoat: Starting application"
docker compose up -d datadog-agent webgoat
wait_for "WebGoat" "http://localhost:8080/WebGoat"
print "INFO" "WebGoat: Logs are available at http://localhost:8181/webgoat/"
print "INFO" "WebGoat: Start navigating the application and watch for vulnerabilities at Datadog"
}
run_benchmark() {
print "INFO" "Benchmark: Starting application"
docker compose up -d datadog-agent benchmark
wait_for "Benchmark" "http://localhost:8181/scorecard/"
print "INFO" "Benchmark: Logs are available at http://localhost:8181/benchmark/"
print "INFO" "Benchmark: Scorecards are available at http://localhost:8181/scorecard/"
print "INFO" "Benchmark: Vulnerabilities should be available at Datadog"
}
run_insecure_bank() {
print "INFO" "Insecure Bank: Starting application"
docker compose up -d datadog-agent insecure-bank
wait_for "Insecure Bank" "http://localhost:8080"
print "INFO" "Insecure Bank: Logs are available at http://localhost:8181/insecure-bank/"
print "INFO" "Insecure Bank: Start navigating the application and watch for vulnerabilities at Datadog"
}
start() {
case $1 in
"${tests[0]}")
run_web_goat
;;
"${tests[1]}")
run_benchmark
;;
"${tests[2]}")
run_insecure_bank
;;
*)
print "ERROR" "Invalid sample '$1' chose one of: ${tests[*]}"
exit 1
;;
esac
}
stop() {
docker compose down
}
logs() {
docker compose logs -f
}
command -v docker >/dev/null 2>&1 || {
print "ERROR" "Please install 'docker' before running the samples.";
exit 1
}
if ! [ -f "$basedir/.env" ]; then
print "ERROR" "Missing .env file, create a new one with the following contents:"
echo "DD_API_KEY=(Required) your API key here"
exit 1
fi
if [ $# -lt 1 ]; then
print "ERROR" "Choose one of the available commands: start, stop, logs"
echo
print_help
exit 1
fi
case $1 in
"start")
if [ $# -lt 2 ]; then
print "ERROR" "Missing sample name, chose one of: ${tests[*]}"
echo
print_help
exit 1
fi
start "$2"
;;
"stop")
stop
;;
"logs")
logs
;;
-h|--help)
print_help
exit 0
;;
*)
print "ERROR" "Invalid command '$1' chose one of: start, stop, logs"
echo
print_help
exit 1
;;
esac
exit 0