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

Function NewStructuredViolation

pkg/policies/engine/engine.go:197–213  ·  view source on GitHub ↗

NewStructuredViolation creates a PolicyViolation from a structured (map) violation object. The object must contain a "message" string field. The full object is preserved in RawFinding for downstream validation.

(policyName string, obj map[string]any)

Source from the content-addressed store, hash-verified

195// violation object. The object must contain a "message" string field.
196// The full object is preserved in RawFinding for downstream validation.
197func NewStructuredViolation(policyName string, obj map[string]any) (*PolicyViolation, error) {
198 msg, ok := obj["message"]
199 if !ok {
200 return nil, fmt.Errorf("missing required \"message\" field in structured violation")
201 }
202
203 msgStr, ok := msg.(string)
204 if !ok {
205 return nil, fmt.Errorf("\"message\" field must be a string, got %T", msg)
206 }
207
208 return &PolicyViolation{
209 Subject: policyName,
210 Violation: msgStr,
211 RawFinding: obj,
212 }, nil
213}
214
215type ResultFormatError struct {
216 Field string

Callers 3

parseWasmFindingFunction · 0.92
parseWasmViolationFunction · 0.92
parseResultRuleFunction · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected