Skip to content

Commit 9b7d4de

Browse files
committed
check semver compatibility for installed wsh
1 parent 002e964 commit 9b7d4de

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ require (
6363
go.opentelemetry.io/otel/metric v1.29.0 // indirect
6464
go.opentelemetry.io/otel/trace v1.29.0 // indirect
6565
go.uber.org/atomic v1.7.0 // indirect
66+
golang.org/x/mod v0.22.0 // indirect
6667
golang.org/x/net v0.33.0 // indirect
6768
golang.org/x/oauth2 v0.24.0 // indirect
6869
golang.org/x/sync v0.10.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
133133
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
134134
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
135135
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
136+
golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4=
137+
golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
136138
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
137139
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
138140
golang.org/x/oauth2 v0.24.0 h1:KTBBxWqUa0ykRPLtV69rRto9TLXcqYkeswu48x/gvNE=

pkg/remote/conncontroller/conncontroller.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"github.com/wavetermdev/waveterm/pkg/wshrpc"
3434
"github.com/wavetermdev/waveterm/pkg/wshutil"
3535
"golang.org/x/crypto/ssh"
36+
"golang.org/x/mod/semver"
3637
)
3738

3839
const (
@@ -315,9 +316,9 @@ func (conn *SSHConn) CheckAndInstallWsh(ctx context.Context, clientDisplayName s
315316
return fmt.Errorf("client is nil")
316317
}
317318
// check that correct wsh extensions are installed
318-
expectedVersion := fmt.Sprintf("wsh v%s", wavebase.WaveVersion)
319+
expectedVersion := fmt.Sprintf("v%s", wavebase.WaveVersion)
319320
clientVersion, err := remote.GetWshVersion(client)
320-
if err == nil && clientVersion == expectedVersion && !opts.Force {
321+
if err == nil && !opts.Force && semver.Compare(clientVersion, expectedVersion) >= 0 {
321322
return nil
322323
}
323324
var queryText string

pkg/remote/connutil.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/wavetermdev/waveterm/pkg/util/shellutil"
2121
"github.com/wavetermdev/waveterm/pkg/wavebase"
2222
"golang.org/x/crypto/ssh"
23+
"golang.org/x/mod/semver"
2324
)
2425

2526
var userHostRe = regexp.MustCompile(`^([a-zA-Z0-9][a-zA-Z0-9._@\\-]*@)?([a-zA-Z0-9][a-zA-Z0-9.-]*)(?::([0-9]+))?$`)
@@ -54,6 +55,7 @@ func DetectShell(client *ssh.Client) (string, error) {
5455
return fmt.Sprintf(`"%s"`, strings.TrimSpace(string(out))), nil
5556
}
5657

58+
// returns a valid semver version string
5759
func GetWshVersion(client *ssh.Client) (string, error) {
5860
wshPath := GetWshPath(client)
5961

@@ -66,8 +68,17 @@ func GetWshVersion(client *ssh.Client) (string, error) {
6668
if err != nil {
6769
return "", err
6870
}
69-
70-
return strings.TrimSpace(string(out)), nil
71+
// output is expected to be in the form of "wsh v0.10.4"
72+
// should strip off the "wsh" prefix, and return a semver object
73+
fields := strings.Fields(strings.TrimSpace(string(out)))
74+
if len(fields) != 2 {
75+
return "", fmt.Errorf("unexpected output from wsh version: %s", out)
76+
}
77+
wshVersion := strings.TrimSpace(fields[1])
78+
if !semver.IsValid(wshVersion) {
79+
return "", fmt.Errorf("invalid semver version: %s", wshVersion)
80+
}
81+
return wshVersion, nil
7182
}
7283

7384
func GetWshPath(client *ssh.Client) string {

0 commit comments

Comments
 (0)