test-sprocket-example.sh raw

   1  #!/bin/bash
   2  
   3  # Example sprocket script that demonstrates event processing
   4  # This script reads JSON events from stdin and outputs JSONL responses
   5  
   6  # Read events from stdin line by line
   7  while IFS= read -r line; do
   8      # Parse the event JSON
   9      event_id=$(echo "$line" | jq -r '.id')
  10      event_kind=$(echo "$line" | jq -r '.kind')
  11      event_content=$(echo "$line" | jq -r '.content')
  12      
  13      # Example policy: reject events with certain content
  14      if [[ "$event_content" == *"spam"* ]]; then
  15          echo "{\"id\":\"$event_id\",\"action\":\"reject\",\"msg\":\"content contains spam\"}"
  16          continue
  17      fi
  18      
  19      # Example policy: shadow reject events from certain kinds
  20      if [[ "$event_kind" == "9999" ]]; then
  21          echo "{\"id\":\"$event_id\",\"action\":\"shadowReject\",\"msg\":\"\"}"
  22          continue
  23      fi
  24      
  25      # Default: accept the event
  26      echo "{\"id\":\"$event_id\",\"action\":\"accept\",\"msg\":\"\"}"
  27      
  28  done
  29