From f5601e3a54dc1ea694b45430b01a7e2cbbd94381 Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Tue, 12 Nov 2024 13:04:21 -0500 Subject: [PATCH] reworked 'tail' function for subordinate access (#789) --- agent/access.go | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/agent/access.go b/agent/access.go index 8c164b4a..4ea8fe4b 100644 --- a/agent/access.go +++ b/agent/access.go @@ -46,24 +46,37 @@ func (a *access) tail(data []byte) { if line, err := a.readBuffer.ReadString('\n'); err == nil { line = strings.Trim(line, "\n") if !a.booted { - in := make(map[string]interface{}) - if err := json.Unmarshal([]byte(line), &in); err == nil { - if v, found := in["frontend_token"]; found { - if str, ok := v.(string); ok { - a.frontendToken = str - } - } - if v, found := in["bind_address"]; found { - if str, ok := v.(string); ok { - a.bindAddress = str + if strings.HasPrefix(line, "{") { + in := make(map[string]interface{}) + if err := json.Unmarshal([]byte(line), &in); err == nil { + if v, found := in["message"]; found { + if str, ok := v.(string); ok { + if str == "boot" { + if v, found := in["frontend_token"]; found { + if str, ok := v.(string); ok { + a.frontendToken = str + } + } + if v, found := in["bind_address"]; found { + if str, ok := v.(string); ok { + a.bindAddress = str + } + } + a.booted = true + } + } else { + a.bootErr = errors.New(line) + } + } else { + logrus.Warn(line) } + } else { + a.bootErr = errors.New(line) } - a.booted = true + close(a.bootComplete) } else { - a.bootErr = errors.New(line) + logrus.Warn(line) } - close(a.bootComplete) - } else { if strings.HasPrefix(line, "{") { in := make(map[string]interface{})