mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-12 19:32:48 -06:00
opa inspect: Fix path of data namespaces on windows (#5508)
Instead of a hard-coded "/", we're now using os.PathSeparator to process the file path. It's also cleaned before displaying. Fixes part of #5503. Signed-off-by: shm12 <shm.bia@gmail.com>
This commit is contained in:
@@ -3,6 +3,13 @@ set -eo pipefail
|
||||
OPA_EXEC="$1"
|
||||
TARGET="$2"
|
||||
|
||||
PATH_SEPARATOR="/"
|
||||
if [[ $OPA_EXEC == *".exe" ]]; then
|
||||
PATH_SEPARATOR="\\"
|
||||
fi
|
||||
|
||||
|
||||
|
||||
github_actions_group() {
|
||||
local args="$*"
|
||||
echo "::group::$args"
|
||||
@@ -42,3 +49,8 @@ echo '{"yay": "bar"}' | opa eval --format pretty --bundle o2.tar.gz -I data.test
|
||||
# Tar paths
|
||||
opa build --output o3.tar.gz test/cli/smoke
|
||||
github_actions_group assert_contains '/test/cli/smoke/test.rego' "$(tar -tf o3.tar.gz /test/cli/smoke/test.rego)"
|
||||
|
||||
# Data files - correct namespaces
|
||||
echo "::group:: Data files - correct namespaces"
|
||||
assert_contains "data.namesapce | test${PATH_SEPARATOR}cli${PATH_SEPARATOR}smoke${PATH_SEPARATOR}namesapce${PATH_SEPARATOR}data.json" "$(opa inspect test/cli/smoke)"
|
||||
echo "::endgroup::"
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
@@ -128,11 +129,11 @@ func (bi *Info) getBundleDataWasmAndSignatures(name string) error {
|
||||
|
||||
for _, f := range descriptors {
|
||||
path := filepath.Clean(f.Path())
|
||||
key := strings.Split(strings.TrimPrefix(path, "/"), "/")
|
||||
key := strings.Split(strings.TrimPrefix(path, string(os.PathSeparator)), string(os.PathSeparator))
|
||||
|
||||
value := path
|
||||
if bl.IsDir {
|
||||
value = f.URL()
|
||||
value = filepath.Clean(f.URL())
|
||||
}
|
||||
|
||||
if len(key) > 1 {
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"foo": "bar"
|
||||
}
|
||||
Reference in New Issue
Block a user