-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
54 lines (46 loc) · 1.07 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
package main
import (
"flag"
"os"
"strings"
"github.com/lucasgomide/snitch/config"
"github.com/lucasgomide/snitch/hook"
"github.com/lucasgomide/snitch/tsuru"
"github.com/lucasgomide/snitch/types"
"github.com/lucasgomide/snitch/utils"
)
var (
appNameContains = flag.String("app-name-contains", "", "Execute webhook if the tsuru app name contains it")
configFilePath = flag.String("c", "", "File path of snitch config")
)
func init() {
flag.Parse()
}
func main() {
if *configFilePath == "" {
utils.LogError("Flag -c is required")
} else {
if *appNameContains != "" && !strings.Contains(os.Getenv("TSURU_APPNAME"), *appNameContains) {
utils.LogError("Tsuru App Name does not contains " + *appNameContains)
} else {
run()
}
}
}
func run() {
err := config.ReadConfigFile(*configFilePath)
if err != nil {
utils.LogError(err.Error())
} else {
var (
h types.Hook
t types.Tsuru
)
t = tsuru.TsuruAPI{
AppToken: os.Getenv("TSURU_APP_TOKEN"),
Host: os.Getenv("TSURU_HOST"),
AppName: os.Getenv("TSURU_APPNAME"),
}
hook.Execute(h, t)
}
}