-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
55 lines (45 loc) · 1.17 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
package main
import (
"fmt"
"log"
"os"
"os/user"
"github.com/syndtr/goleveldb/leveldb"
"github.com/urfave/cli/v2"
"github.com/zalopay-oss/tokeny/pkg/keyvalue"
"github.com/zalopay-oss/tokeny/pkg/password"
"github.com/zalopay-oss/tokeny/pkg/session"
"github.com/zalopay-oss/tokeny/pkg/tokeny"
"github.com/zalopay-oss/tokeny/pkg/tokenycli"
)
func main() {
usr, err := user.Current()
if err != nil {
log.Fatal(err)
}
dbDir := fmt.Sprintf("%s/.tokeny", usr.HomeDir)
if err := os.MkdirAll(dbDir, os.ModePerm); err != nil {
log.Fatal(err)
}
db, err := leveldb.OpenFile(fmt.Sprintf("%s/ld.db", dbDir), nil)
if err != nil {
log.Fatal(err)
}
defer func() { _ = db.Close() }()
kvStore := keyvalue.NewLevelDBStore(db)
pwdManager := password.NewManager(kvStore)
sessionManager := session.NewManager(kvStore)
tokenRepo := tokeny.NewRepository(kvStore)
cliSvc := tokenycli.NewService(pwdManager, sessionManager, tokenRepo)
app := cli.NewApp()
app.EnableBashCompletion = true
app.Usage = "Another TOTP generator"
err = cliSvc.Register(app)
if err != nil {
log.Fatal(err)
}
if err = app.Run(os.Args); err != nil {
log.SetFlags(0)
log.Println(err.Error())
}
}