-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.go
105 lines (99 loc) · 2.46 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package main
import (
"os"
"time"
"github.com/seatgeek/aws-dynamic-consul-catalog/service/rds"
cli "gopkg.in/urfave/cli.v1"
)
func main() {
app := cli.NewApp()
app.Name = "consul-aws-catalog"
app.Usage = "Easily maintain AWS RDS information in Consul service catalog"
app.Version = "0.1"
app.Flags = []cli.Flag{
cli.StringSliceFlag{
Name: "instance-filter",
Usage: "AWS filters",
EnvVar: "INSTANCE_FILTER",
},
cli.StringSliceFlag{
Name: "tag-filter",
Usage: "AWS tag filters",
EnvVar: "TAG_FILTER",
},
cli.StringFlag{
Name: "consul-service-prefix",
Usage: "Consul catalog service prefix",
EnvVar: "CONSUL_SERVICE_PREFIX",
Value: "",
},
cli.StringFlag{
Name: "consul-service-suffix",
Usage: "Consul catalog service suffix",
EnvVar: "CONSUL_SERVICE_SUFFIX",
Value: "",
},
cli.StringFlag{
Name: "on-duplicate",
Usage: "What to do if duplicate services/check are found in RDS (e.g. multiple instances with same DB name or consul_service_name tag - and same RDS Replication Role",
EnvVar: "ON_DUPLICATE",
Value: "ignore-skip-last",
},
cli.DurationFlag{
Name: "check-interval",
Usage: "How often to check for RDS changes (eg. 30s, 1h, 1h10m, 1d)",
EnvVar: "CHECK_INTERVAL",
Value: 60 * time.Second,
},
cli.StringFlag{
Name: "log-level",
Usage: "Define log level",
EnvVar: "LOG_LEVEL",
Value: "info",
},
cli.StringFlag{
Name: "log-format",
Usage: "Define log format",
EnvVar: "LOG_FORMAT",
Value: "text",
},
}
app.Commands = []cli.Command{
{
Name: "rds",
Usage: "Run the script",
Flags: []cli.Flag{
cli.StringFlag{
Name: "consul-master-tag",
Usage: "The Consul service tag for master instances",
Value: "master",
EnvVar: "CONSUL_MASTER_TAG",
},
cli.StringFlag{
Name: "consul-replica-tag",
Usage: "The Consul service tag for replica instances",
Value: "replica",
EnvVar: "CONSUL_REPLICA_TAG",
},
cli.StringFlag{
Name: "consul-node-name",
Usage: "Consul catalog node name",
Value: "rds",
EnvVar: "CONSUL_NODE_NAME",
},
cli.DurationFlag{
Name: "rds-tag-cache-time",
Usage: "The time RDS tags should be cached (eg. 30s, 1h, 1h10m, 1d)",
EnvVar: "RDS_TAG_CACHE_TIME",
Value: 30 * time.Minute,
},
},
Action: func(c *cli.Context) error {
app := rds.New(c)
app.Run()
return nil
},
},
}
app.Run(os.Args)
}