forked from Luzifer/awsenv
/
cmdUnlock.go
43 lines (35 loc) · 854 Bytes
/
cmdUnlock.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
package main
import (
"fmt"
"github.com/Luzifer/awsenv/security"
log "github.com/Sirupsen/logrus"
"github.com/bgentry/speakeasy"
"github.com/spf13/cobra"
)
func getCmdUnlock() *cobra.Command {
cmd := cobra.Command{
Use: "unlock",
Short: "unlock the database",
Run: actionCmdUnlock,
}
return &cmd
}
func actionCmdUnlock(cmd *cobra.Command, args []string) {
var pwd *security.DatabasePassword
var err error
if len(cfg.Password) > 0 {
pwd = security.LoadDatabasePasswordFromInput(cfg.Password)
} else {
line, err := speakeasy.Ask("Password: ")
if err != nil {
log.Errorln(err)
}
pwd = security.LoadDatabasePasswordFromInput(line)
}
err = pwd.SpawnLockAgent(fmt.Sprintf("%s.lock", cfg.Database))
if err != nil {
log.Errorf("Unable to spawn lockagent: %s", err)
return
}
fmt.Println("Database unlocked.")
}