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

65 lines
1.5 KiB
Go
Raw Permalink Normal View History

2023-07-17 03:23:26 +02:00
package cmd
import (
"fmt"
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 pinCmd = &cobra.Command{
Use: "pin",
Short: "Manage the vault pin",
Long: `Manage the vault pin. The pin is used to unlock the vault.`,
}
var setPinCmd = &cobra.Command{
Use: "set",
Short: "Set a new pin",
Long: `Set a new pin. The pin is used to unlock the vault.`,
Run: func(cmd *cobra.Command, args []string) {
2023-09-20 03:05:44 +02:00
result, err := commandClient.SendToAgent(messages.UpdateVaultPINRequest{})
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 {
fmt.Println("Pin updated")
2023-07-17 03:23:26 +02:00
} else {
fmt.Println("Pin updating failed: " + result.(messages.ActionResponse).Message)
2023-07-17 03:23:26 +02:00
}
default:
fmt.Println("Wrong response type")
2023-07-17 03:23:26 +02:00
}
},
}
var pinStatusCmd = &cobra.Command{
Use: "status",
Short: "Check if a pin is set",
Long: `Check if a pin is set. The pin is used to unlock the vault.`,
Run: func(cmd *cobra.Command, args []string) {
2023-09-20 03:05:44 +02:00
result, err := commandClient.SendToAgent(messages.GetVaultPINRequest{})
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:
fmt.Println("Pin status: " + result.(messages.ActionResponse).Message)
2023-07-17 03:23:26 +02:00
default:
fmt.Println("Wrong response type")
2023-07-17 03:23:26 +02:00
}
},
}
func init() {
vaultCmd.AddCommand(pinCmd)
pinCmd.AddCommand(setPinCmd)
pinCmd.AddCommand(pinStatusCmd)
}