Add client version to the client app and send it to the management service (#218)

* moved wiretrustee version from main to system.info

* added wiretrustee version for all supported platforms

* typo corrected

* refactor: use single WiretrusteeVersion() func to get version of the client

Co-authored-by: braginini <bangvalo@gmail.com>
This commit is contained in:
shatoboar 2022-02-03 18:35:54 +01:00 committed by GitHub
parent b339a9321a
commit efbb5acf63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 48 additions and 20 deletions

View File

@ -23,7 +23,7 @@ builds:
- goos: windows
goarch: arm
ldflags:
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.CommitDate}} -X main.builtBy=goreleaser
- -s -w -X github.com/wiretrustee/wiretrustee/client/system.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.CommitDate}} -X main.builtBy=goreleaser
mod_timestamp: '{{ .CommitTimestamp }}'
tags:
- load_wgnt_from_rsrc

View File

@ -1,14 +1,16 @@
package cmd
import "github.com/spf13/cobra"
import (
"github.com/spf13/cobra"
"github.com/wiretrustee/wiretrustee/client/system"
)
var (
Version string
versionCmd = &cobra.Command{
Use: "version",
Short: "prints wiretrustee version",
Run: func(cmd *cobra.Command, args []string) {
cmd.Println(Version)
cmd.Println(system.WiretrusteeVersion())
},
}
)

View File

@ -1,15 +1,12 @@
package main
import (
"github.com/wiretrustee/wiretrustee/client/cmd"
"os"
"github.com/wiretrustee/wiretrustee/client/cmd"
)
var version = "development"
func main() {
cmd.Version = version
if err := cmd.Execute(); err != nil {
os.Exit(1)
}

View File

@ -1,5 +1,9 @@
package system
// this is the wiretrustee version
// will be replaced with the release version when using goreleaser
var version = "development"
//Info is an object that contains machine information
// Most of the code is taken from https://github.com/matishsiao/goInfo
type Info struct {
@ -11,4 +15,9 @@ type Info struct {
OSVersion string
Hostname string
CPUs int
WiretrusteeVersion string
}
func WiretrusteeVersion() string {
return version
}

View File

@ -21,6 +21,7 @@ func GetInfo() *Info {
osInfo := strings.Split(osStr, " ")
gio := &Info{Kernel: osInfo[0], OSVersion: osInfo[1], Core: osInfo[1], Platform: osInfo[2], OS: osInfo[0], GoOS: runtime.GOOS, CPUs: runtime.NumCPU()}
gio.Hostname, _ = os.Hostname()
gio.WiretrusteeVersion = WiretrusteeVersion()
return gio
}

View File

@ -21,6 +21,7 @@ func GetInfo() *Info {
osInfo := strings.Split(osStr, " ")
gio := &Info{Kernel: osInfo[0], Core: osInfo[1], Platform: runtime.GOARCH, OS: osInfo[2], GoOS: runtime.GOOS, CPUs: runtime.NumCPU()}
gio.Hostname, _ = os.Hostname()
gio.WiretrusteeVersion = WiretrusteeVersion()
return gio
}

View File

@ -44,6 +44,8 @@ func GetInfo() *Info {
}
gio := &Info{Kernel: osInfo[0], Core: osInfo[1], Platform: osInfo[2], OS: osName, OSVersion: osVer, GoOS: runtime.GOOS, CPUs: runtime.NumCPU()}
gio.Hostname, _ = os.Hostname()
gio.WiretrusteeVersion = WiretrusteeVersion()
return gio
}

View File

@ -0,0 +1,13 @@
package system
import (
"testing"
"github.com/stretchr/testify/assert"
)
func Test_LocalVersion(t *testing.T) {
got := GetInfo()
want := "development"
assert.Equal(t, want, got.WiretrusteeVersion)
}

View File

@ -31,5 +31,7 @@ func GetInfo() *Info {
}
gio := &Info{Kernel: "windows", OSVersion: ver, Core: ver, Platform: "unknown", OS: "windows", GoOS: runtime.GOOS, CPUs: runtime.NumCPU()}
gio.Hostname, _ = os.Hostname()
gio.WiretrusteeVersion = WiretrusteeVersion()
return gio
}

View File

@ -4,6 +4,9 @@ import (
"context"
"crypto/tls"
"fmt"
"io"
"time"
"github.com/cenkalti/backoff/v4"
log "github.com/sirupsen/logrus"
"github.com/wiretrustee/wiretrustee/client/system"
@ -15,8 +18,6 @@ import (
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/keepalive"
"io"
"time"
)
type GrpcClient struct {
@ -241,7 +242,7 @@ func (c *GrpcClient) Register(serverKey wgtypes.Key, setupKey string) (*proto.Lo
Core: gi.OSVersion,
Platform: gi.Platform,
Kernel: gi.Kernel,
WiretrusteeVersion: "",
WiretrusteeVersion: gi.WiretrusteeVersion,
}
log.Debugf("detected system %v", meta)
return c.login(serverKey, &proto.LoginRequest{SetupKey: setupKey, Meta: meta})