iop/packages/go/policy/engine.go

25 lines
803 B
Go

package policy
import "context"
// Spec is a policy specification map passed in ExecutionSpec.Policy.
type Spec map[string]any
// Engine applies and validates policies on execution specs.
type Engine interface {
// Apply enriches or modifies spec fields based on policy rules.
Apply(ctx context.Context, adapter, target string, policy Spec) (Spec, error)
// Validate returns an error if the policy rejects the request.
Validate(ctx context.Context, adapter, target string, policy Spec) error
}
// Passthrough is a no-op policy engine used when no policy is configured.
type Passthrough struct{}
func (Passthrough) Apply(_ context.Context, _, _ string, policy Spec) (Spec, error) {
return policy, nil
}
func (Passthrough) Validate(_ context.Context, _, _ string, _ Spec) error {
return nil
}