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:
shm12
2023-01-03 10:53:14 +02:00
committed by GitHub
parent 9664d4a151
commit 0e398fdcd7
3 changed files with 18 additions and 2 deletions
+12
View File
@@ -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::"
+3 -2
View File
@@ -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 {
+3
View File
@@ -0,0 +1,3 @@
{
"foo": "bar"
}