ValidateScanConfig mirrors the migration-038 CHECK constraints so callers get a clean pre-query error rather than a raw constraint violation.
(c ScanConfig)
| 49 | // ValidateScanConfig mirrors the migration-038 CHECK constraints so callers get a |
| 50 | // clean pre-query error rather than a raw constraint violation. |
| 51 | func ValidateScanConfig(c ScanConfig) error { |
| 52 | if !validScanAction(c.InboundPolicyAction) { |
| 53 | return fmt.Errorf("inbound_policy_action must be flag, review, or block") |
| 54 | } |
| 55 | if !validScanAction(c.OutboundPolicyAction) { |
| 56 | return fmt.Errorf("outbound_policy_action must be flag, review, or block") |
| 57 | } |
| 58 | if !validOutboundPolicy(c.OutboundPolicy) { |
| 59 | return fmt.Errorf("outbound_policy must be open, allowlist, or domain") |
| 60 | } |
| 61 | if len(c.OutboundAllowlist) > maxInboundAllowlist { |
| 62 | return fmt.Errorf("outbound_allowlist has %d entries, max %d", len(c.OutboundAllowlist), maxInboundAllowlist) |
| 63 | } |
| 64 | if !validScanToggle(c.InboundScan) { |
| 65 | return fmt.Errorf("inbound_scan must be off or on") |
| 66 | } |
| 67 | if !validScanToggle(c.OutboundScan) { |
| 68 | return fmt.Errorf("outbound_scan must be off or on") |
| 69 | } |
| 70 | if err := validThresholds("inbound", c.InboundScanReviewThreshold, c.InboundScanBlockThreshold); err != nil { |
| 71 | return err |
| 72 | } |
| 73 | if err := validThresholds("outbound", c.OutboundScanReviewThreshold, c.OutboundScanBlockThreshold); err != nil { |
| 74 | return err |
| 75 | } |
| 76 | return nil |
| 77 | } |
| 78 | |
| 79 | func validThresholds(dir string, review, block float64) error { |
| 80 | if review < 0 || review > 1 || block < 0 || block > 1 { |