diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cae13412..8d281445 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,9 +33,9 @@ jobs: run: go test -v -race -cover -tags full ./... - name: golangci-lint - uses: golangci/golangci-lint-action@v6 + uses: golangci/golangci-lint-action@v8 with: - args: --timeout=60m -E gofmt --verbose --print-resources-usage --build-tags full + args: --timeout=60m --verbose --print-resources-usage --build-tags full -D errcheck env: GOGC: "10" diff --git a/cmd/sshpiperd/asciicast.go b/cmd/sshpiperd/asciicast.go index b4e51381..1b0d2125 100644 --- a/cmd/sshpiperd/asciicast.go +++ b/cmd/sshpiperd/asciicast.go @@ -60,7 +60,8 @@ func newAsciicastLogger(recorddir string, prefix string) *asciicastLogger { } func (l *asciicastLogger) uphook(msg []byte) error { - if msg[0] == msgChannelData { + switch msg[0] { + case msgChannelData: clientChannelID := binary.BigEndian.Uint32(msg[1:5]) f, ok := l.channels[clientChannelID] @@ -74,7 +75,7 @@ func (l *asciicastLogger) uphook(msg []byte) error { return err } } - } else if msg[0] == msgChannelOpenConfirm { + case msgChannelOpenConfirm: clientChannelID := binary.BigEndian.Uint32(msg[1:5]) serverChannelID := binary.BigEndian.Uint32(msg[5:9]) l.channelIDMap[serverChannelID] = clientChannelID diff --git a/cmd/sshpiperd/daemon.go b/cmd/sshpiperd/daemon.go index f61eef3c..711f255c 100644 --- a/cmd/sshpiperd/daemon.go +++ b/cmd/sshpiperd/daemon.go @@ -244,7 +244,9 @@ func (d *daemon) run() error { log.Errorf("cannot create screen recording dir %v: %v", recorddir, err) return } - if d.recordfmt == "asciicast" { + + switch d.recordfmt { + case "asciicast": prefix := "" if d.usernameAsRecorddir { // add prefix to avoid conflict @@ -255,7 +257,7 @@ func (d *daemon) run() error { uphookchain.append(ssh.InspectPacketHook(recorder.uphook)) downhookchain.append(ssh.InspectPacketHook(recorder.downhook)) - } else if d.recordfmt == "typescript" { + case "typescript": recorder, err := newFilePtyLogger(recorddir) if err != nil { log.Errorf("cannot create screen recording logger: %v", err) diff --git a/cmd/sshpiperd/internal/plugin/grpc.go b/cmd/sshpiperd/internal/plugin/grpc.go index d31c9c0e..d052bb1c 100644 --- a/cmd/sshpiperd/internal/plugin/grpc.go +++ b/cmd/sshpiperd/internal/plugin/grpc.go @@ -346,7 +346,7 @@ func (g *GrpcPlugin) createUpstream(conn ssh.ConnMetadata, challengeCtx ssh.Chal caCertificate, ok := caPublicKey.(*ssh.Certificate) if !ok { - return nil, fmt.Errorf("Failed to convert the caPublicKey to an ssh.Certificate") + return nil, fmt.Errorf("failed to convert the caPublicKey to an ssh.Certificate") } private, err = ssh.NewCertSigner(caCertificate, private) diff --git a/cmd/sshpiperd/main.go b/cmd/sshpiperd/main.go index 8e01392a..1f9aa120 100644 --- a/cmd/sshpiperd/main.go +++ b/cmd/sshpiperd/main.go @@ -260,10 +260,7 @@ func main() { args := ctx.Args().Slice() remain := args - for { - if len(remain) <= 0 { - break - } + for len(remain) > 0 { args, remain = splitByDash(remain) diff --git a/cmd/sshpiperd/typescript.go b/cmd/sshpiperd/typescript.go index a29362a5..cd78f485 100644 --- a/cmd/sshpiperd/typescript.go +++ b/cmd/sshpiperd/typescript.go @@ -30,7 +30,7 @@ func newFilePtyLogger(outputdir string) (*filePtyLogger, error) { return nil, err } - _, err = typescript.Write([]byte(fmt.Sprintf("Script started on %v\n", now.Format(time.ANSIC)))) + _, err = fmt.Fprintf(typescript, "Script started on %v\n", now.Format(time.ANSIC)) if err != nil { return nil, err @@ -79,7 +79,7 @@ func (l *filePtyLogger) Close() (err error) { // if _, err = ; err != nil { // return err // } - _, _ = l.typescript.Write([]byte(fmt.Sprintf("Script done on %v\n", time.Now().Format(time.ANSIC)))) + _, _ = fmt.Fprintf(l.typescript, "Script done on %v\n", time.Now().Format(time.ANSIC)) l.typescript.Close() l.timing.Close() diff --git a/e2e/fixed_test.go b/e2e/fixed_test.go index 0a181097..89263b96 100644 --- a/e2e/fixed_test.go +++ b/e2e/fixed_test.go @@ -73,7 +73,7 @@ func TestOldSshd(t *testing.T) { enterPassword(stdin, stdout, "pass") waitForStdoutContains(stdout, "SSHREADY", func(_ string) { - _, _ = stdin.Write([]byte(fmt.Sprintf("%v\n", "triggerping"))) + _, _ = fmt.Fprintf(stdin, "%v\n", "triggerping") }) time.Sleep(time.Second * 3) // wait for file flush diff --git a/e2e/main_test.go b/e2e/main_test.go index 912e5342..4a342959 100644 --- a/e2e/main_test.go +++ b/e2e/main_test.go @@ -108,7 +108,7 @@ func waitForStdoutContains(stdout io.Reader, text string, cb func(string)) { func enterPassword(stdin io.Writer, stdout io.Reader, password string) { waitForStdoutContains(stdout, "'s password", func(_ string) { - _, _ = stdin.Write([]byte(fmt.Sprintf("%v\n", password))) + _, _ = fmt.Fprintf(stdin, "%v\n", password) log.Printf("got password prompt, sending password") }) } diff --git a/libplugin/ioconn/listener.go b/libplugin/ioconn/listener.go index a4f35ddd..28b08578 100644 --- a/libplugin/ioconn/listener.go +++ b/libplugin/ioconn/listener.go @@ -18,7 +18,7 @@ func (l *singleConnListener) Accept() (net.Conn, error) { // Addr implements net.Listener func (l *singleConnListener) Addr() net.Addr { - return l.conn.LocalAddr() + return l.LocalAddr() } // Close implements net.Listener diff --git a/plugin/yaml/yaml.go b/plugin/yaml/yaml.go index fc191b96..f7f37c6b 100644 --- a/plugin/yaml/yaml.go +++ b/plugin/yaml/yaml.go @@ -67,7 +67,7 @@ func (l *listOrString) UnmarshalYAML(value *yaml.Node) error { l.Str = str return nil } - return fmt.Errorf("Failed to unmarshal OneOfType") + return fmt.Errorf("failed to unmarshal OneOfType") } type yamlPipe struct {