createFallbackValidationContext precomputes the fallback validation context once
(ctx context.Context, config *FallbackConfig)
| 108 | |
| 109 | // createFallbackValidationContext precomputes the fallback validation context once |
| 110 | func CreateFallbackValidationContext(ctx context.Context, config *FallbackConfig) (*FallbackValidationContext, error) { |
| 111 | log.Debugf("🔄 Precomputing fallback validation context...") |
| 112 | |
| 113 | // Get policy configuration (same as VSA command) |
| 114 | policyConfiguration, err := getPolicyConfig(ctx, config.PolicyConfig) |
| 115 | if err != nil { |
| 116 | return nil, fmt.Errorf("fallback validation: failed to get policy configuration: %w", err) |
| 117 | } |
| 118 | |
| 119 | log.Debugf("🔄 Fallback context: Policy configuration resolved to: %s", policyConfiguration) |
| 120 | |
| 121 | // Create policy options with fallback public key |
| 122 | policyOptions := policy.Options{ |
| 123 | IgnoreRekor: true, |
| 124 | EffectiveTime: config.EffectiveTime, |
| 125 | PolicyRef: policyConfiguration, |
| 126 | PublicKey: config.FallbackPublicKey, // Different public key for fallback |
| 127 | } |
| 128 | |
| 129 | log.Debugf("🔄 Fallback context: Policy options: %+v", policyOptions) |
| 130 | |
| 131 | // Process policy with fallback public key |
| 132 | fallbackPolicy, _, err := policy.PreProcessPolicy(ctx, policyOptions) |
| 133 | if err != nil { |
| 134 | return nil, fmt.Errorf("fallback validation: failed to process policy: %w", err) |
| 135 | } |
| 136 | |
| 137 | log.Debugf("🔄 Fallback context: Policy processed successfully") |
| 138 | log.Debugf("🔄 Fallback context: Policy spec sources count: %d", len(fallbackPolicy.Spec().Sources)) |
| 139 | |
| 140 | // Note: evaluators will be created per-worker for thread safety |
| 141 | log.Debugf("🔄 Fallback context: Evaluators will be created per-worker for thread safety") |
| 142 | |
| 143 | return &FallbackValidationContext{ |
| 144 | PolicyConfiguration: policyConfiguration, |
| 145 | FallbackPolicy: fallbackPolicy, |
| 146 | }, nil |
| 147 | } |
| 148 | |
| 149 | // createWorkerFallbackContext creates evaluators once per worker thread |
| 150 | // This ensures thread safety while reusing evaluators within the worker |
no test coverage detected