Skip to content

Commit

Permalink
Opa should be capable of accessing Rego policies from the following i…
Browse files Browse the repository at this point in the history
…nput sources:

Existing Inputs:
1. Absolute file paths (e.g., /a/b/c/example.rego)
2. Paths with URLs (e.g., file:///path/to/file.json)
3. Paths with drive letters and URLs (e.g., "C:file:///C:/a/b/c")

New Inputs:
1. Paths with drive letters (e.g., C:\a\b\c\example.rego)

This requirement ensures that Opa can handle a variety of input formats, including local file paths, remote URLs, and even mixed formats that include both drive letters and URLs.

open-policy-agent#6910
Signed-off-by: pckvcode <[email protected]>
  • Loading branch information
pckvcode committed Aug 21, 2024
1 parent 3a9a702 commit 02dc039
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 4 additions & 2 deletions loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,8 +572,10 @@ func SplitPrefix(path string) ([]string, string) {
return nil, path
}
parts := strings.SplitN(path, ":", 2)
if len(parts) == 2 && len(parts[0]) > 1 {
return strings.Split(parts[0], "."), parts[1]
if len(parts) == 2 && len(parts[0]) > 0 {
if strings.HasPrefix(parts[1], "file:///") || len(parts[0]) > 1 {
return strings.Split(parts[0], "."), parts[1]
}
}
return nil, path
}
Expand Down
5 changes: 5 additions & 0 deletions loader/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,11 @@ func TestSplitPrefix(t *testing.T) {
input: "c:/a/b/c",
wantPath: "c:/a/b/c",
},
{
input: "c:file:///c:/a/b/c",
wantParts: []string{"c"},
wantPath: "file:///c:/a/b/c",
},
}

for _, tc := range tests {
Expand Down

0 comments on commit 02dc039

Please sign in to comment.