vscode-opa
vscode-opa copied to clipboard
Allow for customizing input source
As-is it is just input.json
in the project root. It would be nice if we could provide arguments to a command or generate a task/run configuration that would allow for customized input file names/locations (or even just some adhoc string)
I think a practical solution would be some file naming convention, for example, if I'm evaluating mypolicy.rego
the extension can look for a file called input.mypolicy.json
or mypolicy.input.json
or whatever we decide.
WDYT? I can implement this if it sounds good solution.
I think a practical solution would be some file naming convention, for example, if I'm evaluating mypolicy.rego the extension can look for a file called input.mypolicy.json or mypolicy.input.json or whatever we decide.
That would probably work, although I like the relative input.json
approach in #30 better.
I think the main goal of this enhancement was to try and let someone customize the evaluation to take in any arbitrary path. I think while having some naming convention would work.. there will always be users and use-cases where it doesn't. I think, until we know it isn't possible, that having some ability to just specify a file path either in a custom run config or as part of the command somehow it would be a better long term solution.
Since this issue is still open, I'd like to add a different use case. We often have rego code and related data in a project but where there are are other things as well, like go or Typescript code, deployment files and scripts etc, so it's common to put all the rego and related files in a subfolder off the project root e.g. ${workspaceFolder}/rego
, and set this in the opa.roots
setting. This stops OPA from trying to parse every YAML or JSON file in the entire project. Also common is that there is a main entry point in the top level opa.root folder (e.g. main.rego
), with packages and libraries in subfolders.
The issue is that the plugin only looks for input.json
in the current folder (i.e. the open file) or in the project root, which is one level above where the main.rego file, and default input.json
is. This means that when you are editing a file in any of the other folders, e.g. in a library or package, you can't evaluate anything because there is no input.json
in that folder, nor is there one in the project root.
Could the input.json
search function also look in the opa.roots
folders if there isn't one in the current folder or in the project root? I realise we could just put it in the project root folder, but that would be kind of odd given that everything else OPA-related is in its own subfolder.
Some other alternatives:
- Search upwards through parent folders until an
input.json
is found (stopping at${workspaceFolder}
, obviously) - Have an additional optional setting that gives the path to
input.json