mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-18 08:16:39 +00:00
pass caller context by metadata to daemon
This commit is contained in:
@@ -16,6 +16,8 @@ type Info struct {
|
||||
Hostname string
|
||||
CPUs int
|
||||
WiretrusteeVersion string
|
||||
Caller string
|
||||
CallerVersion string
|
||||
}
|
||||
|
||||
func WiretrusteeVersion() string {
|
||||
|
||||
@@ -2,15 +2,18 @@ package system
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"google.golang.org/grpc/metadata"
|
||||
)
|
||||
|
||||
func GetInfo() *Info {
|
||||
func GetInfo(ctx context.Context) *Info {
|
||||
info := _getInfo()
|
||||
for strings.Contains(info, "broken pipe") {
|
||||
info = _getInfo()
|
||||
@@ -46,6 +49,13 @@ func GetInfo() *Info {
|
||||
gio.Hostname, _ = os.Hostname()
|
||||
gio.WiretrusteeVersion = WiretrusteeVersion()
|
||||
|
||||
metadata, ok := metadata.FromIncomingContext(ctx)
|
||||
|
||||
if ok {
|
||||
gio.Caller = metadata["caller"][0]
|
||||
gio.CallerVersion = metadata["callerVersion"][0]
|
||||
}
|
||||
|
||||
return gio
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
func Test_LocalVersion(t *testing.T) {
|
||||
got := GetInfo()
|
||||
got := GetInfo(nil)
|
||||
want := "development"
|
||||
assert.Equal(t, want, got.WiretrusteeVersion)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user