-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9881401
commit 9d829c1
Showing
6 changed files
with
587 additions
and
281 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,71 @@ | ||
package agent | ||
|
||
import ( | ||
"github.com/openziti/zrok/agent/agentGrpc" | ||
"bytes" | ||
"encoding/json" | ||
"errors" | ||
"github.com/michaelquigley/pfxlog" | ||
"github.com/openziti/zrok/agent/proctree" | ||
"github.com/sirupsen/logrus" | ||
"strings" | ||
) | ||
|
||
type access struct { | ||
token string | ||
|
||
frontendToken string | ||
token string | ||
bindAddress string | ||
responseHeaders []string | ||
|
||
process *proctree.Child | ||
} | ||
process *proctree.Child | ||
readBuffer bytes.Buffer | ||
booted bool | ||
bootComplete chan struct{} | ||
bootErr error | ||
|
||
type agentGrpcImpl struct { | ||
agentGrpc.UnimplementedAgentServer | ||
a *Agent | ||
} | ||
|
||
func (a *access) monitor() { | ||
if err := proctree.WaitChild(a.process); err != nil { | ||
pfxlog.ChannelLogger(a.token).Error(err) | ||
} | ||
a.a.outAccesses <- a | ||
} | ||
|
||
func (a *access) tail(data []byte) { | ||
defer func() { | ||
if r := recover(); r != nil { | ||
logrus.Errorf("recovering: %v", r) | ||
} | ||
}() | ||
a.readBuffer.Write(data) | ||
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 | ||
} | ||
} | ||
a.booted = true | ||
} else { | ||
a.bootErr = errors.New(line) | ||
} | ||
close(a.bootComplete) | ||
|
||
} else { | ||
if strings.HasPrefix(line, "{") { | ||
in := make(map[string]interface{}) | ||
if err := json.Unmarshal([]byte(line), &in); err == nil { | ||
pfxlog.ChannelLogger(a.token).Info(in) | ||
} | ||
} else { | ||
pfxlog.ChannelLogger(a.token).Info(strings.Trim(line, "\n")) | ||
} | ||
} | ||
} else { | ||
a.readBuffer.WriteString(line) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,3 +106,8 @@ func (a *Agent) manager() { | |
} | ||
} | ||
} | ||
|
||
type agentGrpcImpl struct { | ||
agentGrpc.UnimplementedAgentServer | ||
a *Agent | ||
} |
Oops, something went wrong.