/
config.go
87 lines (80 loc) · 1.81 KB
/
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package config
import (
"io"
"log"
"os"
"github.com/urfave/cli"
"github.com/garlsecurity/securepassctl"
"github.com/garlsecurity/securepassctl/spctl/service"
)
// Command holds the config command
var Command = cli.Command{
Name: "config",
Usage: "configure SecurePass",
ArgsUsage: " ",
Description: "Create or update SecurePass configuration.",
Action: ActionConfig,
Flags: []cli.Flag{
cli.StringFlag{
Name: "config, c",
Usage: "Configuration file",
Value: "/etc/securepass.conf",
},
cli.StringFlag{
Name: "appid, i",
Usage: "Application ID",
},
cli.StringFlag{
Name: "endpoint, e",
Usage: "Endpoint URL",
Value: securepassctl.DefaultRemote,
},
cli.StringFlag{
Name: "appsecret, s",
Usage: "App secret",
},
cli.StringFlag{
Name: "realm, r",
Usage: "Default Domain/Realm (and allow NSS login)",
},
cli.StringFlag{
Name: "root",
Usage: "Coma separated list of allowed root users",
},
cli.BoolFlag{
Name: "stdout",
Usage: "Write to stdout instead of file",
},
},
}
// ActionConfig is the config command handler
func ActionConfig(c *cli.Context) {
var writer io.Writer = os.Stdout
if !c.Bool("stdout") {
w, err := os.OpenFile(c.String("config"),
os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
if err != nil {
log.Fatalf("error: %v", err)
}
writer = w
}
s := service.Service
nss := service.NSSSettings
ssh := service.SSHSettings
if c.String("appid") != "" {
s.AppID = c.String("appid")
}
if c.String("endpoint") != "" {
s.Endpoint = c.String("endpoint")
}
if c.String("appsecret") != "" {
s.AppSecret = c.String("appsecret")
}
if c.String("realm") != "" {
nss.Realm = c.String("realm")
}
if c.String("root") != "" {
ssh.Root = c.String("root")
}
service.WriteConfiguration(writer, s, nss, ssh)
}