forked from ubccr/mokey
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
109 lines (96 loc) · 2.33 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
// Copyright 2015 mokey Authors. All rights reserved.
// Use of this source code is governed by a BSD style
// license that can be found in the LICENSE file.
package main
import (
"fmt"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
"github.com/urfave/cli"
)
func init() {
viper.SetConfigName("mokey")
viper.SetConfigType("yaml")
viper.AddConfigPath("/etc/mokey/")
}
func main() {
app := cli.NewApp()
app.Name = "mokey"
app.Authors = []cli.Author{cli.Author{Name: "Andrew E. Bruno", Email: "[email protected]"}}
app.Usage = "mokey"
app.Version = "0.0.6"
app.Flags = []cli.Flag{
&cli.StringFlag{Name: "conf,c", Usage: "Path to conf file"},
&cli.BoolFlag{Name: "debug,d", Usage: "Print debug messages"},
}
app.Before = func(c *cli.Context) error {
if c.GlobalBool("debug") {
log.SetLevel(log.InfoLevel)
} else {
log.SetLevel(log.WarnLevel)
}
conf := c.GlobalString("conf")
if len(conf) > 0 {
viper.SetConfigFile(conf)
}
err := viper.ReadInConfig()
if err != nil {
return fmt.Errorf("Failed reading config file - %s", err)
}
if !viper.IsSet("enc_key") || !viper.IsSet("auth_key") {
log.Fatal("Please ensure authentication and encryption keys are set")
}
return nil
}
app.Commands = []cli.Command{
{
Name: "server",
Usage: "Run http server",
Action: func(c *cli.Context) {
Server()
},
},
{
Name: "status",
Usage: "Display security question and token status for user",
Flags: []cli.Flag{
&cli.StringFlag{Name: "uid, u", Usage: "User id"},
},
Action: func(c *cli.Context) {
uid := c.String("uid")
if len(uid) == 0 {
log.Fatal("Please provide a user uid")
}
Status(uid)
},
},
{
Name: "resetpw",
Usage: "Send reset password email",
Flags: []cli.Flag{
&cli.StringFlag{Name: "uid, u", Usage: "User id"},
},
Action: func(c *cli.Context) {
uid := c.String("uid")
if len(uid) == 0 {
log.Fatal("Please provide a user uid")
}
ResetPasswordEmail(uid)
},
},
{
Name: "newacct",
Usage: "Send new account email",
Flags: []cli.Flag{
&cli.StringFlag{Name: "uid, u", Usage: "User id"},
},
Action: func(c *cli.Context) {
uid := c.String("uid")
if len(uid) == 0 {
log.Fatal("Please provide a user uid")
}
NewAccountEmail(uid)
},
}}
app.RunAndExitOnError()
}