* Start of richer results from verification * Pull out VSA code from signing * Expose attestation signing fns * Add VSA test * Notes for policy result * Require separate policy for VSA creation * Load test signing key from tests * Return rich object from policy * Add result object schema and fix tests * Ensure example test runs * Remove data.yaml files from mock policies * Don't run example - TUF policy isn't compatible * Add attestation to manifests for all subjects * Ensure adding attestation doesn't touch statements * Don't export sign function * Remove attestations from VerificationResult * Change bool to Outcome enum in result * Use outputLayout directly * Make clearer that Outcome strings are for VSA * Return multiple SLSA levels from policy * Fix unmarshalling of policy-id (#39) * Rename function * Rename policy.VerificationResult -> policy.Result * Re-add test for canonical input --------- Co-authored-by: James Carnegie <james.carnegie@docker.com> Co-authored-by: James Carnegie <kipz@users.noreply.github.com>
31 lines
866 B
Go
31 lines
866 B
Go
package policy
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/docker/attest/pkg/oci"
|
|
)
|
|
|
|
type policyEvaluatorCtxKeyType struct{}
|
|
|
|
var PolicyEvaluatorCtxKey policyEvaluatorCtxKeyType
|
|
|
|
// sets PolicyEvaluator in context
|
|
func WithPolicyEvaluator(ctx context.Context, pe PolicyEvaluator) context.Context {
|
|
return context.WithValue(ctx, PolicyEvaluatorCtxKey, pe)
|
|
}
|
|
|
|
// gets PolicyEvaluator from context, defaults to Rego PolicyEvaluator if not set
|
|
func GetPolicyEvaluator(ctx context.Context) (PolicyEvaluator, error) {
|
|
t, ok := ctx.Value(PolicyEvaluatorCtxKey).(PolicyEvaluator)
|
|
if !ok {
|
|
return nil, fmt.Errorf("no policy evaluator client set on context (set one with policy.WithPolicyEvaluator)")
|
|
}
|
|
return t, nil
|
|
}
|
|
|
|
type PolicyEvaluator interface {
|
|
Evaluate(ctx context.Context, resolver oci.AttestationResolver, pctx *Policy, input *PolicyInput) (*Result, error)
|
|
}
|