parseWasmViolation parses a single violation from WASM output. Accepts both strings (legacy) and objects (deprecated, use findings instead).
(policyName string, raw json.RawMessage)
| 255 | // parseWasmViolation parses a single violation from WASM output. |
| 256 | // Accepts both strings (legacy) and objects (deprecated, use findings instead). |
| 257 | func parseWasmViolation(policyName string, raw json.RawMessage) (*engine.PolicyViolation, error) { |
| 258 | var v any |
| 259 | if err := json.Unmarshal(raw, &v); err != nil { |
| 260 | return nil, fmt.Errorf("invalid violation JSON: %w", err) |
| 261 | } |
| 262 | |
| 263 | switch typed := v.(type) { |
| 264 | case string: |
| 265 | return &engine.PolicyViolation{ |
| 266 | Subject: policyName, |
| 267 | Violation: typed, |
| 268 | }, nil |
| 269 | case map[string]any: |
| 270 | return engine.NewStructuredViolation(policyName, typed) |
| 271 | default: |
| 272 | return nil, fmt.Errorf("violation must be a string or object, got %T", v) |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | // MatchesParameters is a stub implementation for WASM policies |
| 277 | // WASM policies don't currently support parameter matching |
no test coverage detected