validateWasmFile validates a WASM policy file by checking that it exports the required Execute function
(file *File)
| 218 | |
| 219 | // validateWasmFile validates a WASM policy file by checking that it exports the required Execute function |
| 220 | func (p *PolicyToLint) validateWasmFile(file *File) { |
| 221 | ctx := context.Background() |
| 222 | |
| 223 | // Create Extism manifest |
| 224 | manifest := extism.Manifest{ |
| 225 | Wasm: []extism.Wasm{ |
| 226 | extism.WasmData{Data: file.Content}, |
| 227 | }, |
| 228 | } |
| 229 | |
| 230 | cfg := extism.PluginConfig{ |
| 231 | EnableWasi: true, |
| 232 | } |
| 233 | |
| 234 | // Create plugin |
| 235 | plugin, err := extism.NewPlugin(ctx, manifest, cfg, []extism.HostFunction{}) |
| 236 | if err != nil { |
| 237 | p.AddError(file.Path, fmt.Sprintf("failed to load WASM module: %v", err), 0) |
| 238 | return |
| 239 | } |
| 240 | defer plugin.Close(ctx) |
| 241 | |
| 242 | // Check if Execute function is exported |
| 243 | if !plugin.FunctionExists("Execute") { |
| 244 | p.AddError(file.Path, "WASM module missing required 'Execute' function export", 0) |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | func (p *PolicyToLint) validateAndFormatRego(content, path string) string { |
| 249 | // 1. Optionally format |