Skip to content

Commit

Permalink
Fix more lints found by golangci-lint's default config
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperSandro2000 committed Mar 15, 2024
1 parent 1479d9f commit 17f62c1
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 62 deletions.
2 changes: 1 addition & 1 deletion agent/actions/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions agent/bitwarden/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
3 changes: 1 addition & 2 deletions agent/bitwarden/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"strings"
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions agent/systemauth/pinentry/keybase-pinentry/pinentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down
81 changes: 39 additions & 42 deletions autotype/libportalautotype.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
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
} else {
log.Info("State 3")
return
}
bus.Close()
return
default:
return
}
}
}
4 changes: 2 additions & 2 deletions cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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, "")
}
5 changes: 3 additions & 2 deletions cmd/logins.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"os"
"strings"

"github.com/icza/gox/stringsx"
Expand All @@ -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()
},
}

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ var runCmd = &cobra.Command{
command.Stdout = os.Stdout
command.Stderr = os.Stderr
command.Stdin = os.Stdin
command.Run()
_ = command.Run()
},
}

Expand Down
5 changes: 3 additions & 2 deletions cmd/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
"os"

"github.com/quexten/goldwarden/ipc/messages"
"github.com/spf13/cobra"
Expand All @@ -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()
},
}

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cmd/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var sessionCmd = &cobra.Command{
text = strings.TrimSuffix(text, "\n")
args := strings.Split(text, " ")
rootCmd.SetArgs(args)
rootCmd.Execute()
_ = rootCmd.Execute()
}
},
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/setup_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
},
}

Expand Down
9 changes: 5 additions & 4 deletions cmd/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
"os"

"github.com/atotto/clipboard"
"github.com/quexten/goldwarden/ipc/messages"
Expand All @@ -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()
},
}

Expand Down Expand Up @@ -52,7 +53,7 @@ var sshAddCmd = &cobra.Command{
panic(err)
}
}
break
return
case messages.ActionResponse:
fmt.Println("Error: " + result.(messages.ActionResponse).Message)
return
Expand Down Expand Up @@ -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
Expand All @@ -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)
}

0 comments on commit 17f62c1

Please sign in to comment.