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)
|
||||
}()
|
||||
|
||||
Reference in New Issue
Block a user