-
Notifications
You must be signed in to change notification settings - Fork 10
/
main.go
122 lines (101 loc) · 2.39 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package main
import (
"os"
"os/signal"
"strings"
log "github.com/Sirupsen/logrus"
"github.com/calavera/dkvolume"
"github.com/codegangsta/cli"
"github.com/ehazlett/docker-volume-libsecret/version"
"github.com/ehazlett/libsecret/store"
// supported backends
"github.com/ehazlett/libsecret/store/vault"
)
func init() {
log.SetLevel(log.DebugLevel)
// register vault backend
vault.Register()
}
func getStoreOpts(c *cli.Context) map[string]interface{} {
opts := c.StringSlice("store-opt")
data := map[string]interface{}{}
for _, o := range opts {
parts := strings.Split(o, "=")
if len(parts) > 1 {
data[parts[0]] = parts[1]
} else {
data[parts[0]] = ""
}
}
return data
}
func getBackend(b string) store.Backend {
switch b {
case "vault":
return store.VAULT
}
return ""
}
func main() {
app := cli.NewApp()
app.Version = version.FullVersion()
app.Name = "docker-volume-libsecret"
app.Usage = "docker volume driver plugin for libsecret"
app.Author = "@ehazlett"
app.Email = "github.com/ehazlett/docker-volume-libsecret"
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "root, r",
Usage: "root path for volumes",
Value: "/var/lib/docker/volumes/libsecret",
},
cli.StringFlag{
Name: "addr",
Usage: "secret backend addr",
Value: "",
},
cli.StringFlag{
Name: "backend",
Usage: "secret backend",
Value: "",
},
cli.StringSliceFlag{
Name: "store-opt",
Usage: "options to pass to libsecret store (key=val)",
Value: &cli.StringSlice{},
},
}
app.Action = func(c *cli.Context) {
log.Infof("%s v%s", app.Name, app.Version)
rootPath := c.String("root")
backendAddr := c.String("addr")
backendName := c.String("backend")
opts := getStoreOpts(c)
if backendAddr == "" {
log.Fatal("you must specify a backend address")
}
if backendName == "" {
log.Fatal("you must specify a backend type")
}
backend := getBackend(backendName)
log.Debugf("initializing secret driver: backend=%s addr=%s", backend, backendAddr)
d, err := NewSecretDriver(rootPath, backend, backendAddr, opts)
if err != nil {
log.Fatal(err)
}
h := dkvolume.NewHandler(d)
if err := h.ServeUnix("root", "libsecret"); err != nil {
log.Fatal(err)
}
cs := make(chan os.Signal, 1)
signal.Notify(cs, os.Interrupt)
go func() {
for _ = range cs {
// cleanup
}
}()
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}