Enhance logging and add policy test client
- Refactored logOutput function to trace-log stdout and stderr lines for better debugging. - Introduced a new policy test client in cmd/policytest/main.go to publish events and check policy responses. - Added a script to run the policy test, ensuring proper cleanup and error handling. - Updated policy event processing to ensure newline-terminated JSON for compatibility with shell-readers.
This commit is contained in:
@@ -684,8 +684,8 @@ func (pm *PolicyManager) ProcessEvent(evt *PolicyEvent) (*PolicyResponse, error)
|
||||
return nil, fmt.Errorf("failed to serialize event: %v", err)
|
||||
}
|
||||
|
||||
// Send the event JSON to the policy script
|
||||
if _, err := stdin.Write(eventJSON); chk.E(err) {
|
||||
// Send the event JSON to the policy script (newline-terminated for shell-readers)
|
||||
if _, err := stdin.Write(append(eventJSON, '\n')); chk.E(err) {
|
||||
return nil, fmt.Errorf("failed to write event to policy: %v", err)
|
||||
}
|
||||
|
||||
@@ -734,13 +734,9 @@ func (pm *PolicyManager) readResponses() {
|
||||
|
||||
// logOutput logs the output from stdout and stderr
|
||||
func (pm *PolicyManager) logOutput(stdout, stderr io.ReadCloser) {
|
||||
defer stdout.Close()
|
||||
defer stderr.Close()
|
||||
|
||||
go func() {
|
||||
io.Copy(os.Stdout, stdout)
|
||||
}()
|
||||
|
||||
// Only log stderr, stdout is used by readResponses
|
||||
go func() {
|
||||
io.Copy(os.Stderr, stderr)
|
||||
}()
|
||||
|
||||
@@ -374,14 +374,9 @@ func (r *Client) ConnectWithTLS(
|
||||
if env, message, err = okenvelope.Parse(message); chk.E(err) {
|
||||
continue
|
||||
}
|
||||
if okCallback, exist := r.okCallbacks.Load(string(env.EventID)); exist {
|
||||
eventIDHex := hex.Enc(env.EventID)
|
||||
if okCallback, exist := r.okCallbacks.Load(eventIDHex); exist {
|
||||
okCallback(env.OK, env.ReasonString())
|
||||
} else {
|
||||
// log.I.F(
|
||||
// "{%s} got an unexpected OK message for event %0x",
|
||||
// r.URL,
|
||||
// env.EventID,
|
||||
// )
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
v0.17.1
|
||||
v0.17.2
|
||||
Reference in New Issue
Block a user