From fa646888d467019cf97c106fe329710758746b63 Mon Sep 17 00:00:00 2001 From: marco Date: Mon, 15 Jul 2024 11:45:49 +0200 Subject: [PATCH 1/3] version: don't duplicate version tag if already part of the string --- version/version.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/version/version.go b/version/version.go index 9f4d31b..c75539f 100644 --- a/version/version.go +++ b/version/version.go @@ -3,6 +3,7 @@ package version import ( "fmt" "runtime" + "strings" ) var ( @@ -14,7 +15,7 @@ var ( ) func FullString() string { - ret := fmt.Sprintf("version: %s-%s\n", Version, Tag) + ret := fmt.Sprintf("version: %s\n", String()) ret += fmt.Sprintf("BuildDate: %s\n", BuildDate) ret += fmt.Sprintf("GoVersion: %s\n", GoVersion) ret += fmt.Sprintf("Platform: %s\n", System) @@ -23,5 +24,12 @@ func FullString() string { } func String() string { - return fmt.Sprintf("%s-%s", Version, Tag) + // if the version number already contains the tag, don't duplicate it + ret := Version + + if !strings.HasSuffix(ret, Tag) && !strings.HasSuffix(ret, "g"+Tag+"-dirty") { + ret += "-" + Tag + } + + return ret } From 1206e7d15c56379bfff0fc6b58a6de81a9384611 Mon Sep 17 00:00:00 2001 From: marco Date: Mon, 15 Jul 2024 12:12:27 +0200 Subject: [PATCH 2/3] version/DetectOS() --- version/os.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 version/os.go diff --git a/version/os.go b/version/os.go new file mode 100644 index 0000000..a725ad9 --- /dev/null +++ b/version/os.go @@ -0,0 +1,18 @@ +package version + +import ( + "github.com/blackfireio/osinfo" +) + +func DetectOS() (string, string) { + osInfo, err := osinfo.GetOSInfo() + if err != nil { + return System, "???" + } + + if osInfo.Name != "" && System == "docker" { + return osInfo.Name + " (docker)", osInfo.Version + } + + return osInfo.Name, osInfo.Version +} From ef881673eb196cd284366dd74add1110a9bdfac2 Mon Sep 17 00:00:00 2001 From: marco Date: Mon, 15 Jul 2024 12:13:39 +0200 Subject: [PATCH 3/3] require osinfo --- go.mod | 1 + go.sum | 2 ++ 2 files changed, 3 insertions(+) diff --git a/go.mod b/go.mod index e944853..f625c24 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/crowdsecurity/go-cs-lib go 1.20 require ( + github.com/blackfireio/osinfo v1.0.5 github.com/coreos/go-systemd/v22 v22.5.0 github.com/sirupsen/logrus v1.9.3 github.com/stretchr/testify v1.8.4 diff --git a/go.sum b/go.sum index 16ddd2c..d1eceba 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +github.com/blackfireio/osinfo v1.0.5 h1:6hlaWzfcpb87gRmznVf7wSdhysGqLRz9V/xuSdCEXrA= +github.com/blackfireio/osinfo v1.0.5/go.mod h1:Pd987poVNmd5Wsx6PRPw4+w7kLlf9iJxoRKPtPAjOrA= github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=