Skip to content

Remove github.com/pkg/errors, Go 1.16 CI; bump up go.mod #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
main:
strategy:
matrix:
go-version: [1.16.x, 1.17.x]
go-version: [1.17.x]
platform: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.platform }}
steps:
Expand Down
9 changes: 5 additions & 4 deletions cmd/sshocker/run.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package main

import (
"errors"
"fmt"
"net"
"os/user"
"path/filepath"
Expand All @@ -10,7 +12,6 @@ import (
"github.com/lima-vm/sshocker/pkg/mount"
"github.com/lima-vm/sshocker/pkg/ssh"
"github.com/lima-vm/sshocker/pkg/sshocker"
"github.com/pkg/errors"
"github.com/urfave/cli/v2"
)

Expand Down Expand Up @@ -145,15 +146,15 @@ func parseFlagV(s string) (mount.Mount, error) {
if split[2] == "ro" {
m.Readonly = true
} else {
return m, errors.Errorf("cannot parse %q: unknown option %q", s, split[2])
return m, fmt.Errorf("cannot parse %q: unknown option %q", s, split[2])
}
default:
return m, errors.Errorf("cannot parse %q", s)
return m, fmt.Errorf("cannot parse %q", s)
}
var err error
m.Source, err = expandLocalPath(m.Source)
if err != nil {
return m, errors.Wrapf(err, "cannot use %q", s)
return m, fmt.Errorf("cannot use %q: %w", s, err)
}
return m, nil
}
14 changes: 6 additions & 8 deletions cmd/sshocker/run_p.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"fmt"
"strconv"
"strings"

"github.com/pkg/errors"
)

// parseFlagP parses -p flag, akin to `docker run -p` flags.
Expand All @@ -16,30 +14,30 @@ func parseFlagP(s string) (string, error) {
case 1:
port, err := strconv.Atoi(split[0])
if err != nil {
return "", errors.Errorf("invalid port %q", split[0])
return "", fmt.Errorf("invalid port %q", split[0])
}
return fmt.Sprintf("0.0.0.0:%d:localhost:%d", port, port), nil
case 2:
localPort, err := strconv.Atoi(split[0])
if err != nil {
return "", errors.Errorf("invalid port %q", split[0])
return "", fmt.Errorf("invalid port %q", split[0])
}
remotePort, err := strconv.Atoi(split[1])
if err != nil {
return "", errors.Errorf("invalid port %q", split[1])
return "", fmt.Errorf("invalid port %q", split[1])
}
return fmt.Sprintf("0.0.0.0:%d:localhost:%d", localPort, remotePort), nil
case 3:
localIP := split[0]
localPort, err := strconv.Atoi(split[1])
if err != nil {
return "", errors.Errorf("invalid port %q", split[1])
return "", fmt.Errorf("invalid port %q", split[1])
}
remotePort, err := strconv.Atoi(split[2])
if err != nil {
return "", errors.Errorf("invalid port %q", split[2])
return "", fmt.Errorf("invalid port %q", split[2])
}
return fmt.Sprintf("%s:%d:localhost:%d", localIP, localPort, remotePort), nil
}
return "", errors.Errorf("cannot parse %q, should be [[LOCALIP:]LOCALPORT:]REMOTEPORT", s)
return "", fmt.Errorf("cannot parse %q, should be [[LOCALIP:]LOCALPORT:]REMOTEPORT", s)
}
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ go 1.17

require (
github.com/hashicorp/go-multierror v1.1.1
github.com/pkg/errors v0.9.1
github.com/pkg/sftp v1.13.4
github.com/sirupsen/logrus v1.8.1
github.com/urfave/cli/v2 v2.4.0
Expand All @@ -15,6 +14,6 @@ require (
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/kr/fs v0.1.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
golang.org/x/sys v0.0.0-20210818153620-00dd8d7831e7 // indirect
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd // indirect
golang.org/x/sys v0.0.0-20220317061510-51cd9980dadf // indirect
)
13 changes: 7 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+l
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/kr/fs v0.1.0 h1:Jskdu9ieNAYnjxsi0LbQp1ulIKZV1LAFgK1tWhpZgl8=
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/sftp v1.13.4 h1:Lb0RYJCmgUcBgZosfoi9Y9sbl6+LJgOIgk/2Y4YjMFg=
github.com/pkg/sftp v1.13.4/go.mod h1:LzqnAvaD5TWeNBsZpfKxSYn1MbjWwOsCIAFFJbpIsK8=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand All @@ -27,18 +25,21 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/urfave/cli/v2 v2.4.0 h1:m2pxjjDFgDxSPtO8WSdbndj17Wu2y8vOT86wE/tjr+I=
github.com/urfave/cli/v2 v2.4.0/go.mod h1:NX9W0zmTvedE5oDoOMs2RTC8RvdK98NTYZE5LbaEYPg=
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ=
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd h1:XcWmESyNjXJMLahc3mqVQJcgSTDxFxhETVlfk9uGc38=
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210818153620-00dd8d7831e7 h1:/bmDWM82ZX7TawqxuI8kVjKI0TXHdSY6pHJArewwHtU=
golang.org/x/sys v0.0.0-20210818153620-00dd8d7831e7/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220317061510-51cd9980dadf h1:Fm4IcnUL803i92qDlmB0obyHmosDrxZWxJL3gIeNqOw=
golang.org/x/sys v0.0.0-20220317061510-51cd9980dadf/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down
11 changes: 6 additions & 5 deletions pkg/reversesshfs/reversesshfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package reversesshfs

import (
"bytes"
"errors"
"fmt"
"html/template"
"io"
"os"
Expand All @@ -11,7 +13,6 @@ import (

"github.com/lima-vm/sshocker/pkg/ssh"
"github.com/lima-vm/sshocker/pkg/util"
"github.com/pkg/errors"
"github.com/pkg/sftp"
"github.com/sirupsen/logrus"
)
Expand All @@ -31,7 +32,7 @@ func (rsf *ReverseSSHFS) Prepare() error {
sshBinary := rsf.SSHConfig.Binary()
sshArgs := rsf.SSHConfig.Args()
if !filepath.IsAbs(rsf.RemotePath) {
return errors.Errorf("unexpected relative path: %q", rsf.RemotePath)
return fmt.Errorf("unexpected relative path: %q", rsf.RemotePath)
}
if rsf.Port != 0 {
sshArgs = append(sshArgs, "-p", strconv.Itoa(rsf.Port))
Expand All @@ -42,7 +43,7 @@ func (rsf *ReverseSSHFS) Prepare() error {
logrus.Debugf("executing ssh for preparing sshfs: %s %v", sshCmd.Path, sshCmd.Args)
out, err := sshCmd.CombinedOutput()
if err != nil {
return errors.Wrapf(err, "failed to mkdir %q (remote): %q", rsf.RemotePath, string(out))
return fmt.Errorf("failed to mkdir %q (remote): %q: %w", rsf.RemotePath, string(out), err)
}
return nil
}
Expand All @@ -51,10 +52,10 @@ func (rsf *ReverseSSHFS) Start() error {
sshBinary := rsf.SSHConfig.Binary()
sshArgs := rsf.SSHConfig.Args()
if !filepath.IsAbs(rsf.LocalPath) {
return errors.Errorf("unexpected relative path: %q", rsf.LocalPath)
return fmt.Errorf("unexpected relative path: %q", rsf.LocalPath)
}
if !filepath.IsAbs(rsf.RemotePath) {
return errors.Errorf("unexpected relative path: %q", rsf.RemotePath)
return fmt.Errorf("unexpected relative path: %q", rsf.RemotePath)
}
if rsf.Port != 0 {
sshArgs = append(sshArgs, "-p", strconv.Itoa(rsf.Port))
Expand Down
16 changes: 8 additions & 8 deletions pkg/ssh/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package ssh
import (
"bufio"
"bytes"
"errors"
"fmt"
"os"
"os/exec"
"strconv"
"strings"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -54,7 +55,7 @@ func ExitMaster(host string, port int, c *SSHConfig) error {
logrus.Debugf("executing ssh for exiting the master: %s %v", cmd.Path, cmd.Args)
out, err := cmd.CombinedOutput()
if err != nil {
return errors.Wrapf(err, "failed to execute `%s -O exit -p %d %s`, out=%q", c.Binary(), port, host, string(out))
return fmt.Errorf("failed to execute `%s -O exit -p %d %s`, out=%q: %w", c.Binary(), port, host, string(out), err)
}
return nil
}
Expand All @@ -65,17 +66,17 @@ func ParseScriptInterpreter(script string) (string, error) {
r := bufio.NewReader(strings.NewReader(script))
firstLine, partial, err := r.ReadLine()
if err != nil {
return "", errors.Wrapf(err, "cannot determine interpreter from script %q", script)
return "", fmt.Errorf("cannot determine interpreter from script %q: %w", script, err)
}
if partial {
return "", errors.Errorf("cannot determine interpreter from script %q: cannot read the first line", script)
return "", fmt.Errorf("cannot determine interpreter from script %q: cannot read the first line", script)
}
if !strings.HasPrefix(string(firstLine), "#!") {
return "", errors.Errorf("cannot determine interpreter from script %q: the first line lacks `#!`", script)
return "", fmt.Errorf("cannot determine interpreter from script %q: the first line lacks `#!`", script)
}
interp := strings.TrimPrefix(string(firstLine), "#!")
if interp == "" {
return "", errors.Errorf("cannot determine interpreter from script %q: empty?", script)
return "", fmt.Errorf("cannot determine interpreter from script %q: empty?", script)
}
return interp, nil
}
Expand Down Expand Up @@ -105,8 +106,7 @@ func ExecuteScript(host string, port int, c *SSHConfig, script, scriptName strin
logrus.Debugf("executing ssh for script %q: %s %v", scriptName, sshCmd.Path, sshCmd.Args)
out, err := sshCmd.Output()
if err != nil {
return string(out), stderr.String(), errors.Wrapf(err, "failed to execute script %q: stdout=%q, stderr=%q",
scriptName, string(out), stderr.String())
return string(out), stderr.String(), fmt.Errorf("failed to execute script %q: stdout=%q, stderr=%q: %w", scriptName, string(out), stderr.String(), err)
}
return string(out), stderr.String(), nil
}
11 changes: 6 additions & 5 deletions pkg/sshocker/sshocker.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package sshocker

import (
"errors"
"fmt"
"os"
"os/exec"
"strconv"

"github.com/lima-vm/sshocker/pkg/mount"
"github.com/lima-vm/sshocker/pkg/reversesshfs"
"github.com/lima-vm/sshocker/pkg/ssh"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -56,20 +57,20 @@ func (x *Sshocker) Run() error {
SSHFSAdditionalArgs: x.SSHFSAdditionalArgs,
}
if err := rsf.Prepare(); err != nil {
return errors.Wrapf(err, "failed to prepare mounting %q (local) onto %q (remote)", rsf.LocalPath, rsf.RemotePath)
return fmt.Errorf("failed to prepare mounting %q (local) onto %q (remote): %w", rsf.LocalPath, rsf.RemotePath, err)
}
if err := rsf.Start(); err != nil {
return errors.Wrapf(err, "failed to mount %q (local) onto %q (remote)", rsf.LocalPath, rsf.RemotePath)
return fmt.Errorf("failed to mount %q (local) onto %q (remote): %w", rsf.LocalPath, rsf.RemotePath, err)
}
defer func() {
if cErr := rsf.Close(); cErr != nil {
logrus.WithError(cErr).Warnf("failed to unmount %q (remote)", rsf.RemotePath)
}
}()
case mount.MountTypeInvalid:
return errors.Errorf("invalid mount type %v", m.Type)
return fmt.Errorf("invalid mount type %v", m.Type)
default:
return errors.Errorf("unknown mount type %v", m.Type)
return fmt.Errorf("unknown mount type %v", m.Type)
}
}
defer func() {
Expand Down