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

62 lines
1.4 KiB
Go
Raw Normal View History

2023-07-17 03:23:26 +02:00
package cmd
import (
"os"
2023-08-21 13:52:06 +02:00
"github.com/quexten/goldwarden/agent"
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-08-21 18:37:34 +02:00
"github.com/quexten/goldwarden/ipc"
2023-07-17 03:23:26 +02:00
"github.com/spf13/cobra"
)
2023-08-21 13:52:06 +02:00
var commandClient client.Client
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
2023-08-21 13:52:06 +02:00
goldwardenSingleProcess := os.Getenv("GOLDWARDEN_SINGLE_PROCESS")
if goldwardenSingleProcess == "true" {
2023-08-21 18:37:34 +02:00
recv, send := agent.StartVirtualAgent(runtimeConfig)
2023-08-21 13:52:06 +02:00
commandClient = client.NewVirtualClient(send, recv)
} else {
commandClient = client.NewUnixSocketClient()
}
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" {
_, err = commandClient.SendToAgent(ipc.DoLoginRequest{
Email: runtimeConfig.User,
Password: runtimeConfig.Password,
})
} else if runtimeConfig.AuthMethod == "passwordless" {
_, err = commandClient.SendToAgent(ipc.DoLoginRequest{
Email: runtimeConfig.User,
Passwordless: true,
})
}
return err
}