forked from harbur/kubebot
-
Notifications
You must be signed in to change notification settings - Fork 20
/
main.go
55 lines (45 loc) · 1.32 KB
/
main.go
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
package main
import (
"errors"
"fmt"
"os"
"github.com/go-chat-bot/bot/slack"
)
const (
slackTokenLabel string = "KUBEBOT_SLACK_TOKEN"
slackChannelsLabel string = "KUBEBOT_SLACK_CHANNELS_IDS"
slackAdminsLabel string = "KUBEBOT_SLACK_ADMINS_NICKNAMES"
slackCommandsLabel string = "KUBEBOT_SLACK_VALID_COMMANDS"
notDefinedErrorMessage string = "%s env variable not defined"
)
var (
kb *Kubebot
)
func validateEnvParams() error {
if os.Getenv(slackTokenLabel) == "" {
return errors.New(fmt.Sprintf(notDefinedErrorMessage, slackTokenLabel))
}
if os.Getenv(slackChannelsLabel) == "" {
return errors.New(fmt.Sprintf(notDefinedErrorMessage, slackChannelsLabel))
}
if os.Getenv(slackAdminsLabel) == "" {
return errors.New(fmt.Sprintf(notDefinedErrorMessage, slackAdminsLabel))
}
if os.Getenv(slackCommandsLabel) == "" {
return errors.New(fmt.Sprintf(notDefinedErrorMessage, slackCommandsLabel))
}
return nil
}
func main() {
if err := validateEnvParams(); err != nil {
fmt.Printf("Kubebot cannot run. Error: %s\n", err.Error())
return
}
kb = &Kubebot{
token: os.Getenv(slackTokenLabel),
admins: stringToMap(os.Getenv(slackAdminsLabel), " "),
channels: stringToMap(os.Getenv(slackChannelsLabel), " "),
commands: stringToMap(os.Getenv(slackCommandsLabel), " "),
}
slack.Run(kb.token)
}