opa icon indicating copy to clipboard operation
opa copied to clipboard

Allow `opa inspect` to inspect a single file

Open anderseknert opened this issue 1 year ago • 0 comments

It's not often I get to use opa inspect, but when I do, it's often to help me understand how annotations have been processed in a file. However..

> opa inspect -a p.rego
error: bundle p.rego: bundle read failed: archive read failed: gzip: invalid header

In order to get the output I want, I have to do something like this:

> mkdir tmp
> cp p.rego tmp/
> opa inspect -a tmp
NAMESPACES:
+-------------+------------+
|  NAMESPACE  |    FILE    |
+-------------+------------+
| data.policy | tmp/p.rego |
+-------------+------------+
ANNOTATIONS:
allow
=====

Package:  policy
Rule:     allow
Location: tmp/p.rego:7
Scope: rule

Nothing in that output is specific to bundles, and there's no obvious connection between the bundle format and annotations. The documentaton section on annotations covering this also makes no mention of that requirement:

Annotations can be listed through the inspect command by using the -a flag: opa inspect -a

Having to copy the file into a directory that can be treated as a bundle is... not a great experience. Dropping the bundle requirement and allow inspecting single files as they are would be one solution. But even if we keep the bundle requirement, perhaps pointing opa inspect at a single file could just mean "as if it was the only file in a bundle directory". Basically doing what the user currently has to do for it to work.

anderseknert avatar Jun 06 '24 21:06 anderseknert