mirror of
https://github.com/gravitational/teleport.git
synced 2026-10-30 18:29:21 +08:00
Remove direct dependency on github.com/hashicorp/go-version (#43735)
Teleport had 3 dependencies to parse semantic versions: - golang.org/x/mod/semver - github.com/coreos/go-semver/semver - github.com/hashicorp/go-version The last of the three was only used in `integrations/lib.AssertServerVersion` which was a clone of `lib/utils.CheckVersion`. By converting all code in integrations to use `lib/utils.CheckVersion` the direct dependency on github.com/hashicorp/go-version can be dropped. The depguard rules have also been updated to prevent it from sneaking back into the dependency tree. A follow up change will further consolidate semver dependencies to a single package.
This commit is contained in:
@@ -104,6 +104,8 @@ linters-settings:
|
||||
desc: 'experimental project, not to be confused with official Go packages'
|
||||
- pkg: golang.org/x/exp/slices
|
||||
desc: 'use "slices" instead'
|
||||
- pkg: github.com/hashicorp/go-version
|
||||
desc: 'use "golang.org/x/mod/semver" or "coreos/go-semver/semver" instead'
|
||||
# Prevent logrus from being imported by api. Once everything in teleport has been converted
|
||||
# to use log/slog this should be moved into the main block above.
|
||||
logrus:
|
||||
|
||||
@@ -122,7 +122,6 @@ require (
|
||||
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1
|
||||
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0
|
||||
github.com/guptarohit/asciigraph v0.7.1
|
||||
github.com/hashicorp/go-version v1.6.0
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7
|
||||
github.com/icza/mjpeg v0.0.0-20230330134156-38318e5ab8f4
|
||||
github.com/jackc/pgconn v1.14.3
|
||||
@@ -378,6 +377,7 @@ require (
|
||||
github.com/hashicorp/go-multierror v1.1.1 // indirect
|
||||
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
|
||||
github.com/hashicorp/go-uuid v1.0.3 // indirect
|
||||
github.com/hashicorp/go-version v1.6.0 // indirect
|
||||
github.com/hashicorp/hcl v1.0.1-vault-5 // indirect
|
||||
github.com/huandu/xstrings v1.4.0 // indirect
|
||||
github.com/imdario/mergo v0.3.16 // indirect
|
||||
|
||||
@@ -29,6 +29,7 @@ import (
|
||||
"github.com/gravitational/teleport/integrations/access/common/teleport"
|
||||
"github.com/gravitational/teleport/integrations/lib"
|
||||
"github.com/gravitational/teleport/integrations/lib/logger"
|
||||
"github.com/gravitational/teleport/lib/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -96,7 +97,7 @@ func (a *BaseApp) checkTeleportVersion(ctx context.Context) (proto.PingResponse,
|
||||
}
|
||||
return pong, trace.Wrap(err, "Unable to get Teleport server version")
|
||||
}
|
||||
err = lib.AssertServerVersion(pong, minServerVersion)
|
||||
err = utils.CheckVersion(pong.ServerVersion, minServerVersion)
|
||||
return pong, trace.Wrap(err)
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ import (
|
||||
"github.com/gravitational/teleport/integrations/lib"
|
||||
"github.com/gravitational/teleport/integrations/lib/logger"
|
||||
"github.com/gravitational/teleport/integrations/lib/watcherjob"
|
||||
"github.com/gravitational/teleport/lib/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -160,7 +161,7 @@ func (a *App) checkTeleportVersion(ctx context.Context) (proto.PingResponse, err
|
||||
log.Error("Unable to get Teleport server version")
|
||||
return pong, trace.Wrap(err)
|
||||
}
|
||||
err = lib.AssertServerVersion(pong, minServerVersion)
|
||||
err = utils.CheckVersion(pong.ServerVersion, minServerVersion)
|
||||
return pong, trace.Wrap(err)
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ import (
|
||||
"github.com/gravitational/teleport/integrations/lib/backoff"
|
||||
"github.com/gravitational/teleport/integrations/lib/logger"
|
||||
"github.com/gravitational/teleport/integrations/lib/watcherjob"
|
||||
"github.com/gravitational/teleport/lib/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -235,7 +236,7 @@ func (a *App) checkTeleportVersion(ctx context.Context) (proto.PingResponse, err
|
||||
log.Error("Unable to get Teleport server version")
|
||||
return pong, trace.Wrap(err)
|
||||
}
|
||||
err = lib.AssertServerVersion(pong, minServerVersion)
|
||||
err = utils.CheckVersion(pong.ServerVersion, minServerVersion)
|
||||
return pong, trace.Wrap(err)
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ import (
|
||||
pd "github.com/gravitational/teleport/integrations/lib/plugindata"
|
||||
"github.com/gravitational/teleport/integrations/lib/stringset"
|
||||
"github.com/gravitational/teleport/integrations/lib/watcherjob"
|
||||
"github.com/gravitational/teleport/lib/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -227,7 +228,7 @@ func (a *App) checkTeleportVersion(ctx context.Context) (proto.PingResponse, err
|
||||
return pong, trace.Wrap(err)
|
||||
}
|
||||
|
||||
err = lib.AssertServerVersion(pong, minServerVersion)
|
||||
err = utils.CheckVersion(pong.ServerVersion, minServerVersion)
|
||||
|
||||
return pong, trace.Wrap(err)
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ import (
|
||||
"github.com/gravitational/teleport/integrations/lib/backoff"
|
||||
"github.com/gravitational/teleport/integrations/lib/logger"
|
||||
"github.com/gravitational/teleport/integrations/lib/watcherjob"
|
||||
"github.com/gravitational/teleport/lib/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -176,7 +177,7 @@ func (a *App) checkTeleportVersion(ctx context.Context) (proto.PingResponse, err
|
||||
log.Error("Unable to get Teleport server version")
|
||||
return pong, trace.Wrap(err)
|
||||
}
|
||||
err = lib.AssertServerVersion(pong, minServerVersion)
|
||||
err = utils.CheckVersion(pong.ServerVersion, minServerVersion)
|
||||
return pong, trace.Wrap(err)
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ import (
|
||||
"github.com/gravitational/teleport/integrations/lib/backoff"
|
||||
"github.com/gravitational/teleport/integrations/lib/logger"
|
||||
"github.com/gravitational/teleport/integrations/lib/watcherjob"
|
||||
"github.com/gravitational/teleport/lib/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -188,7 +189,7 @@ func (a *App) checkTeleportVersion(ctx context.Context) (proto.PingResponse, err
|
||||
log.Error("Unable to get Teleport server version")
|
||||
return pong, trace.Wrap(err)
|
||||
}
|
||||
err = lib.AssertServerVersion(pong, minServerVersion)
|
||||
err = utils.CheckVersion(pong.ServerVersion, minServerVersion)
|
||||
return pong, trace.Wrap(err)
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ import (
|
||||
"github.com/gravitational/teleport/integrations/lib/backoff"
|
||||
"github.com/gravitational/teleport/integrations/lib/logger"
|
||||
"github.com/gravitational/teleport/integrations/lib/watcherjob"
|
||||
"github.com/gravitational/teleport/lib/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -182,7 +183,7 @@ func (a *App) checkTeleportVersion(ctx context.Context) (proto.PingResponse, err
|
||||
log.Error("Unable to get Teleport server version")
|
||||
return pong, trace.Wrap(err)
|
||||
}
|
||||
err = lib.AssertServerVersion(pong, minServerVersion)
|
||||
err = utils.CheckVersion(pong.ServerVersion, minServerVersion)
|
||||
return pong, trace.Wrap(err)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Teleport
|
||||
* Copyright (C) 2023 Gravitational, Inc.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package lib
|
||||
|
||||
import (
|
||||
"github.com/gravitational/trace"
|
||||
"github.com/hashicorp/go-version"
|
||||
|
||||
"github.com/gravitational/teleport/api/client/proto"
|
||||
)
|
||||
|
||||
// AssertServerVersion returns an error if server version in ping response is
|
||||
// less than minimum required version.
|
||||
func AssertServerVersion(pong proto.PingResponse, minVersion string) error {
|
||||
actual, err := version.NewVersion(pong.ServerVersion)
|
||||
if err != nil {
|
||||
return trace.Wrap(err)
|
||||
}
|
||||
required, err := version.NewVersion(minVersion)
|
||||
if err != nil {
|
||||
return trace.Wrap(err)
|
||||
}
|
||||
if actual.LessThan(required) {
|
||||
return trace.Errorf("server version %s is less than %s", pong.ServerVersion, minVersion)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -38,7 +38,7 @@ import (
|
||||
"google.golang.org/grpc/grpclog"
|
||||
|
||||
"github.com/gravitational/teleport/api/client"
|
||||
"github.com/gravitational/teleport/integrations/lib"
|
||||
"github.com/gravitational/teleport/lib/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -391,7 +391,7 @@ func (p *Provider) checkTeleportVersion(ctx context.Context, client *client.Clie
|
||||
resp.Diagnostics.AddError("Unable to get Teleport server version!", "Unable to get Teleport server version!")
|
||||
return false
|
||||
}
|
||||
err = lib.AssertServerVersion(pong, minServerVersion)
|
||||
err = utils.CheckVersion(pong.ServerVersion, minServerVersion)
|
||||
if err != nil {
|
||||
log.WithError(err).Debug("Teleport version check error!")
|
||||
resp.Diagnostics.AddError("Teleport version check error!", err.Error())
|
||||
|
||||
Reference in New Issue
Block a user