MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / parseWasmViolation

Function parseWasmViolation

pkg/policies/engine/wasm/engine.go:257–274  ·  view source on GitHub ↗

parseWasmViolation parses a single violation from WASM output. Accepts both strings (legacy) and objects (deprecated, use findings instead).

(policyName string, raw json.RawMessage)

Source from the content-addressed store, hash-verified

255// parseWasmViolation parses a single violation from WASM output.
256// Accepts both strings (legacy) and objects (deprecated, use findings instead).
257func 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

Callers 1

VerifyMethod · 0.85

Calls 1

NewStructuredViolationFunction · 0.92

Tested by

no test coverage detected