goldwarden-vaultwarden-bitw.../cmd/vault.go

98 lines
2.2 KiB
Go
Raw Normal View History

2023-07-17 03:23:26 +02:00
package cmd
import (
2023-09-20 03:05:44 +02:00
"github.com/quexten/goldwarden/ipc/messages"
2023-07-17 03:23:26 +02:00
"github.com/spf13/cobra"
)
var vaultCmd = &cobra.Command{
Use: "vault",
Short: "Manage the vault",
Long: `Manage the vault.`,
}
var unlockCmd = &cobra.Command{
Use: "unlock",
Short: "Unlocks the vault",
Long: `Unlocks the vault. You will be prompted for your pin. The pin is empty by default.`,
Run: func(cmd *cobra.Command, args []string) {
2023-09-20 03:05:44 +02:00
request := messages.UnlockVaultRequest{}
2023-07-17 03:23:26 +02:00
2023-08-21 13:52:06 +02:00
result, err := commandClient.SendToAgent(request)
2023-07-17 03:23:26 +02:00
if err != nil {
2023-09-11 22:45:01 +02:00
handleSendToAgentError(err)
2023-07-17 03:23:26 +02:00
return
}
switch result.(type) {
2023-09-20 03:05:44 +02:00
case messages.ActionResponse:
if result.(messages.ActionResponse).Success {
2023-07-17 03:23:26 +02:00
println("Unlocked")
} else {
2023-09-20 03:05:44 +02:00
println("Not unlocked: " + result.(messages.ActionResponse).Message)
2023-07-17 03:23:26 +02:00
}
default:
println("Wrong response type")
}
},
}
var lockCmd = &cobra.Command{
Use: "lock",
Short: "Locks the vault",
Long: `Locks the vault.`,
Run: func(cmd *cobra.Command, args []string) {
2023-09-20 03:05:44 +02:00
request := messages.LockVaultRequest{}
2023-07-17 03:23:26 +02:00
2023-08-21 13:52:06 +02:00
result, err := commandClient.SendToAgent(request)
2023-07-17 03:23:26 +02:00
if err != nil {
2023-09-11 22:45:01 +02:00
handleSendToAgentError(err)
2023-07-17 03:23:26 +02:00
return
}
switch result.(type) {
2023-09-20 03:05:44 +02:00
case messages.ActionResponse:
if result.(messages.ActionResponse).Success {
2023-07-17 03:23:26 +02:00
println("Locked")
} else {
2023-09-20 03:05:44 +02:00
println("Not locked: " + result.(messages.ActionResponse).Message)
2023-07-17 03:23:26 +02:00
}
default:
println("Wrong response type")
}
},
}
var purgeCmd = &cobra.Command{
Use: "purge",
Short: "Wipes the vault",
Long: `Wipes the vault and encryption keys from ram and config. Does not delete any entries on the server side.`,
Run: func(cmd *cobra.Command, args []string) {
2023-09-20 03:05:44 +02:00
request := messages.WipeVaultRequest{}
2023-07-17 03:23:26 +02:00
2023-08-21 13:52:06 +02:00
result, err := commandClient.SendToAgent(request)
2023-07-17 03:23:26 +02:00
if err != nil {
2023-09-11 22:45:01 +02:00
handleSendToAgentError(err)
2023-07-17 03:23:26 +02:00
return
}
switch result.(type) {
2023-09-20 03:05:44 +02:00
case messages.ActionResponse:
if result.(messages.ActionResponse).Success {
2023-07-17 03:23:26 +02:00
println("Purged")
} else {
2023-09-20 03:05:44 +02:00
println("Not purged: " + result.(messages.ActionResponse).Message)
2023-07-17 03:23:26 +02:00
}
default:
println("Wrong response type")
}
},
}
func init() {
rootCmd.AddCommand(vaultCmd)
vaultCmd.AddCommand(unlockCmd)
vaultCmd.AddCommand(lockCmd)
vaultCmd.AddCommand(purgeCmd)
}