-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathec2-vuls-config.go
64 lines (55 loc) · 1.4 KB
/
ec2-vuls-config.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
package main
import (
"fmt"
"os"
"gopkg.in/urfave/cli.v1"
)
func main() {
app := cli.NewApp()
app.Name = "ec2-vuls-config"
app.Usage = "Generate Vuls config by filtering the Amazon EC2 information."
app.Author = "Shuichi Ohsawa"
app.Email = "[email protected]"
app.Version = "0.1.0"
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "filters, f",
Usage: "Filter options (default: Name=tag:vuls:scan,Values=true, Name=instance-state-name,Values=running)",
},
cli.StringFlag{
Name: "config, c",
Value: os.Getenv("PWD") + "/config.toml",
Usage: "Config file path",
},
cli.StringFlag{
Name: "out, o",
Value: os.Getenv("PWD") + "/config.toml",
Usage: "Output file path of config",
},
cli.BoolFlag{
Name: "print, p",
Usage: "Echo the standard output instead of write into specified config file.",
},
}
app.Action = func(c *cli.Context) error {
instances, err := DescribeInstances(c.String("filters"))
if err != nil {
return cli.NewExitError(err.Error(), 1)
}
config, err := LoadFile(c.String("config"))
if err != nil {
return cli.NewExitError(err.Error(), 1)
}
new_config := MergeConfig(config, GenerateServerSection(instances))
if c.Bool("print") {
fmt.Println(string(new_config))
} else {
err = WriteFile(c.String("out"), new_config)
if err != nil {
return cli.NewExitError(err.Error(), 1)
}
}
return nil
}
app.Run(os.Args)
}