2023-07-17 03:23:26 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2024-02-08 16:35:07 +01:00
|
|
|
"fmt"
|
2023-07-17 03:23:26 +02:00
|
|
|
"os"
|
|
|
|
|
2023-08-21 18:37:34 +02:00
|
|
|
"github.com/quexten/goldwarden/agent/config"
|
2023-08-21 13:52:06 +02:00
|
|
|
"github.com/quexten/goldwarden/client"
|
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"
|
|
|
|
)
|
|
|
|
|
2024-02-09 00:24:28 +01:00
|
|
|
var commandClient client.UnixSocketClient
|
2023-08-21 18:37:34 +02:00
|
|
|
var runtimeConfig config.RuntimeConfig
|
2023-08-21 13:52:06 +02:00
|
|
|
|
2023-07-17 03:23:26 +02:00
|
|
|
var rootCmd = &cobra.Command{
|
|
|
|
Use: "goldwarden",
|
|
|
|
Short: "OS level integration for Bitwarden",
|
|
|
|
Long: `Goldwarden is a daemon that runs in the background and provides
|
|
|
|
OS level integration for Bitwarden, such as SSH agent integration,
|
|
|
|
biometric unlock, and more.`,
|
|
|
|
}
|
|
|
|
|
2023-08-21 18:37:34 +02:00
|
|
|
func Execute(cfg config.RuntimeConfig) {
|
|
|
|
runtimeConfig = cfg
|
2023-07-17 03:23:26 +02:00
|
|
|
|
2024-02-09 00:24:28 +01:00
|
|
|
commandClient = client.NewUnixSocketClient(&cfg)
|
2023-08-21 13:52:06 +02:00
|
|
|
|
2023-08-21 18:37:34 +02:00
|
|
|
err := rootCmd.Execute()
|
|
|
|
if err != nil {
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2023-07-17 03:23:26 +02:00
|
|
|
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
|
|
|
}
|
2023-08-21 18:37:34 +02:00
|
|
|
|
|
|
|
func loginIfRequired() error {
|
|
|
|
var err error
|
|
|
|
|
|
|
|
if runtimeConfig.AuthMethod == "password" {
|
2023-09-20 03:05:44 +02:00
|
|
|
_, err = commandClient.SendToAgent(messages.DoLoginRequest{
|
2023-08-21 18:37:34 +02:00
|
|
|
Email: runtimeConfig.User,
|
|
|
|
Password: runtimeConfig.Password,
|
|
|
|
})
|
|
|
|
} else if runtimeConfig.AuthMethod == "passwordless" {
|
2023-09-20 03:05:44 +02:00
|
|
|
_, err = commandClient.SendToAgent(messages.DoLoginRequest{
|
2023-08-21 18:37:34 +02:00
|
|
|
Email: runtimeConfig.User,
|
|
|
|
Passwordless: true,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
2023-09-11 22:45:01 +02:00
|
|
|
|
|
|
|
func handleSendToAgentError(err error) {
|
|
|
|
if err != nil {
|
2024-02-08 16:35:07 +01:00
|
|
|
fmt.Println("Error: " + err.Error())
|
|
|
|
fmt.Println("Is the daemon running?")
|
2023-09-11 22:45:01 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|