Fix more lints found by golangci-lint's default config

This commit is contained in:
Sandro Jäckel 2024-03-15 16:23:11 +01:00
parent 1479d9f8fd
commit 17f62c130e
No known key found for this signature in database
GPG Key ID: 3AF5A43A3EECC2E5
12 changed files with 61 additions and 63 deletions

View File

@ -17,7 +17,7 @@ func handleAddSSH(msg messages.IPCMessage, cfg *config.Config, vault *vault.Vaul
req := messages.ParsePayload(msg).(messages.CreateSSHKeyRequest) req := messages.ParsePayload(msg).(messages.CreateSSHKeyRequest)
cipher, publicKey := ssh.NewSSHKeyCipher(req.Name, vault.Keyring) cipher, publicKey := ssh.NewSSHKeyCipher(req.Name, vault.Keyring)
response, err = messages.IPCMessageFromPayload(messages.ActionResponse{ _, err = messages.IPCMessageFromPayload(messages.ActionResponse{
Success: true, Success: true,
}) })
if err != nil { if err != nil {

View File

@ -162,10 +162,10 @@ func LoginWithMasterpassword(ctx context.Context, email string, cfg *config.Conf
return LoginResponseToken{}, crypto.MasterKey{}, "", err return LoginResponseToken{}, crypto.MasterKey{}, "", err
} }
} else if err != nil && strings.Contains(err.Error(), "Captcha required.") { } 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") return LoginResponseToken{}, crypto.MasterKey{}, "", fmt.Errorf("captcha required, please login via the web interface")
} else if err != nil { } 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) return LoginResponseToken{}, crypto.MasterKey{}, "", fmt.Errorf("could not login via password: %v", err)
} }

View File

@ -7,7 +7,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"net/url" "net/url"
"strings" "strings"
@ -105,7 +104,7 @@ func makeAuthenticatedHTTPRequest(ctx context.Context, req *http.Request, recv i
return err return err
} }
defer res.Body.Close() defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body) body, err := io.ReadAll(res.Body)
if err != nil { if err != nil {
return err return err
} }

View File

@ -99,7 +99,7 @@ func (pe *Pinentry) Get(arg keybase1.SecretEntryArg) (res *keybase1.SecretEntryR
func (pi *pinentryInstance) Close() { func (pi *pinentryInstance) Close() {
pi.stdin.Close() pi.stdin.Close()
pi.cmd.Wait() _ = pi.cmd.Wait()
} }
type pinentryInstance struct { type pinentryInstance struct {
@ -123,7 +123,6 @@ func (pi *pinentryInstance) Set(cmd, val string, errp *error) {
if string(line) != "OK" { if string(line) != "OK" {
*errp = fmt.Errorf("Response to " + cmd + " was " + string(line)) *errp = fmt.Errorf("Response to " + cmd + " was " + string(line))
} }
return
} }
func (pi *pinentryInstance) Init() (err error) { func (pi *pinentryInstance) Init() (err error) {

View File

@ -42,50 +42,47 @@ func TypeString(textToType string) {
var sessionHandle dbus.ObjectPath var sessionHandle dbus.ObjectPath
for { for {
select { message := <-signals
case message := <-signals: switch state {
if state == 0 { case 0:
log.Info("Selecting Devices") log.Info("Selecting Devices")
result := message.Body[1].(map[string]dbus.Variant) result := message.Body[1].(map[string]dbus.Variant)
resultSessionHandle := result["session_handle"] resultSessionHandle := result["session_handle"]
sessionHandle = dbus.ObjectPath(resultSessionHandle.String()[1 : len(resultSessionHandle.String())-1]) sessionHandle = dbus.ObjectPath(resultSessionHandle.String()[1 : len(resultSessionHandle.String())-1])
res := obj.Call("org.freedesktop.portal.RemoteDesktop.SelectDevices", 0, sessionHandle, map[string]dbus.Variant{ res := obj.Call("org.freedesktop.portal.RemoteDesktop.SelectDevices", 0, sessionHandle, map[string]dbus.Variant{
"types": dbus.MakeVariant(uint32(1)), "types": dbus.MakeVariant(uint32(1)),
}) })
if res.Err != nil { if res.Err != nil {
log.Error("Error selecting devices: %s", res.Err.Error()) 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
} }
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
} }
} }
} }

View File

@ -13,7 +13,7 @@ import (
var loginCmd = &cobra.Command{ var loginCmd = &cobra.Command{
Use: "login", Use: "login",
Short: "Starts the login process for Bitwarden", 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.`, You will be prompted to enter your password, and confirm your second factor if you have one.`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
request := messages.DoLoginRequest{} request := messages.DoLoginRequest{}
@ -49,6 +49,6 @@ var loginCmd = &cobra.Command{
func init() { func init() {
vaultCmd.AddCommand(loginCmd) vaultCmd.AddCommand(loginCmd)
loginCmd.PersistentFlags().String("email", "", "") loginCmd.PersistentFlags().String("email", "", "")
loginCmd.MarkFlagRequired("email") _ = loginCmd.MarkFlagRequired("email")
loginCmd.PersistentFlags().Bool("passwordless", false, "") loginCmd.PersistentFlags().Bool("passwordless", false, "")
} }

View File

@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"os"
"strings" "strings"
"github.com/icza/gox/stringsx" "github.com/icza/gox/stringsx"
@ -17,7 +18,7 @@ var baseLoginCmd = &cobra.Command{
Short: "Commands for managing logins.", Short: "Commands for managing logins.",
Long: `Commands for managing logins.`, Long: `Commands for managing logins.`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
cmd.Help() _ = cmd.Help()
}, },
} }
@ -55,7 +56,7 @@ var getLoginCmd = &cobra.Command{
} else { } else {
fmt.Println(response.Result.Password) fmt.Println(response.Result.Password)
} }
break return
case messages.ActionResponse: case messages.ActionResponse:
fmt.Println("Error: " + resp.(messages.ActionResponse).Message) fmt.Println("Error: " + resp.(messages.ActionResponse).Message)
return return

View File

@ -54,7 +54,7 @@ var runCmd = &cobra.Command{
command.Stdout = os.Stdout command.Stdout = os.Stdout
command.Stderr = os.Stderr command.Stderr = os.Stderr
command.Stdin = os.Stdin command.Stdin = os.Stdin
command.Run() _ = command.Run()
}, },
} }

View File

@ -2,6 +2,7 @@ package cmd
import ( import (
"fmt" "fmt"
"os"
"github.com/quexten/goldwarden/ipc/messages" "github.com/quexten/goldwarden/ipc/messages"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -12,7 +13,7 @@ var sendCmd = &cobra.Command{
Short: "Commands for managing sends", Short: "Commands for managing sends",
Long: `Commands for managing sends.`, Long: `Commands for managing sends.`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
cmd.Help() _ = cmd.Help()
}, },
} }
@ -42,7 +43,7 @@ var sendCreateCmd = &cobra.Command{
switch result.(type) { switch result.(type) {
case messages.CreateSendResponse: case messages.CreateSendResponse:
fmt.Println("Send created: " + result.(messages.CreateSendResponse).URL) fmt.Println("Send created: " + result.(messages.CreateSendResponse).URL)
break return
case messages.ActionResponse: case messages.ActionResponse:
fmt.Println("Error: " + result.(messages.ActionResponse).Message) fmt.Println("Error: " + result.(messages.ActionResponse).Message)
return return

View File

@ -23,7 +23,7 @@ var sessionCmd = &cobra.Command{
text = strings.TrimSuffix(text, "\n") text = strings.TrimSuffix(text, "\n")
args := strings.Split(text, " ") args := strings.Split(text, " ")
rootCmd.SetArgs(args) rootCmd.SetArgs(args)
rootCmd.Execute() _ = rootCmd.Execute()
} }
}, },
} }

View File

@ -181,7 +181,7 @@ var setupCmd = &cobra.Command{
Short: "Sets up Goldwarden integrations", Short: "Sets up Goldwarden integrations",
Long: "Sets up Goldwarden integrations", Long: "Sets up Goldwarden integrations",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
cmd.Help() _ = cmd.Help()
}, },
} }

View File

@ -2,6 +2,7 @@ package cmd
import ( import (
"fmt" "fmt"
"os"
"github.com/atotto/clipboard" "github.com/atotto/clipboard"
"github.com/quexten/goldwarden/ipc/messages" "github.com/quexten/goldwarden/ipc/messages"
@ -13,7 +14,7 @@ var sshCmd = &cobra.Command{
Short: "Commands for managing SSH keys", Short: "Commands for managing SSH keys",
Long: `Commands for managing SSH keys.`, Long: `Commands for managing SSH keys.`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
cmd.Help() _ = cmd.Help()
}, },
} }
@ -52,7 +53,7 @@ var sshAddCmd = &cobra.Command{
panic(err) panic(err)
} }
} }
break return
case messages.ActionResponse: case messages.ActionResponse:
fmt.Println("Error: " + result.(messages.ActionResponse).Message) fmt.Println("Error: " + result.(messages.ActionResponse).Message)
return return
@ -83,7 +84,7 @@ var listSSHCmd = &cobra.Command{
for _, key := range response.Keys { for _, key := range response.Keys {
fmt.Println(key) fmt.Println(key)
} }
break return
case messages.ActionResponse: case messages.ActionResponse:
fmt.Println("Error: " + result.(messages.ActionResponse).Message) fmt.Println("Error: " + result.(messages.ActionResponse).Message)
return return
@ -95,7 +96,7 @@ func init() {
rootCmd.AddCommand(sshCmd) rootCmd.AddCommand(sshCmd)
sshCmd.AddCommand(sshAddCmd) sshCmd.AddCommand(sshAddCmd)
sshAddCmd.PersistentFlags().String("name", "", "") sshAddCmd.PersistentFlags().String("name", "", "")
sshAddCmd.MarkFlagRequired("name") _ = sshAddCmd.MarkFlagRequired("name")
sshAddCmd.PersistentFlags().Bool("clipboard", false, "Copy the public key to the clipboard") sshAddCmd.PersistentFlags().Bool("clipboard", false, "Copy the public key to the clipboard")
sshCmd.AddCommand(listSSHCmd) sshCmd.AddCommand(listSSHCmd)
} }