forked from jezdez/dokku-sentry-webhook
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommands
executable file
·68 lines (59 loc) · 1.38 KB
/
commands
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
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
PLUGIN_BASE_PATH="$PLUGIN_PATH"
if [[ -n $DOKKU_API_VERSION ]]; then
PLUGIN_BASE_PATH="$PLUGIN_ENABLED_PATH"
fi
source "$PLUGIN_BASE_PATH/common/functions"
is_webhook() {
echo "$1" | grep -E '^http[s]?://'
}
get_sentry_root() {
if [[ -z $(is_webhook "$1") ]]; then
verify_app_name "$1"
APP="$1"
echo "$DOKKU_ROOT/$APP"
else
echo "$DOKKU_ROOT"
fi
}
get_webhook() {
if [[ -n $1 && -n $2 ]]; then
echo "$2"
else
echo "$1"
fi
}
case "$1" in
sentry:set)
SENTRY_ROOT=$(get_sentry_root "$2")
WEBHOOK=$(get_webhook "$2" "$3")
[[ -z $WEBHOOK ]] && echo "Please specify at least a webhook URL" && exit 1
[[ -z $(is_webhook "$WEBHOOK") ]] && echo "Webhook has to be an URL" && exit 1
echo "$WEBHOOK" > "$SENTRY_ROOT/SENTRY_URL"
;;
sentry:clear)
SENTRY_ROOT=$(get_sentry_root "$2")
rm "$SENTRY_ROOT/SENTRY_URL"
;;
sentry:get)
SENTRY_ROOT=$(get_sentry_root "$2")
cat "$SENTRY_ROOT/SENTRY_URL"
;;
help)
HELP=$(cat<<EOF
sentry:set [app] <webhook_url>, Set Sentry WebHook URL
sentry:clear [app], Clears Sentry WebHook URL
sentry:get [app], Display Sentry WebHook URL
EOF
)
if [[ -n $DOKKU_API_VERSION ]]; then
echo "$HELP"
else
cat && echo "$HELP"
fi
;;
*)
exit $DOKKU_NOT_IMPLEMENTED_EXIT
;;
esac