forked from chrisurwin/aws-spot-instance-helper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
78 lines (72 loc) · 1.74 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"fmt"
"os"
"time"
log "github.com/Sirupsen/logrus"
"github.com/chrisurwin/aws-spot-instance-helper/agent"
"github.com/urfave/cli"
)
//VERSION of the program
var VERSION = "v0.1.0-dev"
func beforeApp(c *cli.Context) error {
if c.GlobalBool("debug") {
log.SetLevel(log.DebugLevel)
}
return nil
}
func main() {
app := cli.NewApp()
app.Name = "aws-spot-instance-helper"
app.Version = VERSION
app.Usage = "Evacuates an AWS Spot Instance host when marked for termination"
app.Action = start
app.Before = beforeApp
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "debug,d",
Usage: "Debug logging",
EnvVar: "DEBUG",
},
cli.DurationFlag{
Name: "poll-interval,i",
Value: 5 * time.Second,
Usage: "Polling interval for checks",
EnvVar: "POLL_INTERVAL",
},
cli.StringFlag{
Name: "cattleURL,u",
Usage: "Cattle URL",
EnvVar: "CATTLE_URL",
},
cli.StringFlag{
Name: "cattleAccessKey,ck",
Usage: "Cattle Access Key",
EnvVar: "CATTLE_ACCESS_KEY",
},
cli.StringFlag{
Name: "cattleSecretKey,cs",
Usage: "Cattle Secret Key",
EnvVar: "CATTLE_SECRET_KEY",
},
cli.StringFlag{
Name: "slackWebhookUrl,s",
Usage: "Slack Webhook URL",
EnvVar: "SLACK_WEBHOOK",
},
}
app.Run(os.Args)
}
func start(c *cli.Context) error {
if c.String("cattleURL") == "" {
return fmt.Errorf("Cattle URL required")
}
if c.String("cattleAccessKey") == "" {
return fmt.Errorf("Cattle Access Key required")
}
if c.String("cattleSecretKey") == "" {
return fmt.Errorf("Cattle Secret Key required")
}
a := agent.NewAgent(c.Duration("poll-interval"), c.String("cattleURL"), c.String("cattleAccessKey"), c.String("cattleSecretKey"), c.String("slackWebhookUrl"))
return a.Start()
}