VerifyStatement verifies that the statement is compliant with the policies present in the schema
(ctx context.Context, statement *intoto.Statement)
| 571 | |
| 572 | // VerifyStatement verifies that the statement is compliant with the policies present in the schema |
| 573 | func (pv *PolicyVerifier) VerifyStatement(ctx context.Context, statement *intoto.Statement) ([]*v12.PolicyEvaluation, error) { |
| 574 | policies := pv.policies.GetAttestation() |
| 575 | |
| 576 | // Marshal statement once — it's read-only input shared across evaluations |
| 577 | statementJSON, err := protojson.Marshal(statement) |
| 578 | if err != nil { |
| 579 | return nil, NewPolicyError(err) |
| 580 | } |
| 581 | |
| 582 | results := make([]*v12.PolicyEvaluation, len(policies)) |
| 583 | g, gCtx := errgroup.WithContext(ctx) |
| 584 | g.SetLimit(pv.maxConcurrency) |
| 585 | |
| 586 | for i, policyAtt := range policies { |
| 587 | g.Go(func() error { |
| 588 | ev, err := pv.evaluatePolicyAttachment(gCtx, policyAtt, statementJSON, &evalOpts{kind: v1.CraftingSchema_Material_ATTESTATION}) |
| 589 | if err != nil { |
| 590 | return NewPolicyError(err) |
| 591 | } |
| 592 | results[i] = ev |
| 593 | return nil |
| 594 | }) |
| 595 | } |
| 596 | |
| 597 | if err := g.Wait(); err != nil { |
| 598 | return nil, err |
| 599 | } |
| 600 | |
| 601 | // Filter nil entries (skipped policies) |
| 602 | result := make([]*v12.PolicyEvaluation, 0, len(policies)) |
| 603 | for _, ev := range results { |
| 604 | if ev != nil { |
| 605 | result = append(result, ev) |
| 606 | } |
| 607 | } |
| 608 | |
| 609 | return result, nil |
| 610 | } |
| 611 | |
| 612 | func (pv *PolicyVerifier) executeScript(ctx context.Context, script *engine.Policy, material []byte, args map[string]string) (*engine.EvaluationResult, error) { |
| 613 | // Detect policy type |