From db75f9e237ddafb20ef6990eab75b8dea2d557f9 Mon Sep 17 00:00:00 2001 From: Punith C K Date: Tue, 3 Sep 2024 17:05:40 +0530 Subject: [PATCH] fix: Conftest encounters errors on Windows when loading file paths that include drive letters (e.g., `C:/path/to/data.yaml`). Even when using a file URL (e.g., `file:///C:/path/to/data.yaml`), we still face issues. With these code changes, Conftest can now successfully load files using a file URL (e.g., `file:///C:/path/to/data.yaml`). We opted for file URLs instead of paths with drive letters (e.g., `C:/path/to/data.yaml`) because OPA does not support file paths with drive letters. For more details, see [this issue comment](https://github.com/open-policy-agent/opa/pull/6922#issuecomment-2312969000). Resolves: https://github.com/open-policy-agent/conftest/issues/979 Signed-off-by: Punith C K --- policy/engine.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/policy/engine.go b/policy/engine.go index 2fcf16aabf..84b9500835 100644 --- a/policy/engine.go +++ b/policy/engine.go @@ -134,7 +134,9 @@ func LoadWithData(policyPaths []string, dataPaths []string, capabilities string, return nil, fmt.Errorf("filter data paths: %w", err) } - documents, err := loader.NewFileLoader().All(allDocumentPaths) + documents, err := loader.NewFileLoader().WithProcessAnnotation(true).Filtered(dataPaths, func(_ string, info os.FileInfo, _ int) bool { + return !info.IsDir() && !contains([]string{".yaml", ".yml", ".json"}, filepath.Ext(info.Name())) + }) if err != nil { return nil, fmt.Errorf("load documents: %w", err) }