Enhance logging and add policy test client
Some checks failed
Go / build (push) Has been cancelled
Go / release (push) Has been cancelled

- 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:
2025-10-20 16:30:39 +01:00
parent 105e372712
commit 65e8ab4fbe
6 changed files with 137 additions and 17 deletions

View File

@@ -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)
}()