Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for customizing input source #28

Open
patrick-east opened this issue Mar 10, 2020 · 3 comments
Open

Allow for customizing input source #28

patrick-east opened this issue Mar 10, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@patrick-east
Copy link
Contributor

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)

@itaysk
Copy link
Contributor

itaysk commented May 24, 2020

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.

@patrick-east
Copy link
Contributor Author

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.

@patrick-east patrick-east added the enhancement New feature or request label May 26, 2020
@teq0
Copy link

teq0 commented May 14, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants