-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
110 lines (95 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
package main
import (
"flag"
"fmt"
"os"
)
func usage() {
fmt.Printf("Usage: springboard <subcommand> -s <secrets file> -t <transit key> [args]\n\n")
fmt.Printf("Subcommands:\n")
fmt.Printf(" help display this help screen and exit\n")
fmt.Printf(" set <key> <value> set/encrypt 'value' in local secrets file\n")
fmt.Printf(" get <key> get/decrypt 'value' from local secrets file\n")
fmt.Printf(" remove <key> remove 'key' (and its value) from local secrets file\n")
fmt.Printf(" push <path> publish secrets in local secrets file to\n")
fmt.Printf(" 'path' in vault generic secrets backend\n\n")
fmt.Printf("Flags:\n")
fmt.Printf(" -s string secrets file\n")
fmt.Printf(" -t string transit key\n\n")
fmt.Printf("Examples:\n")
fmt.Printf(" springboard set -s secrets.yml -t my-key user_name supersecret\n")
fmt.Printf(" springboard get -s secrets.yml -t my-key user_name\n")
fmt.Printf(" springboard remove -s secrets.yml -t my-key user_name\n")
fmt.Printf(" springboard push -s secrets.yml -t my-key secret/my-space\n\n")
fmt.Printf("github.com/benschw/springboard\n")
}
func main() {
// flags
f := flag.NewFlagSet("", flag.ExitOnError)
f.Usage = usage
secretsFile := f.String("s", "", "secrets file path")
transitKey := f.String("t", "", "transit key")
if len(os.Args) < 2 {
f.Usage()
os.Exit(2)
}
f.Parse(os.Args[2:])
if *secretsFile == "" || *transitKey == "" {
f.Usage()
os.Exit(2)
}
args := f.Args()
// App
app, err := NewApp(*secretsFile, *transitKey)
if err != nil {
f.Usage()
os.Exit(1)
}
// subcommands
switch os.Args[1] {
case "get":
if len(args) != 1 {
f.Usage()
os.Exit(2)
}
if err := app.get(args[0]); err != nil {
fmt.Println(err)
os.Exit(1)
}
case "set":
if len(args) != 2 {
f.Usage()
os.Exit(2)
}
if err := app.set(args[0], args[1]); err != nil {
fmt.Println(err)
os.Exit(1)
}
case "remove":
if len(args) != 1 {
f.Usage()
os.Exit(2)
}
if err := app.remove(args[0]); err != nil {
fmt.Println(err)
os.Exit(1)
}
case "push":
if len(args) != 1 {
f.Usage()
os.Exit(2)
}
if err := app.push(args[0]); err != nil {
fmt.Println(err)
os.Exit(1)
}
case "help":
f.Usage()
os.Exit(0)
default:
fmt.Printf("%q is not valid command.\n", os.Args[1])
f.Usage()
os.Exit(2)
}
os.Exit(0)
}