goldwarden/cmd/pin.go

63 lines
1.5 KiB
Go
Raw Normal View History

2023-07-17 04:23:26 +03:00
package cmd
import (
2023-09-20 04:05:44 +03:00
"github.com/quexten/goldwarden/ipc/messages"
2023-07-17 04:23:26 +03: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 04:05:44 +03:00
result, err := commandClient.SendToAgent(messages.UpdateVaultPINRequest{})
2023-07-17 04:23:26 +03:00
if err != nil {
2023-09-11 23:45:01 +03:00
handleSendToAgentError(err)
2023-07-17 04:23:26 +03:00
return
}
switch result.(type) {
2023-09-20 04:05:44 +03:00
case messages.ActionResponse:
if result.(messages.ActionResponse).Success {
2023-07-17 04:23:26 +03:00
println("Pin updated")
} else {
2023-09-20 04:05:44 +03:00
println("Pin updating failed: " + result.(messages.ActionResponse).Message)
2023-07-17 04:23:26 +03:00
}
default:
println("Wrong response type")
}
},
}
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 04:05:44 +03:00
result, err := commandClient.SendToAgent(messages.GetVaultPINRequest{})
2023-07-17 04:23:26 +03:00
if err != nil {
2023-09-11 23:45:01 +03:00
handleSendToAgentError(err)
2023-07-17 04:23:26 +03:00
return
}
switch result.(type) {
2023-09-20 04:05:44 +03:00
case messages.ActionResponse:
println("Pin status: " + result.(messages.ActionResponse).Message)
2023-07-17 04:23:26 +03:00
default:
println("Wrong response type")
}
},
}
func init() {
vaultCmd.AddCommand(pinCmd)
pinCmd.AddCommand(setPinCmd)
pinCmd.AddCommand(pinStatusCmd)
}