From 17f62c130ea0b1049c576560571140aba5ee8d1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Fri, 15 Mar 2024 16:23:11 +0100 Subject: [PATCH] Fix more lints found by golangci-lint's default config --- agent/actions/ssh.go | 2 +- agent/bitwarden/auth.go | 4 +- agent/bitwarden/http.go | 3 +- .../pinentry/keybase-pinentry/pinentry.go | 3 +- autotype/libportalautotype.go | 83 +++++++++---------- cmd/login.go | 4 +- cmd/logins.go | 5 +- cmd/run.go | 2 +- cmd/send.go | 5 +- cmd/session.go | 2 +- cmd/setup_linux.go | 2 +- cmd/ssh.go | 9 +- 12 files changed, 61 insertions(+), 63 deletions(-) diff --git a/agent/actions/ssh.go b/agent/actions/ssh.go index c373e47..5c1fa97 100644 --- a/agent/actions/ssh.go +++ b/agent/actions/ssh.go @@ -17,7 +17,7 @@ func handleAddSSH(msg messages.IPCMessage, cfg *config.Config, vault *vault.Vaul req := messages.ParsePayload(msg).(messages.CreateSSHKeyRequest) cipher, publicKey := ssh.NewSSHKeyCipher(req.Name, vault.Keyring) - response, err = messages.IPCMessageFromPayload(messages.ActionResponse{ + _, err = messages.IPCMessageFromPayload(messages.ActionResponse{ Success: true, }) if err != nil { diff --git a/agent/bitwarden/auth.go b/agent/bitwarden/auth.go index 213840c..bf35411 100644 --- a/agent/bitwarden/auth.go +++ b/agent/bitwarden/auth.go @@ -162,10 +162,10 @@ func LoginWithMasterpassword(ctx context.Context, email string, cfg *config.Conf return LoginResponseToken{}, crypto.MasterKey{}, "", err } } else if err != nil && strings.Contains(err.Error(), "Captcha required.") { - notify.Notify("Goldwarden", fmt.Sprintf("Captcha required"), "", 0, func() {}) + notify.Notify("Goldwarden", "Captcha required", "", 0, func() {}) return LoginResponseToken{}, crypto.MasterKey{}, "", fmt.Errorf("captcha required, please login via the web interface") } else if err != nil { - notify.Notify("Goldwarden", fmt.Sprintf("Could not login via password: %v", err), "", 0, func() {}) + notify.Notify("Goldwarden", fmt.Sprintf("Could not login via password: %s", err.Error()), "", 0, func() {}) return LoginResponseToken{}, crypto.MasterKey{}, "", fmt.Errorf("could not login via password: %v", err) } diff --git a/agent/bitwarden/http.go b/agent/bitwarden/http.go index 2e6d1a7..3fef11d 100644 --- a/agent/bitwarden/http.go +++ b/agent/bitwarden/http.go @@ -7,7 +7,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "net/url" "strings" @@ -105,7 +104,7 @@ func makeAuthenticatedHTTPRequest(ctx context.Context, req *http.Request, recv i return err } defer res.Body.Close() - body, err := ioutil.ReadAll(res.Body) + body, err := io.ReadAll(res.Body) if err != nil { return err } diff --git a/agent/systemauth/pinentry/keybase-pinentry/pinentry.go b/agent/systemauth/pinentry/keybase-pinentry/pinentry.go index 4d871eb..c2b2608 100644 --- a/agent/systemauth/pinentry/keybase-pinentry/pinentry.go +++ b/agent/systemauth/pinentry/keybase-pinentry/pinentry.go @@ -99,7 +99,7 @@ func (pe *Pinentry) Get(arg keybase1.SecretEntryArg) (res *keybase1.SecretEntryR func (pi *pinentryInstance) Close() { pi.stdin.Close() - pi.cmd.Wait() + _ = pi.cmd.Wait() } type pinentryInstance struct { @@ -123,7 +123,6 @@ func (pi *pinentryInstance) Set(cmd, val string, errp *error) { if string(line) != "OK" { *errp = fmt.Errorf("Response to " + cmd + " was " + string(line)) } - return } func (pi *pinentryInstance) Init() (err error) { diff --git a/autotype/libportalautotype.go b/autotype/libportalautotype.go index b5b5ce6..304a464 100644 --- a/autotype/libportalautotype.go +++ b/autotype/libportalautotype.go @@ -42,50 +42,47 @@ func TypeString(textToType string) { var sessionHandle dbus.ObjectPath for { - select { - case message := <-signals: - if state == 0 { - log.Info("Selecting Devices") - result := message.Body[1].(map[string]dbus.Variant) - resultSessionHandle := result["session_handle"] - sessionHandle = dbus.ObjectPath(resultSessionHandle.String()[1 : len(resultSessionHandle.String())-1]) - res := obj.Call("org.freedesktop.portal.RemoteDesktop.SelectDevices", 0, sessionHandle, map[string]dbus.Variant{ - "types": dbus.MakeVariant(uint32(1)), - }) - if res.Err != nil { - log.Error("Error selecting devices: %s", res.Err.Error()) - } - state = 1 - } else if state == 1 { - log.Info("Starting Session") - res := obj.Call("org.freedesktop.portal.RemoteDesktop.Start", 0, sessionHandle, "", map[string]dbus.Variant{}) - if res.Err != nil { - log.Error("Error starting session: %s", res.Err.Error()) - } - state = 2 - } else if state == 2 { - log.Info("Performing Typing") - state = 3 - time.Sleep(1000 * time.Millisecond) - for _, char := range textToType { - if char == '\t' { - obj.Call("org.freedesktop.portal.RemoteDesktop.NotifyKeyboardKeycode", 0, sessionHandle, map[string]dbus.Variant{}, 15, uint32(1)) - time.Sleep(autoTypeDelay) - obj.Call("org.freedesktop.portal.RemoteDesktop.NotifyKeyboardKeycode", 0, sessionHandle, map[string]dbus.Variant{}, 15, uint32(0)) - time.Sleep(autoTypeDelay) - } else { - obj.Call("org.freedesktop.portal.RemoteDesktop.NotifyKeyboardKeysym", 0, sessionHandle, map[string]dbus.Variant{}, int32(char), uint32(1)) - time.Sleep(autoTypeDelay) - obj.Call("org.freedesktop.portal.RemoteDesktop.NotifyKeyboardKeysym", 0, sessionHandle, map[string]dbus.Variant{}, int32(char), uint32(0)) - time.Sleep(autoTypeDelay) - } - } - bus.Close() - return - } else { - log.Info("State 3") - return + message := <-signals + switch state { + case 0: + log.Info("Selecting Devices") + result := message.Body[1].(map[string]dbus.Variant) + resultSessionHandle := result["session_handle"] + sessionHandle = dbus.ObjectPath(resultSessionHandle.String()[1 : len(resultSessionHandle.String())-1]) + res := obj.Call("org.freedesktop.portal.RemoteDesktop.SelectDevices", 0, sessionHandle, map[string]dbus.Variant{ + "types": dbus.MakeVariant(uint32(1)), + }) + if res.Err != nil { + log.Error("Error selecting devices: %s", res.Err.Error()) } + state = 1 + case 1: + log.Info("Starting Session") + res := obj.Call("org.freedesktop.portal.RemoteDesktop.Start", 0, sessionHandle, "", map[string]dbus.Variant{}) + if res.Err != nil { + log.Error("Error starting session: %s", res.Err.Error()) + } + state = 2 + case 2: + log.Info("Performing Typing") + time.Sleep(1000 * time.Millisecond) + for _, char := range textToType { + if char == '\t' { + obj.Call("org.freedesktop.portal.RemoteDesktop.NotifyKeyboardKeycode", 0, sessionHandle, map[string]dbus.Variant{}, 15, uint32(1)) + time.Sleep(autoTypeDelay) + obj.Call("org.freedesktop.portal.RemoteDesktop.NotifyKeyboardKeycode", 0, sessionHandle, map[string]dbus.Variant{}, 15, uint32(0)) + time.Sleep(autoTypeDelay) + } else { + obj.Call("org.freedesktop.portal.RemoteDesktop.NotifyKeyboardKeysym", 0, sessionHandle, map[string]dbus.Variant{}, int32(char), uint32(1)) + time.Sleep(autoTypeDelay) + obj.Call("org.freedesktop.portal.RemoteDesktop.NotifyKeyboardKeysym", 0, sessionHandle, map[string]dbus.Variant{}, int32(char), uint32(0)) + time.Sleep(autoTypeDelay) + } + } + bus.Close() + return + default: + return } } } diff --git a/cmd/login.go b/cmd/login.go index 9fc53b2..a3dc002 100644 --- a/cmd/login.go +++ b/cmd/login.go @@ -13,7 +13,7 @@ import ( var loginCmd = &cobra.Command{ Use: "login", Short: "Starts the login process for Bitwarden", - Long: `Starts the login process for Bitwarden. + Long: `Starts the login process for Bitwarden. You will be prompted to enter your password, and confirm your second factor if you have one.`, Run: func(cmd *cobra.Command, args []string) { request := messages.DoLoginRequest{} @@ -49,6 +49,6 @@ var loginCmd = &cobra.Command{ func init() { vaultCmd.AddCommand(loginCmd) loginCmd.PersistentFlags().String("email", "", "") - loginCmd.MarkFlagRequired("email") + _ = loginCmd.MarkFlagRequired("email") loginCmd.PersistentFlags().Bool("passwordless", false, "") } diff --git a/cmd/logins.go b/cmd/logins.go index 142f327..b23560e 100644 --- a/cmd/logins.go +++ b/cmd/logins.go @@ -4,6 +4,7 @@ import ( "encoding/json" "errors" "fmt" + "os" "strings" "github.com/icza/gox/stringsx" @@ -17,7 +18,7 @@ var baseLoginCmd = &cobra.Command{ Short: "Commands for managing logins.", Long: `Commands for managing logins.`, Run: func(cmd *cobra.Command, args []string) { - cmd.Help() + _ = cmd.Help() }, } @@ -55,7 +56,7 @@ var getLoginCmd = &cobra.Command{ } else { fmt.Println(response.Result.Password) } - break + return case messages.ActionResponse: fmt.Println("Error: " + resp.(messages.ActionResponse).Message) return diff --git a/cmd/run.go b/cmd/run.go index 381d0c0..e74aca1 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -54,7 +54,7 @@ var runCmd = &cobra.Command{ command.Stdout = os.Stdout command.Stderr = os.Stderr command.Stdin = os.Stdin - command.Run() + _ = command.Run() }, } diff --git a/cmd/send.go b/cmd/send.go index 70673c2..83f61c5 100644 --- a/cmd/send.go +++ b/cmd/send.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "os" "github.com/quexten/goldwarden/ipc/messages" "github.com/spf13/cobra" @@ -12,7 +13,7 @@ var sendCmd = &cobra.Command{ Short: "Commands for managing sends", Long: `Commands for managing sends.`, Run: func(cmd *cobra.Command, args []string) { - cmd.Help() + _ = cmd.Help() }, } @@ -42,7 +43,7 @@ var sendCreateCmd = &cobra.Command{ switch result.(type) { case messages.CreateSendResponse: fmt.Println("Send created: " + result.(messages.CreateSendResponse).URL) - break + return case messages.ActionResponse: fmt.Println("Error: " + result.(messages.ActionResponse).Message) return diff --git a/cmd/session.go b/cmd/session.go index d2a69a2..17b7ae7 100644 --- a/cmd/session.go +++ b/cmd/session.go @@ -23,7 +23,7 @@ var sessionCmd = &cobra.Command{ text = strings.TrimSuffix(text, "\n") args := strings.Split(text, " ") rootCmd.SetArgs(args) - rootCmd.Execute() + _ = rootCmd.Execute() } }, } diff --git a/cmd/setup_linux.go b/cmd/setup_linux.go index bf10d00..844f407 100644 --- a/cmd/setup_linux.go +++ b/cmd/setup_linux.go @@ -181,7 +181,7 @@ var setupCmd = &cobra.Command{ Short: "Sets up Goldwarden integrations", Long: "Sets up Goldwarden integrations", Run: func(cmd *cobra.Command, args []string) { - cmd.Help() + _ = cmd.Help() }, } diff --git a/cmd/ssh.go b/cmd/ssh.go index bf9ba0b..6e3349a 100644 --- a/cmd/ssh.go +++ b/cmd/ssh.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "os" "github.com/atotto/clipboard" "github.com/quexten/goldwarden/ipc/messages" @@ -13,7 +14,7 @@ var sshCmd = &cobra.Command{ Short: "Commands for managing SSH keys", Long: `Commands for managing SSH keys.`, Run: func(cmd *cobra.Command, args []string) { - cmd.Help() + _ = cmd.Help() }, } @@ -52,7 +53,7 @@ var sshAddCmd = &cobra.Command{ panic(err) } } - break + return case messages.ActionResponse: fmt.Println("Error: " + result.(messages.ActionResponse).Message) return @@ -83,7 +84,7 @@ var listSSHCmd = &cobra.Command{ for _, key := range response.Keys { fmt.Println(key) } - break + return case messages.ActionResponse: fmt.Println("Error: " + result.(messages.ActionResponse).Message) return @@ -95,7 +96,7 @@ func init() { rootCmd.AddCommand(sshCmd) sshCmd.AddCommand(sshAddCmd) sshAddCmd.PersistentFlags().String("name", "", "") - sshAddCmd.MarkFlagRequired("name") + _ = sshAddCmd.MarkFlagRequired("name") sshAddCmd.PersistentFlags().Bool("clipboard", false, "Copy the public key to the clipboard") sshCmd.AddCommand(listSSHCmd) }