cmd/inspect: Add namespace for data file at root

Earlier we used an empty namespace for data file located
at bundle root. This change now uses "data" as the
namespace for a data file at root.

Fixes: #4022

Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
This commit is contained in:
Ashutosh Narkar
2021-11-22 15:30:21 -08:00
parent 95c25b4b4e
commit ec62838bb2
3 changed files with 6 additions and 6 deletions
+2 -2
View File
@@ -51,7 +51,7 @@ func TestDoInspect(t *testing.T) {
res := `{
"manifest": {"revision": "rev", "roots": ["foo", "bar", "fuz", "baz", "a", "x"]},
"signatures_config": {},
"namespaces": {"": ["/data.json"], "data.foo": ["/example/foo.rego"]}
"namespaces": {"data": ["/data.json"], "data.foo": ["/example/foo.rego"]}
}`
exp := util.MustUnmarshalJSON([]byte(res))
@@ -131,7 +131,7 @@ NAMESPACES:
+-----------------------------+----------------------------------------------------+
| NAMESPACE | FILE |
+-----------------------------+----------------------------------------------------+
| | /data.json |
| data | /data.json |
| data.a.b.y | /a/b/y/foo.rego |
| | /a/...xxxxxxxxxxxxxx/yyyyyyyyyyyyyyyyyyyy/foo.rego |
| data.foo | /example/foo.rego |
+1 -1
View File
@@ -126,7 +126,7 @@ func (bi *Info) getBundleDataWasmAndSignatures(name string) error {
path := fmt.Sprintf("%v.%v", ast.DefaultRootDocument, strings.Join(key, "."))
bi.Namespaces[path] = append(bi.Namespaces[path], value)
} else {
bi.Namespaces[""] = append(bi.Namespaces[""], value) // data file at bundle root
bi.Namespaces[ast.DefaultRootDocument.String()] = append(bi.Namespaces[ast.DefaultRootDocument.String()], value) // data file at bundle root
}
}
+3 -3
View File
@@ -48,7 +48,7 @@ func TestGenerateBundleInfoWithFileDir(t *testing.T) {
}
expectedNamespaces := map[string][]string{
"": {filepath.Join(rootDir, "data.json")},
"data": {filepath.Join(rootDir, "data.json")},
"data.bar": {filepath.Join(rootDir, "base.rego")},
"data.foo": {filepath.Join(rootDir, "baz/authz.rego"), filepath.Join(rootDir, "foo/policy.rego")},
"data.fuz": {filepath.Join(rootDir, "fuz/fuz.rego"), filepath.Join(rootDir, "fuz/data.json")},
@@ -114,7 +114,7 @@ func TestGenerateBundleInfoWithFile(t *testing.T) {
}
expectedNamespaces := map[string][]string{
"": {"/data.json"},
"data": {"/data.json"},
"data.b.c": {"/policy.rego"},
}
@@ -181,7 +181,7 @@ func TestGenerateBundleInfoWithBundleTarGz(t *testing.T) {
expectedNamespaces := map[string][]string{
"data.example": {"/example/example.rego"},
"": {"/data.json"},
"data": {"/data.json"},
"data.a.b.c": {"/a/b/c/data.json"},
"data.a.b.d": {"/a/b/d/data.json"},
"data.a.b.y": {"/a/b/y/foo.rego", "/a/b/y/data.yaml"},