-
Notifications
You must be signed in to change notification settings - Fork 30
/
commands
executable file
·68 lines (59 loc) · 1.35 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_slack_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
slack:set)
SLACK_ROOT=$(get_slack_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" > "$SLACK_ROOT/SLACK_URL"
;;
slack:clear)
SLACK_ROOT=$(get_slack_root "$2")
rm "$SLACK_ROOT/SLACK_URL"
;;
slack:get)
SLACK_ROOT=$(get_slack_root "$2")
cat "$SLACK_ROOT/SLACK_URL"
;;
help)
HELP=$(cat<<EOF
slack:set [app] <webhook_url>, Set Slack WebHook URL
slack:clear [app], Clears Slack WebHook URL
slack:get [app], Display Slack WebHook URL
EOF
)
if [[ -n $DOKKU_API_VERSION ]]; then
echo "$HELP"
else
cat && echo "$HELP"
fi
;;
*)
exit $DOKKU_NOT_IMPLEMENTED_EXIT
;;
esac