From bfc9179729467117ab45b9bab0a0d9869ddaa2d0 Mon Sep 17 00:00:00 2001 From: nicksherron Date: Mon, 17 Feb 2020 06:44:06 -0500 Subject: [PATCH] cmd/transfer,cmd/server: make SessionID pointer so sql null doesn't panic and improve transfer performance --- Makefile | 8 ++-- cmd/root.go | 4 +- cmd/transfer.go | 110 ++++++++++++++++++++++++++++--------------- cmd/transfer_test.go | 38 ++------------- go.mod | 1 - go.sum | 40 +--------------- internal/server.go | 16 +++---- 7 files changed, 91 insertions(+), 126 deletions(-) diff --git a/Makefile b/Makefile index d1feed4..89219f6 100644 --- a/Makefile +++ b/Makefile @@ -14,12 +14,12 @@ help: @echo 'Management commands for bashhub-server:' @echo @echo 'Usage:' - @echo ' make build Compile the project.' + @echo ' make build Compile the project' @echo ' make docker-build Build docker image' @echo ' make clean Clean the directory tree' - @echo ' make test Run tests on a compiled project.' - @echo ' make test-postgres Start postgres in ephemeral docker container and run backend tests.' - @echo ' make test-all Run test and test-postgres.' + @echo ' make test Run tests on a compiled project' + @echo ' make test-postgres Start postgres in ephemeral docker container and run backend tests' + @echo ' make test-all Run test and test-postgres' @echo build: diff --git a/cmd/root.go b/cmd/root.go index 5fa3b28..6f4e955 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -77,9 +77,7 @@ func startupMessage() { `, Version, addr) color.HiGreen(banner) - fmt.Print("\n") - log.Printf("Listening and serving HTTP on %v", addr) - fmt.Print("\n") + log.Printf("\nListening and serving HTTP on %v\n", addr) } func listenAddr() string { diff --git a/cmd/transfer.go b/cmd/transfer.go index 91dec5b..f38e40f 100644 --- a/cmd/transfer.go +++ b/cmd/transfer.go @@ -28,6 +28,8 @@ import ( "os" "strings" "sync" + "sync/atomic" + "time" "github.com/cheggaaa/pb/v3" "github.com/spf13/cobra" @@ -35,6 +37,7 @@ import ( ) type cList struct { + Retries int UUID string `json:"uuid"` Command string `json:"command"` Created int64 `json:"created"` @@ -58,10 +61,14 @@ var ( workers int unique bool limit int - wg sync.WaitGroup + dstCounter uint64 + srcCounter uint64 + inserted uint64 wgSrc sync.WaitGroup + wgDst sync.WaitGroup cmdList commandsList - transferCmd = &cobra.Command{ + + transferCmd = &cobra.Command{ Use: "transfer", Short: "Transfer bashhub history from one server to another", Run: func(cmd *cobra.Command, args []string) { @@ -127,41 +134,56 @@ func run() { sysRegistered = false dstToken = getToken(dstURL, dstUser, dstPass) cmdList = getCommandList() - counter := 0 if !progress { bar = pb.ProgressBarTemplate(barTemplate).Start(len(cmdList)).SetMaxWidth(70) bar.Set("message", "transferring ") } fmt.Print("\nstarting transfer...\n\n") - client := &http.Client{} - pipe := make(chan []byte) + queue := make(chan cList, len(cmdList)) + pipe := make(chan []byte, len(cmdList)) + + // ignore http errors. We try and recover them + log.SetOutput(nil) go func() { for { select { - case data := <-pipe: + case item := <-queue: + wgDst.Add(1) + atomic.AddUint64(&dstCounter, 1) + go func(cmd cList) { + defer wgDst.Done() + commandLookup(cmd, pipe, queue) + }(item) + if atomic.CompareAndSwapUint64(&dstCounter, uint64(workers), 0) { + wgDst.Wait() + } + case result := <-pipe: wgSrc.Add(1) - go srcSend(data, client) + atomic.AddUint64(&srcCounter, 1) + go func(data []byte) { + srcSend(data, 0) + }(result) + if atomic.CompareAndSwapUint64(&srcCounter, uint64(workers), 0) { + wgSrc.Wait() + } } - } }() - // ignore http errors. We try and recover them - log.SetOutput(nil) for _, v := range cmdList { - wg.Add(1) - counter++ - go commandLookup(v.UUID, client, 0, pipe) - if counter > workers { - wg.Wait() - counter = 0 + v.Retries = 0 + queue <- v + } + + for { + if atomic.CompareAndSwapUint64(&inserted, uint64(len(cmdList)), 0) { + break } + time.Sleep(200 * time.Millisecond) } - wg.Wait() if !progress { bar.Finish() } - wgSrc.Wait() } func sysRegister(mac string, site string, user string, pass string) string { @@ -329,21 +351,20 @@ func getCommandList() commandsList { return result } -func commandLookup(uuid string, client *http.Client, retries int, pipe chan []byte) { + +func commandLookup(item cList, pipe chan []byte, queue chan cList) { defer func() { - wg.Done() if r := recover(); r != nil { mem := strings.Contains(fmt.Sprintf("%v", r), "runtime error: invalid memory address") eof := strings.Contains(fmt.Sprintf("%v", r), "EOF") if mem || eof { - if retries < 10 { - retries++ - wg.Add(1) - go commandLookup(uuid, client, retries, pipe) - + if item.Retries < 10 { + item.Retries++ + queue <- item + return } else { log.SetOutput(os.Stderr) - log.Println("ERROR: failed over 10 times looking up command from source with uuid: ", uuid) + log.Println("ERROR: failed over 10 times looking up command from source with uuid: ", item.UUID) log.SetOutput(nil) } } else { @@ -353,7 +374,7 @@ func commandLookup(uuid string, client *http.Client, retries int, pipe chan []by } }() - u := strings.TrimSpace(srcURL) + "/api/v1/command/" + strings.TrimSpace(uuid) + u := strings.TrimSpace(srcURL) + "/api/v1/command/" + strings.TrimSpace(item.UUID) req, err := http.NewRequest("GET", u, nil) if err != nil { @@ -361,29 +382,44 @@ func commandLookup(uuid string, client *http.Client, retries int, pipe chan []by } req.Header.Add("Authorization", srcToken) - resp, err := client.Do(req) + resp, err := http.DefaultClient.Do(req) if err != nil { panic(err) } defer resp.Body.Close() - if resp.StatusCode != 200 { - log.Fatalf("failed command lookup from %v, go status code %v", srcURL, resp.StatusCode) - } + body, err := ioutil.ReadAll(resp.Body) if err != nil { panic(err) } + if resp.StatusCode != 200 { + err = fmt.Errorf("%v response from %v: %v", resp.StatusCode, srcURL, string(body)) + log.SetOutput(os.Stderr) + log.Fatal(err) + } pipe <- body } -func srcSend(data []byte, client *http.Client) { +func srcSend(data []byte, retries int) { defer func() { + if r := recover(); r != nil { + retries++ + if retries < 10 { + srcSend(data, retries) + return + } + log.SetOutput(os.Stderr) + log.Println("Error on response.\n", r) + log.SetOutput(nil) + } if !progress { bar.Add(1) } + atomic.AddUint64(&inserted, 1) wgSrc.Done() }() + body := bytes.NewReader(data) u := dstURL + "/api/v1/import" @@ -392,17 +428,13 @@ func srcSend(data []byte, client *http.Client) { log.SetOutput(os.Stderr) log.Fatal(err) } - req.Header.Add("Authorization", dstToken) - - resp, err := client.Do(req) + req.Header.Add("Authorization", dstToken) + _, err = http.DefaultClient.Do(req) if err != nil { log.SetOutput(os.Stderr) - log.Println("Error on response.\n", err) - log.SetOutput(nil) + log.Fatal(err) } - - defer resp.Body.Close() } func check(err error) { diff --git a/cmd/transfer_test.go b/cmd/transfer_test.go index 6c874f6..4049f01 100644 --- a/cmd/transfer_test.go +++ b/cmd/transfer_test.go @@ -26,7 +26,6 @@ import ( "io" "io/ioutil" "log" - "math/rand" "net/http" "os" "os/exec" @@ -113,6 +112,9 @@ func TestMain(m *testing.M) { var err error testDir, err = ioutil.TempDir("", "bashhub-server-test-") check(err) + if testWork { + log.Println("TESTWORK=", testDir) + } src, err = startSrc() check(err) @@ -178,6 +180,7 @@ func TestCreateToken(t *testing.T) { if srcToken == "" { t.Fatal("srcToken token is blank") } + sysRegistered = false dstToken = getToken(dstURL, dstUser, dstPass) if dstToken == "" { @@ -246,37 +249,6 @@ func TestTransfer(t *testing.T) { assert.Equal(t, dstStatus.TotalCommands, srcStatus.TotalCommands) } -func BenchmarkGoInserts(b *testing.B) { - client := &http.Client{} - counter := 0 - pipe := make(chan []byte) - go func() { - for { - select { - case data := <-pipe: - wgSrc.Add(1) - go srcSend(data, client) - } - - } - }() - for i := 0; i < b.N; i++ { - wg.Add(1) - counter++ - n := rand.Intn(commandsN) - go commandLookup(cmdList[n].UUID, client, 0, pipe) - if counter > workers { - wg.Wait() - counter = 0 - } - } - wg.Wait() - if !progress { - bar.Finish() - } - wgSrc.Wait() -} - func getStatus(t *testing.T, u string, token string) internal.Status { u = fmt.Sprintf("%v/api/v1/client-view/status?processId=1000&startTime=%v", u, sessionStartTime) req, err := http.NewRequest("GET", u, nil) @@ -318,5 +290,5 @@ func cleanup() { return } log.SetOutput(os.Stderr) - log.Println("TESTWORK=", testDir) + } diff --git a/go.mod b/go.mod index f005117..0812cb9 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,6 @@ require ( github.com/jinzhu/gorm v1.9.12 github.com/lib/pq v1.3.0 github.com/magiconair/properties v1.8.0 - github.com/manifoldco/promptui v0.7.0 github.com/mattn/go-sqlite3 v2.0.3+incompatible github.com/spf13/cobra v0.0.5 github.com/stretchr/testify v1.4.0 diff --git a/go.sum b/go.sum index aa6d5a9..604066c 100644 --- a/go.sum +++ b/go.sum @@ -4,19 +4,14 @@ github.com/Masterminds/semver v1.4.2/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF0 github.com/Masterminds/vcs v1.13.0/go.mod h1:N09YCmOQr6RLxC6UNHzuVwAdodYbbnycGHSmwVJjcKA= github.com/VividCortex/ewma v1.1.1 h1:MnEK4VOv6n0RSY4vtRe3h11qjxL3+t0B8yOL8iMXdcM= github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA= +github.com/appleboy/gin-jwt v2.5.0+incompatible h1:oLQTP1fiGDoDKoC2UDqXD9iqCP44ABIZMMenfH/xCqw= github.com/appleboy/gin-jwt/v2 v2.6.3 h1:aK4E3DjihWEBUTjEeRnGkA5nUkmwJPL1CPonMa2usRs= github.com/appleboy/gin-jwt/v2 v2.6.3/go.mod h1:MfPYA4ogzvOcVkRwAxT7quHOtQmVKDpTwxyUrC2DNw0= -github.com/appleboy/gofight/v2 v2.1.2 h1:VOy3jow4vIK8BRQJoC/I9muxyYlJ2yb9ht2hZoS3rf4= github.com/appleboy/gofight/v2 v2.1.2/go.mod h1:frW+U1QZEdDgixycTj4CygQ48yLTUhplt43+Wczp3rw= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= +github.com/cheggaaa/pb v2.0.7+incompatible h1:gLKifR1UkZ/kLkda5gC0K6c8g+jU2sINPtBeOiNlMhU= github.com/cheggaaa/pb/v3 v3.0.4 h1:QZEPYOj2ix6d5oEg63fbHmpolrnNiwjUsk+h74Yt4bM= github.com/cheggaaa/pb/v3 v3.0.4/go.mod h1:7rgWxLrAUcFMkvJuv09+DYi7mMUYi8nO9iOWcvGJPfw= -github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE= -github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= -github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8= -github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= -github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 h1:q763qf9huN11kDQavWsoZXJNW3xEE4JJyHa5Q25/sd8= -github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/codegangsta/cli v1.20.0/go.mod h1:/qJNoX69yVSKu5o4jLyXAENLRyk1uhi7zkbQ3slBdOA= github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= @@ -27,11 +22,9 @@ github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwc github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd h1:83Wprp6ROGeiHFAP8WJdI2RoxALQYgdllERc3N5N2DM= github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU= github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= -github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5 h1:Yzb9+7DPaBjB8zlTR87/ElzFsnQfuHnVUVqpZZIcV5Y= github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5/go.mod h1:a2zkGnVExMxdzMo3M0Hi/3sEU+cWnZpSni0O6/Yb/P0= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s= @@ -47,9 +40,7 @@ github.com/go-playground/locales v0.12.1 h1:2FITxuFt/xuCNP1Acdhv62OzaCiviiE4kotf github.com/go-playground/locales v0.12.1/go.mod h1:IUMDtCfWo/w/mtMfIE/IG2K+Ey3ygWanZIBtBW0W2TM= github.com/go-playground/universal-translator v0.16.0 h1:X++omBR/4cE2MNg91AoC3rmGrCjJ8eAeUP/K/EKx4DM= github.com/go-playground/universal-translator v0.16.0/go.mod h1:1AnU7NaIRDWWzGEKwgtJRd2xk99HeFyHw3yid4rvQIY= -github.com/go-sql-driver/mysql v1.4.1 h1:g24URVg0OFbNUTx9qqY1IRZ9D9z3iPyi5zKhQZpNwpA= github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= -github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe h1:lXe2qZdvpiX5WZkZR4hgp4KJVfY3nMkvmwbVkpv1rVY= github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -61,40 +52,24 @@ github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+ github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/icrowley/fake v0.0.0-20180203215853-4178557ae428 h1:Mo9W14pwbO9VfRe+ygqZ8dFbPpoIK1HFrG/zjTuQ+nc= github.com/icrowley/fake v0.0.0-20180203215853-4178557ae428/go.mod h1:uhpZMVGznybq1itEKXj6RYw9I71qK4kH+OGMjRC4KEo= -github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/jinzhu/gorm v1.9.12 h1:Drgk1clyWT9t9ERbzHza6Mj/8FY/CqMyVzOiHviMo6Q= github.com/jinzhu/gorm v1.9.12/go.mod h1:vhTjlKSJUTWNtcbQtrMBFCxy7eXTzeCAzfL5fBZT/Qs= github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= -github.com/jinzhu/now v1.0.1 h1:HjfetcXq097iXP0uoPCdnM4Efp5/9MsM0/M+XOTeR3M= github.com/jinzhu/now v1.0.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= -github.com/json-iterator/go v1.1.7 h1:KfgG9LzI+pYjr4xvmz/5H4FXjokeP+rlHLhv3iH62Fo= github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a h1:FaWFmfWdAUKbSCtOU2QjDaorUexogfaMgbipgYATUMU= -github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a/go.mod h1:UJSiEoRfvx3hP73CvoARgeLjaIOjybY9vj8PUPPFGeU= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/leodido/go-urn v1.1.0 h1:Sm1gr51B1kKyfD2BlRcLSiEkffoG96g6TPv6eRoEiB8= github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw= github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lib/pq v1.3.0 h1:/qkRGz8zljWiDcFvgpwUpwIAPu3r07TDvs3Rws+o/pU= github.com/lib/pq v1.3.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= -github.com/lunixbochs/vtclean v0.0.0-20180621232353-2d01aacdc34a h1:weJVJJRzAJBFRlAiJQROKQs8oC9vOxvm4rZmBBk0ONw= -github.com/lunixbochs/vtclean v0.0.0-20180621232353-2d01aacdc34a/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI= github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= -github.com/manifoldco/promptui v0.7.0 h1:3l11YT8tm9MnwGFQ4kETwkzpAwY2Jt9lCrumCUW4+z4= -github.com/manifoldco/promptui v0.7.0/go.mod h1:n4zTdgP0vr0S3w7/O/g98U+e0gwLScEXGwov2nIKuGQ= -github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA= github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= -github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ= @@ -109,10 +84,8 @@ github.com/mattn/go-sqlite3 v2.0.3+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/ngdinhtoan/glide-cleanup v0.2.0/go.mod h1:UQzsmiDOb8YV3nOsCxK/c9zPpCZVNoHScRE3EO9pVMM= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= @@ -132,11 +105,8 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/tidwall/gjson v1.3.5 h1:2oW9FBNu8qt9jy5URgrzsVx/T/KSn3qn/smJQ0crlDQ= github.com/tidwall/gjson v1.3.5/go.mod h1:P256ACg0Mn+j1RXIDXoss50DeIABTYK1PULOJHhxOls= -github.com/tidwall/match v1.0.1 h1:PnKP62LPNxHKTwvHHZZzdOAOCtsJTjo6dZLCwpKm5xc= github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E= -github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4= github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo= @@ -154,7 +124,6 @@ golang.org/x/crypto v0.0.0-20200214034016-1d94cc7ab1c6/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -165,13 +134,8 @@ golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9 h1:ZBzSG/7F4eNKz2L3GE9o300RX0Az1Bw5HF7PDraD+qU= golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM= gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= gopkg.in/go-playground/validator.v8 v8.18.2/go.mod h1:RX2a/7Ha8BgOhfk7j780h4/u/RRjR0eouCJSH80/M2Y= gopkg.in/go-playground/validator.v9 v9.29.1 h1:SvGtYmN60a5CVKTOzMSyfzWDeZRxRuGvRQyEAKbw1xc= diff --git a/internal/server.go b/internal/server.go index cbbd4aa..424ef04 100644 --- a/internal/server.go +++ b/internal/server.go @@ -44,14 +44,14 @@ type User struct { } type Query struct { - Command string `json:"command"` - Path string `json:"path"` - Created int64 `json:"created"` - Uuid string `json:"uuid"` - ExitStatus int `json:"exitStatus"` - Username string `json:"username"` - SystemName string `gorm:"-" json:"systemName"` - SessionID string `json:"sessionId"` + Command string `json:"command"` + Path string `json:"path"` + Created int64 `json:"created"` + Uuid string `json:"uuid"` + ExitStatus int `json:"exitStatus"` + Username string `json:"username"` + SystemName string `gorm:"-" json:"systemName"` + SessionID *string `json:"sessionId"` } type Command struct {