| 159 | } |
| 160 | |
| 161 | func (p *PolicyToLint) processFile(filePath string) error { |
| 162 | ext := strings.ToLower(filepath.Ext(filePath)) |
| 163 | |
| 164 | // Read file content once |
| 165 | content, err := os.ReadFile(filePath) |
| 166 | if err != nil { |
| 167 | return err |
| 168 | } |
| 169 | |
| 170 | switch ext { |
| 171 | case ".wasm": |
| 172 | // Verify magic bytes |
| 173 | if engine.DetectPolicyType(content) != engine.PolicyTypeWASM { |
| 174 | return fmt.Errorf("file has .wasm extension but is not a valid WASM file") |
| 175 | } |
| 176 | p.WASMFiles = append(p.WASMFiles, &File{Path: filePath, Content: content}) |
| 177 | case ".yaml", ".yml": |
| 178 | p.YAMLFiles = append(p.YAMLFiles, &File{ |
| 179 | Path: filePath, |
| 180 | Content: content, |
| 181 | }) |
| 182 | case ".rego": |
| 183 | p.RegoFiles = append(p.RegoFiles, &File{ |
| 184 | Path: filePath, |
| 185 | Content: content, |
| 186 | }) |
| 187 | default: |
| 188 | return fmt.Errorf("unsupported file extension %s, must be .yaml/.yml, .rego, or .wasm", ext) |
| 189 | } |
| 190 | |
| 191 | return nil |
| 192 | } |
| 193 | |
| 194 | func (p *PolicyToLint) Validate() { |
| 195 | // Validate standalone rego files |