forked from lmars/dokku-slack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands
executable file
·78 lines (62 loc) · 1.52 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
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$(dirname $0)/../common/functions"
main() {
case "$1" in
slack:enable)
slack_enable "$2" "$3"
;;
slack:disable)
slack_disable "$2"
;;
slack:info)
slack_info "$2"
;;
help)
slack_usage
;;
esac
}
slack_usage() {
cat >&2 <<USAGE
slack:enable <app> <webhook> Enable Slack notifications for app.
slack:disable <app> Disable Slack notifications for app.
slack:info <app> Print Slack notification settings for app.
USAGE
}
slack_enable() {
local app="$1"
local webhook="$2"
if [[ -z "${app}" ]] || [[ -z "${webhook}" ]]; then
slack_usage
exit 1
fi
verify_app_name "${app}"
dokku_log_info1 "Enabling Slack notifications for ${app}"
echo "${webhook}" > "${DOKKU_ROOT}/${app}/SLACK_WEBHOOK"
}
slack_disable() {
local app="$1"
if [[ -z "${app}" ]]; then
slack_usage
exit 1
fi
verify_app_name "${app}"
dokku_log_info1 "Disabling Slack notifications for ${app}"
rm -f "${DOKKU_ROOT}/${app}/SLACK_WEBHOOK"
}
slack_info() {
local app="$1"
if [[ -z "${app}" ]]; then
slack_usage
exit 1
fi
verify_app_name "${app}"
local file="${DOKKU_ROOT}/${app}/SLACK_WEBHOOK"
if [[ -s "${file}" ]]; then
dokku_log_info1 "Slack notifications enabled for ${app} (webhook: $(cat "${file}"))"
else
dokku_log_info1 "Slack notifications disabled for ${app}"
fi
}
main $@