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

55 lines
1.3 KiB
Go
Raw Normal View History

2023-07-17 03:23:26 +02:00
/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
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 loginCmd = &cobra.Command{
Use: "login",
Short: "Starts the login process for Bitwarden",
Long: `Starts the login process for Bitwarden.
2023-07-17 03:23:26 +02:00
You will be prompted to enter your password, and confirm your second factor if you have one.`,
Run: func(cmd *cobra.Command, args []string) {
2023-09-20 03:05:44 +02:00
request := messages.DoLoginRequest{}
2023-07-17 03:23:26 +02:00
email, _ := cmd.Flags().GetString("email")
2023-09-11 22:45:01 +02:00
if email == "" {
fmt.Println("Error: No email specified")
2023-09-11 22:45:01 +02:00
return
}
2023-07-17 03:23:26 +02:00
request.Email = email
2023-08-21 13:52:06 +02:00
passwordless, _ := cmd.Flags().GetBool("passwordless")
request.Passwordless = passwordless
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 {
fmt.Println("Logged in")
2023-07-17 03:23:26 +02:00
} else {
fmt.Println("Login failed: " + result.(messages.ActionResponse).Message)
2023-07-17 03:23:26 +02:00
}
default:
fmt.Println("Wrong IPC response type for login")
2023-07-17 03:23:26 +02:00
}
},
}
func init() {
vaultCmd.AddCommand(loginCmd)
loginCmd.PersistentFlags().String("email", "", "")
_ = loginCmd.MarkFlagRequired("email")
2023-08-21 13:52:06 +02:00
loginCmd.PersistentFlags().Bool("passwordless", false, "")
2023-07-17 03:23:26 +02:00
}