mirror of
https://github.com/netbirdio/netbird.git
synced 2025-06-20 17:58:02 +02:00
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:
parent
b339a9321a
commit
efbb5acf63
@ -23,7 +23,7 @@ builds:
|
|||||||
- goos: windows
|
- goos: windows
|
||||||
goarch: arm
|
goarch: arm
|
||||||
ldflags:
|
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 }}'
|
mod_timestamp: '{{ .CommitTimestamp }}'
|
||||||
tags:
|
tags:
|
||||||
- load_wgnt_from_rsrc
|
- load_wgnt_from_rsrc
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import "github.com/spf13/cobra"
|
import (
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/wiretrustee/wiretrustee/client/system"
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
Version string
|
|
||||||
versionCmd = &cobra.Command{
|
versionCmd = &cobra.Command{
|
||||||
Use: "version",
|
Use: "version",
|
||||||
Short: "prints wiretrustee version",
|
Short: "prints wiretrustee version",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
cmd.Println(Version)
|
cmd.Println(system.WiretrusteeVersion())
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -1,15 +1,12 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/wiretrustee/wiretrustee/client/cmd"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/wiretrustee/wiretrustee/client/cmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
var version = "development"
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
cmd.Version = version
|
|
||||||
if err := cmd.Execute(); err != nil {
|
if err := cmd.Execute(); err != nil {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,23 @@
|
|||||||
package system
|
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
|
//Info is an object that contains machine information
|
||||||
// Most of the code is taken from https://github.com/matishsiao/goInfo
|
// Most of the code is taken from https://github.com/matishsiao/goInfo
|
||||||
type Info struct {
|
type Info struct {
|
||||||
GoOS string
|
GoOS string
|
||||||
Kernel string
|
Kernel string
|
||||||
Core string
|
Core string
|
||||||
Platform string
|
Platform string
|
||||||
OS string
|
OS string
|
||||||
OSVersion string
|
OSVersion string
|
||||||
Hostname string
|
Hostname string
|
||||||
CPUs int
|
CPUs int
|
||||||
|
WiretrusteeVersion string
|
||||||
|
}
|
||||||
|
|
||||||
|
func WiretrusteeVersion() string {
|
||||||
|
return version
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ func GetInfo() *Info {
|
|||||||
osInfo := strings.Split(osStr, " ")
|
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 := &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.Hostname, _ = os.Hostname()
|
||||||
|
gio.WiretrusteeVersion = WiretrusteeVersion()
|
||||||
return gio
|
return gio
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ func GetInfo() *Info {
|
|||||||
osInfo := strings.Split(osStr, " ")
|
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 := &Info{Kernel: osInfo[0], Core: osInfo[1], Platform: runtime.GOARCH, OS: osInfo[2], GoOS: runtime.GOOS, CPUs: runtime.NumCPU()}
|
||||||
gio.Hostname, _ = os.Hostname()
|
gio.Hostname, _ = os.Hostname()
|
||||||
|
gio.WiretrusteeVersion = WiretrusteeVersion()
|
||||||
return gio
|
return gio
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 := &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.Hostname, _ = os.Hostname()
|
||||||
|
gio.WiretrusteeVersion = WiretrusteeVersion()
|
||||||
|
|
||||||
return gio
|
return gio
|
||||||
}
|
}
|
||||||
|
|
||||||
|
13
client/system/info_test.go
Normal file
13
client/system/info_test.go
Normal 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)
|
||||||
|
}
|
@ -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 := &Info{Kernel: "windows", OSVersion: ver, Core: ver, Platform: "unknown", OS: "windows", GoOS: runtime.GOOS, CPUs: runtime.NumCPU()}
|
||||||
gio.Hostname, _ = os.Hostname()
|
gio.Hostname, _ = os.Hostname()
|
||||||
|
gio.WiretrusteeVersion = WiretrusteeVersion()
|
||||||
|
|
||||||
return gio
|
return gio
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,9 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/cenkalti/backoff/v4"
|
"github.com/cenkalti/backoff/v4"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/wiretrustee/wiretrustee/client/system"
|
"github.com/wiretrustee/wiretrustee/client/system"
|
||||||
@ -15,8 +18,6 @@ import (
|
|||||||
"google.golang.org/grpc/credentials"
|
"google.golang.org/grpc/credentials"
|
||||||
"google.golang.org/grpc/credentials/insecure"
|
"google.golang.org/grpc/credentials/insecure"
|
||||||
"google.golang.org/grpc/keepalive"
|
"google.golang.org/grpc/keepalive"
|
||||||
"io"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type GrpcClient struct {
|
type GrpcClient struct {
|
||||||
@ -241,7 +242,7 @@ func (c *GrpcClient) Register(serverKey wgtypes.Key, setupKey string) (*proto.Lo
|
|||||||
Core: gi.OSVersion,
|
Core: gi.OSVersion,
|
||||||
Platform: gi.Platform,
|
Platform: gi.Platform,
|
||||||
Kernel: gi.Kernel,
|
Kernel: gi.Kernel,
|
||||||
WiretrusteeVersion: "",
|
WiretrusteeVersion: gi.WiretrusteeVersion,
|
||||||
}
|
}
|
||||||
log.Debugf("detected system %v", meta)
|
log.Debugf("detected system %v", meta)
|
||||||
return c.login(serverKey, &proto.LoginRequest{SetupKey: setupKey, Meta: meta})
|
return c.login(serverKey, &proto.LoginRequest{SetupKey: setupKey, Meta: meta})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user