mirror of
https://github.com/netbirdio/netbird.git
synced 2024-11-25 01:23:22 +01:00
94fbfcdb85
Send Desktop UI client version as user-agent to daemon This is sent on every login request to the management Parse the GRPC context on the system package and retrieves the user-agent Management receives the new UIVersion field and store in the Peer's system meta
53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
package system
|
|
|
|
import (
|
|
"context"
|
|
"google.golang.org/grpc/metadata"
|
|
"strings"
|
|
)
|
|
|
|
// 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 {
|
|
GoOS string
|
|
Kernel string
|
|
Core string
|
|
Platform string
|
|
OS string
|
|
OSVersion string
|
|
Hostname string
|
|
CPUs int
|
|
WiretrusteeVersion string
|
|
UIVersion string
|
|
}
|
|
|
|
// NetbirdVersion returns the Netbird version
|
|
func NetbirdVersion() string {
|
|
return version
|
|
}
|
|
|
|
// extractUserAgent extracts Netbird's agent (client) name and version from the outgoing context
|
|
func extractUserAgent(ctx context.Context) string {
|
|
md, hasMeta := metadata.FromOutgoingContext(ctx)
|
|
if hasMeta {
|
|
agent, ok := md["user-agent"]
|
|
if ok {
|
|
nbAgent := strings.Split(agent[0], " ")[0]
|
|
if strings.HasPrefix(nbAgent, "netbird") {
|
|
return nbAgent
|
|
}
|
|
return ""
|
|
}
|
|
}
|
|
return ""
|
|
}
|
|
|
|
// GetDesktopUIUserAgent returns the Desktop ui user agent
|
|
func GetDesktopUIUserAgent() string {
|
|
return "netbird-desktop-ui/" + NetbirdVersion()
|
|
}
|