pass caller context by metadata to daemon

This commit is contained in:
shatoboar
2022-05-20 16:59:53 +02:00
parent 77e58295e7
commit 252f92c029
17 changed files with 209 additions and 147 deletions

View File

@@ -16,6 +16,8 @@ type Info struct {
Hostname string
CPUs int
WiretrusteeVersion string
Caller string
CallerVersion string
}
func WiretrusteeVersion() string {

View File

@@ -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
}

View File

@@ -7,7 +7,7 @@ import (
)
func Test_LocalVersion(t *testing.T) {
got := GetInfo()
got := GetInfo(nil)
want := "development"
assert.Equal(t, want, got.WiretrusteeVersion)
}