diff --git a/.golangci.yml b/.golangci.yml index e2d6e2c48d074..a8d235807902d 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -58,6 +58,10 @@ linters-settings: desc: 'use "github.com/sirupsen/logrus" instead' - pkg: go.uber.org/atomic desc: 'use "sync/atomic" instead' + - pkg: golang.design + desc: 'experimental project, not to be confused with official Go packages' + - pkg: github.com/hashicorp/go-version + desc: 'use "golang.org/x/mod/semver" or "coreos/go-semver/semver" instead' gci: sections: - standard # Standard section: captures all standard packages. diff --git a/go.mod b/go.mod index e34d5cea17a59..eb598819a3943 100644 --- a/go.mod +++ b/go.mod @@ -108,7 +108,6 @@ require ( github.com/gravitational/ttlmap v0.0.0-20171116003245-91fd36b9004c github.com/grpc-ecosystem/go-grpc-middleware/providers/openmetrics/v2 v2.0.0-rc.3 github.com/guptarohit/asciigraph v0.5.6 - github.com/hashicorp/go-version v1.6.0 github.com/hashicorp/golang-lru/v2 v2.0.6 github.com/icza/mjpeg v0.0.0-20220812133530-f79265a232f2 github.com/jackc/pgconn v1.14.3 @@ -332,6 +331,7 @@ require ( github.com/hashicorp/go-cleanhttp v0.5.2 // 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.3.3 // indirect github.com/imdario/mergo v0.3.16 // indirect diff --git a/integrations/access/common/app.go b/integrations/access/common/app.go index f100710de9ffb..6aa463272d9bc 100644 --- a/integrations/access/common/app.go +++ b/integrations/access/common/app.go @@ -27,6 +27,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 ( @@ -94,7 +95,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) } diff --git a/integrations/access/jira/app.go b/integrations/access/jira/app.go index 169738a637947..12a5830e65cb6 100644 --- a/integrations/access/jira/app.go +++ b/integrations/access/jira/app.go @@ -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 ( @@ -233,7 +234,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) } diff --git a/integrations/access/opsgenie/app.go b/integrations/access/opsgenie/app.go index acdd1c977a7ce..5bc241f684e65 100644 --- a/integrations/access/opsgenie/app.go +++ b/integrations/access/opsgenie/app.go @@ -35,6 +35,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 ( @@ -168,7 +169,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) } diff --git a/integrations/access/pagerduty/app.go b/integrations/access/pagerduty/app.go index 328c834139842..cca924831c7f3 100644 --- a/integrations/access/pagerduty/app.go +++ b/integrations/access/pagerduty/app.go @@ -34,6 +34,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 ( @@ -186,7 +187,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) } diff --git a/integrations/access/servicenow/app.go b/integrations/access/servicenow/app.go index 1afd04fb22f6f..b57a53a8b6405 100644 --- a/integrations/access/servicenow/app.go +++ b/integrations/access/servicenow/app.go @@ -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 ( @@ -180,7 +181,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) } diff --git a/integrations/lib/testing/integration/integration.go b/integrations/lib/testing/integration/integration.go index 7be831ed638ff..5b9e574f0a470 100644 --- a/integrations/lib/testing/integration/integration.go +++ b/integrations/lib/testing/integration/integration.go @@ -32,8 +32,8 @@ import ( "sync" "time" + "github.com/coreos/go-semver/semver" "github.com/gravitational/trace" - "github.com/hashicorp/go-version" "google.golang.org/grpc" "github.com/gravitational/teleport/api/client" @@ -47,7 +47,7 @@ import ( const IntegrationAdminRole = "integration-admin" const DefaultLicensePath = "/var/lib/teleport/license.pem" -var regexpVersion = regexp.MustCompile(`^Teleport( Enterprise)? ([^ ]+)`) +var regexpVersion = regexp.MustCompile(`^Teleport( Enterprise)? v([^ ]+)`) type Integration struct { mu sync.Mutex @@ -85,7 +85,7 @@ type Service interface { } type Version struct { - *version.Version + *semver.Version IsEnterprise bool } @@ -97,12 +97,12 @@ type SignTLSPaths struct { const serviceShutdownTimeout = 10 * time.Second -func requireBinaryVersion(ctx context.Context, path string, targetVersion *version.Version) error { +func requireBinaryVersion(ctx context.Context, path string, targetVersion *semver.Version) error { v, err := getBinaryVersion(ctx, path) if err != nil { return trace.Wrap(err, "failed to get %s version", filepath.Base(path)) } - if !targetVersion.Equal(v.Version) { + if !targetVersion.Equal(*v.Version) { return trace.Errorf("%s version %s does not match target version %s", filepath.Base(path), v.Version, targetVersion) } @@ -522,7 +522,7 @@ func getBinaryVersion(ctx context.Context, binaryPath string) (Version, error) { return Version{}, trace.Wrap(err) } - version, err := version.NewVersion(submatch[2]) + version, err := semver.NewVersion(submatch[2]) if err != nil { return Version{}, trace.Wrap(err) } diff --git a/integrations/lib/versions.go b/integrations/lib/versions.go deleted file mode 100644 index bc8ca554d660a..0000000000000 --- a/integrations/lib/versions.go +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2023 Gravitational, Inc -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -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 -}